summaryrefslogtreecommitdiffstats
path: root/include/linux/perf_event.h
diff options
context:
space:
mode:
authorSean Christopherson <seanjc@google.com>2021-11-11 02:07:30 +0000
committerPeter Zijlstra <peterz@infradead.org>2021-11-17 14:49:09 +0100
commit87b940a0675e25261f022ac3e53e0dfff9cdb995 (patch)
treedd444ca4e1ac34f6e0bf0b46317c9f24f666b279 /include/linux/perf_event.h
parent2aef6f306b39bbe74e2287d6e2ee07c4867d87d0 (diff)
downloadlinux-87b940a0675e25261f022ac3e53e0dfff9cdb995.tar.bz2
perf/core: Use static_call to optimize perf_guest_info_callbacks
Use static_call to optimize perf's guest callbacks on arm64 and x86, which are now the only architectures that define the callbacks. Use DEFINE_STATIC_CALL_RET0 as the default/NULL for all guest callbacks, as the callback semantics are that a return value '0' means "not in guest". static_call obviously avoids the overhead of CONFIG_RETPOLINE=y, but is also advantageous versus other solutions, e.g. per-cpu callbacks, in that a per-cpu memory load is not needed to detect the !guest case. Based on code from Peter and Like. Suggested-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Link: https://lore.kernel.org/r/20211111020738.2512932-10-seanjc@google.com
Diffstat (limited to 'include/linux/perf_event.h')
-rw-r--r--include/linux/perf_event.h34
1 files changed, 8 insertions, 26 deletions
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index ea47ef616ee0..0ac7d867ca0c 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -1244,40 +1244,22 @@ extern void perf_event_bpf_event(struct bpf_prog *prog,
#ifdef CONFIG_GUEST_PERF_EVENTS
extern struct perf_guest_info_callbacks __rcu *perf_guest_cbs;
-static inline struct perf_guest_info_callbacks *perf_get_guest_cbs(void)
-{
- /*
- * Callbacks are RCU-protected and must be READ_ONCE to avoid reloading
- * the callbacks between a !NULL check and dereferences, to ensure
- * pending stores/changes to the callback pointers are visible before a
- * non-NULL perf_guest_cbs is visible to readers, and to prevent a
- * module from unloading callbacks while readers are active.
- */
- return rcu_dereference(perf_guest_cbs);
-}
+
+DECLARE_STATIC_CALL(__perf_guest_state, *perf_guest_cbs->state);
+DECLARE_STATIC_CALL(__perf_guest_get_ip, *perf_guest_cbs->get_ip);
+DECLARE_STATIC_CALL(__perf_guest_handle_intel_pt_intr, *perf_guest_cbs->handle_intel_pt_intr);
+
static inline unsigned int perf_guest_state(void)
{
- struct perf_guest_info_callbacks *guest_cbs = perf_get_guest_cbs();
-
- return guest_cbs ? guest_cbs->state() : 0;
+ return static_call(__perf_guest_state)();
}
static inline unsigned long perf_guest_get_ip(void)
{
- struct perf_guest_info_callbacks *guest_cbs = perf_get_guest_cbs();
-
- /*
- * Arbitrarily return '0' in the unlikely scenario that the callbacks
- * are unregistered between checking guest state and getting the IP.
- */
- return guest_cbs ? guest_cbs->get_ip() : 0;
+ return static_call(__perf_guest_get_ip)();
}
static inline unsigned int perf_guest_handle_intel_pt_intr(void)
{
- struct perf_guest_info_callbacks *guest_cbs = perf_get_guest_cbs();
-
- if (guest_cbs && guest_cbs->handle_intel_pt_intr)
- return guest_cbs->handle_intel_pt_intr();
- return 0;
+ return static_call(__perf_guest_handle_intel_pt_intr)();
}
extern void perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *cbs);
extern void perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *cbs);