[PATCH] sched/fair: Fix the runtime check in preempt_sync()
From: Peng Wang
Date: Fri Nov 06 2026 - 03:55:33 EST
With NEXT_BUDDY enabled, preempt_sync() only lets a WF_SYNC wakeup
force a reschedule once the current task has run long enough. It
computes the runtime as rq_clock_task() - se->exec_start, but
wakeup_preempt_fair() has already called update_curr_fair() at that
point, which sets se->exec_start to rq_clock_task(). The result is
always 0.
Use sum_exec_runtime - prev_sum_exec_runtime instead, which is the time
the task has run since it was picked, and drop the now unused rq
argument.
Fixes: e837456fdca8 ("sched/fair: Reimplement NEXT_BUDDY to align with EEVDF goals")
Signed-off-by: Peng Wang <peng_wang@xxxxxxxxxxxxxxxxx>
---
kernel/sched/fair.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index cfc9822..6164cb7 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -10090,8 +10090,8 @@ static inline bool set_short_buddy(struct cfs_rq *cfs_rq, struct sched_entity *p
* multiple tasks must be woken up.
*/
static inline enum preempt_wakeup_action
-preempt_sync(struct rq *rq, int wake_flags,
- struct sched_entity *pse, struct sched_entity *se)
+preempt_sync(int wake_flags, struct sched_entity *pse,
+ struct sched_entity *se)
{
u64 threshold, delta;
@@ -10102,7 +10102,7 @@ preempt_sync(struct rq *rq, int wake_flags,
WARN_ON_ONCE(!(wake_flags & WF_TTWU));
threshold = sysctl_sched_migration_cost;
- delta = rq_clock_task(rq) - se->exec_start;
+ delta = se->sum_exec_runtime - se->prev_sum_exec_runtime;
if ((s64)delta < 0)
delta = 0;
@@ -10226,7 +10226,7 @@ static void wakeup_preempt_fair(struct rq *rq, struct task_struct *p, int wake_f
* waker and less likely to be cache hot.
*/
if (wake_flags & WF_SYNC)
- preempt_action = preempt_sync(rq, wake_flags, pse, se);
+ preempt_action = preempt_sync(wake_flags, pse, se);
}
switch (preempt_action) {
--
2.47.0
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4