From: Arnaldo Carvalho de Melo <acme@infradead.org>
To: Ingo Molnar <mingo@elte.hu>
Cc: linux-kernel@vger.kernel.org,
Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@elte.hu>,
Peter Zijlstra <peterz@infradead.org>,
Frederic Weisbecker <fweisbec@gmail.com>,
Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 09/11] perf session: Cache sample objects
Date: Tue, 30 Nov 2010 18:10:54 -0200 [thread overview]
Message-ID: <1291147856-17459-10-git-send-email-acme@infradead.org> (raw)
In-Reply-To: <1291147856-17459-1-git-send-email-acme@infradead.org>
From: Thomas Gleixner <tglx@linutronix.de>
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: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/session.c | 30 ++++++++++++++++++++++++++----
tools/perf/util/session.h | 1 +
2 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index c989583..9fef587 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -113,6 +113,7 @@ struct perf_session *perf_session__new(const char *filename, int mode, bool forc
self->machines = RB_ROOT;
self->repipe = repipe;
INIT_LIST_HEAD(&self->ordered_samples.samples);
+ INIT_LIST_HEAD(&self->ordered_samples.sample_cache);
machine__init(&self->host_machine, "", HOST_KERNEL_ID);
if (mode == O_RDONLY) {
@@ -398,6 +399,19 @@ struct sample_queue {
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,
struct perf_event_ops *ops)
{
@@ -418,7 +432,7 @@ static void flush_sample_queue(struct perf_session *s,
os->last_flush = iter->timestamp;
list_del(&iter->list);
- free(iter);
+ list_add(&iter->list, &os->sample_cache);
}
if (list_empty(head)) {
@@ -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,
struct perf_session *s)
{
+ struct list_head *sc = &s->ordered_samples.sample_cache;
u64 timestamp = data->time;
struct sample_queue *new;
@@ -535,9 +550,14 @@ static int queue_sample_event(event_t *event, struct sample_data *data,
return -EINVAL;
}
- new = malloc(sizeof(*new));
- if (!new)
- return -ENOMEM;
+ if (!list_empty(sc)) {
+ new = list_entry(sc->next, struct sample_queue, list);
+ list_del(&new->list);
+ } else {
+ new = malloc(sizeof(*new));
+ if (!new)
+ return -ENOMEM;
+ }
new->timestamp = timestamp;
new->event = event;
@@ -730,6 +750,7 @@ more:
done:
err = 0;
out_err:
+ perf_session_free_sample_buffers(self);
return err;
}
@@ -862,6 +883,7 @@ out_err:
session->hists.stats.nr_unknown_events);
}
+ perf_session_free_sample_buffers(session);
return err;
}
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index a00f32e..e4a7ff2 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -18,6 +18,7 @@ struct ordered_samples {
u64 next_flush;
u64 max_timestamp;
struct list_head samples;
+ struct list_head sample_cache;
struct sample_queue *last_sample;
};
--
1.6.2.5
next prev parent reply other threads:[~2010-11-30 20:11 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-30 20:10 [GIT PULL 00/11] perf/core performance improvements Arnaldo Carvalho de Melo
2010-11-30 20:10 ` [PATCH 01/11] perf events: Precalculate the header space for PERF_SAMPLE_ fields Arnaldo Carvalho de Melo
2010-11-30 20:10 ` [PATCH 02/11] perf session: Fix list sort algorithm Arnaldo Carvalho de Melo
2010-11-30 20:10 ` [PATCH 03/11] perf session: Use appropriate pointer type instead of silly typecasting Arnaldo Carvalho de Melo
2010-11-30 20:10 ` [PATCH 04/11] perf session: Cleanup __perf_session__process_events() Arnaldo Carvalho de Melo
2010-11-30 20:10 ` [PATCH 05/11] perf session: Move ui_progress_update in __perf_session__process_events() Arnaldo Carvalho de Melo
2010-11-30 20:10 ` [PATCH 06/11] perf session: Simplify termination checks Arnaldo Carvalho de Melo
2010-11-30 20:10 ` [PATCH 07/11] perf session: Use sensible mmap size Arnaldo Carvalho de Melo
2010-11-30 20:10 ` [PATCH 08/11] perf session: Keep file mmaped instead of malloc/memcpy Arnaldo Carvalho de Melo
2010-11-30 20:10 ` Arnaldo Carvalho de Melo [this message]
2010-11-30 20:10 ` [PATCH 10/11] perf session: Allocate chunks of sample objects Arnaldo Carvalho de Melo
2010-11-30 20:10 ` [PATCH 11/11] perf debug: Simplify trace_event Arnaldo Carvalho de Melo
2010-12-01 8:22 ` [GIT PULL 00/11] perf/core performance improvements Ingo Molnar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1291147856-17459-10-git-send-email-acme@infradead.org \
--to=acme@infradead.org \
--cc=acme@redhat.com \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®