Re: [PATCH,RFC] perf: panic due to inclied cpu context task_ctxvalue

From: Peter Zijlstra
Date: Sat Mar 26 2011 - 12:36:23 EST


On Sat, 2011-03-26 at 17:13 +0100, Oleg Nesterov wrote:
>
> I don't think this is right.
>
> It is too late to clear ->task_ctx when the task exits. It is simply
> wrong that cpuctx->task_ctx != NULL after context_switch(). And, once
> again ->is_active is still true.

Ah, indeed. Somehow I was thinking we did remove_from_context on
close(), I thought about adding it to list_del_event() because that's
the place we empty the context and I guess I should have done something
like that.

The problem with adding it to list_del_event() is that it isn't
necessarily called on the correct cpu.

/me ponders things for a bit ...

The alternative seems to be to put it in event_sched_out(), right where
we decrease ctx->nr_active. Again, I might have missed something quite
trivial.. let me try and get that test-case running someplace.


---
kernel/perf_event.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/kernel/perf_event.c b/kernel/perf_event.c
index c75925c..e9e4e35 100644
--- a/kernel/perf_event.c
+++ b/kernel/perf_event.c
@@ -1073,6 +1073,8 @@ event_sched_out(struct perf_event *event,
if (!is_software_event(event))
cpuctx->active_oncpu--;
ctx->nr_active--;
+ if (!ctx->nr_active && cpuctx->task_ctx == ctx)
+ cpuctx->task_ctx = NULL;
if (event->attr.exclusive || !cpuctx->active_oncpu)
cpuctx->exclusive = 0;
}


--
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/