Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sched: Simplify wake_up_*idle*()

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) <peterz@infradead.org>
Acked-by: Vasily Gorbik <gor@linux.ibm.com>
Tested-by: Vasily Gorbik <gor@linux.ibm.com> # on s390
Link: https://lkml.kernel.org/r/20210929152428.769328779@infradead.org

+8 -12
+5 -9
kernel/sched/core.c
··· 3695 3695 if (!is_idle_task(rcu_dereference(rq->curr))) 3696 3696 goto out; 3697 3697 3698 - if (set_nr_if_polling(rq->idle)) { 3699 - trace_sched_wake_idle_without_ipi(cpu); 3700 - } else { 3701 - rq_lock_irqsave(rq, &rf); 3702 - if (is_idle_task(rq->curr)) 3703 - smp_send_reschedule(cpu); 3704 - /* Else CPU is not idle, do nothing here: */ 3705 - rq_unlock_irqrestore(rq, &rf); 3706 - } 3698 + rq_lock_irqsave(rq, &rf); 3699 + if (is_idle_task(rq->curr)) 3700 + resched_curr(rq); 3701 + /* Else CPU is not idle, do nothing here: */ 3702 + rq_unlock_irqrestore(rq, &rf); 3707 3703 3708 3704 out: 3709 3705 rcu_read_unlock();
+3 -3
kernel/smp.c
··· 1170 1170 { 1171 1171 int cpu; 1172 1172 1173 - preempt_disable(); 1173 + cpus_read_lock(); 1174 1174 for_each_online_cpu(cpu) { 1175 - if (cpu == smp_processor_id()) 1175 + if (cpu == raw_smp_processor_id()) 1176 1176 continue; 1177 1177 1178 1178 wake_up_if_idle(cpu); 1179 1179 } 1180 - preempt_enable(); 1180 + cpus_read_unlock(); 1181 1181 } 1182 1182 EXPORT_SYMBOL_GPL(wake_up_all_idle_cpus); 1183 1183