Re: [PATCH] sched: Add logic to handle parallel try_to_wake_up() of the same task
From: Kirill Tkhai
Date: Mon Jul 15 2013 - 16:29:13 EST
16.07.2013, 00:19, "Peter Zijlstra" <peterz@xxxxxxxxxxxxx>:
> On Mon, Jul 15, 2013 at 06:14:34PM +0400, Kirill Tkhai wrote:
>
>>>> #ifdef CONFIG_SMP
>>>> + p->state = TASK_WAKING;
>>>> + smp_wmb();
>>>> +
>>> This too is broken; the loop below needs to be completed first,
>>> otherwise we change p->state while the task is still on the CPU and it
>>> might read the wrong p->state.
>> This place is below (on_rq && ttwu_remote) check, so the task
>> either 'dequeued and on_cpu == 0'
>> or it's in the middle of schedule() on arch, which wants unlocked
>> context switch.
>>
>> Nobody scheduler's probes p->state between prepare_lock_switch() and
>> finish_lock_switch(). Archs with unlocked ctx switch (mips and ia64)
>> don't change or probe state of previous process during context_switch.
>
> It means its after deactivate_task(), but before context_switch(). It so
> happens that
> context_switch()->prepare_task_switch()->trace_sched_switch() inspects
> p->state.
>
> Even if this was not the case, touching a task that is 'life' on another
> CPU is very _very_ bad practise.
Thanks for the explanation.
Kirill
--
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/