Skip to content

Commit 8850cb6

Browse files
author
Peter Zijlstra
committed
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
1 parent 00619f7 commit 8850cb6

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

kernel/sched/core.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3695,15 +3695,11 @@ void wake_up_if_idle(int cpu)
36953695
if (!is_idle_task(rcu_dereference(rq->curr)))
36963696
goto out;
36973697

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);
37073703

37083704
out:
37093705
rcu_read_unlock();

kernel/smp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,14 +1170,14 @@ void wake_up_all_idle_cpus(void)
11701170
{
11711171
int cpu;
11721172

1173-
preempt_disable();
1173+
cpus_read_lock();
11741174
for_each_online_cpu(cpu) {
1175-
if (cpu == smp_processor_id())
1175+
if (cpu == raw_smp_processor_id())
11761176
continue;
11771177

11781178
wake_up_if_idle(cpu);
11791179
}
1180-
preempt_enable();
1180+
cpus_read_unlock();
11811181
}
11821182
EXPORT_SYMBOL_GPL(wake_up_all_idle_cpus);
11831183

0 commit comments

Comments
 (0)