mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] sched_ext: Update other_load_avgs on set_next_task_scx
@ 2026-11-22  3:33 Peng Huang
  2026-11-22  6:21 ` [PATCH v2] sched_ext: Update other_load_avgs on set_next_task_scx and idle entry Peng Huang
  0 siblings, 1 reply; 2+ messages in thread
From: Peng Huang @ 2026-11-22  3:33 UTC (permalink / raw)
  To: Tejun Heo, David Vernet, Andrea Righi, Changwoo Min, sched-ext
  Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider, K Prateek Nayak, Barret Rhoden, Josh Don,
	Hao Luo, linux-kernel, penghuang

When scx_switched_all() is enabled, scheduler_tick() skips
sched_balance_trigger(), so __update_blocked_others() no longer runs to
decay RT, DL, IRQ, and HW pressure load averages. Other-class load
averages then depend on scx_tick() and SCX_RQ_CAN_STOP_TICK transitions
in set_next_task_scx().

If SCX_RQ_CAN_STOP_TICK stays unchanged (e.g., remaining set across an
idle or RT interval on tickless CPUs, or remaining clear on finite-slice
switches before a tick fires or before going idle), stale RT/DL PELT
values can remain elevated when consumers such as effective_cpu_util()
or update_idle_rq_clock_pelt() read them.

Track load-average updates explicitly with @update_load_avgs in
set_next_task_scx() and refresh update_other_load_avgs() on SNT_PICK as
well as when SCX_RQ_CAN_STOP_TICK toggles.

Fixes: 22a920209ab6 ("sched_ext: Implement tickless support")
Cc: stable@vger.kernel.org
Signed-off-by: Peng Huang <penghuang@google.com>
---
 kernel/sched/ext/ext.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
index 10de6bd865e8..e29c9c18e1ab 100644
--- a/kernel/sched/ext/ext.c
+++ b/kernel/sched/ext/ext.c
@@ -3553,6 +3553,7 @@ static void kick_sync_wait_bal_cb(struct rq *rq);
 static void set_next_task_scx(struct rq *rq, struct task_struct *p, enum snt_e type)
 {
 	bool first = type == SNT_PICK;
+	bool update_load_avgs = first;
 	bool can_stop_tick;
 
 	/*
@@ -3619,10 +3620,6 @@ static void set_next_task_scx(struct rq *rq, struct task_struct *p, enum snt_e t
 	 * @p is getting newly scheduled or got kicked after someone updated its
 	 * slice. Update SCX_RQ_CAN_STOP_TICK to reflect whether the tick can be
 	 * stopped. See scx_can_stop_tick().
-	 *
-	 * Moreover, refresh the load_avgs just when transitioning in and out of
-	 * nohz. In the future, we might want to add a mechanism to update
-	 * load_avgs periodically on tick-stopped CPUs.
 	 */
 	if (can_stop_tick) {
 		if (!(rq->scx.flags & SCX_RQ_CAN_STOP_TICK)) {
@@ -3634,13 +3631,12 @@ static void set_next_task_scx(struct rq *rq, struct task_struct *p, enum snt_e t
 			 */
 			rq->scx.flags |= SCX_RQ_CAN_STOP_TICK;
 			sched_update_tick_dependency(rq);
-
-			update_other_load_avgs(rq);
+			update_load_avgs = true;
 		}
 	} else {
 		if (rq->scx.flags & SCX_RQ_CAN_STOP_TICK) {
 			rq->scx.flags &= ~SCX_RQ_CAN_STOP_TICK;
-			update_other_load_avgs(rq);
+			update_load_avgs = true;
 		}
 
 		/*
@@ -3651,6 +3647,15 @@ static void set_next_task_scx(struct rq *rq, struct task_struct *p, enum snt_e t
 		if (tick_nohz_full_cpu(cpu_of(rq)))
 			tick_nohz_dep_set_cpu(cpu_of(rq), TICK_DEP_BIT_SCHED);
 	}
+
+	/*
+	 * Refresh other-class (RT/DL/IRQ/HW) load averages when picking a new
+	 * task or toggling nohz tick dependency while CFS PELT is dormant.
+	 * In the future, we might want to add a mechanism to update load_avgs
+	 * periodically on tick-stopped CPUs.
+	 */
+	if (update_load_avgs)
+		update_other_load_avgs(rq);
 }
 
 void scx_proxy_donor_start(struct rq *rq)
-- 
2.56.1.750.gf70dc682cf-goog


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH v2] sched_ext: Update other_load_avgs on set_next_task_scx and idle entry
  2026-11-22  3:33 [PATCH] sched_ext: Update other_load_avgs on set_next_task_scx Peng Huang
@ 2026-11-22  6:21 ` Peng Huang
  0 siblings, 0 replies; 2+ messages in thread
From: Peng Huang @ 2026-11-22  6:21 UTC (permalink / raw)
  To: tj, void, arighi, changwoo, sched-ext
  Cc: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
	rostedt, bsegall, mgorman, vschneid, kprateek.nayak, haoluo,
	brho, joshdon, linux-kernel, penghuang

When scx_switched_all() is enabled, scheduler_tick() skips
sched_balance_trigger(), so __update_blocked_others() no longer runs to
decay RT, DL, IRQ, and HW pressure load averages. Other-class load
averages then depend on scx_tick() and SCX_RQ_CAN_STOP_TICK transitions
in set_next_task_scx().

If SCX_RQ_CAN_STOP_TICK stays unchanged (e.g., remaining set across an
idle or RT interval on tickless CPUs, or remaining clear on finite-slice
switches before a tick fires), or when an SCX task goes idle after an
RT/DL interval without an intervening tick, stale RT/DL PELT values
can remain elevated when consumers such as effective_cpu_util() or
update_idle_rq_clock_pelt() read them.

Refresh update_other_load_avgs() once at the entry of set_next_task_scx()
(before SNT_REPICK early return and before ops.running() for SNT_PICK /
SNT_NORMAL), and in put_prev_task_scx() when transitioning to the idle
class.

Fixes: 22a920209ab6 ("sched_ext: Implement tickless support")
Cc: stable@vger.kernel.org
Signed-off-by: Peng Huang <penghuang@google.com>
---
Changes in v2:
- Call update_other_load_avgs() once before SNT_REPICK return and before
  ops.running() in set_next_task_scx() so BPF callbacks such as
  scx_bpf_cpuperf_set() see updated PELT values, and cover SNT_REPICK.
- Refresh other-class load_avgs in put_prev_task_scx() when transitioning to
  idle_sched_class before ops.update_idle() and update_idle_rq_clock_pelt().
- Link to v1: https://lore.kernel.org/r/20261122033316.2819845-1-penghuang@google.com
 kernel/sched/ext/ext.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
index 10de6bd865e8..523f86be4d26 100644
--- a/kernel/sched/ext/ext.c
+++ b/kernel/sched/ext/ext.c
@@ -3579,6 +3579,15 @@ static void set_next_task_scx(struct rq *rq, struct task_struct *p, enum snt_e t
 	if (unlikely(rq->scx.kick_sync_pending) && (type == SNT_PICK || type == SNT_REPICK))
 		queue_balance_callback(rq, &rq->scx.kick_sync_bal_cb, kick_sync_wait_bal_cb);
 
+	/*
+	 * Refresh other-class (RT/DL/IRQ/HW) load averages before ops.running()
+	 * (or returning on SNT_REPICK) so BPF callbacks such as
+	 * scx_bpf_cpuperf_set() observe fresh utilization while CFS PELT is
+	 * dormant. In the future, we might want to add a mechanism to update
+	 * load_avgs periodically on tick-stopped CPUs.
+	 */
+	update_other_load_avgs(rq);
+
 	if (type == SNT_REPICK)
 		return;
 
@@ -3619,10 +3628,6 @@ static void set_next_task_scx(struct rq *rq, struct task_struct *p, enum snt_e t
 	 * @p is getting newly scheduled or got kicked after someone updated its
 	 * slice. Update SCX_RQ_CAN_STOP_TICK to reflect whether the tick can be
 	 * stopped. See scx_can_stop_tick().
-	 *
-	 * Moreover, refresh the load_avgs just when transitioning in and out of
-	 * nohz. In the future, we might want to add a mechanism to update
-	 * load_avgs periodically on tick-stopped CPUs.
 	 */
 	if (can_stop_tick) {
 		if (!(rq->scx.flags & SCX_RQ_CAN_STOP_TICK)) {
@@ -3634,14 +3639,10 @@ static void set_next_task_scx(struct rq *rq, struct task_struct *p, enum snt_e t
 			 */
 			rq->scx.flags |= SCX_RQ_CAN_STOP_TICK;
 			sched_update_tick_dependency(rq);
-
-			update_other_load_avgs(rq);
 		}
 	} else {
-		if (rq->scx.flags & SCX_RQ_CAN_STOP_TICK) {
+		if (rq->scx.flags & SCX_RQ_CAN_STOP_TICK)
 			rq->scx.flags &= ~SCX_RQ_CAN_STOP_TICK;
-			update_other_load_avgs(rq);
-		}
 
 		/*
 		 * @rq still references the outgoing scheduling context. A finite
@@ -3863,6 +3864,14 @@ static void put_prev_task_scx(struct rq *rq, struct task_struct *p,
 	if (next && next->sched_class != &ext_sched_class) {
 		scx_cid_sched_update(rq, NULL);
 		switch_class(rq, next);
+
+		/*
+		 * Refresh other-class load averages before entering idle so
+		 * ops.update_idle() and update_idle_rq_clock_pelt() observe
+		 * decayed RT/DL/IRQ/HW metrics while CFS PELT is dormant.
+		 */
+		if (sched_class_above(&ext_sched_class, next->sched_class))
+			update_other_load_avgs(rq);
 	}
 }
 
-- 
2.56.1.750.gf70dc682cf-goog


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-22  6:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-22  3:33 [PATCH] sched_ext: Update other_load_avgs on set_next_task_scx Peng Huang
2026-11-22  6:21 ` [PATCH v2] sched_ext: Update other_load_avgs on set_next_task_scx and idle entry Peng Huang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®