linux/arch/mips
Wu Zhangjin 29c5d3462f MIPS: Tracing: Add function graph tracer support for MIPS
The implementation of function graph tracer for MIPS is a little
different from X86.

in MIPS, gcc(with -pg) only transfer the caller's return address(at) and
the _mcount's return address(ra) to us.

For the kernel part without -mlong-calls:

move at, ra
jal _mcount

For the module part with -mlong-calls:

lui v1, hi16bit_of_mcount
addiu v1, v1, low16bit_of_mcount
move at, ra
jal _mcount

Without -mlong-calls,

if the function is a leaf, it will not save the return address(ra):

ffffffff80101298 <au1k_wait>:
ffffffff80101298:       67bdfff0        daddiu  sp,sp,-16
ffffffff8010129c:       ffbe0008        sd      s8,8(sp)
ffffffff801012a0:       03a0f02d        move    s8,sp
ffffffff801012a4:       03e0082d        move    at,ra
ffffffff801012a8:       0c042930        jal     ffffffff8010a4c0 <_mcount>
ffffffff801012ac:       00020021        nop

so, we can hijack it directly in _mcount, but if the function is non-leaf, the
return address is saved in the stack.

ffffffff80133030 <copy_process>:
ffffffff80133030:       67bdff50        daddiu  sp,sp,-176
ffffffff80133034:       ffbe00a0        sd      s8,160(sp)
ffffffff80133038:       03a0f02d        move    s8,sp
ffffffff8013303c:       ffbf00a8        sd      ra,168(sp)
ffffffff80133040:       ffb70098        sd      s7,152(sp)
ffffffff80133044:       ffb60090        sd      s6,144(sp)
ffffffff80133048:       ffb50088        sd      s5,136(sp)
ffffffff8013304c:       ffb40080        sd      s4,128(sp)
ffffffff80133050:       ffb30078        sd      s3,120(sp)
ffffffff80133054:       ffb20070        sd      s2,112(sp)
ffffffff80133058:       ffb10068        sd      s1,104(sp)
ffffffff8013305c:       ffb00060        sd      s0,96(sp)
ffffffff80133060:       03e0082d        move    at,ra
ffffffff80133064:       0c042930        jal     ffffffff8010a4c0 <_mcount>
ffffffff80133068:       00020021        nop

but we can not get the exact stack address(which saved ra) directly in
_mcount, we need to search the content of at register in the stack space
or search the "s{d,w} ra, offset(sp)" instruction in the text. 'Cause we
can not prove there is only a match in the stack space, so, we search
the text instead.

as we can see, if the first instruction above "move at, ra" is not a
store instruction, there should be a leaf function, so we hijack the at
register directly via putting &return_to_handler into it, otherwise, we
search the "s{d,w} ra, offset(sp)" instruction to get the stack offset,
and then the stack address. we use the above copy_process() as an
example, we at last find "ffbf00a8", 0xa8 is the stack offset, we plus
it with s8(fp), that is the stack address, we hijack the content via
writing the &return_to_handler in.

If with -mlong-calls, since there are two more instructions above "move
at, ra", so, we can move the pointer to the position above "lui v1,
hi16bit_of_mcount".

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/677/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
2009-12-17 01:57:25 +00:00
..
alchemy MIPS: Alchemy: Fix hang with high-frequency edge interrupts 2009-11-02 12:00:08 +01:00
ar7 MIPS: AR7: register watchdog device only if enabled in hw configuration 2009-11-02 12:00:03 +01:00
basler/excite MIPS: Excite: Get rid of BKL. 2009-09-30 21:47:01 +02:00
bcm47xx MIPS: Replace all usages of CL_SIZE by COMMAND_LINE_SIZE 2009-12-17 01:56:56 +00:00
bcm63xx MIPS: bcm63xx: Set the correct BCM3302 CPU name 2009-11-02 12:00:07 +01:00
boot MIPS: Remove addinitrd and CONFIG_PROBE_INITRD_HEADER 2009-12-17 01:57:07 +00:00
cavium-octeon MIPS: Octeon: Add platform devices MGMT Ethernet ports. 2009-12-17 01:56:59 +00:00
cobalt Update Yoichi Yuasa's e-mail address 2009-07-03 15:45:29 +01:00
configs MIPS: PowerTV: Base files for Cisco PowerTV platform 2009-12-17 01:57:17 +00:00
dec Merge branch 'timers-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip 2009-09-18 09:15:24 -07:00
emma MIPS: Remove useless zero initializations. 2009-09-17 20:07:51 +02:00
fw MIPS: IP22: Remove an unused function 2009-12-17 01:56:56 +00:00
gt64120/wrppmc Update Yoichi Yuasa's e-mail address 2009-07-03 15:45:29 +01:00
include/asm MIPS: Tracing: Add IRQENTRY_EXIT section for MIPS 2009-12-17 01:57:24 +00:00
jazz MIPS: Add IRQF_TIMER flag for timer interrupts 2009-11-02 12:00:02 +01:00
kernel MIPS: Tracing: Add function graph tracer support for MIPS 2009-12-17 01:57:25 +00:00
lasat MIPS: Replace all usages of CL_SIZE by COMMAND_LINE_SIZE 2009-12-17 01:56:56 +00:00
lib MIPS: Fix __ndelay build error and add 'ull' suffix for 32-bit kernel 2009-06-17 11:06:24 +01:00
loongson MIPS: Loongson 2F: Add CPU frequency scaling support 2009-12-17 01:57:20 +00:00
math-emu MIPS: Collect FPU emulator statistics per-CPU. 2009-12-17 01:57:08 +00:00
mipssim MIPS: MIPSsim: Remove unused code 2009-12-17 01:57:01 +00:00
mm MIPS: Sibyte: Use hweight8 instead of counting bits 2009-12-17 01:57:16 +00:00
mti-malta MIPS: Replace all usages of CL_SIZE by COMMAND_LINE_SIZE 2009-12-17 01:56:56 +00:00
nxp MIPS: Fixup last users of irq_chip->typename 2009-12-17 01:57:21 +00:00
oprofile MIPS: oprofile: Only do performance counter handling for counter interrupts 2009-12-17 01:57:10 +00:00
pci MIPS: Lemote 2F: Add PCI support 2009-12-17 01:57:12 +00:00
pmc-sierra cpumask: arch_send_call_function_ipi_mask: mips 2009-09-24 09:34:45 +09:30
power MIPS: Use PAGE_SIZE in assembly instead of _PAGE_SIZE. 2009-09-17 20:07:48 +02:00
powertv MIPS: PowerTV: Base files for Cisco PowerTV platform 2009-12-17 01:57:17 +00:00
rb532 MIPS: Replace all usages of CL_SIZE by COMMAND_LINE_SIZE 2009-12-17 01:56:56 +00:00
sgi-ip22 MIPS: Tracing: Add IRQENTRY_EXIT section for MIPS 2009-12-17 01:57:24 +00:00
sgi-ip27 MIPS: Add IRQF_TIMER flag for timer interrupts 2009-11-02 12:00:02 +01:00
sgi-ip32 MIPS: IP32: Remove unnecessary if not even harmful volatile keywords. 2009-05-22 13:52:06 +01:00
sibyte MIPS: Replace all usages of CL_SIZE by COMMAND_LINE_SIZE 2009-12-17 01:56:56 +00:00
sni MIPS: Fixup last users of irq_chip->typename 2009-12-17 01:57:21 +00:00
txx9 MIPS: Replace all usages of CL_SIZE by COMMAND_LINE_SIZE 2009-12-17 01:56:56 +00:00
vr41xx genirq: Convert irq_desc.lock to raw_spinlock 2009-12-14 23:55:33 +01:00
Kconfig MIPS: Tracing: Add function graph tracer support for MIPS 2009-12-17 01:57:25 +00:00
Kconfig.debug MIPS: Kconfig: Fix the arch-specific header path 2008-12-12 18:12:23 +00:00
Makefile MIPS: Tracing: Add static function tracer support for MIPS 2009-12-17 01:57:21 +00:00