Commit 5c891f38 authored by Thomas Gleixner's avatar Thomas Gleixner Committed by Arnaldo Carvalho de Melo

perf session: Allocate chunks of sample objects

The ordered sample code allocates singular reference objects struct
sample_queue which have 48byte size on 64bit and 20 bytes on 32bit. That's
silly. Allocate ~64k sized chunks and hand them out.

Performance gain: ~ 15%

Cc: Ingo Molnar <mingo@elte.hu>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <20101130163820.398713983@linutronix.de>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 020bb75a
...@@ -114,6 +114,7 @@ struct perf_session *perf_session__new(const char *filename, int mode, bool forc ...@@ -114,6 +114,7 @@ struct perf_session *perf_session__new(const char *filename, int mode, bool forc
self->repipe = repipe; self->repipe = repipe;
INIT_LIST_HEAD(&self->ordered_samples.samples); INIT_LIST_HEAD(&self->ordered_samples.samples);
INIT_LIST_HEAD(&self->ordered_samples.sample_cache); INIT_LIST_HEAD(&self->ordered_samples.sample_cache);
INIT_LIST_HEAD(&self->ordered_samples.to_free);
machine__init(&self->host_machine, "", HOST_KERNEL_ID); machine__init(&self->host_machine, "", HOST_KERNEL_ID);
if (mode == O_RDONLY) { if (mode == O_RDONLY) {
...@@ -403,10 +404,10 @@ static void perf_session_free_sample_buffers(struct perf_session *session) ...@@ -403,10 +404,10 @@ static void perf_session_free_sample_buffers(struct perf_session *session)
{ {
struct ordered_samples *os = &session->ordered_samples; struct ordered_samples *os = &session->ordered_samples;
while (!list_empty(&os->sample_cache)) { while (!list_empty(&os->to_free)) {
struct sample_queue *sq; struct sample_queue *sq;
sq = list_entry(os->sample_cache.next, struct sample_queue, list); sq = list_entry(os->to_free.next, struct sample_queue, list);
list_del(&sq->list); list_del(&sq->list);
free(sq); free(sq);
} }
...@@ -538,10 +539,13 @@ static void __queue_sample_event(struct sample_queue *new, ...@@ -538,10 +539,13 @@ static void __queue_sample_event(struct sample_queue *new,
} }
} }
#define MAX_SAMPLE_BUFFER (64 * 1024 / sizeof(struct sample_queue))
static int queue_sample_event(event_t *event, struct sample_data *data, static int queue_sample_event(event_t *event, struct sample_data *data,
struct perf_session *s) struct perf_session *s)
{ {
struct list_head *sc = &s->ordered_samples.sample_cache; struct ordered_samples *os = &s->ordered_samples;
struct list_head *sc = &os->sample_cache;
u64 timestamp = data->time; u64 timestamp = data->time;
struct sample_queue *new; struct sample_queue *new;
...@@ -553,10 +557,17 @@ static int queue_sample_event(event_t *event, struct sample_data *data, ...@@ -553,10 +557,17 @@ static int queue_sample_event(event_t *event, struct sample_data *data,
if (!list_empty(sc)) { if (!list_empty(sc)) {
new = list_entry(sc->next, struct sample_queue, list); new = list_entry(sc->next, struct sample_queue, list);
list_del(&new->list); list_del(&new->list);
} else if (os->sample_buffer) {
new = os->sample_buffer + os->sample_buffer_idx;
if (++os->sample_buffer_idx == MAX_SAMPLE_BUFFER)
os->sample_buffer = NULL;
} else { } else {
new = malloc(sizeof(*new)); os->sample_buffer = malloc(MAX_SAMPLE_BUFFER * sizeof(*new));
if (!new) if (!os->sample_buffer)
return -ENOMEM; return -ENOMEM;
list_add(&os->sample_buffer->list, &os->to_free);
os->sample_buffer_idx = 2;
new = os->sample_buffer + 1;
} }
new->timestamp = timestamp; new->timestamp = timestamp;
......
...@@ -19,7 +19,10 @@ struct ordered_samples { ...@@ -19,7 +19,10 @@ struct ordered_samples {
u64 max_timestamp; u64 max_timestamp;
struct list_head samples; struct list_head samples;
struct list_head sample_cache; struct list_head sample_cache;
struct list_head to_free;
struct sample_queue *sample_buffer;
struct sample_queue *last_sample; struct sample_queue *last_sample;
int sample_buffer_idx;
}; };
struct perf_session { struct perf_session {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment