mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] sched/pelt: Fix truncation of the PELT period count
@ 2026-10-23  2:52 Hui Su
  2026-10-23  3:22 ` K Prateek Nayak
  2026-11-06  9:50 ` [tip: sched/urgent] sched/pelt: Fix u32 " tip-bot2 for Hui Su
  0 siblings, 2 replies; 3+ messages in thread
From: Hui Su @ 2026-10-23  2:52 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, Kayra Cizmeci, 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 the period count as u64 so the caller can test it without
truncation.

Fixes: a481db34b9be ("sched/fair: Optimize ___update_sched_avg()")
Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org>
Reviewed-by: Kayra Cizmeci <kayracizmeci@gmail.com>
Signed-off-by: Hui Su <sh_def@163.com>
---
Changes in v2:
- Return the PELT period count as u64.
- Add the Fixes tag and Kayra Cizmeci's Reviewed-by.

v1: https://lore.kernel.org/lkml/20261022034930.225042-1-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..d10d57b6b8ec 100644
--- a/kernel/sched/pelt.c
+++ b/kernel/sched/pelt.c
@@ -99,7 +99,7 @@ static u32 __accumulate_pelt_segments(u64 periods, u32 d1, u32 d3)
  *      d1 y^p + 1024 \Sum y^n + d3 y^0		(Step 2)
  *                     n=1
  */
-static __always_inline u32
+static __always_inline u64
 accumulate_sum(u64 delta, struct sched_avg *sa,
 	       unsigned long load, unsigned long runnable, int running)
 {

base-commit: a804c5742bff224d4cb4d25dd383554d598be32b
-- 
2.55.0


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

* Re: [PATCH v2] sched/pelt: Fix truncation of the PELT period count
  2026-10-23  2:52 [PATCH v2] sched/pelt: Fix truncation of the PELT period count Hui Su
@ 2026-10-23  3:22 ` K Prateek Nayak
  2026-11-06  9:50 ` [tip: sched/urgent] sched/pelt: Fix u32 " tip-bot2 for Hui Su
  1 sibling, 0 replies; 3+ messages in thread
From: K Prateek Nayak @ 2026-10-23  3:22 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, Kayra Cizmeci, linux-kernel

Hello Hui,

On 10/23/2026 8:22 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
> 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 the period count as u64 so the caller can test it without
> truncation.
> 
> Fixes: a481db34b9be ("sched/fair: Optimize ___update_sched_avg()")
> Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org>
> Reviewed-by: Kayra Cizmeci <kayracizmeci@gmail.com>
> Signed-off-by: Hui Su <sh_def@163.com>

Feel free to include:

Reviewed-by: K Prateek Nayak <kprateek.nayak@amd.com>

> ---
> Changes in v2:
> - Return the PELT period count as u64.
> - Add the Fixes tag and Kayra Cizmeci's Reviewed-by.
> 
> v1: https://lore.kernel.org/lkml/20261022034930.225042-1-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..d10d57b6b8ec 100644
> --- a/kernel/sched/pelt.c
> +++ b/kernel/sched/pelt.c
> @@ -99,7 +99,7 @@ static u32 __accumulate_pelt_segments(u64 periods, u32 d1, u32 d3)
>   *      d1 y^p + 1024 \Sum y^n + d3 y^0		(Step 2)
>   *                     n=1
>   */
> -static __always_inline u32
> +static __always_inline u64
>  accumulate_sum(u64 delta, struct sched_avg *sa,
>  	       unsigned long load, unsigned long runnable, int running)
>  {
> 
> base-commit: a804c5742bff224d4cb4d25dd383554d598be32b

-- 
Thanks and Regards,
Prateek


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

* [tip: sched/urgent] sched/pelt: Fix u32 truncation of the PELT period count
  2026-10-23  2:52 [PATCH v2] sched/pelt: Fix truncation of the PELT period count Hui Su
  2026-10-23  3:22 ` K Prateek Nayak
@ 2026-11-06  9:50 ` tip-bot2 for Hui Su
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Hui Su @ 2026-11-06  9:50 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Hui Su, Peter Zijlstra (Intel),
	Ingo Molnar, Vincent Guittot, Kayra Cizmeci, x86, linux-kernel

The following commit has been merged into the sched/urgent branch of tip:

Commit-ID:     a0c755e574e37fddb59edf175f27dc3877e7fe23
Gitweb:        https://git.kernel.org/tip/a0c755e574e37fddb59edf175f27dc3877e7fe23
Author:        Hui Su <sh_def@163.com>
AuthorDate:    Fri, 23 Oct 2026 11:52:07 +09:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Fri, 06 Nov 2026 10:04:11 +01:00

sched/pelt: Fix u32 truncation of the PELT period count

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 the period count as u64 so the caller can test it without
truncation.

Fixes: a481db34b9be ("sched/fair: Optimize ___update_sched_avg()")
Signed-off-by: Hui Su <sh_def@163.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org>
Reviewed-by: Kayra Cizmeci <kayracizmeci@gmail.com>
Link: https://patch.msgid.link/20261023025207.2967903-1-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 779eb58..d10d57b 100644
--- a/kernel/sched/pelt.c
+++ b/kernel/sched/pelt.c
@@ -99,7 +99,7 @@ static u32 __accumulate_pelt_segments(u64 periods, u32 d1, u32 d3)
  *      d1 y^p + 1024 \Sum y^n + d3 y^0		(Step 2)
  *                     n=1
  */
-static __always_inline u32
+static __always_inline u64
 accumulate_sum(u64 delta, struct sched_avg *sa,
 	       unsigned long load, unsigned long runnable, int running)
 {

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

end of thread, other threads:[~2026-11-06  9:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-23  2:52 [PATCH v2] sched/pelt: Fix truncation of the PELT period count Hui Su
2026-10-23  3:22 ` K Prateek Nayak
2026-11-06  9:50 ` [tip: sched/urgent] sched/pelt: Fix u32 " tip-bot2 for 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®