]> git.baikalelectronics.ru Git - kernel.git/commitdiff
perf: x86/core: Add interface to query perfmon_event_map[] directly
authorLike Xu <likexu@tencent.com>
Wed, 18 May 2022 13:25:10 +0000 (21:25 +0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 8 Jun 2022 08:49:01 +0000 (04:49 -0400)
Currently, we have [intel|knc|p4|p6]_perfmon_event_map on the Intel
platforms and amd_[f17h]_perfmon_event_map on the AMD platforms.

Early clumsy KVM code or other potential perf_event users may have
hard-coded these perfmon_maps (e.g., arch/x86/kvm/svm/pmu.c), so
it would not make sense to program a common hardware event based
on the generic "enum perf_hw_id" once the two tables do not match.

Let's provide an interface for callers outside the perf subsystem to get
the counter config based on the perfmon_event_map currently in use,
and it also helps to save bytes.

Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Like Xu <likexu@tencent.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Message-Id: <20220518132512.37864-10-likexu@tencent.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/events/core.c
arch/x86/include/asm/perf_event.h

index 330825160b9a25e041f57ca0b98a8cee9a808a0e..2e16c268a00509fc6009cc1de8a99da66387a982 100644 (file)
@@ -3005,3 +3005,14 @@ void perf_get_x86_pmu_capability(struct x86_pmu_capability *cap)
        cap->pebs_ept           = x86_pmu.pebs_ept;
 }
 EXPORT_SYMBOL_GPL(perf_get_x86_pmu_capability);
+
+u64 perf_get_hw_event_config(int hw_event)
+{
+       int max = x86_pmu.max_events;
+
+       if (hw_event < max)
+               return x86_pmu.event_map(array_index_nospec(hw_event, max));
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(perf_get_hw_event_config);
index 58e2fcbb8bcc843f6c09ff1f2289a4e630cd6cd9..cc47044401ff3bee44a6e4e91eaf8a1f60506027 100644 (file)
@@ -505,6 +505,7 @@ struct x86_pmu_lbr {
 };
 
 extern void perf_get_x86_pmu_capability(struct x86_pmu_capability *cap);
+extern u64 perf_get_hw_event_config(int hw_event);
 extern void perf_check_microcode(void);
 extern void perf_clear_dirty_counters(void);
 extern int x86_perf_rdpmc_index(struct perf_event *event);
@@ -514,6 +515,11 @@ static inline void perf_get_x86_pmu_capability(struct x86_pmu_capability *cap)
        memset(cap, 0, sizeof(*cap));
 }
 
+static inline u64 perf_get_hw_event_config(int hw_event)
+{
+       return 0;
+}
+
 static inline void perf_events_lapic_init(void)        { }
 static inline void perf_check_microcode(void) { }
 #endif