[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1408977943-16594-3-git-send-email-jolsa@kernel.org>
Date: Mon, 25 Aug 2014 16:45:36 +0200
From: Jiri Olsa <jolsa@...nel.org>
To: linux-kernel@...r.kernel.org
Cc: Jiri Olsa <jolsa@...nel.org>, Andi Kleen <andi@...stfloor.org>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Corey Ashford <cjashfor@...ux.vnet.ibm.com>,
David Ahern <dsahern@...il.com>,
Frederic Weisbecker <fweisbec@...il.com>,
Ingo Molnar <mingo@...nel.org>,
"Jen-Cheng(Tommy) Huang" <tommy24@...ech.edu>,
Namhyung Kim <namhyung@...nel.org>,
Paul Mackerras <paulus@...ba.org>,
Peter Zijlstra <a.p.zijlstra@...llo.nl>,
Stephane Eranian <eranian@...gle.com>
Subject: [PATCH 2/9] perf: Deny optimized switch for events read by PERF_SAMPLE_READ
The optimized task context switch for cloned perf events just
swaps whole perf event contexts (of current and next process)
if it finds them suitable. Events from the 'current' context
will now measure data of the 'next' context and vice versa.
This is ok for cases where we are not directly interested in
the event->count value of separate child events, like:
- standard sampling, where we take 'period' value for the
event count
- counting, where we accumulate all events (children)
into a single count value
But in case we read event by using the PERF_SAMPLE_READ sample
type, we are interested in direct event->count value measured
in specific task. Switching events within tasks for this kind
of measurements corrupts data.
Fixing this by setting/unsetting pin_count for perf event context
once cloned event with PERF_SAMPLE_READ read is added/removed.
The pin_count value != 0 makes the context not suitable for
optimized switch.
Cc: Andi Kleen <andi@...stfloor.org>
Cc: Arnaldo Carvalho de Melo <acme@...nel.org>
Cc: Corey Ashford <cjashfor@...ux.vnet.ibm.com>
Cc: David Ahern <dsahern@...il.com>
Cc: Frederic Weisbecker <fweisbec@...il.com>
Cc: Ingo Molnar <mingo@...nel.org>
Cc: Jen-Cheng(Tommy) Huang <tommy24@...ech.edu>
Cc: Namhyung Kim <namhyung@...nel.org>
Cc: Paul Mackerras <paulus@...ba.org>
Cc: Peter Zijlstra <a.p.zijlstra@...llo.nl>
Cc: Stephane Eranian <eranian@...gle.com>
Signed-off-by: Jiri Olsa <jolsa@...nel.org>
---
kernel/events/core.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 4ad4ba2bc106..ff6a17607ddb 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -1117,6 +1117,12 @@ ctx_group_list(struct perf_event *event, struct perf_event_context *ctx)
return &ctx->flexible_groups;
}
+static bool is_clone_with_read(struct perf_event *event)
+{
+ return event->parent &&
+ (event->attr.sample_type & PERF_SAMPLE_READ);
+}
+
/*
* Add a event from the lists for its context.
* Must be called with ctx->mutex and ctx->lock held.
@@ -1148,6 +1154,9 @@ list_add_event(struct perf_event *event, struct perf_event_context *ctx)
if (has_branch_stack(event))
ctx->nr_branch_stack++;
+ if (is_clone_with_read(event))
+ ctx->pin_count++;
+
list_add_rcu(&event->event_entry, &ctx->event_list);
if (!ctx->nr_events)
perf_pmu_rotate_start(ctx->pmu);
@@ -1313,6 +1322,9 @@ list_del_event(struct perf_event *event, struct perf_event_context *ctx)
if (has_branch_stack(event))
ctx->nr_branch_stack--;
+ if (is_clone_with_read(event))
+ ctx->pin_count--;
+
ctx->nr_events--;
if (event->attr.inherit_stat)
ctx->nr_stat--;
--
1.8.3.1
--
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