summaryrefslogtreecommitdiffstats
path: root/arch/x86/events
diff options
context:
space:
mode:
authorLike Xu <like.xu@linux.intel.com>2021-11-11 02:07:27 +0000
committerPeter Zijlstra <peterz@infradead.org>2021-11-17 14:49:07 +0100
commitb9f5621c9547dd787900f005a9e1c3d5712de512 (patch)
treedb92d35feaaacd204506fa4cb5e32c2566a88b7f /arch/x86/events
parent84af21d850ee1ccc990df37dd47c13fdfe93be75 (diff)
downloadlinux-b9f5621c9547dd787900f005a9e1c3d5712de512.tar.bz2
perf/core: Rework guest callbacks to prepare for static_call support
To prepare for using static_calls to optimize perf's guest callbacks, replace ->is_in_guest and ->is_user_mode with a new multiplexed hook ->state, tweak ->handle_intel_pt_intr to play nice with being called when there is no active guest, and drop "guest" from ->get_guest_ip. Return '0' from ->state and ->handle_intel_pt_intr to indicate "not in guest" so that DEFINE_STATIC_CALL_RET0 can be used to define the static calls, i.e. no callback == !guest. [sean: extracted from static_call patch, fixed get_ip() bug, wrote changelog] Suggested-by: Peter Zijlstra (Intel) <peterz@infradead.org> Originally-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Like Xu <like.xu@linux.intel.com> Signed-off-by: Zhu Lingshan <lingshan.zhu@intel.com> Signed-off-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Link: https://lore.kernel.org/r/20211111020738.2512932-7-seanjc@google.com
Diffstat (limited to 'arch/x86/events')
-rw-r--r--arch/x86/events/core.c13
-rw-r--r--arch/x86/events/intel/core.c5
2 files changed, 8 insertions, 10 deletions
diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index 32cec290d3ad..e29312a1003a 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -2772,7 +2772,7 @@ perf_callchain_kernel(struct perf_callchain_entry_ctx *entry, struct pt_regs *re
struct unwind_state state;
unsigned long addr;
- if (guest_cbs && guest_cbs->is_in_guest()) {
+ if (guest_cbs && guest_cbs->state()) {
/* TODO: We don't support guest os callchain now */
return;
}
@@ -2876,7 +2876,7 @@ perf_callchain_user(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs
struct stack_frame frame;
const struct stack_frame __user *fp;
- if (guest_cbs && guest_cbs->is_in_guest()) {
+ if (guest_cbs && guest_cbs->state()) {
/* TODO: We don't support guest os callchain now */
return;
}
@@ -2955,8 +2955,8 @@ unsigned long perf_instruction_pointer(struct pt_regs *regs)
{
struct perf_guest_info_callbacks *guest_cbs = perf_get_guest_cbs();
- if (guest_cbs && guest_cbs->is_in_guest())
- return guest_cbs->get_guest_ip();
+ if (guest_cbs && guest_cbs->state())
+ return guest_cbs->get_ip();
return regs->ip + code_segment_base(regs);
}
@@ -2964,10 +2964,11 @@ unsigned long perf_instruction_pointer(struct pt_regs *regs)
unsigned long perf_misc_flags(struct pt_regs *regs)
{
struct perf_guest_info_callbacks *guest_cbs = perf_get_guest_cbs();
+ unsigned int guest_state = guest_cbs ? guest_cbs->state() : 0;
int misc = 0;
- if (guest_cbs && guest_cbs->is_in_guest()) {
- if (guest_cbs->is_user_mode())
+ if (guest_state) {
+ if (guest_state & PERF_GUEST_USER)
misc |= PERF_RECORD_MISC_GUEST_USER;
else
misc |= PERF_RECORD_MISC_GUEST_KERNEL;
diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 2258e02ca350..7ff24d1ecdb7 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -2906,10 +2906,7 @@ static int handle_pmi_common(struct pt_regs *regs, u64 status)
handled++;
guest_cbs = perf_get_guest_cbs();
- if (unlikely(guest_cbs && guest_cbs->is_in_guest() &&
- guest_cbs->handle_intel_pt_intr))
- guest_cbs->handle_intel_pt_intr();
- else
+ if (likely(!guest_cbs || !guest_cbs->handle_intel_pt_intr()))
intel_pt_interrupt();
}