stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sched/pelt: Skip dormant cfs util_sum under scx_switched_all
@ 2026-11-22  1:57 Peng Huang
  2026-11-23 10:34 ` Vincent Guittot
  2026-11-23 20:13 ` [PATCH v2 0/2] sched_ext, sched/fair: Drain blocked fair load on scx_switched_all Peng Huang
  0 siblings, 2 replies; 8+ messages in thread
From: Peng Huang @ 2026-11-22  1:57 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot
  Cc: Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider, K Prateek Nayak, Tejun Heo, David Vernet,
	Andrea Righi, Changwoo Min, linux-kernel, sched-ext, Peng Huang,
	stable

When scx_switched_all() is enabled, all fair-class tasks move to
sched_ext, scheduler_tick() skips sched_balance_trigger(), and fair_rq
scheduling is bypassed. As a result, rq->cfs.avg.util_sum stops updating
and retains whatever stale load was present prior to switching to SCX.

When a CPU later goes idle, update_idle_rq_clock_pelt() still adds this
dormant rq->cfs.avg.util_sum. If stale cfs.avg.util_sum plus active RT
and DL util_sum reaches divider, update_idle_rq_clock_pelt() treats the
rq as overutilized, continuously increments rq->lost_idle_time, and
stalls rq_clock_pelt(), which in turn freezes RT and DL PELT updates.

Exclude rq->cfs.avg.util_sum in update_idle_rq_clock_pelt() while
scx_switched_all() is active so dormant CFS load cannot stall idle
rq_clock_pelt().

Fixes: f0e1a0643a59 ("sched_ext: Implement BPF extensible scheduler class")
Cc: stable@vger.kernel.org
Signed-off-by: Peng Huang <penghuang@google.com>
---
 kernel/sched/pelt.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/pelt.h b/kernel/sched/pelt.h
index f921302dc40f..6d31e1fbd094 100644
--- a/kernel/sched/pelt.h
+++ b/kernel/sched/pelt.h
@@ -138,7 +138,12 @@ static inline void update_rq_clock_pelt(struct rq *rq, s64 delta)
 static inline void update_idle_rq_clock_pelt(struct rq *rq)
 {
 	u32 divider = ((LOAD_AVG_MAX - 1024) << SCHED_CAPACITY_SHIFT) - LOAD_AVG_MAX;
-	u32 util_sum = rq->cfs.avg.util_sum;
+	/*
+	 * Under scx_switched_all(), CFS PELT is dormant and may stay stale;
+	 * exclude it so idle CPUs do not trip lost_idle_time and freeze RT
+	 * PELT.
+	 */
+	u32 util_sum = scx_switched_all() ? 0 : rq->cfs.avg.util_sum;
 	util_sum += rq->avg_rt.util_sum;
 	util_sum += rq->avg_dl.util_sum;
 
-- 
2.56.1.750.gf70dc682cf-goog


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

* Re: [PATCH] sched/pelt: Skip dormant cfs util_sum under scx_switched_all
  2026-11-22  1:57 [PATCH] sched/pelt: Skip dormant cfs util_sum under scx_switched_all Peng Huang
@ 2026-11-23 10:34 ` Vincent Guittot
  2026-11-23 16:09   ` Peng Huang
  2026-11-23 20:13 ` [PATCH v2 0/2] sched_ext, sched/fair: Drain blocked fair load on scx_switched_all Peng Huang
  1 sibling, 1 reply; 8+ messages in thread
From: Vincent Guittot @ 2026-11-23 10:34 UTC (permalink / raw)
  To: Peng Huang
  Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Dietmar Eggemann,
	Steven Rostedt, Ben Segall, Mel Gorman, Valentin Schneider,
	K Prateek Nayak, Tejun Heo, David Vernet, Andrea Righi,
	Changwoo Min, linux-kernel, sched-ext, stable

On Sun, 22 Nov 2026 at 02:57, Peng Huang <penghuang@google.com> wrote:
>
> When scx_switched_all() is enabled, all fair-class tasks move to
> sched_ext, scheduler_tick() skips sched_balance_trigger(), and fair_rq
> scheduling is bypassed. As a result, rq->cfs.avg.util_sum stops updating
> and retains whatever stale load was present prior to switching to SCX.

When all tasks are moved to sched_ext, fair utilization should be 0

>
> When a CPU later goes idle, update_idle_rq_clock_pelt() still adds this
> dormant rq->cfs.avg.util_sum. If stale cfs.avg.util_sum plus active RT
> and DL util_sum reaches divider, update_idle_rq_clock_pelt() treats the
> rq as overutilized, continuously increments rq->lost_idle_time, and
> stalls rq_clock_pelt(), which in turn freezes RT and DL PELT updates.
>
> Exclude rq->cfs.avg.util_sum in update_idle_rq_clock_pelt() while
> scx_switched_all() is active so dormant CFS load cannot stall idle
> rq_clock_pelt().

This is not the right solution but a bandaid to hide the issue. When
there is not fair task,  rq->cfs.avg.util_sum shoudl become null.
Please look at why it is not null.
It could be that the update stops before everything has been
propagated correctly in the task group tree

>
> Fixes: f0e1a0643a59 ("sched_ext: Implement BPF extensible scheduler class")
> Cc: stable@vger.kernel.org
> Signed-off-by: Peng Huang <penghuang@google.com>
> ---
>  kernel/sched/pelt.h | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/sched/pelt.h b/kernel/sched/pelt.h
> index f921302dc40f..6d31e1fbd094 100644
> --- a/kernel/sched/pelt.h
> +++ b/kernel/sched/pelt.h
> @@ -138,7 +138,12 @@ static inline void update_rq_clock_pelt(struct rq *rq, s64 delta)
>  static inline void update_idle_rq_clock_pelt(struct rq *rq)
>  {
>         u32 divider = ((LOAD_AVG_MAX - 1024) << SCHED_CAPACITY_SHIFT) - LOAD_AVG_MAX;
> -       u32 util_sum = rq->cfs.avg.util_sum;
> +       /*
> +        * Under scx_switched_all(), CFS PELT is dormant and may stay stale;
> +        * exclude it so idle CPUs do not trip lost_idle_time and freeze RT
> +        * PELT.
> +        */
> +       u32 util_sum = scx_switched_all() ? 0 : rq->cfs.avg.util_sum;
>         util_sum += rq->avg_rt.util_sum;
>         util_sum += rq->avg_dl.util_sum;
>
> --
> 2.56.1.750.gf70dc682cf-goog
>

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

* Re: [PATCH] sched/pelt: Skip dormant cfs util_sum under scx_switched_all
  2026-11-23 10:34 ` Vincent Guittot
@ 2026-11-23 16:09   ` Peng Huang
  2026-11-23 17:07     ` Vincent Guittot
  0 siblings, 1 reply; 8+ messages in thread
From: Peng Huang @ 2026-11-23 16:09 UTC (permalink / raw)
  To: Vincent Guittot
  Cc: Peng Huang, Ingo Molnar, Peter Zijlstra, Juri Lelli,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider, K Prateek Nayak, Tejun Heo, David Vernet,
	Andrea Righi, Changwoo Min, linux-kernel, sched-ext, stable

On Mon, 23 Nov 2026 at 11:34, Vincent Guittot <vincent.guittot@linaro.org> wrote:
>
> When all tasks are moved to sched_ext, fair utilization should be 0
>
> ...
>
> This is not the right solution but a bandaid to hide the issue. When
> there is not fair task,  rq->cfs.avg.util_sum shoudl become null.
> Please look at why it is not null.
> It could be that the update stops before everything has been
> propagated correctly in the task group tree

Thanks for pointing this out -- you are right, and looking into the
code confirms your suspicion about stopped updates and incomplete task
group propagation:

1. Deferred cfs_rq->removed and unvisited sibling task groups:
   Tasks that exited (task_dead_fair()) or migrated while sleeping
   (migrate_task_rq_fair()) before scx_enable() queue their load/util
   in cfs_rq->removed via remove_entity_load_avg() rather than
   deducting and propagating immediately.

   During scx_enable(), switched_from_fair() -> detach_task_cfs_rq()
   only visits and propagates along cfs_rq chains that still have at
   least one live attached fair task. Any CPU or sibling cgroup cfs_rq
   with no remaining live fair task is never visited, so its
   cfs_rq->removed stays undrained and its tg_se contribution remains
   in rq->cfs.avg. Once __scx_switched_all is enabled,
   scheduler_tick() skips sched_balance_trigger() and fair_sched_class
   is bypassed, so __update_blocked_fair() never runs to drain and
   propagate those remaining leaf cfs_rqs.

2. Sub-divider util_sum residuals:
   Even on visited chains, if tg_se->avg.util_avg has already decayed
   to 0 (with 0 < tg_se->avg.util_sum < divider) when the child
   gcfs_rq's last task detaches, update_tg_cfs_util() sees
   delta_avg == 0 and returns early without subtracting
   tg_se->avg.util_sum from the parent cfs_rq. Independent PELT decay
   truncation and integer removed.util_avg accounting can also leave a
   < divider remainder in cfs_rq->avg.util_sum after util_avg hits 0.

For v2, rather than touching update_idle_rq_clock_pelt(), how about
adding a fair helper (similar in spirit to rq_offline_fair() ->
clear_tg_offline_cfs_rqs()) and calling it from scx_enable() in the
existing per-CPU scx_switched_all() loop (where rq->lock is held,
rq->clock is updated, and rq->cfs.h_nr_queued == 0)? Specifically, it
would walk leaf_cfs_rq_list bottom-up (plus &rq->cfs) to:
- flush cfs_rq->removed,
- clear load/runnable/util _sum and _avg on the empty cfs_rqs and
  their tg_ses while preserving last_update_time and period_contrib,
- clear tg contributions via clear_tg_load_avg(), remove the empty
  cfs_rqs from leaf_cfs_rq_list, and update rq->has_blocked_load.

Does this direction look reasonable to you?

Thanks,
Peng

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

* Re: [PATCH] sched/pelt: Skip dormant cfs util_sum under scx_switched_all
  2026-11-23 16:09   ` Peng Huang
@ 2026-11-23 17:07     ` Vincent Guittot
  2026-11-23 20:14       ` Peng Huang
  0 siblings, 1 reply; 8+ messages in thread
From: Vincent Guittot @ 2026-11-23 17:07 UTC (permalink / raw)
  To: Peng Huang
  Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Dietmar Eggemann,
	Steven Rostedt, Ben Segall, Mel Gorman, Valentin Schneider,
	K Prateek Nayak, Tejun Heo, David Vernet, Andrea Righi,
	Changwoo Min, linux-kernel, sched-ext, stable

On Mon, 23 Nov 2026 at 17:09, Peng Huang <penghuang@google.com> wrote:
>
> On Mon, 23 Nov 2026 at 11:34, Vincent Guittot <vincent.guittot@linaro.org> wrote:
> >
> > When all tasks are moved to sched_ext, fair utilization should be 0
> >
> > ...
> >
> > This is not the right solution but a bandaid to hide the issue. When
> > there is not fair task,  rq->cfs.avg.util_sum shoudl become null.
> > Please look at why it is not null.
> > It could be that the update stops before everything has been
> > propagated correctly in the task group tree
>
> Thanks for pointing this out -- you are right, and looking into the
> code confirms your suspicion about stopped updates and incomplete task
> group propagation:
>
> 1. Deferred cfs_rq->removed and unvisited sibling task groups:
>    Tasks that exited (task_dead_fair()) or migrated while sleeping
>    (migrate_task_rq_fair()) before scx_enable() queue their load/util
>    in cfs_rq->removed via remove_entity_load_avg() rather than
>    deducting and propagating immediately.
>
>    During scx_enable(), switched_from_fair() -> detach_task_cfs_rq()
>    only visits and propagates along cfs_rq chains that still have at
>    least one live attached fair task. Any CPU or sibling cgroup cfs_rq
>    with no remaining live fair task is never visited, so its
>    cfs_rq->removed stays undrained and its tg_se contribution remains
>    in rq->cfs.avg. Once __scx_switched_all is enabled,
>    scheduler_tick() skips sched_balance_trigger() and fair_sched_class
>    is bypassed, so __update_blocked_fair() never runs to drain and
>    propagate those remaining leaf cfs_rqs.
>
> 2. Sub-divider util_sum residuals:
>    Even on visited chains, if tg_se->avg.util_avg has already decayed
>    to 0 (with 0 < tg_se->avg.util_sum < divider) when the child
>    gcfs_rq's last task detaches, update_tg_cfs_util() sees
>    delta_avg == 0 and returns early without subtracting
>    tg_se->avg.util_sum from the parent cfs_rq. Independent PELT decay
>    truncation and integer removed.util_avg accounting can also leave a
>    < divider remainder in cfs_rq->avg.util_sum after util_avg hits 0.
>
> For v2, rather than touching update_idle_rq_clock_pelt(), how about
> adding a fair helper (similar in spirit to rq_offline_fair() ->
> clear_tg_offline_cfs_rqs()) and calling it from scx_enable() in the
> existing per-CPU scx_switched_all() loop (where rq->lock is held,
> rq->clock is updated, and rq->cfs.h_nr_queued == 0)? Specifically, it
> would walk leaf_cfs_rq_list bottom-up (plus &rq->cfs) to:
> - flush cfs_rq->removed,
> - clear load/runnable/util _sum and _avg on the empty cfs_rqs and
>   their tg_ses while preserving last_update_time and period_contrib,
> - clear tg contributions via clear_tg_load_avg(), remove the empty
>   cfs_rqs from leaf_cfs_rq_list, and update rq->has_blocked_load.
>
> Does this direction look reasonable to you?

Yes this seems a better solution but It would be good to reuse
__update_blocked_fair() which already does the work for pelt signal.
Regarding your issue with util_avg == 0 whereas we still have a
util_sum != 0, we can use delta_sum = gcfs_rq->avg.util_sum -
se->avg.util_sum; in update_tg_cfs_util() instead. When util_avg == 0
we will be sure to clear util_sum too

Thanks,
Vincent
>
> Thanks,
> Peng

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

* [PATCH v2 0/2] sched_ext, sched/fair: Drain blocked fair load on scx_switched_all
  2026-11-22  1:57 [PATCH] sched/pelt: Skip dormant cfs util_sum under scx_switched_all Peng Huang
  2026-11-23 10:34 ` Vincent Guittot
@ 2026-11-23 20:13 ` Peng Huang
  2026-11-23 20:13   ` [PATCH v2 1/2] sched/fair: Clear residual sums on zero task-group avg propagation Peng Huang
  2026-11-23 20:13   ` [PATCH v2 2/2] sched_ext, sched/fair: Drain blocked load on scx_switched_all Peng Huang
  1 sibling, 2 replies; 8+ messages in thread
From: Peng Huang @ 2026-11-23 20:13 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Tejun Heo, David Vernet, Andrea Righi, Changwoo Min
  Cc: Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider, K Prateek Nayak, linux-kernel, sched-ext,
	stable, Peng Huang

v1 [1] skipped rq->cfs.avg.util_sum in update_idle_rq_clock_pelt() when
scx_switched_all() was active. As Vincent Guittot pointed out, that hid
the underlying issue: once all fair tasks switch to sched_ext, fair
blocked load should be properly drained and propagated rather than left
stale in rq->cfs.avg.

Investigating why rq->cfs.avg.util_sum remained non-zero showed two
causes:

1. In update_tg_cfs_{util,runnable,load}(), if the group entity @se's
   _avg had already decayed to 0 while its _sum still held a sub-divider
   residual when the child gcfs_rq's _avg also reached 0, delta_avg == 0
   caused an early return without clearing @se's residual _sum from the
   parent cfs_rq.
2. Tasks that exited or migrated while sleeping before scx_enable()
   leave deferred removals in cfs_rq->removed, and switched_from_fair()
   only visits cfs_rq chains with live fair tasks. Once
   __scx_switched_all is enabled, periodic blocked-load updates stop,
   stranding unvisited leaf cfs_rqs in rq->cfs.avg.

Patch 1 clears residual task-group _sum values on zero-avg propagation
while keeping parent period_contrib divider scaling for non-zero
averages. Patch 2 reuses __sched_balance_update_blocked_averages() in
scx_enable()'s per-CPU scx_switched_all() loop to drain cfs_rq->removed
and propagate blocked averages across all leaf cfs_rqs.

Changes in v2:
- Drop the pelt.h workaround from v1 (Vincent Guittot).
- Clear residual sums in update_tg_cfs_{util,runnable,load}() when
  propagating a zero average (Vincent Guittot).
- Reuse __sched_balance_update_blocked_averages() in scx_enable() under
  scx_switched_all() to drain remaining blocked fair load (Vincent
  Guittot).

[1] https://lore.kernel.org/r/20261122015729.2512645-1-penghuang@google.com

Peng Huang (2):
  sched/fair: Clear residual sums on zero task-group avg propagation
  sched_ext, sched/fair: Drain blocked load on scx_switched_all

 kernel/sched/ext/ext.c |  9 ++++-----
 kernel/sched/fair.c    | 42 +++++++++++++++++++++++++++++++++---------
 kernel/sched/sched.h   |  1 +
 3 files changed, 38 insertions(+), 14 deletions(-)

-- 
2.56.1.831.g720f3f5937-goog


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

* [PATCH v2 1/2] sched/fair: Clear residual sums on zero task-group avg propagation
  2026-11-23 20:13 ` [PATCH v2 0/2] sched_ext, sched/fair: Drain blocked fair load on scx_switched_all Peng Huang
@ 2026-11-23 20:13   ` Peng Huang
  2026-11-23 20:13   ` [PATCH v2 2/2] sched_ext, sched/fair: Drain blocked load on scx_switched_all Peng Huang
  1 sibling, 0 replies; 8+ messages in thread
From: Peng Huang @ 2026-11-23 20:13 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Tejun Heo, David Vernet, Andrea Righi, Changwoo Min
  Cc: Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider, K Prateek Nayak, linux-kernel, sched-ext,
	stable, Peng Huang

In update_load_avg(), __update_load_avg_se() ages the group entity @se
before propagate_entity_load_avg() runs. If @se's _avg has already
decayed to 0 while its _sum still holds a sub-divider residual, and the
child gcfs_rq's _avg also reaches 0 (e.g. when its last task detaches),
update_tg_cfs_{util,runnable,load}() see delta_avg == 0 and return early
without subtracting @se's remaining _sum from the parent cfs_rq.

Keep scaling non-zero averages by the parent cfs_rq's divider to
preserve period_contrib alignment, while letting zero-avg propagations
proceed whenever @se still holds a non-zero _sum so the residual is
cleared from both @se and its parent cfs_rq.

Fixes: 7ceb77103001 ("sched/pelt: Continue to relax the sync of util_sum with util_avg")
Suggested-by: Vincent Guittot <vincent.guittot@linaro.org>
Cc: stable@vger.kernel.org
Signed-off-by: Peng Huang <penghuang@google.com>
---
 kernel/sched/fair.c | 35 +++++++++++++++++++++++++++--------
 1 file changed, 27 insertions(+), 8 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 0c8af1cac2d5..f6c3bbb19557 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -5516,9 +5516,15 @@ update_tg_cfs_util(struct cfs_rq *cfs_rq, struct sched_entity *se, struct cfs_rq
 	long delta_sum, delta_avg = gcfs_rq->avg.util_avg - se->avg.util_avg;
 	u32 new_sum, divider;
 
-	/* Nothing to update */
-	if (!delta_avg)
-		return;
+	if (delta_avg == 0) {
+		/* Keep util_sum as-is for unchanged non-zero avg */
+		if (gcfs_rq->avg.util_avg != 0)
+			return;
+
+		/* Nothing to clear once se->avg.util_sum is also 0 */
+		if (se->avg.util_sum == 0)
+			return;
+	}
 
 	/*
 	 * cfs_rq->avg.period_contrib can be used for both cfs_rq and se.
@@ -5543,9 +5549,15 @@ update_tg_cfs_runnable(struct cfs_rq *cfs_rq, struct sched_entity *se, struct cf
 	u64 new_sum;
 	u32 divider;
 
-	/* Nothing to update */
-	if (!delta_avg)
-		return;
+	if (delta_avg == 0) {
+		/* Keep runnable_sum as-is for unchanged non-zero avg */
+		if (gcfs_rq->avg.runnable_avg != 0)
+			return;
+
+		/* Nothing to clear once se->avg.runnable_sum is 0 */
+		if (se->avg.runnable_sum == 0)
+			return;
+	}
 
 	/*
 	 * cfs_rq->avg.period_contrib can be used for both cfs_rq and se.
@@ -5617,8 +5629,15 @@ update_tg_cfs_load(struct cfs_rq *cfs_rq, struct sched_entity *se, struct cfs_rq
 	load_avg = div_u64(load_sum, divider);
 
 	delta_avg = load_avg - se->avg.load_avg;
-	if (!delta_avg)
-		return;
+	if (delta_avg == 0) {
+		/* Keep load_sum as-is while child load is non-zero */
+		if (load_sum != 0)
+			return;
+
+		/* Nothing to clear once se->avg.load_sum is also 0 */
+		if (se->avg.load_sum == 0)
+			return;
+	}
 
 	delta_sum = load_sum - (s64)se_weight(se) * se->avg.load_sum;
 
-- 
2.56.1.831.g720f3f5937-goog


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

* [PATCH v2 2/2] sched_ext, sched/fair: Drain blocked load on scx_switched_all
  2026-11-23 20:13 ` [PATCH v2 0/2] sched_ext, sched/fair: Drain blocked fair load on scx_switched_all Peng Huang
  2026-11-23 20:13   ` [PATCH v2 1/2] sched/fair: Clear residual sums on zero task-group avg propagation Peng Huang
@ 2026-11-23 20:13   ` Peng Huang
  1 sibling, 0 replies; 8+ messages in thread
From: Peng Huang @ 2026-11-23 20:13 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Tejun Heo, David Vernet, Andrea Righi, Changwoo Min
  Cc: Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider, K Prateek Nayak, linux-kernel, sched-ext,
	stable, Peng Huang

Tasks that exit or migrate while sleeping queue their PELT load and
utilization in cfs_rq->removed rather than deducting and propagating
immediately. When scx_enable() switches all fair tasks to sched_ext,
switched_from_fair() only visits cfs_rq chains that still hold live
fair tasks, leaving unvisited leaf cfs_rqs undrained in rq->cfs.avg.

Once __scx_switched_all is enabled, scheduler_tick() skips
sched_balance_trigger() and fair_sched_class is bypassed, freezing
blocked-load updates. Stale rq->cfs.avg.util_sum can then combine with
active RT/DL util_sum in update_idle_rq_clock_pelt() to exceed divider,
inflating rq->lost_idle_time and stalling rq_clock_pelt().

Export __sched_balance_update_blocked_averages() and call it on each
CPU in scx_enable()'s per-CPU scx_switched_all() loop so pending
cfs_rq->removed entries and task-group propagations are drained cleanly.

Fixes: f0e1a0643a59 ("sched_ext: Implement BPF extensible scheduler class")
Suggested-by: Vincent Guittot <vincent.guittot@linaro.org>
Cc: stable@vger.kernel.org
Signed-off-by: Peng Huang <penghuang@google.com>
---
 kernel/sched/ext/ext.c | 9 ++++-----
 kernel/sched/fair.c    | 7 ++++++-
 kernel/sched/sched.h   | 1 +
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
index 10de6bd865e8..f7c573092e17 100644
--- a/kernel/sched/ext/ext.c
+++ b/kernel/sched/ext/ext.c
@@ -9013,11 +9013,9 @@ static void scx_root_enable_workfn(struct kthread_work *work)
 		static_branch_enable(&__scx_switched_all);
 
 	/*
-	 * Detach the fair_server bandwidth reservation now that the switch
-	 * is fully committed. In full mode (!SCX_OPS_SWITCH_PARTIAL) no
-	 * task will ever run in the fair class, so give that bandwidth
-	 * back to the RT class. The matching ext_server attach already
-	 * happened earlier; this only releases bandwidth and cannot fail.
+	 * Detach the fair_server bandwidth reservation and drain any
+	 * remaining blocked or removed fair load now that the switch is
+	 * fully committed and periodic fair blocked-load updates stop.
 	 *
 	 * In partial mode keep fair_server attached.
 	 */
@@ -9028,6 +9026,7 @@ static void scx_root_enable_workfn(struct kthread_work *work)
 			guard(rq_lock_irqsave)(rq);
 			update_rq_clock(rq);
 			dl_server_detach_bw(&rq->fair_server);
+			__sched_balance_update_blocked_averages(rq);
 		}
 	}
 
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index f6c3bbb19557..f19f498e01a4 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -11655,10 +11655,15 @@ static unsigned long task_h_load(struct task_struct *p)
 }
 #endif /* !CONFIG_FAIR_GROUP_SCHED */
 
-static void __sched_balance_update_blocked_averages(struct rq *rq)
+/*
+ * Update blocked PELT averages for RT/DL/IRQ and fair cfs_rqs on @rq.
+ * Caller must hold @rq's lock and have updated @rq's clock.
+ */
+void __sched_balance_update_blocked_averages(struct rq *rq)
 {
 	bool decayed = false, done = true;
 
+	lockdep_assert_rq_held(rq);
 	update_blocked_load_tick(rq);
 
 	decayed |= __update_blocked_others(rq, &done);
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 220927453a88..71a69f90e5df 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -2977,6 +2977,7 @@ extern struct task_struct *pick_task_idle(struct rq *rq, struct rq_flags *rf);
 extern void update_group_capacity(struct sched_domain *sd, int cpu);
 
 extern void sched_balance_trigger(struct rq *rq);
+void __sched_balance_update_blocked_averages(struct rq *rq);
 
 extern int __set_cpus_allowed_ptr(struct task_struct *p, struct affinity_context *ctx);
 extern void set_cpus_allowed_common(struct task_struct *p, struct affinity_context *ctx);
-- 
2.56.1.831.g720f3f5937-goog


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

* Re: [PATCH] sched/pelt: Skip dormant cfs util_sum under scx_switched_all
  2026-11-23 17:07     ` Vincent Guittot
@ 2026-11-23 20:14       ` Peng Huang
  0 siblings, 0 replies; 8+ messages in thread
From: Peng Huang @ 2026-11-23 20:14 UTC (permalink / raw)
  To: Vincent Guittot
  Cc: Peng Huang, Ingo Molnar, Peter Zijlstra, Juri Lelli,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider, K Prateek Nayak, Tejun Heo, David Vernet,
	Andrea Righi, Changwoo Min, linux-kernel, sched-ext, stable

On Mon, 23 Nov 2026 at 18:07, Vincent Guittot
<vincent.guittot@linaro.org> wrote:
>
> Yes this seems a better solution but It would be good to reuse
> __update_blocked_fair() which already does the work for pelt signal.
> Regarding your issue with util_avg == 0 whereas we still have a
> util_sum != 0, we can use delta_sum = gcfs_rq->avg.util_sum -
> se->avg.util_sum; in update_tg_cfs_util() instead. When util_avg == 0
> we will be sure to clear util_sum too

Thanks for the suggestions, Vincent!

One small detail in update_tg_cfs_util(): under CONFIG_CFS_BANDWIDTH,
gcfs_rq and its parent cfs_rq can have different period_contrib, so for
non-zero util_avg we still want new_sum = se->avg.util_avg * divider
using the parent cfs_rq's divider. Keeping that calculation while only
skipping the update when gcfs_rq->avg.util_avg != 0 or
se->avg.util_sum == 0 preserves period_contrib alignment and clears
residual _sum whenever util_avg reaches 0 (and similarly in
update_tg_cfs_{runnable,load}()).

I have sent out a 2-patch v2 series implementing this along with reusing
__sched_balance_update_blocked_averages() in scx_enable():
  [PATCH v2 0/2] sched_ext, sched/fair: Drain blocked fair load on scx_switched_all

Thanks,
Peng

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

end of thread, other threads:[~2026-11-23 20:14 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-22  1:57 [PATCH] sched/pelt: Skip dormant cfs util_sum under scx_switched_all Peng Huang
2026-11-23 10:34 ` Vincent Guittot
2026-11-23 16:09   ` Peng Huang
2026-11-23 17:07     ` Vincent Guittot
2026-11-23 20:14       ` Peng Huang
2026-11-23 20:13 ` [PATCH v2 0/2] sched_ext, sched/fair: Drain blocked fair load on scx_switched_all Peng Huang
2026-11-23 20:13   ` [PATCH v2 1/2] sched/fair: Clear residual sums on zero task-group avg propagation Peng Huang
2026-11-23 20:13   ` [PATCH v2 2/2] sched_ext, sched/fair: Drain blocked load on scx_switched_all Peng Huang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).