linux/kernel/sched
Johannes Weiner 3840cbe24c sched: psi: fix bogus pressure spikes from aggregation race
Brandon reports sporadic, non-sensical spikes in cumulative pressure
time (total=) when reading cpu.pressure at a high rate. This is due to
a race condition between reader aggregation and tasks changing states.

While it affects all states and all resources captured by PSI, in
practice it most likely triggers with CPU pressure, since scheduling
events are so frequent compared to other resource events.

The race context is the live snooping of ongoing stalls during a
pressure read. The read aggregates per-cpu records for stalls that
have concluded, but will also incorporate ad-hoc the duration of any
active state that hasn't been recorded yet. This is important to get
timely measurements of ongoing stalls. Those ad-hoc samples are
calculated on-the-fly up to the current time on that CPU; since the
stall hasn't concluded, it's expected that this is the minimum amount
of stall time that will enter the per-cpu records once it does.

The problem is that the path that concludes the state uses a CPU clock
read that is not synchronized against aggregators; the clock is read
outside of the seqlock protection. This allows aggregators to race and
snoop a stall with a longer duration than will actually be recorded.

With the recorded stall time being less than the last snapshot
remembered by the aggregator, a subsequent sample will underflow and
observe a bogus delta value, resulting in an erratic jump in pressure.

Fix this by moving the clock read of the state change into the seqlock
protection. This ensures no aggregation can snoop live stalls past the
time that's recorded when the state concludes.

Reported-by: Brandon Duffany <brandon@buildbuddy.io>
Link: https://bugzilla.kernel.org/show_bug.cgi?id=219194
Link: https://lore.kernel.org/lkml/20240827121851.GB438928@cmpxchg.org/
Fixes: df77430639 ("psi: Reduce calls to sched_clock() in psi")
Cc: stable@vger.kernel.org
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Chengming Zhou <chengming.zhou@linux.dev>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2024-10-03 16:03:16 -07:00
..
autogroup.c
autogroup.h
build_policy.c
build_utility.c
clock.c
completion.c
core.c sched, sched_ext: Disable SM_IDLE/rq empty path when scx_enabled() 2024-09-23 05:40:53 -10:00
core_sched.c
cpuacct.c
cpudeadline.c
cpudeadline.h
cpufreq.c
cpufreq_schedutil.c
cpupri.c
cpupri.h
cputime.c
deadline.c
debug.c
ext.c sched_ext: Remove redundant p->nr_cpus_allowed checker 2024-09-27 10:23:45 -10:00
ext.h
fair.c sched_ext: Initial pull request for v6.12 2024-09-21 09:44:57 -07:00
features.h
idle.c
isolation.c
loadavg.c
Makefile
membarrier.c
pelt.c
pelt.h
psi.c sched: psi: fix bogus pressure spikes from aggregation race 2024-10-03 16:03:16 -07:00
rt.c
sched-pelt.h
sched.h sched: Put task_group::idle under CONFIG_GROUP_SCHED_WEIGHT 2024-09-23 05:24:12 -10:00
smp.h
stats.c
stats.h
stop_task.c
swait.c
syscalls.c sched_ext: Initial pull request for v6.12 2024-09-21 09:44:57 -07:00
topology.c
wait.c
wait_bit.c