From 42623ee70852d0677c804f3c67d1e73ae5ac1ac9 Mon Sep 17 00:00:00 2001 From: Stephane Eranian Date: Wed, 27 May 2020 15:46:59 -0700 Subject: [PATCH 2656/2944] perf/x86/rapl: Add AMD Fam17h RAPL support to #33635199 commit 5cde265384cad739b162cf08afba6da8857778bd upstream 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/ [ Artie: fixes conflicts in: arch/x86/events/rapl.c ] Signed-off-by: Stephane Eranian Signed-off-by: Ingo Molnar Link: https://lore.kernel.org/r/20200527224659.206129-6-eranian@google.com Signed-off-by: Artie Ding Reviewed-by: Zelin Deng Reviewed-by: Shile Zhang Reviewed-by: Baolin Wang --- arch/x86/events/rapl.c | 18 ++++++++++++++++++ arch/x86/include/asm/msr-index.h | 3 +++ 2 files changed, 21 insertions(+) diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c index a46c94f..c43cf29 100644 --- a/arch/x86/events/rapl.c +++ b/arch/x86/events/rapl.c @@ -528,6 +528,16 @@ static bool test_msr(int idx, void *data) [PERF_RAPL_PSYS] = { MSR_PLATFORM_ENERGY_STATUS, &rapl_events_psys_group, test_msr }, }; +/* + * Force to PERF_RAPL_MAX size due to: + * - perf_msr_probe(PERF_RAPL_MAX) + * - want to use same event codes across both architectures + */ +static struct perf_msr amd_rapl_msrs[PERF_RAPL_MAX] = { + [PERF_RAPL_PKG] = { MSR_AMD_PKG_ENERGY_STATUS, &rapl_events_pkg_group, test_msr }, +}; + + static int rapl_cpu_offline(unsigned int cpu) { struct rapl_pmu *pmu = cpu_to_rapl_pmu(cpu); @@ -733,6 +743,13 @@ static int __init init_rapl_pmus(void) .rapl_msrs = intel_rapl_msrs, }; +static struct rapl_model model_amd_fam17h = { + .events = BIT(PERF_RAPL_PKG), + .apply_quirk = false, + .msr_power_unit = MSR_AMD_RAPL_POWER_UNIT, + .rapl_msrs = amd_rapl_msrs, +}; + static const struct x86_cpu_id rapl_model_match[] __initconst = { X86_RAPL_MODEL_MATCH(INTEL_FAM6_SANDYBRIDGE, model_snb), X86_RAPL_MODEL_MATCH(INTEL_FAM6_SANDYBRIDGE_X, model_snbep), @@ -760,6 +777,7 @@ static int __init init_rapl_pmus(void) X86_RAPL_MODEL_MATCH(INTEL_FAM6_ICELAKE_MOBILE, model_skl), X86_RAPL_MODEL_MATCH(INTEL_FAM6_ICELAKE_XEON_D, model_hsx), X86_RAPL_MODEL_MATCH(INTEL_FAM6_ICELAKE_X, model_hsx), + X86_MATCH_VENDOR_FAM(AMD, 0x17, &model_amd_fam17h), {}, }; diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h index f03ab77..6d93d70 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -250,6 +250,9 @@ #define MSR_PP1_ENERGY_STATUS 0x00000641 #define MSR_PP1_POLICY 0x00000642 +#define MSR_AMD_PKG_ENERGY_STATUS 0xc001029b +#define MSR_AMD_RAPL_POWER_UNIT 0xc0010299 + /* Config TDP MSRs */ #define MSR_CONFIG_TDP_NOMINAL 0x00000648 #define MSR_CONFIG_TDP_LEVEL_1 0x00000649 -- 1.8.3.1