Skip to content

Commit cbcddaa

Browse files
andyhhpsuryasaimadhu
authored andcommitted
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. ] Signed-off-by: Andrew Cooper <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 280b68a commit cbcddaa

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

arch/x86/events/rapl.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -764,13 +764,14 @@ static struct rapl_model model_spr = {
764764
.rapl_msrs = intel_rapl_spr_msrs,
765765
};
766766

767-
static struct rapl_model model_amd_fam17h = {
767+
static struct rapl_model model_amd_hygon = {
768768
.events = BIT(PERF_RAPL_PKG),
769769
.msr_power_unit = MSR_AMD_RAPL_POWER_UNIT,
770770
.rapl_msrs = amd_rapl_msrs,
771771
};
772772

773773
static const struct x86_cpu_id rapl_model_match[] __initconst = {
774+
X86_MATCH_FEATURE(X86_FEATURE_RAPL, &model_amd_hygon),
774775
X86_MATCH_INTEL_FAM6_MODEL(SANDYBRIDGE, &model_snb),
775776
X86_MATCH_INTEL_FAM6_MODEL(SANDYBRIDGE_X, &model_snbep),
776777
X86_MATCH_INTEL_FAM6_MODEL(IVYBRIDGE, &model_snb),
@@ -803,9 +804,6 @@ static const struct x86_cpu_id rapl_model_match[] __initconst = {
803804
X86_MATCH_INTEL_FAM6_MODEL(ALDERLAKE, &model_skl),
804805
X86_MATCH_INTEL_FAM6_MODEL(ALDERLAKE_L, &model_skl),
805806
X86_MATCH_INTEL_FAM6_MODEL(SAPPHIRERAPIDS_X, &model_spr),
806-
X86_MATCH_VENDOR_FAM(AMD, 0x17, &model_amd_fam17h),
807-
X86_MATCH_VENDOR_FAM(HYGON, 0x18, &model_amd_fam17h),
808-
X86_MATCH_VENDOR_FAM(AMD, 0x19, &model_amd_fam17h),
809807
{},
810808
};
811809
MODULE_DEVICE_TABLE(x86cpu, rapl_model_match);

arch/x86/include/asm/cpufeatures.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
#define X86_FEATURE_EXTD_APICID ( 3*32+26) /* Extended APICID (8 bits) */
109109
#define X86_FEATURE_AMD_DCM ( 3*32+27) /* AMD multi-node processor */
110110
#define X86_FEATURE_APERFMPERF ( 3*32+28) /* P-State hardware coordination feedback capability (APERF/MPERF MSRs) */
111-
/* free ( 3*32+29) */
111+
#define X86_FEATURE_RAPL ( 3*32+29) /* AMD/Hygon RAPL interface */
112112
#define X86_FEATURE_NONSTOP_TSC_S3 ( 3*32+30) /* TSC doesn't stop in S3 state */
113113
#define X86_FEATURE_TSC_KNOWN_FREQ ( 3*32+31) /* TSC has known frequency */
114114

arch/x86/kernel/cpu/amd.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,10 @@ static void early_init_amd(struct cpuinfo_x86 *c)
646646
if (c->x86_power & BIT(12))
647647
set_cpu_cap(c, X86_FEATURE_ACC_POWER);
648648

649+
/* Bit 14 indicates the Runtime Average Power Limit interface. */
650+
if (c->x86_power & BIT(14))
651+
set_cpu_cap(c, X86_FEATURE_RAPL);
652+
649653
#ifdef CONFIG_X86_64
650654
set_cpu_cap(c, X86_FEATURE_SYSCALL32);
651655
#else

arch/x86/kernel/cpu/hygon.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@ static void early_init_hygon(struct cpuinfo_x86 *c)
260260
if (c->x86_power & BIT(12))
261261
set_cpu_cap(c, X86_FEATURE_ACC_POWER);
262262

263+
/* Bit 14 indicates the Runtime Average Power Limit interface. */
264+
if (c->x86_power & BIT(14))
265+
set_cpu_cap(c, X86_FEATURE_RAPL);
266+
263267
#ifdef CONFIG_X86_64
264268
set_cpu_cap(c, X86_FEATURE_SYSCALL32);
265269
#endif

0 commit comments

Comments
 (0)