aboutsummaryrefslogtreecommitdiffstats
path: root/arch/mips/kernel/mcount.S
diff options
context:
space:
mode:
authorWu Zhangjin <wuzhangjin@gmail.com>2009-11-20 07:34:38 -0500
committerRalf Baechle <ralf@linux-mips.org>2009-12-16 20:57:27 -0500
commit7326c4e567b50e689d13c04d58aeffa515277ebb (patch)
treeab3ecf92cf84decb1ff7b419920222770024125b /arch/mips/kernel/mcount.S
parentfc49a3be2be7a0cd44fcd3b37557d6d92cae59b1 (diff)
MIPS: Tracing: Make function graph tracer work with -mmcount-ra-address
That thread "MIPS: Add option to pass return address location to _mcount" from "David Daney <ddaney@caviumnetworks.com>" have added a new option -mmcount-ra-address to gcc(4.5) for MIPS to transfer the location of the return address to _mcount. Benefit from this new feature, function graph tracer on MIPS will be easier and safer to hijack the return address of the kernel function, which will save some overhead and make the whole thing more reliable. In this patch, at first, try to enable the option -mmcount-ra-address in arch/mips/Makefile with cc-option, if gcc support it, it will be enabled, otherwise, no side effect. and then, we need to support this new option of gcc 4.5 and also support the old gcc versions. with _mcount in the old gcc versions, it's not easy to get the location of return address(tracing: add function graph tracer support for MIPS), so, we do it in a C function: ftrace_get_parent_addr(ftrace.c), but with -mmcount-ra-address, only several instructions need to get what we want, so, I put into asm(mcount.S). and also, as the $12(t0) is used by -mmcount-ra-address for transferring the localtion of return address to _mcount, we need to save it into the stack and restore it when enabled dynamic function tracer, 'Cause we have called "ftrace_call" before "ftrace_graph_caller", which may destroy $12(t0). (Thanks to David for providing that -mcount-ra-address and giving the idea of KBUILD_MCOUNT_RA_ADDRESS, both of them have made the whole thing more beautiful!) Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Nicholas Mc Guire <der.herr@hofr.at> Cc: zhangfx@lemote.com Cc: Wu Zhangjin <wuzhangjin@gmail.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: linux-kernel@vger.kernel.org Cc: linux-mips@linux-mips.org Patchwork: http://patchwork.linux-mips.org/patch/681/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch/mips/kernel/mcount.S')
-rw-r--r--arch/mips/kernel/mcount.S14
1 files changed, 14 insertions, 0 deletions
diff --git a/arch/mips/kernel/mcount.S b/arch/mips/kernel/mcount.S
index 522e91c688fc..0a9cfdb271dd 100644
--- a/arch/mips/kernel/mcount.S
+++ b/arch/mips/kernel/mcount.S
@@ -70,6 +70,9 @@ _mcount:
70 nop 70 nop
71 71
72 MCOUNT_SAVE_REGS 72 MCOUNT_SAVE_REGS
73#ifdef KBUILD_MCOUNT_RA_ADDRESS
74 PTR_S t0, PT_R12(sp) /* t0 saved the location of the return address(at) by -mmcount-ra-address */
75#endif
73 76
74 move a0, ra /* arg1: next ip, selfaddr */ 77 move a0, ra /* arg1: next ip, selfaddr */
75 .globl ftrace_call 78 .globl ftrace_call
@@ -133,11 +136,22 @@ ftrace_stub:
133NESTED(ftrace_graph_caller, PT_SIZE, ra) 136NESTED(ftrace_graph_caller, PT_SIZE, ra)
134#ifdef CONFIG_DYNAMIC_FTRACE 137#ifdef CONFIG_DYNAMIC_FTRACE
135 PTR_L a1, PT_R31(sp) /* load the original ra from the stack */ 138 PTR_L a1, PT_R31(sp) /* load the original ra from the stack */
139#ifdef KBUILD_MCOUNT_RA_ADDRESS
140 PTR_L t0, PT_R12(sp) /* load the original t0 from the stack */
141#endif
136#else 142#else
137 MCOUNT_SAVE_REGS 143 MCOUNT_SAVE_REGS
138 move a1, ra /* arg2: next ip, selfaddr */ 144 move a1, ra /* arg2: next ip, selfaddr */
139#endif 145#endif
146
147#ifdef KBUILD_MCOUNT_RA_ADDRESS
148 bnez t0, 1f /* non-leaf func: t0 saved the location of the return address */
149 nop
150 PTR_LA t0, PT_R1(sp) /* leaf func: get the location of at(old ra) from our own stack */
1511: move a0, t0 /* arg1: the location of the return address */
152#else
140 PTR_LA a0, PT_R1(sp) /* arg1: &AT -> a0 */ 153 PTR_LA a0, PT_R1(sp) /* arg1: &AT -> a0 */
154#endif
141 jal prepare_ftrace_return 155 jal prepare_ftrace_return
142#ifdef CONFIG_FRAME_POINTER 156#ifdef CONFIG_FRAME_POINTER
143 move a2, fp /* arg3: frame pointer */ 157 move a2, fp /* arg3: frame pointer */