Re: [RFC][PATCH 5/9] perf: Simplify and fix__perf_install_in_context

From: Peter Zijlstra
Date: Sun Apr 10 2011 - 04:13:43 EST


On Sat, 2011-04-09 at 21:17 +0200, Peter Zijlstra wrote:
> + if (task_ctx) {
> + task_ctx_sched_out(task_ctx);
> + /*
> + * If the context we're installing events in is not the
> + * active task_ctx, flip them.
> + */
> + if (ctx->task && task_ctx != ctx) {
> + raw_spin_unlock(&cpuctx->ctx.lock);
> + raw_spin_lock(&ctx->lock);
> + cpuctx->task_ctx = task_ctx = ctx;
> + }
> + task = task_ctx->task;
> + }

That is actually buggy, it should read something like:

if (task_ctx)
task_ctx_sched_out(task_ctx);

if (ctx->task && task_ctx != ctx) {
raw_spin_unlock(&task_ctx->lock);
raw_spin_lock(&ctx->lock);
cpuctx->task_ctx = task_ctx = ctx;
}

if (task_ctx)
task = task_ctx->task;

Aside from the trivial locking bug fixed, the previous version wouldn't
actually deal with installing a task_ctx where there was none before.
--
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/