perf/x86/rapl: Use CPUID bit on AMD and Hygon parts
Subsystems (3)
PATCH 1/1 perf/x86/rapl: Use CPUID bit on AMD and Hygon parts
AMD and Hygon CPUs have a CPUID bit for RAPL. Drop the fam17h suffix as it is stale already.
Make use of this instead of a model check to work more nicely in virtual environments where RAPL typically isn't available.
---
CC: Peter Zijlstra <[email protected]>
CC: Ingo Molnar <[email protected]>
CC: Arnaldo Carvalho de Melo <[email protected]>
CC: Mark Rutland <[email protected]>
CC: Alexander Shishkin <[email protected]>
CC: Jiri Olsa <[email protected]>
CC: Namhyung Kim <[email protected]>
CC: Thomas Gleixner <[email protected]>
CC: Borislav Petkov <[email protected]>
CC: [email protected]
CC: "H. Peter Anvin" <[email protected]>
CC: Pu Wen <[email protected]>
CC: Tom Lendacky <[email protected]>
CC: Yazen Ghannam <[email protected]>
CC: Joerg Roedel <[email protected]>
CC: [email protected]
--- arch/x86/events/rapl.c | 6 ++---- arch/x86/include/asm/cpufeatures.h | 2 +- arch/x86/kernel/cpu/amd.c | 4 ++++ arch/x86/kernel/cpu/hygon.c | 4 ++++ arch/x86/kernel/cpu/powerflags.c | 2 ++ 5 files changed, 13 insertions(+), 5 deletions(-)
arch/x86/events/rapl.c +2 -4
@@ -764,13 +764,14 @@ static struct rapl_model model_spr = { .rapl_msrs = intel_rapl_spr_msrs, }; -static struct rapl_model model_amd_fam17h = { +static struct rapl_model model_amd_hygon = { .events =BIT (PERF_RAPL_PKG ), .msr_power_unit =MSR_AMD_RAPL_POWER_UNIT , .rapl_msrs = amd_rapl_msrs, };static const struct x86_cpu_id rapl_model_match[]__initconst = { +X86_MATCH_FEATURE (X86_FEATURE_RAPL , &model_amd_hygon),X86_MATCH_INTEL_FAM6_MODEL (SANDYBRIDGE , &model_snb),X86_MATCH_INTEL_FAM6_MODEL (SANDYBRIDGE_X , &model_snbep),X86_MATCH_INTEL_FAM6_MODEL (IVYBRIDGE , &model_snb),
@@ -801,9 +802,6 @@ static const struct x86_cpu_id rapl_model_match[] __initconst = {X86_MATCH_INTEL_FAM6_MODEL (COMETLAKE_L , &model_skl),X86_MATCH_INTEL_FAM6_MODEL (COMETLAKE , &model_skl),X86_MATCH_INTEL_FAM6_MODEL (SAPPHIRERAPIDS_X , &model_spr), -X86_MATCH_VENDOR_FAM (AMD ,0x17 , &model_amd_fam17h), -X86_MATCH_VENDOR_FAM (HYGON ,0x18 , &model_amd_fam17h), - X86_MATCH_VENDOR_FAM(AMD, 0x19, &model_amd_fam17h), {}, };MODULE_DEVICE_TABLE (x86cpu, rapl_model_match);
arch/x86/include/asm/cpufeatures.h +1 -1
@@ -108,7 +108,7 @@#define X86_FEATURE_EXTD_APICID ( 3*32+26)/* Extended APICID (8 bits) */ #define X86_FEATURE_AMD_DCM ( 3*32+27)/* AMD multi-node processor */ #define X86_FEATURE_APERFMPERF ( 3*32+28)/* P-State hardware coordination feedback capability (APERF/MPERF MSRs) */ -/* free ( 3*32+29) */ +#define X86_FEATURE_RAPL ( 3*32+29)/* AMD/Hygon RAPL interface */ #define X86_FEATURE_NONSTOP_TSC_S3 ( 3*32+30)/* TSC doesn't stop in S3 state */ #define X86_FEATURE_TSC_KNOWN_FREQ ( 3*32+31)/* TSC has known frequency */
arch/x86/kernel/cpu/amd.c +4 -0
@@ -646,6 +646,10 @@ static void early_init_amd(struct cpuinfo_x86 *c)if (c->x86_power &BIT (12 ))set_cpu_cap (c,X86_FEATURE_ACC_POWER ); +/* Bit 14 indicates the Runtime Average Power Limit interface. */ +if (c->x86_power &BIT (14 )) +set_cpu_cap (c,X86_FEATURE_RAPL ); +#ifdef CONFIG_X86_64 set_cpu_cap (c,X86_FEATURE_SYSCALL32 );#else
arch/x86/kernel/cpu/hygon.c +4 -0
@@ -260,6 +260,10 @@ static void early_init_hygon(struct cpuinfo_x86 *c)if (c->x86_power &BIT (12 ))set_cpu_cap (c,X86_FEATURE_ACC_POWER ); +/* Bit 14 indicates the Runtime Average Power Limit interface. */ +if (c->x86_power &BIT (14 )) +set_cpu_cap (c,X86_FEATURE_RAPL ); +#ifdef CONFIG_X86_64 set_cpu_cap (c,X86_FEATURE_SYSCALL32 );#endif
arch/x86/kernel/cpu/powerflags.c +2 -0
@@ -21,4 +21,6 @@ const char *const x86_power_flags[32] = {"eff_freq_ro" ,/* Readonly aperf/mperf */ "proc_feedback" ,/* processor feedback interface */ "acc_power" ,/* accumulated power mechanism */ +"conn_standby" ,/* Connected Standby */ + "rapl", /* Runtime Average Power Limit */ };
Signature · 1 line
2.11.0
Borislav Petkov
maintainerarch/x86/kernel/cpu/powerflags.c const char *const x86_power_flags[32] = { · line 25
Quoted 10 lines · Andrew Cooper
arch/x86/kernel/cpu/powerflags.c +2
-0@@ -21,4 +21,6 @@ const char *const x86_power_flags[32] = {"eff_freq_ro" ,/* Readonly aperf/mperf */ "proc_feedback" ,/* processor feedback interface */ "acc_power" ,/* accumulated power mechanism */ +"conn_standby" ,/* Connected Standby */ + "rapl", /* Runtime Average Power Limit */
Yeah, so this repeats the "rapl" bit and that "conn_standby" is probably not gonna be used. Unless you have a really good reason to add that hunk, I'll whack it before applying and let this "power management" thing in /proc/cpuinfo die unchanged.
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteThe following commit has been merged into the x86/cpu branch of tip:
The following commit has been merged into the x86/cpu branch of tip:
Commit-ID: cbcddaa33d7e11a053cb80a4a635c023b4f8b906 Gitweb: https://git.kernel.org/tip/cbcddaa33d7e11a053cb80a4a635c023b4f8b906 Author: Andrew Cooper <[email protected]> AuthorDate: Fri, 14 May 2021 14:59:20 +01:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Tue, 01 Jun 2021 21:10:33 +02:00
perf/x86/rapl: Use CPUID bit on AMD and Hygon parts
AMD and Hygon CPUs have a CPUID bit for RAPL. Drop the fam17h suffix as it is stale already.
Make use of this instead of a model check to work more nicely in virtual environments where RAPL typically isn't available.
[ bp: drop the ../cpu/powerflags.c hunk which is superfluous as the
"rapl" bit name appears already in flags. ]
--- arch/x86/events/rapl.c | 6 ++---- arch/x86/include/asm/cpufeatures.h | 2 +- arch/x86/kernel/cpu/amd.c | 4 ++++ arch/x86/kernel/cpu/hygon.c | 4 ++++ 4 files changed, 11 insertions(+), 5 deletions(-)
arch/x86/events/rapl.c +2 -4
@@ -764,13 +764,14 @@ static struct rapl_model model_spr = { .rapl_msrs = intel_rapl_spr_msrs, }; -static struct rapl_model model_amd_fam17h = { +static struct rapl_model model_amd_hygon = { .events =BIT (PERF_RAPL_PKG ), .msr_power_unit =MSR_AMD_RAPL_POWER_UNIT , .rapl_msrs = amd_rapl_msrs, };static const struct x86_cpu_id rapl_model_match[]__initconst = { +X86_MATCH_FEATURE (X86_FEATURE_RAPL , &model_amd_hygon),X86_MATCH_INTEL_FAM6_MODEL (SANDYBRIDGE , &model_snb),X86_MATCH_INTEL_FAM6_MODEL (SANDYBRIDGE_X , &model_snbep),X86_MATCH_INTEL_FAM6_MODEL (IVYBRIDGE , &model_snb),
@@ -803,9 +804,6 @@ static const struct x86_cpu_id rapl_model_match[] __initconst = {X86_MATCH_INTEL_FAM6_MODEL (ALDERLAKE , &model_skl),X86_MATCH_INTEL_FAM6_MODEL (ALDERLAKE_L , &model_skl),X86_MATCH_INTEL_FAM6_MODEL (SAPPHIRERAPIDS_X , &model_spr), -X86_MATCH_VENDOR_FAM (AMD ,0x17 , &model_amd_fam17h), -X86_MATCH_VENDOR_FAM (HYGON ,0x18 , &model_amd_fam17h), - X86_MATCH_VENDOR_FAM(AMD, 0x19, &model_amd_fam17h), {}, };MODULE_DEVICE_TABLE (x86cpu, rapl_model_match);
arch/x86/include/asm/cpufeatures.h +1 -1
@@ -108,7 +108,7 @@#define X86_FEATURE_EXTD_APICID ( 3*32+26)/* Extended APICID (8 bits) */ #define X86_FEATURE_AMD_DCM ( 3*32+27)/* AMD multi-node processor */ #define X86_FEATURE_APERFMPERF ( 3*32+28)/* P-State hardware coordination feedback capability (APERF/MPERF MSRs) */ -/* free ( 3*32+29) */ +#define X86_FEATURE_RAPL ( 3*32+29)/* AMD/Hygon RAPL interface */ #define X86_FEATURE_NONSTOP_TSC_S3 ( 3*32+30)/* TSC doesn't stop in S3 state */ #define X86_FEATURE_TSC_KNOWN_FREQ ( 3*32+31)/* TSC has known frequency */
arch/x86/kernel/cpu/amd.c +4 -0
@@ -646,6 +646,10 @@ static void early_init_amd(struct cpuinfo_x86 *c)if (c->x86_power &BIT (12 ))set_cpu_cap (c,X86_FEATURE_ACC_POWER ); +/* Bit 14 indicates the Runtime Average Power Limit interface. */ +if (c->x86_power &BIT (14 )) +set_cpu_cap (c,X86_FEATURE_RAPL ); +#ifdef CONFIG_X86_64 set_cpu_cap (c,X86_FEATURE_SYSCALL32 );#else
arch/x86/kernel/cpu/hygon.c +4 -0
@@ -260,6 +260,10 @@ static void early_init_hygon(struct cpuinfo_x86 *c)if (c->x86_power &BIT (12 ))set_cpu_cap (c,X86_FEATURE_ACC_POWER ); +/* Bit 14 indicates the Runtime Average Power Limit interface. */ +if (c->x86_power &BIT (14 )) +set_cpu_cap (c,X86_FEATURE_RAPL ); +#ifdef CONFIG_X86_64 set_cpu_cap (c,X86_FEATURE_SYSCALL32 );#endif