diff options
author | Wu Zhangjin <wuzhangjin@gmail.com> | 2009-11-20 07:34:29 -0500 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2009-12-16 20:57:21 -0500 |
commit | d2bb0762993e11363d8343127516b8fe88f9006f (patch) | |
tree | f210c4c4b0234a776977e6d2b749384e1d3699c1 /arch/mips | |
parent | 8922f79ee56e9dab6fc144defc0bc901ff0a7f8a (diff) |
MIPS: Tracing: Add static function tracer support for MIPS
If -pg of gcc is enabled with CONFIG_FUNCTION_TRACER=y. a calling to
_mcount will be inserted into each kernel function. so, there is a
possibility to trace the kernel functions in _mcount.
This patch add the MIPS specific _mcount support for static function
tracing. by default, ftrace_trace_function is initialized as
ftrace_stub(an empty function), so, the default _mcount will introduce
very little overhead. after enabling ftrace in user-space, it will jump
to a real tracing function and do static function tracing for us.
and -ffunction-sections is incompatible with -pg, so, disable it when
ftracer is enabled.
Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
Reviewed-by: 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/672/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch/mips')
-rw-r--r-- | arch/mips/Kconfig | 1 | ||||
-rw-r--r-- | arch/mips/Makefile | 2 | ||||
-rw-r--r-- | arch/mips/include/asm/ftrace.h | 25 | ||||
-rw-r--r-- | arch/mips/kernel/Makefile | 6 | ||||
-rw-r--r-- | arch/mips/kernel/mcount.S | 83 | ||||
-rw-r--r-- | arch/mips/kernel/mips_ksyms.c | 5 |
6 files changed, 121 insertions, 1 deletions
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig index 435838ec9591..632dba2ac300 100644 --- a/arch/mips/Kconfig +++ b/arch/mips/Kconfig | |||
@@ -5,6 +5,7 @@ config MIPS | |||
5 | select HAVE_IDE | 5 | select HAVE_IDE |
6 | select HAVE_OPROFILE | 6 | select HAVE_OPROFILE |
7 | select HAVE_ARCH_KGDB | 7 | select HAVE_ARCH_KGDB |
8 | select HAVE_FUNCTION_TRACER | ||
8 | # Horrible source of confusion. Die, die, die ... | 9 | # Horrible source of confusion. Die, die, die ... |
9 | select EMBEDDED | 10 | select EMBEDDED |
10 | select RTC_LIB if !MACH_LOONGSON | 11 | select RTC_LIB if !MACH_LOONGSON |
diff --git a/arch/mips/Makefile b/arch/mips/Makefile index 0a7e6146bb4b..3725ee923d05 100644 --- a/arch/mips/Makefile +++ b/arch/mips/Makefile | |||
@@ -48,7 +48,9 @@ ifneq ($(SUBARCH),$(ARCH)) | |||
48 | endif | 48 | endif |
49 | endif | 49 | endif |
50 | 50 | ||
51 | ifndef CONFIG_FUNCTION_TRACER | ||
51 | cflags-y := -ffunction-sections | 52 | cflags-y := -ffunction-sections |
53 | endif | ||
52 | cflags-y += $(call cc-option, -mno-check-zero-division) | 54 | cflags-y += $(call cc-option, -mno-check-zero-division) |
53 | 55 | ||
54 | ifdef CONFIG_32BIT | 56 | ifdef CONFIG_32BIT |
diff --git a/arch/mips/include/asm/ftrace.h b/arch/mips/include/asm/ftrace.h index 40a8c178f10d..5f8ebcf9fa61 100644 --- a/arch/mips/include/asm/ftrace.h +++ b/arch/mips/include/asm/ftrace.h | |||
@@ -1 +1,24 @@ | |||
1 | /* empty */ | 1 | /* |
2 | * This file is subject to the terms and conditions of the GNU General Public | ||
3 | * License. See the file "COPYING" in the main directory of this archive for | ||
4 | * more details. | ||
5 | * | ||
6 | * Copyright (C) 2009 DSLab, Lanzhou University, China | ||
7 | * Author: Wu Zhangjin <wuzj@lemote.com> | ||
8 | */ | ||
9 | |||
10 | #ifndef _ASM_MIPS_FTRACE_H | ||
11 | #define _ASM_MIPS_FTRACE_H | ||
12 | |||
13 | #ifdef CONFIG_FUNCTION_TRACER | ||
14 | |||
15 | #define MCOUNT_ADDR ((unsigned long)(_mcount)) | ||
16 | #define MCOUNT_INSN_SIZE 4 /* sizeof mcount call */ | ||
17 | |||
18 | #ifndef __ASSEMBLY__ | ||
19 | extern void _mcount(void); | ||
20 | #define mcount _mcount | ||
21 | |||
22 | #endif /* __ASSEMBLY__ */ | ||
23 | #endif /* CONFIG_FUNCTION_TRACER */ | ||
24 | #endif /* _ASM_MIPS_FTRACE_H */ | ||
diff --git a/arch/mips/kernel/Makefile b/arch/mips/kernel/Makefile index f442de804d8a..1340ba3dd38d 100644 --- a/arch/mips/kernel/Makefile +++ b/arch/mips/kernel/Makefile | |||
@@ -10,6 +10,10 @@ obj-y += cpu-probe.o branch.o entry.o genex.o irq.o process.o \ | |||
10 | ptrace.o reset.o setup.o signal.o syscall.o \ | 10 | ptrace.o reset.o setup.o signal.o syscall.o \ |
11 | time.o topology.o traps.o unaligned.o watch.o | 11 | time.o topology.o traps.o unaligned.o watch.o |
12 | 12 | ||
13 | ifdef CONFIG_FUNCTION_TRACER | ||
14 | CFLAGS_REMOVE_early_printk.o = -pg | ||
15 | endif | ||
16 | |||
13 | obj-$(CONFIG_CEVT_BCM1480) += cevt-bcm1480.o | 17 | obj-$(CONFIG_CEVT_BCM1480) += cevt-bcm1480.o |
14 | obj-$(CONFIG_CEVT_R4K_LIB) += cevt-r4k.o | 18 | obj-$(CONFIG_CEVT_R4K_LIB) += cevt-r4k.o |
15 | obj-$(CONFIG_MIPS_MT_SMTC) += cevt-smtc.o | 19 | obj-$(CONFIG_MIPS_MT_SMTC) += cevt-smtc.o |
@@ -27,6 +31,8 @@ obj-$(CONFIG_SYNC_R4K) += sync-r4k.o | |||
27 | obj-$(CONFIG_STACKTRACE) += stacktrace.o | 31 | obj-$(CONFIG_STACKTRACE) += stacktrace.o |
28 | obj-$(CONFIG_MODULES) += mips_ksyms.o module.o | 32 | obj-$(CONFIG_MODULES) += mips_ksyms.o module.o |
29 | 33 | ||
34 | obj-$(CONFIG_FUNCTION_TRACER) += mcount.o | ||
35 | |||
30 | obj-$(CONFIG_CPU_LOONGSON2) += r4k_fpu.o r4k_switch.o | 36 | obj-$(CONFIG_CPU_LOONGSON2) += r4k_fpu.o r4k_switch.o |
31 | obj-$(CONFIG_CPU_MIPS32) += r4k_fpu.o r4k_switch.o | 37 | obj-$(CONFIG_CPU_MIPS32) += r4k_fpu.o r4k_switch.o |
32 | obj-$(CONFIG_CPU_MIPS64) += r4k_fpu.o r4k_switch.o | 38 | obj-$(CONFIG_CPU_MIPS64) += r4k_fpu.o r4k_switch.o |
diff --git a/arch/mips/kernel/mcount.S b/arch/mips/kernel/mcount.S new file mode 100644 index 000000000000..cebcc3c11305 --- /dev/null +++ b/arch/mips/kernel/mcount.S | |||
@@ -0,0 +1,83 @@ | |||
1 | /* | ||
2 | * MIPS specific _mcount support | ||
3 | * | ||
4 | * This file is subject to the terms and conditions of the GNU General Public | ||
5 | * License. See the file "COPYING" in the main directory of this archive for | ||
6 | * more details. | ||
7 | * | ||
8 | * Copyright (C) 2009 Lemote Inc. & DSLab, Lanzhou University, China | ||
9 | * Author: Wu Zhangjin <wuzj@lemote.com> | ||
10 | */ | ||
11 | |||
12 | #include <asm/regdef.h> | ||
13 | #include <asm/stackframe.h> | ||
14 | #include <asm/ftrace.h> | ||
15 | |||
16 | .text | ||
17 | .set noreorder | ||
18 | .set noat | ||
19 | |||
20 | .macro MCOUNT_SAVE_REGS | ||
21 | PTR_SUBU sp, PT_SIZE | ||
22 | PTR_S ra, PT_R31(sp) | ||
23 | PTR_S AT, PT_R1(sp) | ||
24 | PTR_S a0, PT_R4(sp) | ||
25 | PTR_S a1, PT_R5(sp) | ||
26 | PTR_S a2, PT_R6(sp) | ||
27 | PTR_S a3, PT_R7(sp) | ||
28 | #ifdef CONFIG_64BIT | ||
29 | PTR_S a4, PT_R8(sp) | ||
30 | PTR_S a5, PT_R9(sp) | ||
31 | PTR_S a6, PT_R10(sp) | ||
32 | PTR_S a7, PT_R11(sp) | ||
33 | #endif | ||
34 | .endm | ||
35 | |||
36 | .macro MCOUNT_RESTORE_REGS | ||
37 | PTR_L ra, PT_R31(sp) | ||
38 | PTR_L AT, PT_R1(sp) | ||
39 | PTR_L a0, PT_R4(sp) | ||
40 | PTR_L a1, PT_R5(sp) | ||
41 | PTR_L a2, PT_R6(sp) | ||
42 | PTR_L a3, PT_R7(sp) | ||
43 | #ifdef CONFIG_64BIT | ||
44 | PTR_L a4, PT_R8(sp) | ||
45 | PTR_L a5, PT_R9(sp) | ||
46 | PTR_L a6, PT_R10(sp) | ||
47 | PTR_L a7, PT_R11(sp) | ||
48 | #endif | ||
49 | #ifdef CONFIG_64BIT | ||
50 | PTR_ADDIU sp, PT_SIZE | ||
51 | #else | ||
52 | PTR_ADDIU sp, (PT_SIZE + 8) | ||
53 | #endif | ||
54 | .endm | ||
55 | |||
56 | .macro RETURN_BACK | ||
57 | jr ra | ||
58 | move ra, AT | ||
59 | .endm | ||
60 | |||
61 | NESTED(_mcount, PT_SIZE, ra) | ||
62 | PTR_LA t0, ftrace_stub | ||
63 | PTR_L t1, ftrace_trace_function /* Prepare t1 for (1) */ | ||
64 | bne t0, t1, static_trace | ||
65 | nop | ||
66 | b ftrace_stub | ||
67 | nop | ||
68 | |||
69 | static_trace: | ||
70 | MCOUNT_SAVE_REGS | ||
71 | |||
72 | move a0, ra /* arg1: next ip, selfaddr */ | ||
73 | jalr t1 /* (1) call *ftrace_trace_function */ | ||
74 | move a1, AT /* arg2: the caller's next ip, parent */ | ||
75 | |||
76 | MCOUNT_RESTORE_REGS | ||
77 | .globl ftrace_stub | ||
78 | ftrace_stub: | ||
79 | RETURN_BACK | ||
80 | END(_mcount) | ||
81 | |||
82 | .set at | ||
83 | .set reorder | ||
diff --git a/arch/mips/kernel/mips_ksyms.c b/arch/mips/kernel/mips_ksyms.c index 225755d0c1f6..1d04807874db 100644 --- a/arch/mips/kernel/mips_ksyms.c +++ b/arch/mips/kernel/mips_ksyms.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include <asm/checksum.h> | 13 | #include <asm/checksum.h> |
14 | #include <asm/pgtable.h> | 14 | #include <asm/pgtable.h> |
15 | #include <asm/uaccess.h> | 15 | #include <asm/uaccess.h> |
16 | #include <asm/ftrace.h> | ||
16 | 17 | ||
17 | extern void *__bzero(void *__s, size_t __count); | 18 | extern void *__bzero(void *__s, size_t __count); |
18 | extern long __strncpy_from_user_nocheck_asm(char *__to, | 19 | extern long __strncpy_from_user_nocheck_asm(char *__to, |
@@ -51,3 +52,7 @@ EXPORT_SYMBOL(csum_partial_copy_nocheck); | |||
51 | EXPORT_SYMBOL(__csum_partial_copy_user); | 52 | EXPORT_SYMBOL(__csum_partial_copy_user); |
52 | 53 | ||
53 | EXPORT_SYMBOL(invalid_pte_table); | 54 | EXPORT_SYMBOL(invalid_pte_table); |
55 | #ifdef CONFIG_FUNCTION_TRACER | ||
56 | /* _mcount is defined in arch/mips/kernel/mcount.S */ | ||
57 | EXPORT_SYMBOL(_mcount); | ||
58 | #endif | ||