Re: [PATCH] sched/pelt: Skip dormant cfs util_sum under scx_switched_all
From: Vincent Guittot
Date: Mon Nov 23 2026 - 12:08:01 EST
On Mon, 23 Nov 2026 at 17:09, Peng Huang <penghuang@xxxxxxxxxx> wrote:
>
> On Mon, 23 Nov 2026 at 11:34, Vincent Guittot <vincent.guittot@xxxxxxxxxx> 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