On Fri, Feb 20, 2015 at 09:34:28PM +0300, Sergei Shtylyov wrote:
Hello.
On 02/20/2015 09:12 PM, Fabian Frederick wrote:
quoted
Use helper functions to access current->state.
Direct assignments are prone to races and therefore buggy.
quoted
current->state = TASK_RUNNING is replaced by __set_current_state()
You sometimes use __set_current_state() and sometimes set_current_state().
It depends on which state; setting yourself TASK_RUNNING is free of
wakeup races -- you're already running after all, so it can safely use
__set_current_state().
Setting a blocking state otoh needs set_current_state() which issues a
full memory barriers with the store (critically in this case,
effectively after the store) such that it orders the state store with a
subsequent load in the condition check if it really needs to go to
sleep.
In full:
current->state = TASK_UNINTERRUPTIBLE; wait = false;
smp_mb(); smp_wmb();
if (wait) p->state = TASK_RUNNING;
schedule();
Without that smp_mb(); the following order is possible:
if (wait)
wait = false;
smp_wmb();
p->state = TASK_RUNNING;
current->state = TASK_UNINTERRUPTIBLE;
schedule();
And we'll wait forever more..