Skip to content

Commit

Permalink
sched: Simplify wake_up_*idle*()
Browse files Browse the repository at this point in the history
Simplify and make wake_up_if_idle() more robust, also don't iterate
the whole machine with preempt_disable() in it's caller:
wake_up_all_idle_cpus().

This prepares for another wake_up_if_idle() user that needs a full
do_idle() cycle.

Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Acked-by: Vasily Gorbik <[email protected]>
Tested-by: Vasily Gorbik <[email protected]> # on s390
Link: https://lkml.kernel.org/r/[email protected]
  • Loading branch information
Peter Zijlstra committed Oct 7, 2021
1 parent 00619f7 commit 8850cb6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
14 changes: 5 additions & 9 deletions kernel/sched/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -3695,15 +3695,11 @@ void wake_up_if_idle(int cpu)
if (!is_idle_task(rcu_dereference(rq->curr)))
goto out;

if (set_nr_if_polling(rq->idle)) {
trace_sched_wake_idle_without_ipi(cpu);
} else {
rq_lock_irqsave(rq, &rf);
if (is_idle_task(rq->curr))
smp_send_reschedule(cpu);
/* Else CPU is not idle, do nothing here: */
rq_unlock_irqrestore(rq, &rf);
}
rq_lock_irqsave(rq, &rf);
if (is_idle_task(rq->curr))
resched_curr(rq);
/* Else CPU is not idle, do nothing here: */
rq_unlock_irqrestore(rq, &rf);

out:
rcu_read_unlock();
Expand Down
6 changes: 3 additions & 3 deletions kernel/smp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1170,14 +1170,14 @@ void wake_up_all_idle_cpus(void)
{
int cpu;

preempt_disable();
cpus_read_lock();
for_each_online_cpu(cpu) {
if (cpu == smp_processor_id())
if (cpu == raw_smp_processor_id())
continue;

wake_up_if_idle(cpu);
}
preempt_enable();
cpus_read_unlock();
}
EXPORT_SYMBOL_GPL(wake_up_all_idle_cpus);

Expand Down

0 comments on commit 8850cb6

Please sign in to comment.