Skip to content

Commit 5cde265

Browse files
Stephane EranianIngo Molnar
authored andcommitted
perf/x86/rapl: Add AMD Fam17h RAPL support
This patch enables AMD Fam17h RAPL support for the Package level metric. The support is as per AMD Fam17h Model31h (Zen2) and model 00-ffh (Zen1) PPR. The same output is available via the energy-pkg pseudo event: $ perf stat -a -I 1000 --per-socket -e power/energy-pkg/ Signed-off-by: Stephane Eranian <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 4c953f8 commit 5cde265

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

arch/x86/events/rapl.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,16 @@ static struct perf_msr intel_rapl_msrs[] = {
537537
[PERF_RAPL_PSYS] = { MSR_PLATFORM_ENERGY_STATUS, &rapl_events_psys_group, test_msr },
538538
};
539539

540+
/*
541+
* Force to PERF_RAPL_MAX size due to:
542+
* - perf_msr_probe(PERF_RAPL_MAX)
543+
* - want to use same event codes across both architectures
544+
*/
545+
static struct perf_msr amd_rapl_msrs[PERF_RAPL_MAX] = {
546+
[PERF_RAPL_PKG] = { MSR_AMD_PKG_ENERGY_STATUS, &rapl_events_pkg_group, test_msr },
547+
};
548+
549+
540550
static int rapl_cpu_offline(unsigned int cpu)
541551
{
542552
struct rapl_pmu *pmu = cpu_to_rapl_pmu(cpu);
@@ -740,6 +750,13 @@ static struct rapl_model model_skl = {
740750
.rapl_msrs = intel_rapl_msrs,
741751
};
742752

753+
static struct rapl_model model_amd_fam17h = {
754+
.events = BIT(PERF_RAPL_PKG),
755+
.apply_quirk = false,
756+
.msr_power_unit = MSR_AMD_RAPL_POWER_UNIT,
757+
.rapl_msrs = amd_rapl_msrs,
758+
};
759+
743760
static const struct x86_cpu_id rapl_model_match[] __initconst = {
744761
X86_MATCH_INTEL_FAM6_MODEL(SANDYBRIDGE, &model_snb),
745762
X86_MATCH_INTEL_FAM6_MODEL(SANDYBRIDGE_X, &model_snbep),
@@ -770,6 +787,7 @@ static const struct x86_cpu_id rapl_model_match[] __initconst = {
770787
X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_X, &model_hsx),
771788
X86_MATCH_INTEL_FAM6_MODEL(COMETLAKE_L, &model_skl),
772789
X86_MATCH_INTEL_FAM6_MODEL(COMETLAKE, &model_skl),
790+
X86_MATCH_VENDOR_FAM(AMD, 0x17, &model_amd_fam17h),
773791
{},
774792
};
775793
MODULE_DEVICE_TABLE(x86cpu, rapl_model_match);

arch/x86/include/asm/msr-index.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,9 @@
301301
#define MSR_PP1_ENERGY_STATUS 0x00000641
302302
#define MSR_PP1_POLICY 0x00000642
303303

304+
#define MSR_AMD_PKG_ENERGY_STATUS 0xc001029b
305+
#define MSR_AMD_RAPL_POWER_UNIT 0xc0010299
306+
304307
/* Config TDP MSRs */
305308
#define MSR_CONFIG_TDP_NOMINAL 0x00000648
306309
#define MSR_CONFIG_TDP_LEVEL_1 0x00000649

0 commit comments

Comments
 (0)