Skip to contentSkip to conversation

sched/pelt: Fix truncation of the PELT period count

PATCH Applied Hui Su 3 participants 3 messages Oct 23 – Nov 6 Scheduler

lore
Share & tools
lore

Hui Su

author
#0 lore raw

PATCH v2 1/1 sched/pelt: Fix 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()")

---
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/[email protected]/

 kernel/sched/pelt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/pelt.c +1 -1
index 779eb58a4261..d10d57b6b8ec 100644
@@ -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

Signature · 1 line
2.55.0
reviewer Reviewed-by on v2 1/1
#1 lore raw

Hello Hui,

Quoted 7 lines · 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.

Quoted 7 lines

Return the period count as u64 so the caller can test it without truncation.

Fixes a481db34b9be ("sched/fair: Optimize ___update_sched_avg()")

Feel free to include:

Quoted 25 lines

---
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/[email protected]/

 kernel/sched/pelt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/pelt.c +1 -1
index 779eb58a4261..d10d57b6b8ec 100644
@@ -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

Signature · 2 lines
Thanks and Regards,
Prateek
merge bot Applied
#2 lore raw

[tip: sched/urgent] sched/pelt: Fix u32 truncation of the PELT period count

In reply to Hui Su
The following commit has been merged into the sched/urgent branch of tip:

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 <[email protected]>
AuthorDate:    Fri, 23 Oct 2026 11:52:07 +09:00
Committer:     Ingo Molnar <[email protected]>
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.

---
 kernel/sched/pelt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/pelt.c +1 -1
index 779eb58..d10d57b 100644
@@ -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)
 {