We're going to want to drop rq->lock in try_to_wake_up() for a
longer period of time, however we also want to deal with concurrent
waking of the same task, which is currently handled by holding
rq->lock.
So introduce a new TASK state, namely TASK_WAKING, which indicates
someone is already waking the task (other wakers will fail p->state
& state).
We also keep preemption disabled over the whole ttwu().
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <new-submission>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
/* in tsk->state again */
#define TASK_DEAD 64
#define TASK_WAKEKILL 128
/* in tsk->state again */
#define TASK_DEAD 64
#define TASK_WAKEKILL 128
/* Convenience macros for the sake of set_task_state */
#define TASK_KILLABLE (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE)
/* Convenience macros for the sake of set_task_state */
#define TASK_KILLABLE (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE)
{
int cpu, orig_cpu, this_cpu, success = 0;
unsigned long flags;
{
int cpu, orig_cpu, this_cpu, success = 0;
unsigned long flags;
struct rq *rq;
if (!sched_feat(SYNC_WAKEUPS))
struct rq *rq;
if (!sched_feat(SYNC_WAKEUPS))
+ this_cpu = get_cpu();
+
smp_wmb();
rq = task_rq_lock(p, &flags);
update_rq_clock(rq);
smp_wmb();
rq = task_rq_lock(p, &flags);
update_rq_clock(rq);
- old_state = p->state;
- if (!(old_state & state))
+ if (!(p->state & state))
goto out;
if (p->se.on_rq)
goto out;
if (p->se.on_rq)
cpu = task_cpu(p);
orig_cpu = cpu;
cpu = task_cpu(p);
orig_cpu = cpu;
- this_cpu = smp_processor_id();
#ifdef CONFIG_SMP
if (unlikely(task_running(rq, p)))
goto out_activate;
#ifdef CONFIG_SMP
if (unlikely(task_running(rq, p)))
goto out_activate;
+ /*
+ * In order to handle concurrent wakeups and release the rq->lock
+ * we put the task in TASK_WAKING state.
+ */
+ p->state = TASK_WAKING;
+ task_rq_unlock(rq, &flags);
+
cpu = p->sched_class->select_task_rq(p, SD_BALANCE_WAKE, sync);
cpu = p->sched_class->select_task_rq(p, SD_BALANCE_WAKE, sync);
- task_rq_unlock(rq, &flags);
- /* might preempt at this point */
- rq = task_rq_lock(p, &flags);
- old_state = p->state;
- if (!(old_state & state))
- goto out;
- if (p->se.on_rq)
- goto out_running;
- this_cpu = smp_processor_id();
- cpu = task_cpu(p);
- }
+ rq = task_rq_lock(p, &flags);
+ WARN_ON(p->state != TASK_WAKING);
+ cpu = task_cpu(p);
#ifdef CONFIG_SCHEDSTATS
schedstat_inc(rq, ttwu_count);
#ifdef CONFIG_SCHEDSTATS
schedstat_inc(rq, ttwu_count);
#endif
out:
task_rq_unlock(rq, &flags);
#endif
out:
task_rq_unlock(rq, &flags);