[PATCH v2 23/35] sched: handle idle preemption for PREEMPT_AUTO
From: Ankur Arora
Date: Mon May 27 2024 - 20:40:33 EST
When running the idle task, we always want to schedule out immediately.
Use tif_resched(RESCHED_NOW) to do that.
This path should be identical across preemption models which is borne
out by comparing latency via perf bench sched pipe (5 runs):
PREEMPT_AUTO: 4.430 usecs/op +- 0.080 ( +- 1.800% )
PREEMPT_DYNAMIC: 4.400 usecs/op +- 0.100 ( +- 2.270% )
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Juri Lelli <juri.lelli@xxxxxxxxxx>
Cc: Vincent Guittot <vincent.guittot@xxxxxxxxxx>
Originally-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Link: https://lore.kernel.org/lkml/87jzshhexi.ffs@tglx/
Signed-off-by: Ankur Arora <ankur.a.arora@xxxxxxxxxx>
---
kernel/sched/core.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index ee846dc9133b..1b930b84eb59 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -1044,6 +1044,9 @@ static resched_t resched_opt_translate(struct task_struct *curr,
if (!IS_ENABLED(CONFIG_PREEMPT_AUTO))
return RESCHED_NOW;
+ if (is_idle_task(curr))
+ return RESCHED_NOW;
+
return RESCHED_LAZY;
}
--
2.31.1