Skip to content

Commit 1946000

Browse files
Frederic WeisbeckerPeter Zijlstra
authored andcommitted
sched/timers: Explain why idle task schedules out on remote timer enqueue
Trying to avoid that didn't bring much value after testing, add comment about this. Signed-off-by: Frederic Weisbecker <frederic@kernel.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Rafael J. Wysocki <rafael@kernel.org> Link: https://lkml.kernel.org/r/20231114193840.4041-3-frederic@kernel.org
1 parent dd54038 commit 1946000

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

kernel/sched/core.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,28 @@ static void wake_up_idle_cpu(int cpu)
11311131
if (cpu == smp_processor_id())
11321132
return;
11331133

1134+
/*
1135+
* Set TIF_NEED_RESCHED and send an IPI if in the non-polling
1136+
* part of the idle loop. This forces an exit from the idle loop
1137+
* and a round trip to schedule(). Now this could be optimized
1138+
* because a simple new idle loop iteration is enough to
1139+
* re-evaluate the next tick. Provided some re-ordering of tick
1140+
* nohz functions that would need to follow TIF_NR_POLLING
1141+
* clearing:
1142+
*
1143+
* - On most archs, a simple fetch_or on ti::flags with a
1144+
* "0" value would be enough to know if an IPI needs to be sent.
1145+
*
1146+
* - x86 needs to perform a last need_resched() check between
1147+
* monitor and mwait which doesn't take timers into account.
1148+
* There a dedicated TIF_TIMER flag would be required to
1149+
* fetch_or here and be checked along with TIF_NEED_RESCHED
1150+
* before mwait().
1151+
*
1152+
* However, remote timer enqueue is not such a frequent event
1153+
* and testing of the above solutions didn't appear to report
1154+
* much benefits.
1155+
*/
11341156
if (set_nr_and_not_polling(rq->idle))
11351157
smp_send_reschedule(cpu);
11361158
else

0 commit comments

Comments
 (0)