Re: [RFC PATCH] perf/x86/rapl: Fix a bug caused by overflow timer being calculated using a 200W Max TDP
From: Borislav Petkov
Date: Wed Nov 11 2026 - 19:01:21 EST
On Wed, Nov 11, 2026 at 03:10:50PM +0000, Dhruv Gupta wrote:
> The RAPL energy status counters are 32 bits wide, so the PMU uses an
> hrtimer to fold them into the 64-bit event count before they can wrap.
> rapl_event_update() sign-extends the 32-bit difference between two
> reads, so the counter must advance by less than half of its range
> between updates. A larger advance is treated as a negative delta and
> the event count goes backwards by 2^32 counter units.
>
> The timer interval is the time it takes to use half the counter range
> at a reference power of 200W. Any package that sustains more than 200W
> between two expirations therefore loses energy. This applies to every
> energy unit, since the interval scales with it: with 2^-16 J units the
> interval is 163.84s and at most 32768 J can be accounted per interval,
> and with 2^-14 J units it is 655.36s with the same 200W limit. Many
> current server processors draw more than that under load.
>
> On an AMD EPYC 9654 (max default TDP 360W) running stress-ng on all
> CPUs, the package draws about 346W, or about 56 kJ per 163.84s
> interval. Over an 1100s run, "perf stat -a -e power/energy-pkg/"
> reported 4294882289.81 Joules, i.e. -85006 J, while reading the same
> event every second with "perf stat -I 1000" gave 373745.7 J. The
> difference is 458752 J, exactly seven wraps of the 65536 J counter.
>
> This patch raises the reference power to 1000W. With 2^-16 J units the
> interval becomes 32.768s, and with 2^-14 J units 131.072s. The cost is
> one MSR read per active event per package per interval.
>
> With this change, the same workload run for 300s reports 104062.71 J
> with plain "perf stat" and 104062.7 J with "perf stat -I 1000".
>
> Additionally this patch drops the hw-unit check and the 1ms fallback. The
Avoid having "This patch" or "This commit" in the commit message. It is
tautologically useless.
Also, do
$ git grep 'This patch' Documentation/process
for more details.
Please read:
https://docs.kernel.org/process/maintainer-tip.html
before submitting tip patches.
Thx.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette