[PATCH v4 06/16] perf, core: always switch pmu specific data during context switch

From: Yan, Zheng
Date: Mon Mar 17 2014 - 02:03:40 EST


If two tasks were both forked from the same parent task, Events in
their perf task contexts can be the same. Perf core may leave out
switching the perf event contexts.

Previous patch inroduces pmu specific data. The data is for saving
the LBR stack, it is task specific. So we need to switch the data
even when context switch is optimized out.

Signed-off-by: Yan, Zheng <zheng.z.yan@xxxxxxxxx>
---
kernel/events/core.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index f262c57..20da73c 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -2336,6 +2336,7 @@ static void perf_event_context_sched_out(struct task_struct *task, int ctxn,
raw_spin_lock(&ctx->lock);
raw_spin_lock_nested(&next_ctx->lock, SINGLE_DEPTH_NESTING);
if (context_equiv(ctx, next_ctx)) {
+ void *ctx_data;
/*
* XXX do we need a memory barrier of sorts
* wrt to rcu_dereference() of perf_event_ctxp
@@ -2344,6 +2345,11 @@ static void perf_event_context_sched_out(struct task_struct *task, int ctxn,
next->perf_event_ctxp[ctxn] = ctx;
ctx->task = next;
next_ctx->task = task;
+
+ ctx_data = next_ctx->task_ctx_data;
+ next_ctx->task_ctx_data = ctx->task_ctx_data;
+ ctx->task_ctx_data = ctx_data;
+
do_switch = 0;

perf_event_sync_stat(ctx, next_ctx);
--
1.8.5.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/