Skip to contentSkip to conversation

sched/core: Fix stale se.load when modifying nice value under sched_ext

PATCH In review Wanwu Li 2 participants 3 messages Jul 14 Scheduler

lore
Share & tools
lore

Wanwu Li

author
#0 lore raw

PATCH 1/1 sched/core: Fix stale se.load when modifying nice value under sched_ext

From: Wanwu Li <[email protected]>

When a task's nice value is modified while running under sched_ext scheduling class, set_load_weight() calls reweight_task() which only updates static_prio but leaves p->se.load unchanged because sched_ext does not use it. After switching back to CFS, the stale se.load leads to incorrect load weight calculation.

Fix this by explicitly refreshing p->se.load for sched_ext tasks after calling reweight_task().

Fixes d32960528702 ("sched/fair: set_load_weight() must also call reweight_task() for SCHED_IDLE tasks")
---
 kernel/sched/core.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
kernel/sched/core.c +13 -2
index 96226707c2f6..ebeadec41eb6 100644
@@ -1538,10 +1538,21 @@ void set_load_weight(struct task_struct *p, bool update_load)
 	 * SCHED_OTHER tasks have to update their load when changing their
 	 * weight
 	 */
-	if (update_load && p->sched_class->reweight_task)
+	if (update_load && p->sched_class->reweight_task) {
 		p->sched_class->reweight_task(task_rq(p), p, &lw);
-	else
+
+		/*
+		 * If modify nice while task runs under ext class, only
+		 * static_prio updates, p->se.load stays stale and mismatches
+		 * the new nice value. After switching back to CFS, outdated
+		 * load leads to incorrect weight. Synchronously refresh
+		 * se.load to keep priority state consistent.
+		 */
+		if (task_on_scx(p))
+			p->se.load = lw;
+	} else {
 		p->se.load = lw;
+	}
 }
 
 #ifdef CONFIG_UCLAMP_TASK
Signature · 1 line
2.25.1
#1 lore raw

Hello Wanwu,

Quoted 10 lines · Wanwu Li

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

From: Wanwu Li <[email protected]>

When a task's nice value is modified while running under sched_ext scheduling class, set_load_weight() calls reweight_task() which only updates static_prio but leaves p->se.load unchanged because sched_ext does not use it. After switching back to CFS, the stale se.load leads to incorrect load weight calculation.

Quoted 5 lines

Fix this by explicitly refreshing p->se.load for sched_ext tasks after calling reweight_task().

Fixes d32960528702 ("sched/fair: set_load_weight() must also call reweight_task() for SCHED_IDLE tasks")

Isn't this solved in
https://lore.kernel.org/lkml/[email protected]/

Signature · 2 lines
Thanks and Regards,
Prateek
#2 lore raw

Hello Prateek,

Thank you for your reply and correction.

I was not aware that this problem had already been addressed by another patch. I appreciate you taking the time to share this information. Please consider my patch withdrawn.

Thank you again for your guidance.

Best regards,
Wanwu Li

Quoted 22 lines · K Prateek Nayak

Hello Wanwu,

Quoted 10 lines · Wanwu Li

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

From: Wanwu Li <[email protected]>

When a task's nice value is modified while running under sched_ext scheduling class, set_load_weight() calls reweight_task() which only updates static_prio but leaves p->se.load unchanged because sched_ext does not use it. After switching back to CFS, the stale se.load leads to incorrect load weight calculation.

Quoted 5 lines

Fix this by explicitly refreshing p->se.load for sched_ext tasks after calling reweight_task().

Fixes d32960528702 ("sched/fair: set_load_weight() must also call reweight_task() for SCHED_IDLE tasks")

Isn't this solved in
https://lore.kernel.org/lkml/[email protected]/