Skip to content

Commit bf89a30

Browse files
Cheng Chaoingomolnar
authored andcommitted
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>
1 parent 0b84735 commit bf89a30

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

‎kernel/sched/core.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,8 +1063,12 @@ static int migration_cpu_stop(void *data)
10631063
* holding rq->lock, if p->on_rq == 0 it cannot get enqueued because
10641064
* we're holding p->pi_lock.
10651065
*/
1066-
if (task_rq(p) == rq && task_on_rq_queued(p))
1067-
rq = __migrate_task(rq, p, arg->dest_cpu);
1066+
if (task_rq(p) == rq) {
1067+
if (task_on_rq_queued(p))
1068+
rq = __migrate_task(rq, p, arg->dest_cpu);
1069+
else
1070+
p->wake_cpu = arg->dest_cpu;
1071+
}
10681072
raw_spin_unlock(&rq->lock);
10691073
raw_spin_unlock(&p->pi_lock);
10701074

‎kernel/stop_machine.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ int stop_one_cpu(unsigned int cpu, cpu_stop_fn_t fn, void *arg)
126126
cpu_stop_init_done(&done, 1);
127127
if (!cpu_stop_queue_work(cpu, &work))
128128
return -ENOENT;
129+
/*
130+
* In case @cpu == smp_proccessor_id() we can avoid a sleep+wakeup
131+
* cycle by doing a preemption:
132+
*/
133+
cond_resched();
129134
wait_for_completion(&done.completion);
130135
return done.ret;
131136
}

0 commit comments

Comments
 (0)