Skip to content

Commit 16b48c3

Browse files
sandip4nPeter Zijlstra
authored andcommitted
perf/x86/amd/uncore: Detect available DF counters
If AMD Performance Monitoring Version 2 (PerfMonV2) is supported, use CPUID leaf 0x80000022 EBX to detect the number of Data Fabric (DF) 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://lore.kernel.org/r/bac7b2806561e03f2acc7fdc9db94f102df80e1d.1652954372.git.sandipan.das@amd.com
1 parent 847f326 commit 16b48c3

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

arch/x86/events/amd/uncore.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#undef pr_fmt
3131
#define pr_fmt(fmt) "amd_uncore: " fmt
3232

33+
static int pmu_version;
3334
static int num_counters_llc;
3435
static int num_counters_nb;
3536
static bool l3_mask;
@@ -629,6 +630,7 @@ static int __init amd_uncore_init(void)
629630
{
630631
struct attribute **df_attr = amd_uncore_df_format_attr;
631632
struct attribute **l3_attr = amd_uncore_l3_format_attr;
633+
union cpuid_0x80000022_ebx ebx;
632634
int ret = -ENODEV;
633635

634636
if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD &&
@@ -638,6 +640,9 @@ static int __init amd_uncore_init(void)
638640
if (!boot_cpu_has(X86_FEATURE_TOPOEXT))
639641
return -ENODEV;
640642

643+
if (boot_cpu_has(X86_FEATURE_PERFMON_V2))
644+
pmu_version = 2;
645+
641646
num_counters_nb = NUM_COUNTERS_NB;
642647
num_counters_llc = NUM_COUNTERS_L2;
643648
if (boot_cpu_data.x86 >= 0x17) {
@@ -666,6 +671,11 @@ static int __init amd_uncore_init(void)
666671
if (ret)
667672
goto fail_nb;
668673

674+
if (pmu_version >= 2) {
675+
ebx.full = cpuid_ebx(EXT_PERFMON_DEBUG_FEATURES);
676+
num_counters_nb = ebx.split.num_df_pmc;
677+
}
678+
669679
pr_info("%d %s %s counters detected\n", num_counters_nb,
670680
boot_cpu_data.x86_vendor == X86_VENDOR_HYGON ? "HYGON" : "",
671681
amd_nb_pmu.name);

arch/x86/include/asm/perf_event.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ union cpuid_0x80000022_ebx {
194194
struct {
195195
/* Number of Core Performance Counters */
196196
unsigned int num_core_pmc:4;
197+
unsigned int reserved:6;
198+
/* Number of Data Fabric Counters */
199+
unsigned int num_df_pmc:6;
197200
} split;
198201
unsigned int full;
199202
};

0 commit comments

Comments
 (0)