sched: latencytop support
[linux-2.6.git] / arch / x86 / kernel / stacktrace.c
1 /*
2  * Stack trace management functions
3  *
4  *  Copyright (C) 2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
5  */
6 #include <linux/sched.h>
7 #include <linux/stacktrace.h>
8 #include <linux/module.h>
9 #include <asm/stacktrace.h>
10
11 static void save_stack_warning(void *data, char *msg)
12 {
13 }
14
15 static void
16 save_stack_warning_symbol(void *data, char *msg, unsigned long symbol)
17 {
18 }
19
20 static int save_stack_stack(void *data, char *name)
21 {
22         return -1;
23 }
24
25 static void save_stack_address(void *data, unsigned long addr)
26 {
27         struct stack_trace *trace = (struct stack_trace *)data;
28         if (trace->skip > 0) {
29                 trace->skip--;
30                 return;
31         }
32         if (trace->nr_entries < trace->max_entries)
33                 trace->entries[trace->nr_entries++] = addr;
34 }
35
36 static void save_stack_address_nosched(void *data, unsigned long addr)
37 {
38         struct stack_trace *trace = (struct stack_trace *)data;
39         if (in_sched_functions(addr))
40                 return;
41         if (trace->skip > 0) {
42                 trace->skip--;
43                 return;
44         }
45         if (trace->nr_entries < trace->max_entries)
46                 trace->entries[trace->nr_entries++] = addr;
47 }
48
49 static const struct stacktrace_ops save_stack_ops = {
50         .warning = save_stack_warning,
51         .warning_symbol = save_stack_warning_symbol,
52         .stack = save_stack_stack,
53         .address = save_stack_address,
54 };
55
56 static const struct stacktrace_ops save_stack_ops_nosched = {
57         .warning = save_stack_warning,
58         .warning_symbol = save_stack_warning_symbol,
59         .stack = save_stack_stack,
60         .address = save_stack_address_nosched,
61 };
62
63 /*
64  * Save stack-backtrace addresses into a stack_trace buffer.
65  */
66 void save_stack_trace(struct stack_trace *trace)
67 {
68         dump_trace(current, NULL, NULL, &save_stack_ops, trace);
69         if (trace->nr_entries < trace->max_entries)
70                 trace->entries[trace->nr_entries++] = ULONG_MAX;
71 }
72 EXPORT_SYMBOL(save_stack_trace);
73
74 void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
75 {
76         dump_trace(tsk, NULL, NULL, &save_stack_ops_nosched, trace);
77         if (trace->nr_entries < trace->max_entries)
78                 trace->entries[trace->nr_entries++] = ULONG_MAX;
79 }