Commit 020bb75a authored by Thomas Gleixner's avatar Thomas Gleixner Committed by Arnaldo Carvalho de Melo

perf session: Cache sample objects

When the sample queue is flushed we free the sample reference objects. Though
we need to malloc new objects when we process further. Stop the malloc/free
orgy and cache the already allocated object for resuage. Only allocate when
the cache is empty.

Performance gain: ~ 10%

Cc: Ingo Molnar <mingo@elte.hu>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <20101130163820.338488630@linutronix.de>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent fe174207
...@@ -113,6 +113,7 @@ struct perf_session *perf_session__new(const char *filename, int mode, bool forc ...@@ -113,6 +113,7 @@ struct perf_session *perf_session__new(const char *filename, int mode, bool forc
self->machines = RB_ROOT; self->machines = RB_ROOT;
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);
machine__init(&self->host_machine, "", HOST_KERNEL_ID); machine__init(&self->host_machine, "", HOST_KERNEL_ID);
if (mode == O_RDONLY) { if (mode == O_RDONLY) {
...@@ -398,6 +399,19 @@ struct sample_queue { ...@@ -398,6 +399,19 @@ struct sample_queue {
struct list_head list; struct list_head list;
}; };
static void perf_session_free_sample_buffers(struct perf_session *session)
{
struct ordered_samples *os = &session->ordered_samples;
while (!list_empty(&os->sample_cache)) {
struct sample_queue *sq;
sq = list_entry(os->sample_cache.next, struct sample_queue, list);
list_del(&sq->list);
free(sq);
}
}
static void flush_sample_queue(struct perf_session *s, static void flush_sample_queue(struct perf_session *s,
struct perf_event_ops *ops) struct perf_event_ops *ops)
{ {
...@@ -418,7 +432,7 @@ static void flush_sample_queue(struct perf_session *s, ...@@ -418,7 +432,7 @@ static void flush_sample_queue(struct perf_session *s,
os->last_flush = iter->timestamp; os->last_flush = iter->timestamp;
list_del(&iter->list); list_del(&iter->list);
free(iter); list_add(&iter->list, &os->sample_cache);
} }
if (list_empty(head)) { if (list_empty(head)) {
...@@ -527,6 +541,7 @@ static void __queue_sample_event(struct sample_queue *new, ...@@ -527,6 +541,7 @@ static void __queue_sample_event(struct sample_queue *new,
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;
u64 timestamp = data->time; u64 timestamp = data->time;
struct sample_queue *new; struct sample_queue *new;
...@@ -535,9 +550,14 @@ static int queue_sample_event(event_t *event, struct sample_data *data, ...@@ -535,9 +550,14 @@ static int queue_sample_event(event_t *event, struct sample_data *data,
return -EINVAL; return -EINVAL;
} }
if (!list_empty(sc)) {
new = list_entry(sc->next, struct sample_queue, list);
list_del(&new->list);
} else {
new = malloc(sizeof(*new)); new = malloc(sizeof(*new));
if (!new) if (!new)
return -ENOMEM; return -ENOMEM;
}
new->timestamp = timestamp; new->timestamp = timestamp;
new->event = event; new->event = event;
...@@ -730,6 +750,7 @@ static int __perf_session__process_pipe_events(struct perf_session *self, ...@@ -730,6 +750,7 @@ static int __perf_session__process_pipe_events(struct perf_session *self,
done: done:
err = 0; err = 0;
out_err: out_err:
perf_session_free_sample_buffers(self);
return err; return err;
} }
...@@ -862,6 +883,7 @@ int __perf_session__process_events(struct perf_session *session, ...@@ -862,6 +883,7 @@ int __perf_session__process_events(struct perf_session *session,
session->hists.stats.nr_unknown_events); session->hists.stats.nr_unknown_events);
} }
perf_session_free_sample_buffers(session);
return err; return err;
} }
......
...@@ -18,6 +18,7 @@ struct ordered_samples { ...@@ -18,6 +18,7 @@ struct ordered_samples {
u64 next_flush; u64 next_flush;
u64 max_timestamp; u64 max_timestamp;
struct list_head samples; struct list_head samples;
struct list_head sample_cache;
struct sample_queue *last_sample; struct sample_queue *last_sample;
}; };
......
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