Re: [PATCH v2 1/2] sched/fair: Clear residual sums on zero task-group avg propagation
From: Vincent Guittot
Date: Tue Nov 24 2026 - 05:23:21 EST
On Mon, 23 Nov 2026 at 21:13, Peng Huang <penghuang@xxxxxxxxxx> wrote:
>
> 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.
When fair tasks are involved, the next decays will clear the *_sum
anyway so I suggest to skip this patch if it's not needed for
scx_switched_all() case
>
> Fixes: 7ceb77103001 ("sched/pelt: Continue to relax the sync of util_sum with util_avg")
> Suggested-by: Vincent Guittot <vincent.guittot@xxxxxxxxxx>
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Peng Huang <penghuang@xxxxxxxxxx>
> ---
> 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
>