[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1408538179-792-22-git-send-email-alexander.shishkin@linux.intel.com>
Date: Wed, 20 Aug 2014 15:36:18 +0300
From: Alexander Shishkin <alexander.shishkin@...ux.intel.com>
To: Peter Zijlstra <a.p.zijlstra@...llo.nl>
Cc: Ingo Molnar <mingo@...hat.com>, linux-kernel@...r.kernel.org,
Robert Richter <rric@...nel.org>,
Frederic Weisbecker <fweisbec@...il.com>,
Mike Galbraith <efault@....de>,
Paul Mackerras <paulus@...ba.org>,
Stephane Eranian <eranian@...gle.com>,
Andi Kleen <ak@...ux.intel.com>, kan.liang@...el.com,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>
Subject: [PATCH v4 21/22] perf: Allow AUX sampling for multiple events
Right now, only one perf event can be annotated with AUX data, however
it should be possible to annotate several events with similar configuration
(wrt exclude_{hv,idle,user,kernel}, config and other event attribute fields).
So every time, before a kernel counter is created for AUX sampling, we
first look for an existing counter that is suitable in terms of configuration
and we use it to annotate the new event as well.
Signed-off-by: Alexander Shishkin <alexander.shishkin@...ux.intel.com>
---
kernel/events/core.c | 93 +++++++++++++++++++++++++++++++++++++---------------
1 file changed, 66 insertions(+), 27 deletions(-)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 9d7f6086d5..73f6f5a5b7 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -4613,45 +4613,84 @@ static void perf_aux_sampler_destroy(struct perf_event *event)
ring_buffer_put(rb); /* can be last */
}
+static bool exclusive_event_match(struct perf_event *e1, struct perf_event *e2);
+
+static bool perf_aux_event_match(struct perf_event *e1, struct perf_event *e2)
+{
+ return has_aux(e1) && exclusive_event_match(e1, e2);
+}
+
static int perf_aux_sampler_init(struct perf_event *event,
struct task_struct *task,
struct pmu *pmu)
{
+ struct perf_event_context *ctx;
struct perf_event_attr attr;
- struct perf_event *sampler;
+ struct perf_event *sampler = NULL;
struct ring_buffer *rb;
- unsigned long nr_pages;
+ unsigned long nr_pages, flags;
if (!pmu || !(pmu->setup_aux))
return -ENOTSUPP;
- memset(&attr, 0, sizeof(attr));
- attr.type = pmu->type;
- attr.config = event->attr.aux_sample_config;
- attr.sample_type = 0;
- attr.disabled = event->attr.disabled;
- attr.enable_on_exec = event->attr.enable_on_exec;
- attr.exclude_hv = event->attr.exclude_hv;
- attr.exclude_idle = event->attr.exclude_idle;
- attr.exclude_user = event->attr.exclude_user;
- attr.exclude_kernel = event->attr.exclude_kernel;
- attr.aux_sample_size = event->attr.aux_sample_size;
-
- sampler = perf_event_create_kernel_counter(&attr, event->cpu, task,
- NULL, NULL);
- if (IS_ERR(sampler))
- return PTR_ERR(sampler);
-
- nr_pages = 1ul << __get_order(event->attr.aux_sample_size);
-
- rb = rb_alloc_kernel(sampler, 0, nr_pages);
- if (!rb) {
- perf_event_release_kernel(sampler);
- return -ENOMEM;
+ ctx = find_get_context(pmu, task, event->cpu);
+ if (ctx) {
+ raw_spin_lock_irqsave(&ctx->lock, flags);
+ list_for_each_entry(sampler, &ctx->event_list, event_entry) {
+ /*
+ * event is not an aux event, but all the relevant
+ * bits should match
+ */
+ if (perf_aux_event_match(sampler, event) &&
+ sampler->attr.type == event->attr.aux_sample_type &&
+ sampler->attr.config == event->attr.aux_sample_config &&
+ sampler->attr.exclude_hv == event->attr.exclude_hv &&
+ sampler->attr.exclude_idle == event->attr.exclude_idle &&
+ sampler->attr.exclude_user == event->attr.exclude_user &&
+ sampler->attr.exclude_kernel == event->attr.exclude_kernel &&
+ sampler->attr.aux_sample_size >= event->attr.aux_sample_size &&
+ atomic_long_inc_not_zero(&sampler->refcount))
+ goto got_event;
+ }
+
+ sampler = NULL;
+
+got_event:
+ --ctx->pin_count;
+ put_ctx(ctx);
+ raw_spin_unlock_irqrestore(&ctx->lock, flags);
+ }
+
+ if (!sampler) {
+ memset(&attr, 0, sizeof(attr));
+ attr.type = pmu->type;
+ attr.config = event->attr.aux_sample_config;
+ attr.sample_type = 0;
+ attr.disabled = event->attr.disabled;
+ attr.enable_on_exec = event->attr.enable_on_exec;
+ attr.exclude_hv = event->attr.exclude_hv;
+ attr.exclude_idle = event->attr.exclude_idle;
+ attr.exclude_user = event->attr.exclude_user;
+ attr.exclude_kernel = event->attr.exclude_kernel;
+ attr.aux_sample_size = event->attr.aux_sample_size;
+
+ sampler = perf_event_create_kernel_counter(&attr, event->cpu,
+ task, NULL, NULL);
+ if (IS_ERR(sampler))
+ return PTR_ERR(sampler);
+
+ nr_pages = 1ul << __get_order(event->attr.aux_sample_size);
+
+ rb = rb_alloc_kernel(sampler, 0, nr_pages);
+ if (!rb) {
+ perf_event_release_kernel(sampler);
+ return -ENOMEM;
+ }
+
+ sampler->destroy = perf_aux_sampler_destroy;
}
event->sampler = sampler;
- sampler->destroy = perf_aux_sampler_destroy;
return 0;
}
@@ -4664,7 +4703,7 @@ static void perf_aux_sampler_fini(struct perf_event *event)
if (!sampler)
return;
- perf_event_release_kernel(sampler);
+ put_event(sampler);
event->sampler = NULL;
}
--
2.1.0
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists