Skip to content

Commit cadbaa0

Browse files
Stephane EranianPeter Zijlstra
authored andcommitted
perf/x86/intel: Make anythread filter support conditional
Starting with Arch Perfmon v5, the anythread filter on generic counters may be deprecated. The current kernel was exporting the any filter without checking. On Icelake, it means you could do cpu/event=0x3c,any/ even though the filter does not exist. This patch corrects the problem by relying on the CPUID 0xa leaf function to determine if anythread is supported or not as described in the Intel SDM Vol3b 18.2.5.1 AnyThread Deprecation section. Signed-off-by: Stephane Eranian <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 1908dc9 commit cadbaa0

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

arch/x86/events/intel/core.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4987,6 +4987,12 @@ __init int intel_pmu_init(void)
49874987

49884988
x86_add_quirk(intel_arch_events_quirk); /* Install first, so it runs last */
49894989

4990+
if (version >= 5) {
4991+
x86_pmu.intel_cap.anythread_deprecated = edx.split.anythread_deprecated;
4992+
if (x86_pmu.intel_cap.anythread_deprecated)
4993+
pr_cont(" AnyThread deprecated, ");
4994+
}
4995+
49904996
/*
49914997
* Install the hw-cache-events table:
49924998
*/
@@ -5512,6 +5518,10 @@ __init int intel_pmu_init(void)
55125518
x86_pmu.intel_ctrl |=
55135519
((1LL << x86_pmu.num_counters_fixed)-1) << INTEL_PMC_IDX_FIXED;
55145520

5521+
/* AnyThread may be deprecated on arch perfmon v5 or later */
5522+
if (x86_pmu.intel_cap.anythread_deprecated)
5523+
x86_pmu.format_attrs = intel_arch_formats_attr;
5524+
55155525
if (x86_pmu.event_constraints) {
55165526
/*
55175527
* event on fixed counter2 (REF_CYCLES) only works on this

arch/x86/events/perf_event.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ union perf_capabilities {
585585
u64 pebs_baseline:1;
586586
u64 perf_metrics:1;
587587
u64 pebs_output_pt_available:1;
588+
u64 anythread_deprecated:1;
588589
};
589590
u64 capabilities;
590591
};

arch/x86/include/asm/perf_event.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ union cpuid10_edx {
137137
struct {
138138
unsigned int num_counters_fixed:5;
139139
unsigned int bit_width_fixed:8;
140-
unsigned int reserved:19;
140+
unsigned int reserved1:2;
141+
unsigned int anythread_deprecated:1;
142+
unsigned int reserved2:16;
141143
} split;
142144
unsigned int full;
143145
};

arch/x86/kvm/cpuid.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,9 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
672672

673673
edx.split.num_counters_fixed = min(cap.num_counters_fixed, MAX_FIXED_COUNTERS);
674674
edx.split.bit_width_fixed = cap.bit_width_fixed;
675-
edx.split.reserved = 0;
675+
edx.split.anythread_deprecated = 1;
676+
edx.split.reserved1 = 0;
677+
edx.split.reserved2 = 0;
676678

677679
entry->eax = eax.full;
678680
entry->ebx = cap.events_mask;

0 commit comments

Comments
 (0)