stop_machine: Avoid a sleep and wakeup in stop_one_cpu()
In case @cpu == smp_proccessor_id(), we can avoid a sleep+wakeup cycle by doing a preemption. Callers such as sched_exec() can benefit from this change. Signed-off-by: Cheng Chao <cs.os.kernel@gmail.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: akpm@linux-foundation.org Cc: chris@chris-wilson.co.uk Cc: tj@kernel.org Link: http://lkml.kernel.org/r/1473818510-6779-1-git-send-email-cs.os.kernel@gmail.com Signed-off-by: Ingo Molnar <mingo@kernel.org>hifive-unleashed-5.1
parent
0b8473570c
commit
bf89a30472
|
@ -1063,8 +1063,12 @@ static int migration_cpu_stop(void *data)
|
||||||
* holding rq->lock, if p->on_rq == 0 it cannot get enqueued because
|
* holding rq->lock, if p->on_rq == 0 it cannot get enqueued because
|
||||||
* we're holding p->pi_lock.
|
* we're holding p->pi_lock.
|
||||||
*/
|
*/
|
||||||
if (task_rq(p) == rq && task_on_rq_queued(p))
|
if (task_rq(p) == rq) {
|
||||||
rq = __migrate_task(rq, p, arg->dest_cpu);
|
if (task_on_rq_queued(p))
|
||||||
|
rq = __migrate_task(rq, p, arg->dest_cpu);
|
||||||
|
else
|
||||||
|
p->wake_cpu = arg->dest_cpu;
|
||||||
|
}
|
||||||
raw_spin_unlock(&rq->lock);
|
raw_spin_unlock(&rq->lock);
|
||||||
raw_spin_unlock(&p->pi_lock);
|
raw_spin_unlock(&p->pi_lock);
|
||||||
|
|
||||||
|
|
|
@ -126,6 +126,11 @@ int stop_one_cpu(unsigned int cpu, cpu_stop_fn_t fn, void *arg)
|
||||||
cpu_stop_init_done(&done, 1);
|
cpu_stop_init_done(&done, 1);
|
||||||
if (!cpu_stop_queue_work(cpu, &work))
|
if (!cpu_stop_queue_work(cpu, &work))
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
|
/*
|
||||||
|
* In case @cpu == smp_proccessor_id() we can avoid a sleep+wakeup
|
||||||
|
* cycle by doing a preemption:
|
||||||
|
*/
|
||||||
|
cond_resched();
|
||||||
wait_for_completion(&done.completion);
|
wait_for_completion(&done.completion);
|
||||||
return done.ret;
|
return done.ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue