perf events, x86/stacktrace: Make stack walking optional
authorFrederic Weisbecker <fweisbec@gmail.com>
Thu, 17 Dec 2009 04:40:33 +0000 (05:40 +0100)
committerIngo Molnar <mingo@elte.hu>
Thu, 17 Dec 2009 08:56:19 +0000 (09:56 +0100)
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: Frederic 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: Ingo Molnar <mingo@elte.hu>
arch/x86/include/asm/stacktrace.h
arch/x86/kernel/cpu/perf_event.c
arch/x86/kernel/dumpstack.c
arch/x86/kernel/dumpstack.h
arch/x86/kernel/dumpstack_32.c
arch/x86/kernel/dumpstack_64.c
arch/x86/kernel/stacktrace.c
arch/x86/oprofile/backtrace.c
kernel/trace/trace_sysprof.c

index cf86a5e73815dde6fb2e0fa997b8628555584063..6c75151a3cca80881cd8e57bca9f8beb0e48ebaf 100644 (file)
@@ -5,6 +5,23 @@ extern int kstack_depth_to_print;
 
 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 */
 
 struct stacktrace_ops {
@@ -14,6 +31,7 @@ struct stacktrace_ops {
        void (*address)(void *data, unsigned long address, int reliable);
        /* On negative return stop dumping */
        int (*stack)(void *data, char *name);
+       walk_stack_t    walk_stack;
 };
 
 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
index 45506d5dd8df7e06f0e35ae8c0db18927ffc00e6..d3802ee5a4168e34b7f61ddbebc2710bb7ceabcf 100644 (file)
@@ -2336,6 +2336,7 @@ static const struct stacktrace_ops backtrace_ops = {
        .warning_symbol         = backtrace_warning_symbol,
        .stack                  = backtrace_stack,
        .address                = backtrace_address,
+       .walk_stack             = print_context_stack,
 };
 
 #include "../dumpstack.h"
index 0a0aa1cec8f1519688a5940cf0f49baefa403f98..8aaa119b7cad2a8ce39841a820806305506cacc3 100644 (file)
@@ -141,10 +141,11 @@ static void print_trace_address(void *data, unsigned long addr, int reliable)
 }
 
 static const struct stacktrace_ops print_trace_ops = {
-       .warning = print_trace_warning,
-       .warning_symbol = print_trace_warning_symbol,
-       .stack = print_trace_stack,
-       .address = print_trace_address,
+       .warning                = print_trace_warning,
+       .warning_symbol         = print_trace_warning_symbol,
+       .stack                  = print_trace_stack,
+       .address                = print_trace_address,
+       .walk_stack             = print_context_stack,
 };
 
 void
index 81086c227ab7cafe28c0c608f1b3eb2bce72b1c0..4fd1420faffa4fd747d8de2844c8d7278b79587c 100644 (file)
 #define get_bp(bp) asm("movq %%rbp, %0" : "=r" (bp) :)
 #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
 show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
                unsigned long *stack, unsigned long bp, char *log_lvl);
index e0ed4c7abb626e13f8f87d735b40576f6b44bb8e..ae775ca47b25c463fb8688cd4e47a92efa6a1a1e 100644 (file)
@@ -58,7 +58,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
 
                context = (struct thread_info *)
                        ((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;
                if (!stack)
index b13af53883aabe04504b402739a280bacf087424..0ad9597073f5a53aabb5f3dbbd85ea4cae947d60 100644 (file)
@@ -188,8 +188,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
                        if (ops->stack(data, id) < 0)
                                break;
 
-                       bp = print_context_stack(tinfo, stack, bp, ops,
-                                                data, estack_end, &graph);
+                       bp = ops->walk_stack(tinfo, stack, bp, ops,
+                                            data, estack_end, &graph);
                        ops->stack(data, "<EOE>");
                        /*
                         * We link to the next stack via the
index c3eb207181feeef5be791127b61798b432935cc4..922eefbb3f6c72b7b511791b083b916040b9f95e 100644 (file)
@@ -53,17 +53,19 @@ save_stack_address_nosched(void *data, unsigned long addr, int reliable)
 }
 
 static const struct stacktrace_ops save_stack_ops = {
-       .warning = save_stack_warning,
-       .warning_symbol = save_stack_warning_symbol,
-       .stack = save_stack_stack,
-       .address = save_stack_address,
+       .warning        = save_stack_warning,
+       .warning_symbol = save_stack_warning_symbol,
+       .stack          = save_stack_stack,
+       .address        = save_stack_address,
+       .walk_stack     = print_context_stack,
 };
 
 static const struct stacktrace_ops save_stack_ops_nosched = {
-       .warning = save_stack_warning,
-       .warning_symbol = save_stack_warning_symbol,
-       .stack = save_stack_stack,
-       .address = save_stack_address_nosched,
+       .warning        = save_stack_warning,
+       .warning_symbol = save_stack_warning_symbol,
+       .stack          = save_stack_stack,
+       .address        = save_stack_address_nosched,
+       .walk_stack     = print_context_stack,
 };
 
 /*
index 044897be021f0ed4a7bfc3eb3ee6208d2ae37dab..3855096c59b81910fe827c76151e84bbac836770 100644 (file)
@@ -41,10 +41,11 @@ static void backtrace_address(void *data, unsigned long addr, int reliable)
 }
 
 static struct stacktrace_ops backtrace_ops = {
-       .warning = backtrace_warning,
-       .warning_symbol = backtrace_warning_symbol,
-       .stack = backtrace_stack,
-       .address = backtrace_address,
+       .warning        = backtrace_warning,
+       .warning_symbol = backtrace_warning_symbol,
+       .stack          = backtrace_stack,
+       .address        = backtrace_address,
+       .walk_stack     = print_context_stack,
 };
 
 struct frame_head {
index f6693969287d83e716733f0d21c6356f70ec8ff5..a7974a552ca90689f3ff358f96b6eb2622c5748c 100644 (file)
@@ -93,6 +93,7 @@ static const struct stacktrace_ops backtrace_ops = {
        .warning_symbol         = backtrace_warning_symbol,
        .stack                  = backtrace_stack,
        .address                = backtrace_address,
+       .walk_stack             = print_context_stack,
 };
 
 static int