Re: [PATCH 4/5] perf_events: add cgroup support (v7)

From: Stephane Eranian
Date: Wed Jan 05 2011 - 16:39:11 EST


Peter,

On Wed, Jan 5, 2011 at 2:01 PM, Stephane Eranian <eranian@xxxxxxxxxx> wrote:
> On Wed, Jan 5, 2011 at 12:23 PM, Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
>> On Mon, 2011-01-03 at 18:20 +0200, Stephane Eranian wrote:
>>> +void
>>> +perf_cgroup_switch(struct task_struct *task, struct task_struct *next)
>>> +{
>>> + Â Â struct perf_cgroup *cgrp_out = perf_cgroup_from_task(task);
>>> + Â Â struct perf_cgroup *cgrp_in = perf_cgroup_from_task(next);
>>> + Â Â struct perf_cpu_context *cpuctx;
>>> + Â Â struct pmu *pmu;
>>> + Â Â /*
>>> + Â Â Â* if task is DEAD, then css_out is irrelevant, it has
>>> + Â Â Â* been changed to init_cgrp in cgroup_exit() from do_exit().
>>> + Â Â Â* Furthermore, perf_cgroup_exit_task(), has scheduled out
>>> + Â Â Â* all css constrained events, only unconstrained events
>>> + Â Â Â* remain. Therefore we need to reschedule based on css_in.
>>> + Â Â Â*/
>>> + Â Â if (task->state != TASK_DEAD && cgrp_out == cgrp_in)
>>> + Â Â Â Â Â Â return;
>>
>> I think that check is broken, TASK_DEAD is set way after calling
>> cgroup_exit(), so if we get preempted in between there you'll still go
>> funny.
>>

I looked at this part again.

The original code checking for TASK_DEAD is correct.

The reason is simple, you're looking at perf_cgroup_switch() which is
invoked as part of schedule() and NOT perf_event_task_exit() (called
prior to cgroup_exit()).
Thus, by the time you do the final schedule(), the task state has indeed
been switched to TASK_DEAD.

I remember testing for this condition during the debug phase.

I will resubmit with the other smaller cleanups.
--
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/