* [PATCH] sched/pelt: Fix truncation of the PELT period count
@ 2026-10-22 3:49 Hui Su
2026-10-22 8:34 ` K Prateek Nayak
2026-10-22 8:37 ` Vincent Guittot
0 siblings, 2 replies; 6+ messages in thread
From: Hui Su @ 2026-10-22 3:49 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, linux-kernel, Hui Su
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
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.
Signed-off-by: Hui Su <sh_def@163.com>
---
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;
}
/*
--
2.55.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] sched/pelt: Fix truncation of the PELT period count
2026-10-22 3:49 [PATCH] sched/pelt: Fix truncation of the PELT period count Hui Su
@ 2026-10-22 8:34 ` K Prateek Nayak
2026-10-22 8:39 ` Vincent Guittot
2026-10-22 9:37 ` Hui Su
2026-10-22 8:37 ` Vincent Guittot
1 sibling, 2 replies; 6+ messages in thread
From: K Prateek Nayak @ 2026-10-22 8:34 UTC (permalink / raw)
To: Hui Su, Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot
Cc: Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, linux-kernel
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.
> 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@163.com>
> ---
> 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
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] sched/pelt: Fix truncation of the PELT period count
2026-10-22 8:34 ` K Prateek Nayak
@ 2026-10-22 8:39 ` Vincent Guittot
2026-10-22 9:37 ` Hui Su
1 sibling, 0 replies; 6+ messages in thread
From: Vincent Guittot @ 2026-10-22 8:39 UTC (permalink / raw)
To: K Prateek Nayak
Cc: Hui Su, Ingo Molnar, Peter Zijlstra, Juri Lelli,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, linux-kernel
On Thu, 22 Oct 2026 at 10:35, K Prateek Nayak <kprateek.nayak@amd.com> 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@163.com>
> > ---
> > 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
>
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] sched/pelt: Fix truncation of the PELT period count
2026-10-22 8:34 ` K Prateek Nayak
2026-10-22 8:39 ` Vincent Guittot
@ 2026-10-22 9:37 ` Hui Su
1 sibling, 0 replies; 6+ messages in thread
From: Hui Su @ 2026-10-22 9:37 UTC (permalink / raw)
To: K Prateek Nayak
Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, linux-kernel
> Probably needs a:
>
> Fixes: a481db34b9be ("sched/fair: Optimize ___update_sched_avg()") # c079629862b2
>
> 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 for the review.
I will use a481db34b9be in v2's Fixes tag and change accumulate_sum() to return u64.
Thanks,
Hui
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] sched/pelt: Fix truncation of the PELT period count
2026-10-22 3:49 [PATCH] sched/pelt: Fix truncation of the PELT period count Hui Su
2026-10-22 8:34 ` K Prateek Nayak
@ 2026-10-22 8:37 ` Vincent Guittot
2026-10-22 9:37 ` Hui Su
1 sibling, 1 reply; 6+ messages in thread
From: Vincent Guittot @ 2026-10-22 8:37 UTC (permalink / raw)
To: Hui Su
Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Dietmar Eggemann,
Steven Rostedt, Ben Segall, Mel Gorman, Valentin Schneider,
K Prateek Nayak, linux-kernel
On Thu, 22 Oct 2026 at 05:50, Hui Su <sh_def@163.com> 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
> truncated to zero even though the PELT sums have been updated.
Did you face this problem, or did you find it only during a code review?
This would happen every multiple of exactly 2^32 ms (~50days) without
updating pelt whereas the latter is supposed to be updated far more
often (within second) until it reaches 0. Then such a large period
would keep it at 0 anyway
>
> 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.
>
> Signed-off-by: Hui Su <sh_def@163.com>
Even if I doubt it can happen, it's better to fix it anyway
Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org>
> ---
> 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;
> }
>
> /*
> --
> 2.55.0
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] sched/pelt: Fix truncation of the PELT period count
2026-10-22 8:37 ` Vincent Guittot
@ 2026-10-22 9:37 ` Hui Su
0 siblings, 0 replies; 6+ messages in thread
From: Hui Su @ 2026-10-22 9:37 UTC (permalink / raw)
To: Vincent Guittot
Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Dietmar Eggemann,
Steven Rostedt, Ben Segall, Mel Gorman, Valentin Schneider,
K Prateek Nayak, linux-kernel
On Thu, Oct 22, 2026, Vincent Guittot wrote:
> Did you face this problem, or did you find it only during a code review?
I found it during code review, not from a production failure.
I reproduced it with a KUnit test that advances PELT by exactly 2^32 periods.
Before the fix, util_avg remained 43 instead of 1024; after the fix, the test
passed. A standalone harness confirmed the same result.
Thanks for the review.
Thanks,
Hui
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-10-22 10:30 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-22 3:49 [PATCH] sched/pelt: Fix truncation of the PELT period count Hui Su
2026-10-22 8:34 ` K Prateek Nayak
2026-10-22 8:39 ` Vincent Guittot
2026-10-22 9:37 ` Hui Su
2026-10-22 8:37 ` Vincent Guittot
2026-10-22 9:37 ` Hui Su
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®