12 #include <linux/module.h>
13 #include <linux/sysctl.h>
17 #include <asm/setup.h>
21 #define STACK_TRACE_ENTRIES 500
27 static struct stack_trace max_stack_trace = {
29 .entries = stack_dump_trace,
32 static unsigned long max_stack_size;
41 static int last_stack_tracer_enabled;
43 static inline void check_stack(
void)
45 unsigned long this_size,
flags;
52 if (this_size <= max_stack_size)
56 if (!object_is_on_stack(&this_size))
63 if (this_size <= max_stack_size)
66 max_stack_size = this_size;
68 max_stack_trace.nr_entries = 0;
69 max_stack_trace.skip = 3;
78 top = (
unsigned long *)
88 while (i < max_stack_trace.nr_entries) {
91 stack_dump_index[
i] = this_size;
94 for (; p < top && i < max_stack_trace.nr_entries; p++) {
95 if (*p == stack_dump_trace[i]) {
96 this_size = stack_dump_index[i++] =
97 (top -
p) *
sizeof(
unsigned long);
114 stack_trace_call(
unsigned long ip,
unsigned long parent_ip,
119 if (
unlikely(!ftrace_enabled || stack_trace_disabled))
126 if (
per_cpu(trace_active, cpu)++ != 0)
137 static struct ftrace_ops trace_ops __read_mostly =
139 .func = stack_trace_call,
140 .flags = FTRACE_OPS_FL_RECURSION_SAFE,
144 stack_max_size_read(
struct file *filp,
char __user *ubuf,
145 size_t count, loff_t *ppos)
151 r =
snprintf(buf,
sizeof(buf),
"%ld\n", *ptr);
158 stack_max_size_write(
struct file *filp,
const char __user *ubuf,
159 size_t count, loff_t *ppos)
192 .read = stack_max_size_read,
193 .write = stack_max_size_write,
202 if (n >= max_stack_trace.nr_entries || stack_dump_trace[n] ==
ULONG_MAX)
210 t_next(
struct seq_file *m,
void *
v, loff_t *pos)
213 return __next(m, pos);
216 static void *t_start(
struct seq_file *m, loff_t *pos)
230 return __next(m, pos);
233 static void t_stop(
struct seq_file *m,
void *
p)
245 static int trace_lookup_stack(
struct seq_file *m,
long i)
247 unsigned long addr = stack_dump_trace[
i];
252 static void print_disabled(
struct seq_file *m)
255 "# Stack tracer disabled\n"
257 "# To enable the stack tracer, either add 'stacktrace' to the\n"
258 "# kernel command line\n"
259 "# or 'echo 1 > /proc/sys/kernel/stack_tracer_enabled'\n"
263 static int t_show(
struct seq_file *m,
void *
v)
271 " ----- ---- --------\n",
272 max_stack_trace.nr_entries - 1);
274 if (!stack_tracer_enabled && !max_stack_size)
282 if (i >= max_stack_trace.nr_entries ||
286 if (i+1 == max_stack_trace.nr_entries ||
288 size = stack_dump_index[
i];
290 size = stack_dump_index[
i] - stack_dump_index[i+1];
292 seq_printf(m,
"%3ld) %8d %5d ", i, stack_dump_index[i], size);
294 trace_lookup_stack(m, i);
308 return seq_open(file, &stack_trace_seq_ops);
312 .open = stack_trace_open,
326 .open = stack_trace_filter_open,
328 .write = ftrace_filter_write,
329 .llseek = ftrace_regex_lseek,
330 .release = ftrace_regex_release,
335 void __user *
buffer,
size_t *lenp,
345 (last_stack_tracer_enabled == !!stack_tracer_enabled))
350 if (stack_tracer_enabled)
362 static __init int enable_stacktrace(
char *
str)
364 if (
strncmp(str,
"_filter=", 8) == 0)
367 stack_tracer_enabled = 1;
368 last_stack_tracer_enabled = 1;
371 __setup(
"stacktrace", enable_stacktrace);
373 static __init int stack_trace_init(
void)
380 &max_stack_size, &stack_max_size_fops);
383 NULL, &stack_trace_fops);
386 NULL, &stack_trace_filter_fops);
388 if (stack_trace_filter_buf[0])
391 if (stack_tracer_enabled)