Skip to contentSkip to conversation

powerpc function graph tracer

GIT PULL In review Steven Rostedt 3 participants 15 messages Feb 13, 2009 – Feb 18, 2009

Subsystems (4)
lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

Benjamin,

I figured you can run it through your test boxes.

Please pull the latest ppc/ftrace tree, which can be found at:

git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git
ppc/ftrace

Steven Rostedt (7):
tracing/function-graph-tracer: make arch generic push pop functions
powerpc64: port of the function graph tracer
powerpc64, tracing: add function graph tracer with dynamic tracing powerpc64, ftrace: save toc only on modules for function graph powerpc32, ftrace: save and restore mcount regs with macro powerpc32, ftrace: port function graph tracer to ppc32, static only powerpc32, ftrace: dynamic function graph tracer

----

 arch/powerpc/Kconfig                 |    1 +
 arch/powerpc/include/asm/ftrace.h    |   39 ++++++++++-
 arch/powerpc/kernel/Makefile         |    9 +-
 arch/powerpc/kernel/entry_32.S       |  115 ++++++++++++++---------------
 arch/powerpc/kernel/entry_64.S       |   89 +++++++++++++++++++++-
 arch/powerpc/kernel/ftrace.c         |  135 ++++++++++++++++++++++++++++++++--
 arch/powerpc/kernel/process.c        |   16 ++++
 arch/powerpc/kernel/vmlinux.lds.S    |    1 +
 arch/x86/include/asm/ftrace.h        |   25 ------
 arch/x86/kernel/ftrace.c             |   75 +------------------
 include/linux/ftrace.h               |   24 ++++++
 kernel/trace/trace_functions_graph.c |   75 +++++++++++++++++++
 12 files changed, 428 insertions(+), 176 deletions(-)
author maintainer
#1 lore raw

PATCH 1/7 tracing/function-graph-tracer: make arch generic push pop functions

From: Steven Rostedt <[email protected]>

There is nothing really arch specific of the push and pop functions used by the function graph tracer. This patch moves them to generic code.

---
 arch/x86/include/asm/ftrace.h        |   25 -----------
 arch/x86/kernel/ftrace.c             |   75 +---------------------------------
 include/linux/ftrace.h               |   24 +++++++++++
 kernel/trace/trace_functions_graph.c |   75 ++++++++++++++++++++++++++++++++++
 4 files changed, 100 insertions(+), 99 deletions(-)
arch/x86/include/asm/ftrace.h +0 -25
index b55b4a7..db24c22 100644
@@ -55,29 +55,4 @@ struct dyn_arch_ftrace {
 #endif /* __ASSEMBLY__ */
 #endif /* CONFIG_FUNCTION_TRACER */
 
-#ifdef CONFIG_FUNCTION_GRAPH_TRACER
-
-#ifndef __ASSEMBLY__
-
-/*
- * Stack of return addresses for functions
- * of a thread.
- * Used in struct thread_info
- */
-struct ftrace_ret_stack {
-	unsigned long ret;
-	unsigned long func;
-	unsigned long long calltime;
-};
-
-/*
- * Primary handler of a function return.
- * It relays on ftrace_return_to_handler.
- * Defined in entry_32/64.S
- */
-extern void return_to_handler(void);
-
-#endif /* __ASSEMBLY__ */
-#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
-
 #endif /* _ASM_X86_FTRACE_H */
arch/x86/kernel/ftrace.c +1 -74

87 lines not on this page · raw message

include/linux/ftrace.h +24 -0
index 677432b..a7f8134 100644
@@ -380,6 +380,30 @@ struct ftrace_graph_ret {
 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
 
 /*
+ * Stack of return addresses for functions
+ * of a thread.
+ * Used in struct thread_info
+ */
+struct ftrace_ret_stack {
+	unsigned long ret;
+	unsigned long func;
+	unsigned long long calltime;
+};
+
+/*
+ * Primary handler of a function return.
+ * It relays on ftrace_return_to_handler.
+ * Defined in entry_32/64.S
+ */
+extern void return_to_handler(void);
+
+extern int
+ftrace_push_return_trace(unsigned long ret, unsigned long long time,
+			 unsigned long func, int *depth);
+extern void
+ftrace_pop_return_trace(struct ftrace_graph_ret *trace, unsigned long *ret);
+
+/*
  * Sometimes we don't want to trace a function with the function
  * graph tracer but we want them to keep traced by the usual function
  * tracer if the function graph tracer is not configured.
kernel/trace/trace_functions_graph.c +75 -0

81 lines not on this page · raw message

Signature · 3 lines
1.5.6.5

-- 
author maintainer
#2 lore raw

Re: [PATCH 1/7] tracing/function-graph-tracer: make arch generic push pop functions

Ingo,

This patch is to make function graph arch generic. But since the PowerPC changes depend on it, we want to push it through the PowerPC tree. But since it touches x86 code, can you give an Acked-by to it?

Thanks,

-- Steve

Quoted 269 lines · Steven Rostedt

From: Steven Rostedt <[email protected]>

There is nothing really arch specific of the push and pop functions used by the function graph tracer. This patch moves them to generic code.

---
 arch/x86/include/asm/ftrace.h        |   25 -----------
 arch/x86/kernel/ftrace.c             |   75 +---------------------------------
 include/linux/ftrace.h               |   24 +++++++++++
 kernel/trace/trace_functions_graph.c |   75 ++++++++++++++++++++++++++++++++++
 4 files changed, 100 insertions(+), 99 deletions(-)
arch/x86/include/asm/ftrace.h +0 -25
index b55b4a7..db24c22 100644
@@ -55,29 +55,4 @@ struct dyn_arch_ftrace {
 #endif /* __ASSEMBLY__ */
 #endif /* CONFIG_FUNCTION_TRACER */
 
-#ifdef CONFIG_FUNCTION_GRAPH_TRACER
-
-#ifndef __ASSEMBLY__
-
-/*
- * Stack of return addresses for functions
- * of a thread.
- * Used in struct thread_info
- */
-struct ftrace_ret_stack {
-	unsigned long ret;
-	unsigned long func;
-	unsigned long long calltime;
-};
-
-/*
- * Primary handler of a function return.
- * It relays on ftrace_return_to_handler.
- * Defined in entry_32/64.S
- */
-extern void return_to_handler(void);
-
-#endif /* __ASSEMBLY__ */
-#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
-
 #endif /* _ASM_X86_FTRACE_H */
arch/x86/kernel/ftrace.c +1 -74
index 1b43086..258c8d5 100644
@@ -389,79 +389,6 @@ void ftrace_nmi_exit(void)
 
 #endif /* !CONFIG_DYNAMIC_FTRACE */
 
-/* Add a function return address to the trace stack on thread info.*/
-static int push_return_trace(unsigned long ret, unsigned long long time,
-				unsigned long func, int *depth)
-{
-	int index;
-
-	if (!current->ret_stack)
-		return -EBUSY;
-
-	/* The return trace stack is full */
-	if (current->curr_ret_stack == FTRACE_RETFUNC_DEPTH - 1) {
-		atomic_inc(&current->trace_overrun);
-		return -EBUSY;
-	}
-
-	index = ++current->curr_ret_stack;
-	barrier();
-	current->ret_stack[index].ret = ret;
-	current->ret_stack[index].func = func;
-	current->ret_stack[index].calltime = time;
-	*depth = index;
-
-	return 0;
-}
-
-/* Retrieve a function return address to the trace stack on thread info.*/
-static void pop_return_trace(struct ftrace_graph_ret *trace, unsigned long *ret)
-{
-	int index;
-
-	index = current->curr_ret_stack;
-
-	if (unlikely(index < 0)) {
-		ftrace_graph_stop();
-		WARN_ON(1);
-		/* Might as well panic, otherwise we have no where to go */
-		*ret = (unsigned long)panic;
-		return;
-	}
-
-	*ret = current->ret_stack[index].ret;
-	trace->func = current->ret_stack[index].func;
-	trace->calltime = current->ret_stack[index].calltime;
-	trace->overrun = atomic_read(&current->trace_overrun);
-	trace->depth = index;
-	barrier();
-	current->curr_ret_stack--;
-
-}
-
-/*
- * Send the trace to the ring-buffer.
- * @return the original return address.
- */
-unsigned long ftrace_return_to_handler(void)
-{
-	struct ftrace_graph_ret trace;
-	unsigned long ret;
-
-	pop_return_trace(&trace, &ret);
-	trace.rettime = cpu_clock(raw_smp_processor_id());
-	ftrace_graph_return(&trace);
-
-	if (unlikely(!ret)) {
-		ftrace_graph_stop();
-		WARN_ON(1);
-		/* Might as well panic. What else to do? */
-		ret = (unsigned long)panic;
-	}
-
-	return ret;
-}
-
 /*
  * Hook the return address and push it in the stack of return addrs
  * in current thread info.
@@ -520,7 +447,7 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr)
 
 	calltime = cpu_clock(raw_smp_processor_id());
 
-	if (push_return_trace(old, calltime,
+	if (ftrace_push_return_trace(old, calltime,
 				self_addr, &trace.depth) == -EBUSY) {
 		*parent = old;
 		return;
include/linux/ftrace.h +24 -0
index 677432b..a7f8134 100644
@@ -380,6 +380,30 @@ struct ftrace_graph_ret {
 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
 
 /*
+ * Stack of return addresses for functions
+ * of a thread.
+ * Used in struct thread_info
+ */
+struct ftrace_ret_stack {
+	unsigned long ret;
+	unsigned long func;
+	unsigned long long calltime;
+};
+
+/*
+ * Primary handler of a function return.
+ * It relays on ftrace_return_to_handler.
+ * Defined in entry_32/64.S
+ */
+extern void return_to_handler(void);
+
+extern int
+ftrace_push_return_trace(unsigned long ret, unsigned long long time,
+			 unsigned long func, int *depth);
+extern void
+ftrace_pop_return_trace(struct ftrace_graph_ret *trace, unsigned long *ret);
+
+/*
  * Sometimes we don't want to trace a function with the function
  * graph tracer but we want them to keep traced by the usual function
  * tracer if the function graph tracer is not configured.
kernel/trace/trace_functions_graph.c +75 -0
index 930c08e..dce71a5 100644
@@ -42,6 +42,81 @@ static struct tracer_flags tracer_flags = {
 /* pid on the last trace processed */
 static pid_t last_pid[NR_CPUS] = { [0 ... NR_CPUS-1] = -1 };
 
+/* Add a function return address to the trace stack on thread info.*/
+int
+ftrace_push_return_trace(unsigned long ret, unsigned long long time,
+			 unsigned long func, int *depth)
+{
+	int index;
+
+	if (!current->ret_stack)
+		return -EBUSY;
+
+	/* The return trace stack is full */
+	if (current->curr_ret_stack == FTRACE_RETFUNC_DEPTH - 1) {
+		atomic_inc(&current->trace_overrun);
+		return -EBUSY;
+	}
+
+	index = ++current->curr_ret_stack;
+	barrier();
+	current->ret_stack[index].ret = ret;
+	current->ret_stack[index].func = func;
+	current->ret_stack[index].calltime = time;
+	*depth = index;
+
+	return 0;
+}
+
+/* Retrieve a function return address to the trace stack on thread info.*/
+void
+ftrace_pop_return_trace(struct ftrace_graph_ret *trace, unsigned long *ret)
+{
+	int index;
+
+	index = current->curr_ret_stack;
+
+	if (unlikely(index < 0)) {
+		ftrace_graph_stop();
+		WARN_ON(1);
+		/* Might as well panic, otherwise we have no where to go */
+		*ret = (unsigned long)panic;
+		return;
+	}
+
+	*ret = current->ret_stack[index].ret;
+	trace->func = current->ret_stack[index].func;
+	trace->calltime = current->ret_stack[index].calltime;
+	trace->overrun = atomic_read(&current->trace_overrun);
+	trace->depth = index;
+	barrier();
+	current->curr_ret_stack--;
+
+}
+
+/*
+ * Send the trace to the ring-buffer.
+ * @return the original return address.
+ */
+unsigned long ftrace_return_to_handler(void)
+{
+	struct ftrace_graph_ret trace;
+	unsigned long ret;
+
+	ftrace_pop_return_trace(&trace, &ret);
+	trace.rettime = cpu_clock(raw_smp_processor_id());
+	ftrace_graph_return(&trace);
+
+	if (unlikely(!ret)) {
+		ftrace_graph_stop();
+		WARN_ON(1);
+		/* Might as well panic. What else to do? */
+		ret = (unsigned long)panic;
+	}
+
+	return ret;
+}
+
 static int graph_trace_init(struct trace_array *tr)
 {
 	int cpu, ret;
Signature · 3 lines
1.5.6.5

-- 
#3 lore raw

Re: [PATCH 1/7] tracing/function-graph-tracer: make arch generic push pop functions

Quoted 6 lines · Steven Rostedt

Ingo,

This patch is to make function graph arch generic. But since the PowerPC changes depend on it, we want to push it through the PowerPC tree. But since it touches x86 code, can you give an Acked-by to it?

hm, but it's all ftrace bits. Could this go through the tracing tree? That's how it's generally done for most cross-arch subsystems. By having it in a separate tree we risk conflicts and various logistics problems. It's not like the PPC tree is modifying its ftrace.c file all that frequently, right?

Ingo

author maintainer
#4 lore raw

Re: [PATCH 1/7] tracing/function-graph-tracer: make arch generic push pop functions

Quoted 10 lines · Ingo Molnar
Quoted 6 lines · Steven Rostedt

Ingo,

This patch is to make function graph arch generic. But since the PowerPC changes depend on it, we want to push it through the PowerPC tree. But since it touches x86 code, can you give an Acked-by to it?

Quoted 5 lines

hm, but it's all ftrace bits. Could this go through the tracing tree? That's how it's generally done for most cross-arch subsystems. By having it in a separate tree we risk conflicts and various logistics problems. It's not like the PPC tree is modifying its ftrace.c file all that frequently, right?

Really doesn't matter to me which tree it goes. I figure tip would be fine in compile testing, but I doubt it would get much actual machine testing.

How fast do you get changes to next? Perhaps you could take it and push it out to next, where Ben could quickly get it back in for testing? Or at least do that with this patch, and then Ben could apply the others on top.

-- Steve

#5 lore raw

Re: [PATCH 1/7] tracing/function-graph-tracer: make arch generic push pop functions

Quoted 6 lines · Steven Rostedt
Quoted 5 lines

hm, but it's all ftrace bits. Could this go through the tracing tree? That's how it's generally done for most cross-arch subsystems. By having it in a separate tree we risk conflicts and various logistics problems. It's not like the PPC tree is modifying its ftrace.c file all that frequently, right?

Quoted 6 lines

Really doesn't matter to me which tree it goes. I figure tip would be fine in compile testing, but I doubt it would get much actual machine testing.

How fast do you get changes to next? Perhaps you could take it and push it out to next, where Ben could quickly get it back in for testing? Or at least do that with this patch, and then Ben could apply the others on top.

Well, it did already conflict with a patch from Kumar that change the opcodes, which I could fix easily in my tree but would have been harder to deal with in the tracing tree...

Also, my next tree will not pull somebody else next tree, as it's a never-rebase-will-merge tree though I have a test branch i can play with (in which your patches currently are).

In any case, I don't care -that- much who the patches go via, it's easier for me to fix them up when conflicts occur in powerpc land and they will probably get more testing via my tree but it's no big deal.

Cheers,
Ben.

author maintainer
#6 lore raw

Re: [PATCH 1/7] tracing/function-graph-tracer: make arch generic push pop functions

In reply to Ingo Molnar
Quoted 10 lines · Ingo Molnar
Quoted 6 lines · Steven Rostedt

Ingo,

This patch is to make function graph arch generic. But since the PowerPC changes depend on it, we want to push it through the PowerPC tree. But since it touches x86 code, can you give an Acked-by to it?

Quoted 5 lines

hm, but it's all ftrace bits. Could this go through the tracing tree? That's how it's generally done for most cross-arch subsystems. By having it in a separate tree we risk conflicts and various logistics problems. It's not like the PPC tree is modifying its ftrace.c file all that frequently, right?

Ingo,

How about this. We could incorporate some of the power of git. I could make a separate branch based off of Linus's 2.6.29-rc5 announcement, and apply just this patch (the ftrace generic and x86 change). If you give me your Acked-by, I'll add that too.

This way, both you and Ben could pull from this branch to get the one change. When it goes upstream, because it has the same SHA1, git could easily resolve it.

-- Steve

#7 lore raw

Re: [PATCH 1/7] tracing/function-graph-tracer: make arch generic push pop functions

Quoted 26 lines · Steven Rostedt
Quoted 10 lines · Ingo Molnar
Quoted 6 lines · Steven Rostedt

Ingo,

This patch is to make function graph arch generic. But since the PowerPC changes depend on it, we want to push it through the PowerPC tree. But since it touches x86 code, can you give an Acked-by to it?

Quoted 5 lines

hm, but it's all ftrace bits. Could this go through the tracing tree? That's how it's generally done for most cross-arch subsystems. By having it in a separate tree we risk conflicts and various logistics problems. It's not like the PPC tree is modifying its ftrace.c file all that frequently, right?

Ingo,

How about this. We could incorporate some of the power of git. I could make a separate branch based off of Linus's 2.6.29-rc5 announcement, and apply just this patch (the ftrace generic and x86 change). If you give me your Acked-by, I'll add that too.

Quoted 3 lines

This way, both you and Ben could pull from this branch to get the one change. When it goes upstream, because it has the same SHA1, git could easily resolve it.

Sure, that's fine too - if the separate tree is semantically meaningful. If it pulls in too many ftrace prerequisites i doubt it's appropriate for the PPC tree.

Ingo

author maintainer
#8 lore raw

Re: [PATCH 1/7] tracing/function-graph-tracer: make arch generic push pop functions

Quoted 29 lines · Ingo Molnar
Quoted 26 lines · Steven Rostedt
Quoted 10 lines · Ingo Molnar
Quoted 6 lines · Steven Rostedt

Ingo,

This patch is to make function graph arch generic. But since the PowerPC changes depend on it, we want to push it through the PowerPC tree. But since it touches x86 code, can you give an Acked-by to it?

Quoted 5 lines

hm, but it's all ftrace bits. Could this go through the tracing tree? That's how it's generally done for most cross-arch subsystems. By having it in a separate tree we risk conflicts and various logistics problems. It's not like the PPC tree is modifying its ftrace.c file all that frequently, right?

Ingo,

How about this. We could incorporate some of the power of git. I could make a separate branch based off of Linus's 2.6.29-rc5 announcement, and apply just this patch (the ftrace generic and x86 change). If you give me your Acked-by, I'll add that too.

Quoted 7 lines
Quoted 3 lines

This way, both you and Ben could pull from this branch to get the one change. When it goes upstream, because it has the same SHA1, git could easily resolve it.

Sure, that's fine too - if the separate tree is semantically meaningful. If it pulls in too many ftrace prerequisites i doubt it's appropriate for the PPC tree.

Yeah, I'll just make a new branch based off of Linus's 2.6.29-rc5 announcement, and add the one patch, and not touch it again. This will be a simple merge of one patch from a change set that is in both trees.

-- Steve

author maintainer
#9 lore raw

PATCH 2/7 powerpc64: port of the function graph tracer

In reply to Steven Rostedt

From: Steven Rostedt <[email protected]>

This is a port of the function graph tracer that was written by Frederic Weisbecker for the x86.

This only works for PPC64 at the moment and only for static tracing. PPC32 and dynamic function graph tracing support will come later.

The trace produces a visual calling of functions:

# tracer: function_graph
#
# CPU DURATION FUNCTION CALLS
# | | | | | | |

  0)   2.224 us    |                        }
  0) ! 271.024 us  |                      }
  0) ! 320.080 us  |                    }
  0) ! 324.656 us  |                  }
  0) ! 329.136 us  |                }
  0)               |                .put_prev_task_fair() {
  0)               |                  .update_curr() {
  0)   2.240 us    |                    .update_min_vruntime();
  0)   6.512 us    |                  }
  0)   2.528 us    |                  .__enqueue_entity();
  0) + 15.536 us   |                }
  0)               |                .pick_next_task_fair() {
  0)   2.032 us    |                  .__pick_next_entity();
  0)   2.064 us    |                  .__clear_buddies();
  0)               |                  .set_next_entity() {
  0)   2.672 us    |                    .__dequeue_entity();
  0)   6.864 us    |                  }

Geoff Lavand tested on PS3.

---
 arch/powerpc/Kconfig              |    1 +
 arch/powerpc/kernel/Makefile      |    9 ++--
 arch/powerpc/kernel/entry_64.S    |   58 +++++++++++++++++++++++++-
 arch/powerpc/kernel/ftrace.c      |   79 ++++++++++++++++++++++++++++++++++++-
 arch/powerpc/kernel/process.c     |   16 +++++++
 arch/powerpc/kernel/vmlinux.lds.S |    1 +
 6 files changed, 154 insertions(+), 10 deletions(-)
arch/powerpc/Kconfig +1 -0
index 74cc312..ca4647e 100644
@@ -111,6 +111,7 @@ config PPC
 	select HAVE_FTRACE_MCOUNT_RECORD
 	select HAVE_DYNAMIC_FTRACE
 	select HAVE_FUNCTION_TRACER
+	select HAVE_FUNCTION_GRAPH_TRACER if !DYNAMIC_FTRACE && PPC64
 	select ARCH_WANT_OPTIONAL_GPIOLIB
 	select HAVE_IDE
 	select HAVE_IOREMAP_PROT
arch/powerpc/kernel/Makefile +4 -5
index 8d1a419..a70aeea 100644
@@ -18,12 +18,10 @@ CFLAGS_REMOVE_cputable.o = -pg -mno-sched-epilog
 CFLAGS_REMOVE_prom_init.o = -pg -mno-sched-epilog
 CFLAGS_REMOVE_btext.o = -pg -mno-sched-epilog
 CFLAGS_REMOVE_prom.o = -pg -mno-sched-epilog
-
-ifdef CONFIG_DYNAMIC_FTRACE
-# dynamic ftrace setup.
+# do not trace tracer code
 CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
-endif
-
+# timers used by tracing
+CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
 endif
 
 obj-y				:= cputable.o ptrace.o syscalls.o \
@@ -94,6 +92,7 @@ obj-$(CONFIG_AUDIT)		+= audit.o
 obj64-$(CONFIG_AUDIT)		+= compat_audit.o
 
 obj-$(CONFIG_DYNAMIC_FTRACE)	+= ftrace.o
+obj-$(CONFIG_FUNCTION_GRAPH_TRACER)	+= ftrace.o
 
 obj-$(CONFIG_8XX_MINIMAL_FPEMU) += softemu8xx.o
 
arch/powerpc/kernel/entry_64.S +55 -3

68 lines not on this page · raw message

arch/powerpc/kernel/ftrace.c +77 -2

100 lines not on this page · raw message

arch/powerpc/kernel/process.c +16 -0
index fb7049c..8ede428 100644
@@ -33,6 +33,7 @@
 #include <linux/mqueue.h>
 #include <linux/hardirq.h>
 #include <linux/utsname.h>
+#include <linux/ftrace.h>
 #include <linux/kernel_stat.h>
 
 #include <asm/pgtable.h>
@@ -1008,6 +1009,14 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
 	unsigned long sp, ip, lr, newsp;
 	int count = 0;
 	int firstframe = 1;
+#ifdef CONFIG_FUNCTION_GRAPH_TRACER
+	int curr_frame = current->curr_ret_stack;
+	extern void return_to_handler(void);
+	unsigned long addr = (unsigned long)return_to_handler;
+#ifdef CONFIG_PPC64
+	addr = *(unsigned long*)addr;
+#endif
+#endif
 
 	sp = (unsigned long) stack;
 	if (tsk == NULL)
@@ -1030,6 +1039,13 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
 		ip = stack[STACK_FRAME_LR_SAVE];
 		if (!firstframe || ip != lr) {
 			printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
+#ifdef CONFIG_FUNCTION_GRAPH_TRACER
+			if (ip == addr && curr_frame >= 0) {
+				printk(" (%pS)",
+				       (void *)current->ret_stack[curr_frame].ret);
+				curr_frame--;
+			}
+#endif
 			if (firstframe)
 				printk(" (unreliable)");
 			printk("\n");
arch/powerpc/kernel/vmlinux.lds.S +1 -0
index 161b9b9..895af44 100644
@@ -58,6 +58,7 @@ SECTIONS
 		SCHED_TEXT
 		LOCK_TEXT
 		KPROBES_TEXT
+		IRQENTRY_TEXT
 
 #ifdef CONFIG_PPC32
 		*(.got1)
Signature · 3 lines
1.5.6.5

-- 
author maintainer
#10 lore raw

PATCH 3/7 powerpc64, tracing: add function graph tracer with dynamic tracing

In reply to Steven Rostedt

From: Steven Rostedt <[email protected]>

This is the port of the function graph tracer to PowerPC with dynamic tracing.

Geoff Lavand tested on PS3.

---
 arch/powerpc/Kconfig           |    2 +-
 arch/powerpc/kernel/entry_64.S |    8 ++++++-
 arch/powerpc/kernel/ftrace.c   |   47 ++++++++++++++++++++++++++++++++++-----
 3 files changed, 49 insertions(+), 8 deletions(-)
arch/powerpc/Kconfig +1 -1
index ca4647e..6e1ee1b 100644
@@ -111,7 +111,7 @@ config PPC
 	select HAVE_FTRACE_MCOUNT_RECORD
 	select HAVE_DYNAMIC_FTRACE
 	select HAVE_FUNCTION_TRACER
-	select HAVE_FUNCTION_GRAPH_TRACER if !DYNAMIC_FTRACE && PPC64
+	select HAVE_FUNCTION_GRAPH_TRACER if PPC64
 	select ARCH_WANT_OPTIONAL_GPIOLIB
 	select HAVE_IDE
 	select HAVE_IOREMAP_PROT
arch/powerpc/kernel/entry_64.S +7 -1
index a32699e..9f61fd6 100644
@@ -908,6 +908,12 @@ _GLOBAL(ftrace_caller)
 ftrace_call:
 	bl	ftrace_stub
 	nop
+#ifdef CONFIG_FUNCTION_GRAPH_TRACER
+.globl ftrace_graph_call
+ftrace_graph_call:
+	b	ftrace_graph_stub
+_GLOBAL(ftrace_graph_stub)
+#endif
 	ld	r0, 128(r1)
 	mtlr	r0
 	addi	r1, r1, 112
@@ -946,7 +952,7 @@ _GLOBAL(ftrace_stub)
 #endif /* CONFIG_DYNAMIC_FTRACE */
 
 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
-ftrace_graph_caller:
+_GLOBAL(ftrace_graph_caller)
 	/* load r4 with local address */
 	ld	r4, 128(r1)
 	subi	r4, r4, MCOUNT_INSN_SIZE
arch/powerpc/kernel/ftrace.c +41 -6

83 lines not on this page · raw message

Signature · 3 lines
1.5.6.5

-- 
author maintainer
#11 lore raw

PATCH 4/7 powerpc64, ftrace: save toc only on modules for function graph

In reply to Steven Rostedt

From: Steven Rostedt <[email protected]>

The TOCS used by modules are different than the one used by the core kernel code. The function graph tracer must save and restore the TOC whenever it traces a module call. But this is an added overhead to burden the majority of core kernel code being traced.

Benjamin Herrenschmidt suggested in testing the entry of the call to tell if it is a core kernel function or a module. He recommended using the REGION_ID() macro to perform this test.

This patch implements Benjamin's idea, and uses a different return_to_handler routine dependent on if the entry is a core kernel function or not. The module version saves the TOC, where as the core kernel version does not.

Geoff Lavand tested on PS3.

---
 arch/powerpc/kernel/entry_64.S |   27 ++++++++++++++++++++++++++-
 arch/powerpc/kernel/ftrace.c   |   13 +++++++++++--
 2 files changed, 37 insertions(+), 3 deletions(-)
arch/powerpc/kernel/entry_64.S +26 -1
index 9f61fd6..abfc323 100644
@@ -971,6 +971,28 @@ _GLOBAL(ftrace_graph_caller)
 
 _GLOBAL(return_to_handler)
 	/* need to save return values */
+	std	r4,  -24(r1)
+	std	r3,  -16(r1)
+	std	r31, -8(r1)
+	mr	r31, r1
+	stdu	r1, -112(r1)
+
+	bl	.ftrace_return_to_handler
+	nop
+
+	/* return value has real return address */
+	mtlr	r3
+
+	ld	r1, 0(r1)
+	ld	r4,  -24(r1)
+	ld	r3,  -16(r1)
+	ld	r31, -8(r1)
+
+	/* Jump back to real return address */
+	blr
+
+_GLOBAL(mod_return_to_handler)
+	/* need to save return values */
 	std	r4,  -32(r1)
 	std	r3,  -24(r1)
 	/* save TOC */
@@ -979,7 +1001,10 @@ _GLOBAL(return_to_handler)
 	mr	r31, r1
 	stdu	r1, -112(r1)
 
-	/* update the TOC */
+	/*
+	 * We are in a module using the module's TOC.
+	 * Switch to our TOC to run inside the core kernel.
+	 */
 	LOAD_REG_IMMEDIATE(r4,ftrace_return_to_handler)
 	ld	r2, 8(r4)
 
arch/powerpc/kernel/ftrace.c +11 -2
index 7538b94..5c6dfa9 100644
@@ -567,6 +567,10 @@ int ftrace_disable_ftrace_graph_caller(void)
 }
 #endif /* CONFIG_DYNAMIC_FTRACE */
 
+#ifdef CONFIG_PPC64
+extern void mod_return_to_handler(void);
+#endif
+
 /*
  * Hook the return address and push it in the stack of return addrs
  * in current thread info.
@@ -577,12 +581,17 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr)
 	unsigned long long calltime;
 	int faulted;
 	struct ftrace_graph_ent trace;
-	unsigned long return_hooker = (unsigned long)
-				&return_to_handler;
+	unsigned long return_hooker = (unsigned long)&return_to_handler;
 
 	if (unlikely(atomic_read(&current->tracing_graph_pause)))
 		return;
 
+#if CONFIG_PPC64
+	/* non core kernel code needs to save and restore the TOC */
+	if (REGION_ID(self_addr) != KERNEL_REGION_ID)
+		return_hooker = (unsigned long)&mod_return_to_handler;
+#endif
+
 	return_hooker = GET_ADDR(return_hooker);
 
 	/*
Signature · 3 lines
1.5.6.5

-- 
author maintainer
#12 lore raw

PATCH 5/7 powerpc32, ftrace: save and restore mcount regs with macro

In reply to Steven Rostedt

From: Steven Rostedt <[email protected]>

Impact: clean up

Use a macro to save and restore the registers for PowerPC32, since that code is duplicated.

This is similar to the work done by Cyrill Gorcunov for the mcount code in x86_64.

---
 arch/powerpc/include/asm/ftrace.h |   39 ++++++++++++++++++++-
 arch/powerpc/kernel/entry_32.S    |   68 +++++--------------------------------
 2 files changed, 47 insertions(+), 60 deletions(-)
arch/powerpc/include/asm/ftrace.h +38 -1
index e5f2ae8..dde1296 100644
@@ -5,7 +5,44 @@
 #define MCOUNT_ADDR		((long)(_mcount))
 #define MCOUNT_INSN_SIZE	4 /* sizeof mcount call */
 
-#ifndef __ASSEMBLY__
+#ifdef __ASSEMBLY__
+
+/* Based off of objdump optput from glibc */
+
+#define MCOUNT_SAVE_FRAME			\
+	stwu	r1,-48(r1);			\
+	stw	r3, 12(r1);			\
+	stw	r4, 16(r1);			\
+	stw	r5, 20(r1);			\
+	stw	r6, 24(r1);			\
+	mflr	r3;				\
+	lwz	r4, 52(r1);			\
+	mfcr	r5;				\
+	stw	r7, 28(r1);			\
+	stw	r8, 32(r1);			\
+	stw	r9, 36(r1);			\
+	stw	r10,40(r1);			\
+	stw	r3, 44(r1);			\
+	stw	r5, 8(r1)
+
+#define MCOUNT_RESTORE_FRAME			\
+	lwz	r6, 8(r1);			\
+	lwz	r0, 44(r1);			\
+	lwz	r3, 12(r1);			\
+	mtctr	r0;				\
+	lwz	r4, 16(r1);			\
+	mtcr	r6;				\
+	lwz	r5, 20(r1);			\
+	lwz	r6, 24(r1);			\
+	lwz	r0, 52(r1);			\
+	lwz	r7, 28(r1);			\
+	lwz	r8, 32(r1);			\
+	mtlr	r0;				\
+	lwz	r9, 36(r1);			\
+	lwz	r10,40(r1);			\
+	addi	r1, r1, 48
+
+#else /* !__ASSEMBLY__ */
 extern void _mcount(void);
 
 #ifdef CONFIG_DYNAMIC_FTRACE
arch/powerpc/kernel/entry_32.S +9 -59

89 lines not on this page · raw message

Signature · 3 lines
1.5.6.5

-- 
author maintainer
#13 lore raw

PATCH 6/7 powerpc32, ftrace: port function graph tracer to ppc32, static only

In reply to Steven Rostedt

From: Steven Rostedt <[email protected]>

This patch ports the function graph tracer for PowerPC, but only for static function tracing.

---
 arch/powerpc/Kconfig           |    2 +-
 arch/powerpc/kernel/entry_32.S |   43 +++++++++++++++++++++++++++++++++++++++-
 arch/powerpc/kernel/ftrace.c   |    2 +-
 3 files changed, 44 insertions(+), 3 deletions(-)
arch/powerpc/Kconfig +1 -1
index 6e1ee1b..9e4bd20 100644
@@ -111,7 +111,7 @@ config PPC
 	select HAVE_FTRACE_MCOUNT_RECORD
 	select HAVE_DYNAMIC_FTRACE
 	select HAVE_FUNCTION_TRACER
-	select HAVE_FUNCTION_GRAPH_TRACER if PPC64
+	select HAVE_FUNCTION_GRAPH_TRACER if PPC64 || !DYNAMIC_FTRACE
 	select ARCH_WANT_OPTIONAL_GPIOLIB
 	select HAVE_IDE
 	select HAVE_IOREMAP_PROT
arch/powerpc/kernel/entry_32.S +42 -1

55 lines not on this page · raw message

arch/powerpc/kernel/ftrace.c +1 -1
index 5c6dfa9..dddd99b 100644
@@ -603,7 +603,7 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr)
 		"1: " PPC_LL "%[old], 0(%[parent])\n"
 		"2: " PPC_STL "%[return_hooker], 0(%[parent])\n"
 		"   li %[faulted], 0\n"
-		"3:"
+		"3:\n"
 
 		".section .fixup, \"ax\"\n"
 		"4: li %[faulted], 1\n"
Signature · 3 lines
1.5.6.5

-- 
author maintainer
#14 lore raw

PATCH 7/7 powerpc32, ftrace: dynamic function graph tracer

In reply to Steven Rostedt

From: Steven Rostedt <[email protected]>

This patch gets function graph tracing working with dynamic function tracer on PowerPC32.

---
 arch/powerpc/Kconfig           |    2 +-
 arch/powerpc/kernel/entry_32.S |    8 ++++++--
 2 files changed, 7 insertions(+), 3 deletions(-)
arch/powerpc/Kconfig +1 -1
index 9e4bd20..40b7981 100644
@@ -111,7 +111,7 @@ config PPC
 	select HAVE_FTRACE_MCOUNT_RECORD
 	select HAVE_DYNAMIC_FTRACE
 	select HAVE_FUNCTION_TRACER
-	select HAVE_FUNCTION_GRAPH_TRACER if PPC64 || !DYNAMIC_FTRACE
+	select HAVE_FUNCTION_GRAPH_TRACER
 	select ARCH_WANT_OPTIONAL_GPIOLIB
 	select HAVE_IDE
 	select HAVE_IOREMAP_PROT
arch/powerpc/kernel/entry_32.S +6 -2
index 9cf7083..529bfbb 100644
@@ -1183,7 +1183,12 @@ _GLOBAL(ftrace_caller)
 ftrace_call:
 	bl	ftrace_stub
 	nop
-
+#ifdef CONFIG_FUNCTION_GRAPH_TRACER
+.globl ftrace_graph_call
+ftrace_graph_call:
+	b	ftrace_graph_stub
+_GLOBAL(ftrace_graph_stub)
+#endif
 	MCOUNT_RESTORE_FRAME
 	/* old link register ends up in ctr reg */
 	bctr
@@ -1205,7 +1210,6 @@ _GLOBAL(_mcount)
 	b	ftrace_graph_caller
 #endif
 	MCOUNT_RESTORE_FRAME
-	
 	bctr
 #endif
 
Signature · 3 lines
1.5.6.5

--