diff options
author | Russell King <rmk@dyn-67.arm.linux.org.uk> | 2007-04-28 04:59:37 -0400 |
---|---|---|
committer | Russell King <rmk+kernel@arm.linux.org.uk> | 2007-04-28 04:59:37 -0400 |
commit | f16fb1ecc5a1cb2f7cc595179d1fe55e711e599f (patch) | |
tree | 6fae06d1edc3cd1235149c4e68058120e00ef4a8 /arch/arm | |
parent | ed519dede3d705e1c0012acd5b8de4074aa30fa4 (diff) |
[ARM] Add stacktrace support and make oprofile use it
Add support for stacktrace. Use the new stacktrace code with
oprofile instead of it's version; there's no point having
multiple versions of stacktracing in the kernel.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Diffstat (limited to 'arch/arm')
-rw-r--r-- | arch/arm/Kconfig | 8 | ||||
-rw-r--r-- | arch/arm/kernel/Makefile | 4 | ||||
-rw-r--r-- | arch/arm/kernel/stacktrace.c | 73 | ||||
-rw-r--r-- | arch/arm/kernel/stacktrace.h | 9 | ||||
-rw-r--r-- | arch/arm/oprofile/backtrace.c | 69 |
5 files changed, 109 insertions, 54 deletions
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index e7baca29f3fb..e25a197af6e8 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig | |||
@@ -67,6 +67,14 @@ config GENERIC_HARDIRQS | |||
67 | bool | 67 | bool |
68 | default y | 68 | default y |
69 | 69 | ||
70 | config STACKTRACE_SUPPORT | ||
71 | bool | ||
72 | default y | ||
73 | |||
74 | config LOCKDEP_SUPPORT | ||
75 | bool | ||
76 | default y | ||
77 | |||
70 | config TRACE_IRQFLAGS_SUPPORT | 78 | config TRACE_IRQFLAGS_SUPPORT |
71 | bool | 79 | bool |
72 | default y | 80 | default y |
diff --git a/arch/arm/kernel/Makefile b/arch/arm/kernel/Makefile index bb28087bf818..593b56509f4f 100644 --- a/arch/arm/kernel/Makefile +++ b/arch/arm/kernel/Makefile | |||
@@ -7,8 +7,8 @@ AFLAGS_head.o := -DTEXT_OFFSET=$(TEXT_OFFSET) | |||
7 | # Object file lists. | 7 | # Object file lists. |
8 | 8 | ||
9 | obj-y := compat.o entry-armv.o entry-common.o irq.o \ | 9 | obj-y := compat.o entry-armv.o entry-common.o irq.o \ |
10 | process.o ptrace.o semaphore.o setup.o signal.o sys_arm.o \ | 10 | process.o ptrace.o semaphore.o setup.o signal.o \ |
11 | time.o traps.o | 11 | sys_arm.o stacktrace.o time.o traps.o |
12 | 12 | ||
13 | obj-$(CONFIG_ISA_DMA_API) += dma.o | 13 | obj-$(CONFIG_ISA_DMA_API) += dma.o |
14 | obj-$(CONFIG_ARCH_ACORN) += ecard.o | 14 | obj-$(CONFIG_ARCH_ACORN) += ecard.o |
diff --git a/arch/arm/kernel/stacktrace.c b/arch/arm/kernel/stacktrace.c new file mode 100644 index 000000000000..77ef35efaa8d --- /dev/null +++ b/arch/arm/kernel/stacktrace.c | |||
@@ -0,0 +1,73 @@ | |||
1 | #include <linux/sched.h> | ||
2 | #include <linux/stacktrace.h> | ||
3 | |||
4 | #include "stacktrace.h" | ||
5 | |||
6 | int walk_stackframe(unsigned long fp, unsigned long low, unsigned long high, | ||
7 | int (*fn)(struct stackframe *, void *), void *data) | ||
8 | { | ||
9 | struct stackframe *frame; | ||
10 | |||
11 | do { | ||
12 | /* | ||
13 | * Check current frame pointer is within bounds | ||
14 | */ | ||
15 | if ((fp - 12) < low || fp + 4 >= high) | ||
16 | break; | ||
17 | |||
18 | frame = (struct stackframe *)(fp - 12); | ||
19 | |||
20 | if (fn(frame, data)) | ||
21 | break; | ||
22 | |||
23 | /* | ||
24 | * Update the low bound - the next frame must always | ||
25 | * be at a higher address than the current frame. | ||
26 | */ | ||
27 | low = fp + 4; | ||
28 | fp = frame->fp; | ||
29 | } while (fp); | ||
30 | |||
31 | return 0; | ||
32 | } | ||
33 | |||
34 | #ifdef CONFIG_STACKTRACE | ||
35 | struct stack_trace_data { | ||
36 | struct stack_trace *trace; | ||
37 | unsigned int skip; | ||
38 | }; | ||
39 | |||
40 | static int save_trace(struct stackframe *frame, void *d) | ||
41 | { | ||
42 | struct stack_trace_data *data = d; | ||
43 | struct stack_trace *trace = data->trace; | ||
44 | |||
45 | if (data->skip) { | ||
46 | data->skip--; | ||
47 | return 0; | ||
48 | } | ||
49 | |||
50 | trace->entries[trace->nr_entries++] = frame->lr; | ||
51 | |||
52 | return trace->nr_entries >= trace->max_entries; | ||
53 | } | ||
54 | |||
55 | void save_stack_trace(struct stack_trace *trace, struct task_struct *task) | ||
56 | { | ||
57 | struct stack_trace_data data; | ||
58 | unsigned long fp, base; | ||
59 | |||
60 | data.trace = trace; | ||
61 | data.skip = trace->skip; | ||
62 | |||
63 | if (task) { | ||
64 | base = (unsigned long)task_stack_page(task); | ||
65 | fp = 0; /* FIXME */ | ||
66 | } else { | ||
67 | base = (unsigned long)task_stack_page(current); | ||
68 | asm("mov %0, fp" : "=r" (fp)); | ||
69 | } | ||
70 | |||
71 | walk_stackframe(fp, base, base + THREAD_SIZE, save_trace, &data); | ||
72 | } | ||
73 | #endif | ||
diff --git a/arch/arm/kernel/stacktrace.h b/arch/arm/kernel/stacktrace.h new file mode 100644 index 000000000000..e9fd20cb5662 --- /dev/null +++ b/arch/arm/kernel/stacktrace.h | |||
@@ -0,0 +1,9 @@ | |||
1 | struct stackframe { | ||
2 | unsigned long fp; | ||
3 | unsigned long sp; | ||
4 | unsigned long lr; | ||
5 | unsigned long pc; | ||
6 | }; | ||
7 | |||
8 | int walk_stackframe(unsigned long fp, unsigned long low, unsigned long high, | ||
9 | int (*fn)(struct stackframe *, void *), void *data); | ||
diff --git a/arch/arm/oprofile/backtrace.c b/arch/arm/oprofile/backtrace.c index 7c22c12618cc..f5ebf30151fa 100644 --- a/arch/arm/oprofile/backtrace.c +++ b/arch/arm/oprofile/backtrace.c | |||
@@ -19,6 +19,19 @@ | |||
19 | #include <asm/ptrace.h> | 19 | #include <asm/ptrace.h> |
20 | #include <asm/uaccess.h> | 20 | #include <asm/uaccess.h> |
21 | 21 | ||
22 | #include "../kernel/stacktrace.h" | ||
23 | |||
24 | static int report_trace(struct stackframe *frame, void *d) | ||
25 | { | ||
26 | unsigned int *depth = d; | ||
27 | |||
28 | if (*depth) { | ||
29 | oprofile_add_trace(frame->lr); | ||
30 | (*depth)--; | ||
31 | } | ||
32 | |||
33 | return *depth == 0; | ||
34 | } | ||
22 | 35 | ||
23 | /* | 36 | /* |
24 | * The registers we're interested in are at the end of the variable | 37 | * The registers we're interested in are at the end of the variable |
@@ -32,21 +45,6 @@ struct frame_tail { | |||
32 | unsigned long lr; | 45 | unsigned long lr; |
33 | } __attribute__((packed)); | 46 | } __attribute__((packed)); |
34 | 47 | ||
35 | |||
36 | #ifdef CONFIG_FRAME_POINTER | ||
37 | static struct frame_tail* kernel_backtrace(struct frame_tail *tail) | ||
38 | { | ||
39 | oprofile_add_trace(tail->lr); | ||
40 | |||
41 | /* frame pointers should strictly progress back up the stack | ||
42 | * (towards higher addresses) */ | ||
43 | if (tail >= tail->fp) | ||
44 | return NULL; | ||
45 | |||
46 | return tail->fp-1; | ||
47 | } | ||
48 | #endif | ||
49 | |||
50 | static struct frame_tail* user_backtrace(struct frame_tail *tail) | 48 | static struct frame_tail* user_backtrace(struct frame_tail *tail) |
51 | { | 49 | { |
52 | struct frame_tail buftail[2]; | 50 | struct frame_tail buftail[2]; |
@@ -67,47 +65,14 @@ static struct frame_tail* user_backtrace(struct frame_tail *tail) | |||
67 | return buftail[0].fp-1; | 65 | return buftail[0].fp-1; |
68 | } | 66 | } |
69 | 67 | ||
70 | /* | ||
71 | * | | /\ Higher addresses | ||
72 | * | | | ||
73 | * --------------- stack base (address of current_thread_info) | ||
74 | * | thread info | | ||
75 | * . . | ||
76 | * | stack | | ||
77 | * --------------- saved regs->ARM_fp value if valid (frame_tail address) | ||
78 | * . . | ||
79 | * --------------- struct pt_regs stored on stack (struct pt_regs *) | ||
80 | * | | | ||
81 | * . . | ||
82 | * | | | ||
83 | * --------------- %esp | ||
84 | * | | | ||
85 | * | | \/ Lower addresses | ||
86 | * | ||
87 | * Thus, &pt_regs <-> stack base restricts the valid(ish) fp values | ||
88 | */ | ||
89 | static int valid_kernel_stack(struct frame_tail *tail, struct pt_regs *regs) | ||
90 | { | ||
91 | unsigned long tailaddr = (unsigned long)tail; | ||
92 | unsigned long stack = (unsigned long)regs; | ||
93 | unsigned long stack_base = (stack & ~(THREAD_SIZE - 1)) + THREAD_SIZE; | ||
94 | |||
95 | return (tailaddr > stack) && (tailaddr < stack_base); | ||
96 | } | ||
97 | |||
98 | void arm_backtrace(struct pt_regs * const regs, unsigned int depth) | 68 | void arm_backtrace(struct pt_regs * const regs, unsigned int depth) |
99 | { | 69 | { |
100 | struct frame_tail *tail; | 70 | struct frame_tail *tail = ((struct frame_tail *) regs->ARM_fp) - 1; |
101 | |||
102 | tail = ((struct frame_tail *) regs->ARM_fp) - 1; | ||
103 | 71 | ||
104 | if (!user_mode(regs)) { | 72 | if (!user_mode(regs)) { |
105 | 73 | unsigned long base = ((unsigned long)regs) & ~(THREAD_SIZE - 1); | |
106 | #ifdef CONFIG_FRAME_POINTER | 74 | walk_stackframe(regs->ARM_fp, base, base + THREAD_SIZE, |
107 | while (depth-- && tail && valid_kernel_stack(tail, regs)) { | 75 | report_trace, &depth); |
108 | tail = kernel_backtrace(tail); | ||
109 | } | ||
110 | #endif | ||
111 | return; | 76 | return; |
112 | } | 77 | } |
113 | 78 | ||