function graph tracer port to PowerPC
Steven Rostedt
maintainercover function graph tracer port to PowerPC
The following set of patches are RFC and not for inclusion (unless everyone is fine with them as is).
This is the port to PowerPC of the function graph tracer that was written by Frederic Weisbecker for the x86 architecture. It is broken up into a series of logical steps.
1) get generic code ready for other archs
2) get PowerPC 64-bit working with just static function tracing
3) get PowerPC 64-bit working with dynamic function tracing
4) get PowerPC 32-bit working with just static function tracing
5) get PowerPC 32-bit working with dynamic function tracing
(with some clean ups in between)
The function graph tracer not only traces the start of a function (uses the function tracer part for that) but also uses the kprobes trick to replace the return address with a hook to trace the exit of the function. These hooks are generic in that other tracers can also use them. But the function graph tracer itself is very powerful. Simply doing the following:
# echo function_graph > /debug/tracing/current_tracer # cat /debug/tracing/trace
# tracer: function_graph
#
# CPU OVERHEAD/DURATION FUNCTION CALLS
# | | | | | | |
------------------------------------------
0) less-2228 => cat-2229
------------------------------------------
0) | .__do_fault() {
0) | .filemap_fault() {
0) | .find_lock_page() {
0) | .find_get_page() {
0) 3.168 us | .__rcu_read_lock();
0) 2.704 us | .__rcu_read_unlock();
0) + 14.640 us | }
0) + 20.112 us | }
0) + 26.464 us | }
0) 2.912 us | ._spin_lock();
0) 2.656 us | .page_add_file_rmap();
0) | .update_mmu_cache() {
0) | .hash_preload() {
0) 2.368 us | .get_slice_psize();
0) 2.752 us | .hash_page_do_lazy_icache();
0) 3.568 us | .native_hpte_insert();
0) + 19.680 us | }
0) + 24.960 us | }
0) 2.336 us | ._spin_unlock();
0) | .unlock_page() {
0) 2.688 us | .page_waitqueue();
0) 2.608 us | .__wake_up_bit();
0) + 12.912 us | }
0) ! 351.776 us | }
0) ! 357.392 us | }
0) 3.040 us | .up_read();
0) | .compat_sys_ioctl() {
0) 3.024 us | .fget_light();
0) | .tty_compat_ioctl() {
0) 2.704 us | .tty_paranoia_check();
0) | .tty_ldisc_ref_wait() {
0) | .tty_ldisc_try() {
0) 2.880 us | ._spin_lock_irqsave();
0) 2.928 us | ._spin_unlock_irqrestore();
0) + 13.776 us | }
0) + 19.424 us | }[...]
As you can see, it gives a nice call trace of the functions being called at run time, as well as a time stamp of how much time the function took to execute.
Adding dynamic tracing to the mix, we can trace a single function:
# echo .do_fork > /debug/tracing/set_graph_function # echo function_graph > /debug/tracing/current_tracer # cat /debug/tracing/trace
# tracer: function_graph
#
# CPU OVERHEAD/DURATION FUNCTION CALLS
# | | | | | | |
1) | .do_fork() {
1) | .copy_process() {
1) | .prepare_to_copy() {
1) 2.944 us | .flush_fp_to_thread();
1) 2.800 us | .flush_altivec_to_thread();
1) 2.608 us | .flush_vsx_to_thread();
1) + 19.184 us | }
1) | .kmem_cache_alloc() {
1) 2.464 us | .slab_should_failslab();
1) 8.304 us | }
1) | .alloc_thread_info() {
1) | .kmem_cache_alloc() {
1) 2.512 us | .slab_should_failslab();
1) 8.224 us | }
1) + 13.344 us | }
1) 7.584 us | .arch_dup_task_struct();
1) | .copy_creds() {
1) 2.736 us | .__mutex_init();
1) | .prepare_creds() {
1) | .kmem_cache_alloc() {
1) 2.640 us | .slab_should_failslab();
1) 8.368 us | }[...]
Note, the '.' in the '.do_fork' is a PowerPC64 thing. PowerPC32 and other archs just need to do 'do_fork', without the dot.
The following patches are in:
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git
branch: rfc/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(-)
Steven Rostedt
maintainerRFC 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
@@ -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
@@ -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 --
Steven Rostedt
maintainerRFC PATCH 2/7 powerpc64: port of the function graph tracer
In reply to Steven RostedtFrom: 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 | }--- 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
@@ -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
@@ -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
@@ -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
@@ -58,6 +58,7 @@ SECTIONS SCHED_TEXT LOCK_TEXT KPROBES_TEXT + IRQENTRY_TEXT #ifdef CONFIG_PPC32 *(.got1)
Signature · 3 lines
1.5.6.5 --
Re: [PATCH 2/7][RFC] powerpc64: port of the function graph tracer
arch/powerpc/kernel/Makefile CFLAGS_REMOVE_cputable.o = -pg -mno-sched-epilog · line 25
Quoted 5 lines · Steven Rostedt
arch/powerpc/kernel/Makefile +2
-0+# timers used by tracing +CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog endif
That means no tracing of the timer interrupts etc... maybe we should just move the specific function that we don't want traced out to a separate file ?
Appart from that, it looks ok, though I might have missed something :-)
Cheers,
Ben.
Steven Rostedt
maintainerRe: [PATCH 2/7][RFC] powerpc64: port of the function graph tracer
Quoted 9 lines · Benjamin Herrenschmidt
arch/powerpc/kernel/Makefile CFLAGS_REMOVE_cputable.o = -pg -mno-sched-epilog · line 25
Quoted 5 lines · Steven Rostedt
arch/powerpc/kernel/Makefile +2
-0+# timers used by tracing +CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog endifThat means no tracing of the timer interrupts etc... maybe we should just move the specific function that we don't want traced out to a separate file ?
The function graph tracer calls cpu_clock, which calls sched_clock, to get the times. There's no protection against recursion here, since we want to let interrupts still be recorded, and we do not need to disable interrupts.
But if the cpu_clock calls something that is traced, it will recurse, and cause a lockup. What ever functions those are, we could annotate with notrace. I just used the x86 blind method of 'dont trace this file'.
Quoted 2 lines
Appart from that, it looks ok, though I might have missed something :-)
Thanks,
-- Steve
Steven Rostedt
maintainerRFC PATCH 3/7 powerpc64, tracing: add function graph tracer with dynamic tracing
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
This is the port of the function graph tracer to PowerPC with dynamic tracing.
--- 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
@@ -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
@@ -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 --
Re: [PATCH 3/7][RFC] powerpc64, tracing: add function graph tracer with dynamic tracing
arch/powerpc/kernel/ftrace.c static unsigned char *ftrace_call_replace(unsigned · line 62
Quoted 11 lines
arch/powerpc/kernel/ftrace.c +3
-2@@ -55,8 +56,9 @@ static unsigned char *ftrace_call_replace(unsignedlong ip, unsigned long addr) */ addr =GET_ADDR (addr); -/* Set to "bl addr" */ - op =0x48000001 | (ftrace_calc_offset (ip, addr) &0x03fffffc ); +/* if (link) set op to 'bl' else 'b' */ + op =0x48000000 | (link ?1 :0 ); + op |= (ftrace_calc_offset (ip, addr) &0x03fffffc );
Any reason why you aren't using the code inarch/powerpc/lib/code-patching.c here ?
arch/powerpc/kernel/ftrace.c int __init ftrace_dyn_arch_init(void *data) · line 553
Quoted 6 lines
arch/powerpc/kernel/ftrace.c +5
-0new =ftrace_call_replace (ip, stub,0 ); +memcpy (old, new,MCOUNT_INSN_SIZE ); + new =ftrace_call_replace (ip, addr,0 ); + +return ftrace_modify_code (ip, old, new); +}
Heh, memcpy of 4 bytes :-) I hope gcc is smart enough to turn that into a simple load/store ..
Cheers,
Ben.
Steven Rostedt
maintainerRe: [PATCH 3/7][RFC] powerpc64, tracing: add function graph tracer with dynamic tracing
Quoted 15 lines · Benjamin Herrenschmidt
arch/powerpc/kernel/ftrace.c static unsigned char *ftrace_call_replace(unsigned · line 62
Quoted 11 lines
arch/powerpc/kernel/ftrace.c +3
-2@@ -55,8 +56,9 @@ static unsigned char *ftrace_call_replace(unsignedlong ip, unsigned long addr) */ addr =GET_ADDR (addr); -/* Set to "bl addr" */ - op =0x48000001 | (ftrace_calc_offset (ip, addr) &0x03fffffc ); +/* if (link) set op to 'bl' else 'b' */ + op =0x48000000 | (link ?1 :0 ); + op |= (ftrace_calc_offset (ip, addr) &0x03fffffc );Any reason why you aren't using the code in
arch/powerpc/lib/code-patching.chere ?
Quoted 9 lines
arch/powerpc/kernel/ftrace.c int __init ftrace_dyn_arch_init(void *data) · line 553
Quoted 6 lines
arch/powerpc/kernel/ftrace.c +5
-0new =ftrace_call_replace (ip, stub,0 ); +memcpy (old, new,MCOUNT_INSN_SIZE ); + new =ftrace_call_replace (ip, addr,0 ); + +return ftrace_modify_code (ip, old, new); +}Heh, memcpy of 4 bytes :-) I hope gcc is smart enough to turn that into a simple load/store ..
hehe, I hated writing that. I just did not want to touch the (already working code) of the dynamic ftrace. I guess I could still use longs and then typecast them to char pointers for the ftrace_modify_code.
Thanks,
-- Steve
Steven Rostedt
maintainerRe: [PATCH 3/7][RFC] powerpc64, tracing: add function graph tracer with dynamic tracing
In reply to Benjamin HerrenschmidtQuoted 6 lines · Benjamin Herrenschmidt
Quoted 6 lines
arch/powerpc/kernel/ftrace.c +0
-0@@ -55,8 +56,9 @@ static unsigned char *ftrace_call_replace(unsignedlong ip, unsigned long addr) */ addr =GET_ADDR (addr);
Quoted 8 lines
arch/powerpc/kernel/ftrace.c static unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr) · line 61
Quoted 5 lines
arch/powerpc/kernel/ftrace.c +3
-2-/* Set to "bl addr" */ - op =0x48000001 | (ftrace_calc_offset (ip, addr) &0x03fffffc ); +/* if (link) set op to 'bl' else 'b' */ + op =0x48000000 | (link ?1 :0 ); + op |= (ftrace_calc_offset (ip, addr) &0x03fffffc );Any reason why you aren't using the code in
arch/powerpc/lib/code-patching.chere ?
Yes, because I did not know about it ;-)
I'll write up a patch to change this. But I'll post this series as is for now.
Thanks,
-- Steve
Steven Rostedt
maintainerRFC PATCH 4/7 powerpc64, ftrace: save toc only on modules for function graph
In reply to Steven RostedtFrom: 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.
--- 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
@@ -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
@@ -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 (¤t->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 --
Steven Rostedt
maintainerRFC PATCH 5/7 powerpc32, ftrace: save and restore mcount regs with macro
In reply to Steven RostedtFrom: Steven Rostedt <rostedt@gollum.(none)>
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
@@ -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 --
Steven Rostedt
maintainerRFC PATCH 6/7 powerpc32, ftrace: port function graph tracer to ppc32, static only
In reply to Steven RostedtFrom: 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
@@ -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
@@ -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 --
Steven Rostedt
maintainerRFC PATCH 7/7 powerpc32, ftrace: dynamic function graph tracer
In reply to Steven RostedtFrom: Steven Rostedt <rostedt@gollum.(none)>
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
@@ -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
@@ -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 --
Quoted 8 lines · Steven Rostedt
The following set of patches are RFC and not for inclusion (unless everyone is fine with them as is).
This is the port to PowerPC of the function graph tracer that was written by Frederic Weisbecker for the x86 architecture. It is broken up into a series of logical steps.
Quoted 8 lines
1) get generic code ready for other archs
2) get PowerPC 64-bit working with just static function tracing
3) get PowerPC 64-bit working with dynamic function tracing
4) get PowerPC 32-bit working with just static function tracing
5) get PowerPC 32-bit working with dynamic function tracing(with some clean ups in between)
Thanks a lot Steven!
I'm sad to not having a Power Pc to test it...
Quoted 132 lines
The function graph tracer not only traces the start of a function (uses the function tracer part for that) but also uses the kprobes trick to replace the return address with a hook to trace the exit of the function. These hooks are generic in that other tracers can also use them. But the function graph tracer itself is very powerful. Simply doing the following:
# echo function_graph > /debug/tracing/current_tracer # cat /debug/tracing/trace# tracer:
function_graph
#
# CPU OVERHEAD/DURATION FUNCTION CALLS
# | | | | | | |
------------------------------------------
0) less-2228 => cat-2229
------------------------------------------0) | .__do_fault() { 0) | .filemap_fault() { 0) | .find_lock_page() { 0) | .find_get_page() { 0) 3.168 us | .__rcu_read_lock(); 0) 2.704 us | .__rcu_read_unlock(); 0) + 14.640 us | } 0) + 20.112 us | } 0) + 26.464 us | } 0) 2.912 us | ._spin_lock(); 0) 2.656 us | .page_add_file_rmap(); 0) | .update_mmu_cache() { 0) | .hash_preload() { 0) 2.368 us | .get_slice_psize(); 0) 2.752 us | .hash_page_do_lazy_icache(); 0) 3.568 us | .native_hpte_insert(); 0) + 19.680 us | } 0) + 24.960 us | } 0) 2.336 us | ._spin_unlock(); 0) | .unlock_page() { 0) 2.688 us | .page_waitqueue(); 0) 2.608 us | .__wake_up_bit(); 0) + 12.912 us | } 0) ! 351.776 us | } 0) ! 357.392 us | } 0) 3.040 us | .up_read(); 0) | .compat_sys_ioctl() { 0) 3.024 us | .fget_light(); 0) | .tty_compat_ioctl() { 0) 2.704 us | .tty_paranoia_check(); 0) | .tty_ldisc_ref_wait() { 0) | .tty_ldisc_try() { 0) 2.880 us | ._spin_lock_irqsave(); 0) 2.928 us | ._spin_unlock_irqrestore(); 0) + 13.776 us | } 0) + 19.424 us | }[...]
As you can see, it gives a nice call trace of the functions being called at run time, as well as a time stamp of how much time the function took to execute.
Adding dynamic tracing to the mix, we can trace a single function:
# echo .do_fork > /debug/tracing/set_graph_function # echo function_graph > /debug/tracing/current_tracer # cat /debug/tracing/trace# tracer:
function_graph
#
# CPU OVERHEAD/DURATION FUNCTION CALLS
# | | | | | | |1) | .do_fork() { 1) | .copy_process() { 1) | .prepare_to_copy() { 1) 2.944 us | .flush_fp_to_thread(); 1) 2.800 us | .flush_altivec_to_thread(); 1) 2.608 us | .flush_vsx_to_thread(); 1) + 19.184 us | } 1) | .kmem_cache_alloc() { 1) 2.464 us | .slab_should_failslab(); 1) 8.304 us | } 1) | .alloc_thread_info() { 1) | .kmem_cache_alloc() { 1) 2.512 us | .slab_should_failslab(); 1) 8.224 us | } 1) + 13.344 us | } 1) 7.584 us | .arch_dup_task_struct(); 1) | .copy_creds() { 1) 2.736 us | .__mutex_init(); 1) | .prepare_creds() { 1) | .kmem_cache_alloc() { 1) 2.640 us | .slab_should_failslab(); 1) 8.368 us | }[...]
Note, the '.' in the '.do_fork' is a PowerPC64 thing. PowerPC32 and other archs just need to do '
do_fork', without the dot.The following patches are in:
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.gitbranch: rfc/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(-)
Steven Rostedt
maintainerQuoted 15 lines · Frederic Weisbecker
Quoted 14 lines · Steven Rostedt
The following set of patches are RFC and not for inclusion (unless everyone is fine with them as is).
This is the port to PowerPC of the function graph tracer that was written by Frederic Weisbecker for the x86 architecture. It is broken up into a series of logical steps.
1) get generic code ready for other archs
2) get PowerPC 64-bit working with just static function tracing
3) get PowerPC 64-bit working with dynamic function tracing
4) get PowerPC 32-bit working with just static function tracing
5) get PowerPC 32-bit working with dynamic function tracing
Quoted 6 lines
Quoted 2 lines
(with some clean ups in between)
Thanks a lot Steven!
I'm sad to not having a Power Pc to test it...
If you had a PowerPC, I doubt I would have been the one to port it ;-)
-- Steve
Quoted 18 lines · Steven Rostedt
Quoted 15 lines · Frederic Weisbecker
Quoted 14 lines · Steven Rostedt
The following set of patches are RFC and not for inclusion (unless everyone is fine with them as is).
This is the port to PowerPC of the function graph tracer that was written by Frederic Weisbecker for the x86 architecture. It is broken up into a series of logical steps.
1) get generic code ready for other archs
2) get PowerPC 64-bit working with just static function tracing
3) get PowerPC 64-bit working with dynamic function tracing
4) get PowerPC 32-bit working with just static function tracing
5) get PowerPC 32-bit working with dynamic function tracing
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
(with some clean ups in between)
Thanks a lot Steven!
I'm sad to not having a Power Pc to test it...If you had a PowerPC, I doubt I would have been the one to port it ;-)
Especially since you already implemented ftrace on PowerPc :) I will acquire an Arm board soon to adapt function graph on Arm...
Quoted 2 lines
-- Steve
Steven Rostedt
maintainerQuoted 15 lines · Frederic Weisbecker
Quoted 14 lines · Steven Rostedt
The following set of patches are RFC and not for inclusion (unless everyone is fine with them as is).
This is the port to PowerPC of the function graph tracer that was written by Frederic Weisbecker for the x86 architecture. It is broken up into a series of logical steps.
1) get generic code ready for other archs
2) get PowerPC 64-bit working with just static function tracing
3) get PowerPC 64-bit working with dynamic function tracing
4) get PowerPC 32-bit working with just static function tracing
5) get PowerPC 32-bit working with dynamic function tracing
Quoted 6 lines
Quoted 2 lines
(with some clean ups in between)
Thanks a lot Steven!
I'm sad to not having a Power Pc to test it...
BTW, Can I count that as an Acked-by: for the first patch. Since the first patch does modify your code.
-- Steve
Quoted 22 lines · Steven Rostedt
Quoted 19 lines · Frederic Weisbecker
Quoted 16 lines · Steven Rostedt
The following set of patches are RFC and not for inclusion (unless everyone is fine with them as is).
This is the port to PowerPC of the function graph tracer that was written by Frederic Weisbecker for the x86 architecture. It is broken up into a series of logical steps.
1) get generic code ready for other archs
2) get PowerPC 64-bit working with just static function tracing
3) get PowerPC 64-bit working with dynamic function tracing
4) get PowerPC 32-bit working with just static function tracing
5) get PowerPC 32-bit working with dynamic function tracing(with some clean ups in between)
Quoted 8 lines
Quoted 2 lines
Thanks a lot Steven!
I'm sad to not having a Power Pc to test it...BTW, Can I count that as an Acked-by: for the first patch. Since the first patch does modify your code.
-- Steve
Yes of course, I knew most of it was architecture independant but I delayed this TODO for future ports, and you've done it.
Thanks.
Just a micro detail: the ftrace_push/pop_return_trace are parts of the core of the entry/return probe, something that could be used by other users than the function graph tracer itself.
Perhaps it would be better to put them in kernel/trace/ftrace.c What do you think?
Anyway, Acked-by: Frederic Weisbecker <[email protected]>
Steven Rostedt
maintainerQuoted 5 lines · Frederic Weisbecker
Yes of course, I knew most of it was architecture independant but I delayed this TODO for future ports, and you've done it.
Quoted 8 lines
Thanks.
Just a micro detail: the ftrace_push/pop_return_trace are parts of the core of the entry/return probe, something that could be used by other users than the function graph tracer itself.
Perhaps it would be better to put them in
kernel/trace/ftrace.cWhat do you think?
I'll go with your above method. We'll move it when it comes to that ;-)
Quoted 2 lines
Anyway, Acked-by: Frederic Weisbecker <[email protected]>
Thanks!
I'll update my repo.
-- Steve
For some reason I didn't get 7/7 ...
Cheers,
Ben.
Quoted 13 lines · Steven Rostedt
The following set of patches are RFC and not for inclusion (unless everyone is fine with them as is).
This is the port to PowerPC of the function graph tracer that was written by Frederic Weisbecker for the x86 architecture. It is broken up into a series of logical steps.
1) get generic code ready for other archs
2) get PowerPC 64-bit working with just static function tracing
3) get PowerPC 64-bit working with dynamic function tracing
4) get PowerPC 32-bit working with just static function tracing
5) get PowerPC 32-bit working with dynamic function tracing
Quoted 7 lines
(with some clean ups in between)
The function graph tracer not only traces the start of a function (uses the function tracer part for that) but also uses the kprobes trick to replace the return address with a hook to trace the exit of the function.
You use the "kprobes trick", but none of the kprobes code (AFAICS). Couldn't there be some common code between the two?
cheers
Signature · 8 lines
Michael Ellerman OzLabs, IBM Australia Development Lab wwweb: http://michael.ellerman.id.au phone: +61 2 6212 1183 (tie line 70 21183) We do not inherit the earth from our ancestors, we borrow it from our children. - S.M.A.R.T Person
Steven Rostedt
maintainerQuoted 9 lines · Michael Ellerman
Quoted 6 lines
The function graph tracer not only traces the start of a function (uses the function tracer part for that) but also uses the kprobes trick to replace the return address with a hook to trace the exit of the function.
You use the "kprobes trick", but none of the kprobes code (AFAICS). Couldn't there be some common code between the two?
I'm not 100% sure how kprobes work, but I believe they use traps. And then they set the return address to take another trap, to fix it. I could be totally off here, on how kprobes does this.
But ftrace is about executing the code directly. The return code jumps to a another function in asm that will set up the call to do the tracing, and then fix the return pointer back. The only thing that is similar between the two approaches that I can tell, is that we both modify the return address of the function. I took a quick peek at the kprobes code and I see no easy way to share it.
-- Steve
Steven Rostedt
maintainerQuoted 8 lines · Steven Rostedt
The following set of patches are RFC and not for inclusion (unless everyone is fine with them as is).
This is the port to PowerPC of the function graph tracer that was written by Frederic Weisbecker for the x86 architecture. It is broken up into a series of logical steps.
Quoted 7 lines
1) get generic code ready for other archs
2) get PowerPC 64-bit working with just static function tracing
3) get PowerPC 64-bit working with dynamic function tracing
4) get PowerPC 32-bit working with just static function tracing
5) get PowerPC 32-bit working with dynamic function tracing(with some clean ups in between)
Ben, if you get some time (no rush really), can you give an acked-by on each of the PPC patches. The first patch is ftrace generic, so you can ignore that one.
I'll keep it in the RFC state, until I have an ack from either you or Paul.
I'm not sure if these changes should go via you or Ingo. I'm thinking that, since the first change modifies core ftrace code, I'll send it towards tip, since all the rest depends on that first change.
Thanks,
-- Steve
Quoted 3 lines · Steven Rostedt
This is the port to PowerPC of the function graph tracer that was written by Frederic Weisbecker for the x86 architecture. It is broken up into a series of logical steps.
I added these to my ps3-linux.git tree. Very casual testing shows they seem to work OK.
Steven Rostedt
maintainerQuoted 10 lines · Geoff Levand
Quoted 3 lines · Steven Rostedt
This is the port to PowerPC of the function graph tracer that was written by Frederic Weisbecker for the x86 architecture. It is broken up into a series of logical steps.
I added these to my ps3-linux.git tree. Very casual testing shows they seem to work OK.
Thanks!
Is the ps3 64 or 32 bit? I'll put your tested by on the appropriate patches.
-- Steve
Quoted 12 lines · Steven Rostedt
Quoted 9 lines · Geoff Levand
Quoted 3 lines · Steven Rostedt
This is the port to PowerPC of the function graph tracer that was written by Frederic Weisbecker for the x86 architecture. It is broken up into a series of logical steps.
I added these to my ps3-linux.git tree. Very casual testing shows they seem to work OK.
Quoted 6 lines
Quoted 1 line
Thanks!
Is the ps3 64 or 32 bit? I'll put your tested by on the appropriate patches.
64-bit.
josh
Quoted 11 lines · Steven Rostedt
Quoted 9 lines · Geoff Levand
Quoted 3 lines · Steven Rostedt
This is the port to PowerPC of the function graph tracer that was written by Frederic Weisbecker for the x86 architecture. It is broken up into a series of logical steps.
I added these to my ps3-linux.git tree. Very casual testing shows they seem to work OK.
Quoted 6 lines
Quoted 1 line
Thanks!
Is the ps3 64 or 32 bit? I'll put your tested by on the appropriate patches.
It uses the Cell processor, which is 64 bit.
-Geoff
Steven Rostedt
maintainerQuoted 12 lines · Geoff Levand
Quoted 11 lines · Steven Rostedt
Quoted 9 lines · Geoff Levand
Quoted 3 lines · Steven Rostedt
This is the port to PowerPC of the function graph tracer that was written by Frederic Weisbecker for the x86 architecture. It is broken up into a series of logical steps.
I added these to my ps3-linux.git tree. Very casual testing shows they seem to work OK.
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Thanks!
Is the ps3 64 or 32 bit? I'll put your tested by on the appropriate patches.
It uses the Cell processor, which is 64 bit.
Thanks guys!
-- Steve