Skip to contentSkip to conversation

perf: Introduce new perf_fetch_caller_regs() for hot regs snapshot

tip:perf/urgent tip-bot for Frederic Weisbecker 1 participant 1 message Mar 10, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw
Commit-ID:  5331d7b84613b8325362dde53dc2bff2fb87d351
Gitweb:     http://git.kernel.org/tip/5331d7b84613b8325362dde53dc2bff2fb87d351
Author:     Frederic Weisbecker <[email protected]>
AuthorDate: Thu, 4 Mar 2010 21:15:56 +0100
Committer:  Frederic Weisbecker <[email protected]>
CommitDate: Wed, 10 Mar 2010 14:39:35 +0100

perf: Introduce new perf_fetch_caller_regs() for hot regs snapshot

Events that trigger overflows by interrupting a context can use get_irq_regs() or task_pt_regs() to retrieve the state when the event triggered. But this is not the case for some other class of events like trace events as tracepoints are executed in the same context than the code that triggered the event.

It means we need a different api to capture the regs there, namely we need a hot snapshot to get the most important informations for perf: the instruction pointer to get the event origin, the frame pointer for the callchain, the code segment for user_mode() tests (we always use __KERNEL_CS as trace events always occur from the kernel) and the eflags for further purposes.

v2: rename perf_save_regs to perf_fetch_caller_regs as per Masami's suggestion.

Cc Ingo Molnar <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Masami Hiramatsu <[email protected]>
Cc Jason Baron <[email protected]>
---
 arch/x86/kernel/cpu/perf_event.c |   12 ++++++++++
 arch/x86/kernel/dumpstack.h      |   15 +++++++++++++
 include/linux/perf_event.h       |   42 +++++++++++++++++++++++++++++++++++++-
 kernel/perf_event.c              |    5 ++++
 4 files changed, 73 insertions(+), 1 deletions(-)
arch/x86/kernel/cpu/perf_event.c +12 -0
index 1d665a0..c6bde7d 100644
@@ -1707,3 +1707,15 @@ struct perf_callchain_entry *perf_callchain(struct pt_regs *regs)
 
 	return entry;
 }
+
+void perf_arch_fetch_caller_regs(struct pt_regs *regs, unsigned long ip, int skip)
+{
+	regs->ip = ip;
+	/*
+	 * perf_arch_fetch_caller_regs adds another call, we need to increment
+	 * the skip level
+	 */
+	regs->bp = rewind_frame_pointer(skip + 1);
+	regs->cs = __KERNEL_CS;
+	local_save_flags(regs->flags);
+}
arch/x86/kernel/dumpstack.h +15 -0
index 4fd1420..29e5f7c 100644
@@ -29,4 +29,19 @@ struct stack_frame {
 	struct stack_frame *next_frame;
 	unsigned long return_address;
 };
+
+static inline unsigned long rewind_frame_pointer(int n)
+{
+	struct stack_frame *frame;
+
+	get_bp(frame);
+
+#ifdef CONFIG_FRAME_POINTER
+	while (n--)
+		frame = frame->next_frame;
 #endif
+
+	return (unsigned long)frame;
+}
+
+#endif /* DUMPSTACK_H */
include/linux/perf_event.h +41 -1

60 lines not on this page · raw message

kernel/perf_event.c +5 -0
index 52c69a3..359d7f6 100644
@@ -2786,6 +2786,11 @@ __weak struct perf_callchain_entry *perf_callchain(struct pt_regs *regs)
 	return NULL;
 }
 
+__weak
+void perf_arch_fetch_caller_regs(struct pt_regs *regs, unsigned long ip, int skip)
+{
+}
+
 /*
  * Output
  */