Re: [PATCH] sched/pelt: Fix truncation of the PELT period count
From: Vincent Guittot
Date: Thu Oct 22 2026 - 04:41:07 EST
On Thu, 22 Oct 2026 at 10:35, K Prateek Nayak <kprateek.nayak@xxxxxxx> wrote:
>
> Hello Hui,
>
> On 10/22/2026 9:19 AM, Hui Su wrote:
> > accumulate_sum() computes the number of elapsed PELT periods in a
> > u64 but returns u32. When the count is a multiple of 2^32, it is
>
> So at least an hour between PELT updates! I suppose it is possible
> with nohz so not too far fetched.
Period is 1ms so it's more in the range of 50 days
>
> > truncated to zero even though the PELT sums have been updated.
> >
> > The caller interprets zero as no period boundary crossed and skips
> > recomputing the averages, leaving *_avg stale relative to *_sum.
> >
> > Return only whether any period elapsed, which is all the caller
> > needs.
> >
>
> Probably needs a:
>
> Fixes: a481db34b9be ("sched/fair: Optimize ___update_sched_avg()") # c079629862b2
>
> > Signed-off-by: Hui Su <sh_def@xxxxxxx>
> > ---
> > kernel/sched/pelt.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/kernel/sched/pelt.c b/kernel/sched/pelt.c
> > index 779eb58a4261..519bc9c40043 100644
> > --- a/kernel/sched/pelt.c
> > +++ b/kernel/sched/pelt.c
> > @@ -146,7 +146,7 @@ accumulate_sum(u64 delta, struct sched_avg *sa,
> > if (running)
> > sa->util_sum += contrib << SCHED_CAPACITY_SHIFT;
> >
> > - return periods;
> > + return !!periods;
>
> I would actually favor changing return type to u64. Since
> accumulate_sum() is only called in one place, and that too within an
> 'if' condition, I'm sure compiler can optimize it similarly.
>
> > }
> >
> > /*
>
> --
> Thanks and Regards,
> Prateek
>