mbox series

[0/2] Fix energy-pkg event for AMD CPUs

Message ID 20240502095115.177713-1-Dhananjay.Ugwekar@amd.com (mailing list archive)
Headers show
Series Fix energy-pkg event for AMD CPUs | expand

Message

Dhananjay Ugwekar May 2, 2024, 9:51 a.m. UTC
After commit 63edbaa48a57 ("x86/cpu/topology: Add support for the AMD 0x80000026 leaf"), 
on AMD processors that support extended CPUID leaf 0x80000026, the 
topology_die_cpumask() and topology_logical_die_id(), no longer return 
the package cpumask and package id, instead they return the CCD (Core 
Complex Die) mask and CCD id respectively. This leads to the energy-pkg 
event scope to be modified to CCD instead of package.

This is functionally incorrect as the AMD energy-pkg is a package scope 
event.

On a 12 CCD 1 Package AMD Zen4 Genoa machine:

$ cat /sys/devices/power/cpumask
0,8,16,24,32,40,48,56,64,72,80,88.

Expected cpumask for 1 Package AMD CPUs energy-pkg event is supposed to 
be just "0".

This in turn leads to incorrect values of package energy consumption.

$ perf stat -C 100 -e power/energy-pkg/ sleep 1

 Performance counter stats for 'CPU(s) 100':

             36.60 Joules power/energy-pkg/

       1.005821050 seconds time elapsed

$ perf stat -a -e power/energy-pkg/ sleep 1

 Performance counter stats for 'system wide':

            414.03 Joules power/energy-pkg/

       1.005252132 seconds time elapsed

In both cases the energy consumption values should have been the same,
but instead, due to the incorrect cpumask, the values are being
aggregated at a CCD level in the second case.

Replacing the die macros with the package macros(for AMD CPUs) fixes 
this issue. 

This patch cleanly applies on top of tip/master after
commit acf68d98cae8 ("perf/x86/rapl: Add support for Intel Lunar Lake"),
but not on Linus' tree.

Dhananjay Ugwekar (2):
  perf/x86/rapl: Rename maxdie to nr_rapl_pmu and dieid to rapl_pmu_idx
  perf/x86/rapl: Fix the energy-pkg event for AMD CPUs

 arch/x86/events/rapl.c | 44 +++++++++++++++++++++++++++++++-----------
 1 file changed, 33 insertions(+), 11 deletions(-)