Skip to content

Commit 56e026a

Browse files
sandip4nPeter Zijlstra
authored andcommitted
perf/x86/amd/core: Detect available counters
If AMD Performance Monitoring Version 2 (PerfMonV2) is supported, use CPUID leaf 0x80000022 EBX to detect the number of Core PMCs. This offers more flexibility if the counts change in later processor families. Signed-off-by: Sandipan Das <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/68a6d9688df189267db26530378870edd34f7b06.1650515382.git.sandipan.das@amd.com
1 parent 21d59e3 commit 56e026a

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

arch/x86/events/amd/core.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,7 @@ static const struct attribute_group *amd_attr_update[] = {
11861186

11871187
static int __init amd_core_pmu_init(void)
11881188
{
1189+
union cpuid_0x80000022_ebx ebx;
11891190
u64 even_ctr_mask = 0ULL;
11901191
int i;
11911192

@@ -1206,9 +1207,14 @@ static int __init amd_core_pmu_init(void)
12061207

12071208
/* Check for Performance Monitoring v2 support */
12081209
if (boot_cpu_has(X86_FEATURE_PERFMON_V2)) {
1210+
ebx.full = cpuid_ebx(EXT_PERFMON_DEBUG_FEATURES);
1211+
12091212
/* Update PMU version for later usage */
12101213
x86_pmu.version = 2;
12111214

1215+
/* Find the number of available Core PMCs */
1216+
x86_pmu.num_counters = ebx.split.num_core_pmc;
1217+
12121218
amd_pmu_global_cntr_mask = (1ULL << x86_pmu.num_counters) - 1;
12131219
}
12141220

arch/x86/include/asm/perf_event.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,18 @@ union cpuid28_ecx {
186186
unsigned int full;
187187
};
188188

189+
/*
190+
* AMD "Extended Performance Monitoring and Debug" CPUID
191+
* detection/enumeration details:
192+
*/
193+
union cpuid_0x80000022_ebx {
194+
struct {
195+
/* Number of Core Performance Counters */
196+
unsigned int num_core_pmc:4;
197+
} split;
198+
unsigned int full;
199+
};
200+
189201
struct x86_pmu_capability {
190202
int version;
191203
int num_counters_gp;
@@ -367,6 +379,11 @@ struct pebs_xmm {
367379
u64 xmm[16*2]; /* two entries for each register */
368380
};
369381

382+
/*
383+
* AMD Extended Performance Monitoring and Debug cpuid feature detection
384+
*/
385+
#define EXT_PERFMON_DEBUG_FEATURES 0x80000022
386+
370387
/*
371388
* IBS cpuid feature detection
372389
*/

0 commit comments

Comments
 (0)