Re: [PATCH] cpufreq: cppc: Reduce cppc delivered perf sampling jitter
From: Breno Leitao
Date: Thu Jun 04 2026 - 05:42:30 EST
On Tue, Jun 02, 2026 at 04:20:52PM -0500, Jeremy Linton wrote:
> CPPC uses a pair of registers cycling at different frequencies to
> determine an accumulated performance level. For userspace reporting we
> want to convert this to an instantaneous CPU frequency, but over short
> time periods small errors caused by CPPC counter reads can cause
> fairly significant reported frequency variations even when the core
> CPU clock isn't changing.
>
> Reduce this by keeping a start sample fixed and retrying the end
> sample until the counter deltas are large enough to reduce short
> window error, or until adjacent delivered performance estimates are
> within the CPU's observed CPPC read noise floor.
>
> To begin, resample the initial pair a small fixed number of times
> looking for matching delivered performance deltas. This reduces the
> chance that a disturbed start sample anchors the rest of the
> calculation.
>
> Then look for an end sample while updating the noise floor from the
> best error seen between samples. The floor remains zero on systems
> with stable feedback reads, but lets noisy systems stop early once
> another retry is unlikely to improve the result. The retry loop is
> capped at 200 iterations, giving an ~20 usec explicit delay budget
> derived from ndelay(100).
>
> Signed-off-by: Jeremy Linton <jeremy.linton@xxxxxxx>
Tested-by: Breno Leitao <leitao@xxxxxxxxxx>
I've tested this on my grace host, checking "cat
/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq" thousand times,
and the result is quite good, reducing the Std Dev by 5x, and getting
a better value.
# cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq
3339000
Baseline:
Average: 3505050.00
P50 (Median): 3388500.00
Std Dev: 462607.66
Min: 2709000.00
Max: 4464000.00
Wth this patch:
Average: 2393550.00
P50 (Median): 2394000.00
Std Dev: 68629.06
Min: 2241000.00
Max: 2529000.00
Thanks,
--breno