path: root/arch/mips/kernel/mcount.S
diff options
authorWu Zhangjin <>2009-11-20 20:34:38 +0800
committerRalf Baechle <>2009-12-17 01:57:27 +0000
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 <>" 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 <> Cc: Steven Rostedt <> Cc: Nicholas Mc Guire <> Cc: Cc: Wu Zhangjin <> Cc: Ingo Molnar <> Cc: Thomas Gleixner <> Cc: Frederic Weisbecker <> Cc: Cc: Patchwork: Signed-off-by: Ralf Baechle <>
Diffstat (limited to 'arch/mips/kernel/mcount.S')
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:
+ PTR_S t0, PT_R12(sp) /* t0 saved the location of the return address(at) by -mmcount-ra-address */
move a0, ra /* arg1: next ip, selfaddr */
.globl ftrace_call
@@ -133,11 +136,22 @@ ftrace_stub:
NESTED(ftrace_graph_caller, PT_SIZE, ra)
PTR_L a1, PT_R31(sp) /* load the original ra from the stack */
+ PTR_L t0, PT_R12(sp) /* load the original t0 from the stack */
move a1, ra /* arg2: next ip, selfaddr */
+ bnez t0, 1f /* non-leaf func: t0 saved the location of the return address */
+ nop
+ PTR_LA t0, PT_R1(sp) /* leaf func: get the location of at(old ra) from our own stack */
+1: move a0, t0 /* arg1: the location of the return address */
PTR_LA a0, PT_R1(sp) /* arg1: &AT -> a0 */
jal prepare_ftrace_return
move a2, fp /* arg3: frame pointer */