Skip to content

Commit bf89a30

Browse files
Cheng ChaoIngo Molnar
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 <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Oleg Nesterov <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 0b84735 commit bf89a30

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

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)