[PATCH 03/21] perf_events: Add a helper to search for an event in a context

Borislav Petkov
2010-07-01T15:54:07Z

This is a straignt-forward helper to look for, e.g. already allocated
and enabled events (think persistent events here).

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
kernel/perf_event.c | 21 +++++++++++++++++++++
1 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/kernel/perf_event.c b/kernel/perf_event.c
index 40478af..168764b 100644
--- a/kernel/perf_event.c
+++ b/kernel/perf_event.c
@@ -307,6 +307,27 @@ list_add_event(struct perf_event *event, struct perf_event_context *ctx)
ctx->nr_stat++;
}

+/*
+ * Find an event in a context.
+ * Must be called with ctx->mutex and ctx->lock held.
+ */
+static struct perf_event *find_event_in_context(struct perf_event_attr *attr,
+ struct perf_event_context *ctx)
+{
+ struct perf_event *event;
+
+ rcu_read_lock();
+ list_for_each_entry_rcu(event, &ctx->event_list, event_entry) {
+ if (event->attr.config == attr->config) {
+ rcu_read_unlock();
+ return event;
+ }
+ }
+ rcu_read_unlock();
+
+ return NULL;
+}
+
static void perf_group_attach(struct perf_event *event)
{
struct perf_event *group_leader = event->group_leader;
--
1.7.1