Skip to content

Commit 26096ae

Browse files
dhananjay-AMDrafaeljw
authored andcommitted
powercap/intel_rapl: Fix the energy-pkg event for AMD CPUs
After commit ("x86/cpu/topology: Add support for the AMD 0x80000026 leaf"), on AMD processors that support extended CPUID leaf 0x80000026, the topology_logical_die_id() macros, no longer returns package id, instead it returns the CCD (Core Complex Die) id. This leads to the energy-pkg event scope to be modified to CCD instead of package. For more historical context, please refer to commit 32fb480 ("powercap/intel_rapl: Support multi-die/package"), which initially changed the RAPL scope from package to die for all systems, as Intel systems with Die enumeration have RAPL scope as die, and those without die enumeration are not affected. So, all systems(Intel, AMD, Hygon), worked correctly with topology_logical_die_id() until recently, but this changed after the "0x80000026 leaf" commit mentioned above. Future multi-die Intel systems will have package scope RAPL counters, but they will be using TPMI RAPL interface, which is not affected by this change. Replacing topology_logical_die_id() with topology_physical_package_id() conditionally only for AMD and Hygon fixes the energy-pkg event. On an AMD 2 socket 8 CCD Zen4 server: Before: linux$ ls /sys/class/powercap/ intel-rapl intel-rapl:4 intel-rapl:8:0 intel-rapl:d intel-rapl:0 intel-rapl:4:0 intel-rapl:9 intel-rapl:d:0 intel-rapl:0:0 intel-rapl:5 intel-rapl:9:0 intel-rapl:e intel-rapl:1 intel-rapl:5:0 intel-rapl:a intel-rapl:e:0 intel-rapl:1:0 intel-rapl:6 intel-rapl:a:0 intel-rapl:f intel-rapl:2 intel-rapl:6:0 intel-rapl:b intel-rapl:f:0 intel-rapl:2:0 intel-rapl:7 intel-rapl:b:0 intel-rapl:3 intel-rapl:7:0 intel-rapl:c intel-rapl:3:0 intel-rapl:8 intel-rapl:c:0 After: linux$ ls /sys/class/powercap/ intel-rapl intel-rapl:0 intel-rapl:0:0 intel-rapl:1 intel-rapl:1:0 Only one sysfs entry per-event per-package is created after this change. Fixes: 63edbaa ("x86/cpu/topology: Add support for the AMD 0x80000026 leaf") Reported-by: Michael Larabel <[email protected]> Signed-off-by: Dhananjay Ugwekar <[email protected]> Reviewed-by: Zhang Rui <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 166df51 commit 26096ae

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

drivers/powercap/intel_rapl_common.c

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2129,15 +2129,36 @@ void rapl_remove_package(struct rapl_package *rp)
21292129
}
21302130
EXPORT_SYMBOL_GPL(rapl_remove_package);
21312131

2132+
/*
2133+
* RAPL Package energy counter scope:
2134+
* 1. AMD/HYGON platforms use per-PKG package energy counter
2135+
* 2. For Intel platforms
2136+
* 2.1 CLX-AP platform has per-DIE package energy counter
2137+
* 2.2 Other platforms that uses MSR RAPL are single die systems so the
2138+
* package energy counter can be considered as per-PKG/per-DIE,
2139+
* here it is considered as per-DIE.
2140+
* 2.3 New platforms that use TPMI RAPL doesn't care about the
2141+
* scope because they are not MSR/CPU based.
2142+
*/
2143+
#define rapl_msrs_are_pkg_scope() \
2144+
(boot_cpu_data.x86_vendor == X86_VENDOR_AMD || \
2145+
boot_cpu_data.x86_vendor == X86_VENDOR_HYGON)
2146+
21322147
/* caller to ensure CPU hotplug lock is held */
21332148
struct rapl_package *rapl_find_package_domain_cpuslocked(int id, struct rapl_if_priv *priv,
21342149
bool id_is_cpu)
21352150
{
21362151
struct rapl_package *rp;
21372152
int uid;
21382153

2139-
if (id_is_cpu)
2140-
uid = topology_logical_die_id(id);
2154+
if (id_is_cpu) {
2155+
uid = rapl_msrs_are_pkg_scope() ?
2156+
topology_physical_package_id(id) : topology_logical_die_id(id);
2157+
if (uid < 0) {
2158+
pr_err("topology_logical_(package/die)_id() returned a negative value");
2159+
return ERR_PTR(-EINVAL);
2160+
}
2161+
}
21412162
else
21422163
uid = id;
21432164

@@ -2169,9 +2190,14 @@ struct rapl_package *rapl_add_package_cpuslocked(int id, struct rapl_if_priv *pr
21692190
return ERR_PTR(-ENOMEM);
21702191

21712192
if (id_is_cpu) {
2172-
rp->id = topology_logical_die_id(id);
2193+
rp->id = rapl_msrs_are_pkg_scope() ?
2194+
topology_physical_package_id(id) : topology_logical_die_id(id);
2195+
if ((int)(rp->id) < 0) {
2196+
pr_err("topology_logical_(package/die)_id() returned a negative value");
2197+
return ERR_PTR(-EINVAL);
2198+
}
21732199
rp->lead_cpu = id;
2174-
if (topology_max_dies_per_package() > 1)
2200+
if (!rapl_msrs_are_pkg_scope() && topology_max_dies_per_package() > 1)
21752201
snprintf(rp->name, PACKAGE_DOMAIN_NAME_LENGTH, "package-%d-die-%d",
21762202
topology_physical_package_id(id), topology_die_id(id));
21772203
else

0 commit comments

Comments
 (0)