[PATCH 1/9] tools/sched_ext: scx_flatcg: Reset the stats baseline on restart

From: Tao Cui

Date: Tue Nov 10 2026 - 07:55:23 EST


From: Tao Cui <cuitao@xxxxxxxxxx>

last_stats holds the previous accumulator snapshot for the stats
deltas and is initialized before the restart: label. A hotplug
fail-safe reload starts the scheduler with fresh counters while
last_stats still carries the previous generation's snapshots, so the
first stats interval prints u64-underflow garbage.

Reset it together with the rest of the reload state. last_cpu_sum and
last_cpu_idle anchor to /proc/stat which persists across reloads and
are intentionally left alone.

Fixes: a4103eacc2ab ("sched_ext: Add a cgroup scheduler which uses flattened hierarchy")
Signed-off-by: Tao Cui <cuitao@xxxxxxxxxx>
---
tools/sched_ext/scx_flatcg.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/tools/sched_ext/scx_flatcg.c b/tools/sched_ext/scx_flatcg.c
index a223bff3746a..4c3c2cca2b85 100644
--- a/tools/sched_ext/scx_flatcg.c
+++ b/tools/sched_ext/scx_flatcg.c
@@ -140,6 +140,7 @@ int main(int argc, char **argv)
signal(SIGINT, sigint_handler);
signal(SIGTERM, sigint_handler);
restart:
+ memset(last_stats, 0, sizeof(last_stats));
optind = 1;
skel = SCX_OPS_OPEN(flatcg_ops, scx_flatcg);

--
2.53.0

base-commit: 5b740a72b55c4267ba4d8010f17dde26b26f52d3