Commit 61c1917f authored by Frederic Weisbecker's avatar Frederic Weisbecker Committed by Ingo Molnar

perf events, x86/stacktrace: Make stack walking optional

The current print_context_stack helper that does the stack
walking job is good for usual stacktraces as it walks through
all the stack and reports even addresses that look unreliable,
which is nice when we don't have frame pointers for example.

But we have users like perf that only require reliable
stacktraces, and those may want a more adapted stack walker, so
lets make this function a callback in stacktrace_ops that users
can tune for their needs.
Signed-off-by: default avatarFrederic Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1261024834-5336-1-git-send-regression-fweisbec@gmail.com>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 5b74ed47
...@@ -5,6 +5,23 @@ extern int kstack_depth_to_print; ...@@ -5,6 +5,23 @@ extern int kstack_depth_to_print;
int x86_is_stack_id(int id, char *name); int x86_is_stack_id(int id, char *name);
struct thread_info;
struct stacktrace_ops;
typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
unsigned long *stack,
unsigned long bp,
const struct stacktrace_ops *ops,
void *data,
unsigned long *end,
int *graph);
extern unsigned long
print_context_stack(struct thread_info *tinfo,
unsigned long *stack, unsigned long bp,
const struct stacktrace_ops *ops, void *data,
unsigned long *end, int *graph);
/* Generic stack tracer with callbacks */ /* Generic stack tracer with callbacks */
struct stacktrace_ops { struct stacktrace_ops {
...@@ -14,6 +31,7 @@ struct stacktrace_ops { ...@@ -14,6 +31,7 @@ struct stacktrace_ops {
void (*address)(void *data, unsigned long address, int reliable); void (*address)(void *data, unsigned long address, int reliable);
/* On negative return stop dumping */ /* On negative return stop dumping */
int (*stack)(void *data, char *name); int (*stack)(void *data, char *name);
walk_stack_t walk_stack;
}; };
void dump_trace(struct task_struct *tsk, struct pt_regs *regs, void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
......
...@@ -2336,6 +2336,7 @@ static const struct stacktrace_ops backtrace_ops = { ...@@ -2336,6 +2336,7 @@ static const struct stacktrace_ops backtrace_ops = {
.warning_symbol = backtrace_warning_symbol, .warning_symbol = backtrace_warning_symbol,
.stack = backtrace_stack, .stack = backtrace_stack,
.address = backtrace_address, .address = backtrace_address,
.walk_stack = print_context_stack,
}; };
#include "../dumpstack.h" #include "../dumpstack.h"
......
...@@ -145,6 +145,7 @@ static const struct stacktrace_ops print_trace_ops = { ...@@ -145,6 +145,7 @@ static const struct stacktrace_ops print_trace_ops = {
.warning_symbol = print_trace_warning_symbol, .warning_symbol = print_trace_warning_symbol,
.stack = print_trace_stack, .stack = print_trace_stack,
.address = print_trace_address, .address = print_trace_address,
.walk_stack = print_context_stack,
}; };
void void
......
...@@ -14,12 +14,6 @@ ...@@ -14,12 +14,6 @@
#define get_bp(bp) asm("movq %%rbp, %0" : "=r" (bp) :) #define get_bp(bp) asm("movq %%rbp, %0" : "=r" (bp) :)
#endif #endif
extern unsigned long
print_context_stack(struct thread_info *tinfo,
unsigned long *stack, unsigned long bp,
const struct stacktrace_ops *ops, void *data,
unsigned long *end, int *graph);
extern void extern void
show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs, show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
unsigned long *stack, unsigned long bp, char *log_lvl); unsigned long *stack, unsigned long bp, char *log_lvl);
......
...@@ -58,7 +58,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs, ...@@ -58,7 +58,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
context = (struct thread_info *) context = (struct thread_info *)
((unsigned long)stack & (~(THREAD_SIZE - 1))); ((unsigned long)stack & (~(THREAD_SIZE - 1)));
bp = print_context_stack(context, stack, bp, ops, data, NULL, &graph); bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
stack = (unsigned long *)context->previous_esp; stack = (unsigned long *)context->previous_esp;
if (!stack) if (!stack)
......
...@@ -188,7 +188,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs, ...@@ -188,7 +188,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
if (ops->stack(data, id) < 0) if (ops->stack(data, id) < 0)
break; break;
bp = print_context_stack(tinfo, stack, bp, ops, bp = ops->walk_stack(tinfo, stack, bp, ops,
data, estack_end, &graph); data, estack_end, &graph);
ops->stack(data, "<EOE>"); ops->stack(data, "<EOE>");
/* /*
......
...@@ -57,6 +57,7 @@ static const struct stacktrace_ops save_stack_ops = { ...@@ -57,6 +57,7 @@ static const struct stacktrace_ops save_stack_ops = {
.warning_symbol = save_stack_warning_symbol, .warning_symbol = save_stack_warning_symbol,
.stack = save_stack_stack, .stack = save_stack_stack,
.address = save_stack_address, .address = save_stack_address,
.walk_stack = print_context_stack,
}; };
static const struct stacktrace_ops save_stack_ops_nosched = { static const struct stacktrace_ops save_stack_ops_nosched = {
...@@ -64,6 +65,7 @@ static const struct stacktrace_ops save_stack_ops_nosched = { ...@@ -64,6 +65,7 @@ static const struct stacktrace_ops save_stack_ops_nosched = {
.warning_symbol = save_stack_warning_symbol, .warning_symbol = save_stack_warning_symbol,
.stack = save_stack_stack, .stack = save_stack_stack,
.address = save_stack_address_nosched, .address = save_stack_address_nosched,
.walk_stack = print_context_stack,
}; };
/* /*
......
...@@ -45,6 +45,7 @@ static struct stacktrace_ops backtrace_ops = { ...@@ -45,6 +45,7 @@ static struct stacktrace_ops backtrace_ops = {
.warning_symbol = backtrace_warning_symbol, .warning_symbol = backtrace_warning_symbol,
.stack = backtrace_stack, .stack = backtrace_stack,
.address = backtrace_address, .address = backtrace_address,
.walk_stack = print_context_stack,
}; };
struct frame_head { struct frame_head {
......
...@@ -93,6 +93,7 @@ static const struct stacktrace_ops backtrace_ops = { ...@@ -93,6 +93,7 @@ static const struct stacktrace_ops backtrace_ops = {
.warning_symbol = backtrace_warning_symbol, .warning_symbol = backtrace_warning_symbol,
.stack = backtrace_stack, .stack = backtrace_stack,
.address = backtrace_address, .address = backtrace_address,
.walk_stack = print_context_stack,
}; };
static int static int
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment