Skip to content

Commit eb467aa

Browse files
Kan LiangIngo Molnar
authored andcommitted
perf/x86/intel: Support Architectural PerfMon Extension leaf
The new CPUID leaf 0x23 reports the "true view" of PMU resources. The sub-leaf 1 reports the available general-purpose counters and fixed counters. Update the number of counters and fixed counters when the sub-leaf is detected. Signed-off-by: Kan Liang <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Acked-by: Peter Zijlstra <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent a018d2e commit eb467aa

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

arch/x86/events/intel/core.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4588,6 +4588,25 @@ static void flip_smm_bit(void *data)
45884588
}
45894589
}
45904590

4591+
static void intel_pmu_check_num_counters(int *num_counters,
4592+
int *num_counters_fixed,
4593+
u64 *intel_ctrl, u64 fixed_mask);
4594+
4595+
static void update_pmu_cap(struct x86_hybrid_pmu *pmu)
4596+
{
4597+
unsigned int sub_bitmaps = cpuid_eax(ARCH_PERFMON_EXT_LEAF);
4598+
unsigned int eax, ebx, ecx, edx;
4599+
4600+
if (sub_bitmaps & ARCH_PERFMON_NUM_COUNTER_LEAF_BIT) {
4601+
cpuid_count(ARCH_PERFMON_EXT_LEAF, ARCH_PERFMON_NUM_COUNTER_LEAF,
4602+
&eax, &ebx, &ecx, &edx);
4603+
pmu->num_counters = fls(eax);
4604+
pmu->num_counters_fixed = fls(ebx);
4605+
intel_pmu_check_num_counters(&pmu->num_counters, &pmu->num_counters_fixed,
4606+
&pmu->intel_ctrl, ebx);
4607+
}
4608+
}
4609+
45914610
static bool init_hybrid_pmu(int cpu)
45924611
{
45934612
struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu);
@@ -4613,6 +4632,9 @@ static bool init_hybrid_pmu(int cpu)
46134632
if (!cpumask_empty(&pmu->supported_cpus))
46144633
goto end;
46154634

4635+
if (this_cpu_has(X86_FEATURE_ARCH_PERFMON_EXT))
4636+
update_pmu_cap(pmu);
4637+
46164638
if (!check_hw_exists(&pmu->pmu, pmu->num_counters, pmu->num_counters_fixed))
46174639
return false;
46184640

arch/x86/include/asm/perf_event.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ union cpuid10_edx {
159159
unsigned int full;
160160
};
161161

162+
/*
163+
* Intel "Architectural Performance Monitoring extension" CPUID
164+
* detection/enumeration details:
165+
*/
166+
#define ARCH_PERFMON_EXT_LEAF 0x00000023
167+
#define ARCH_PERFMON_NUM_COUNTER_LEAF_BIT 0x1
168+
#define ARCH_PERFMON_NUM_COUNTER_LEAF 0x1
169+
162170
/*
163171
* Intel Architectural LBR CPUID detection/enumeration details:
164172
*/

0 commit comments

Comments
 (0)