Merge remote-tracking branch 'remotes/powerpc/topic/xive' into kvm-ppc-next
[linux/fpc-iii.git] / arch / cris / kernel / stacktrace.c
blobf1cc3aaacd8d7b5fe04df9499f20171bfdedbbe7
1 #include <linux/sched.h>
2 #include <linux/sched/debug.h>
3 #include <linux/stacktrace.h>
4 #include <asm/stacktrace.h>
6 void walk_stackframe(unsigned long sp,
7 int (*fn)(unsigned long addr, void *data),
8 void *data)
10 unsigned long high = ALIGN(sp, THREAD_SIZE);
12 for (; sp <= high - 4; sp += 4) {
13 unsigned long addr = *(unsigned long *) sp;
15 if (!kernel_text_address(addr))
16 continue;
18 if (fn(addr, data))
19 break;
23 struct stack_trace_data {
24 struct stack_trace *trace;
25 unsigned int no_sched_functions;
26 unsigned int skip;
29 #ifdef CONFIG_STACKTRACE
31 static int save_trace(unsigned long addr, void *d)
33 struct stack_trace_data *data = d;
34 struct stack_trace *trace = data->trace;
36 if (data->no_sched_functions && in_sched_functions(addr))
37 return 0;
39 if (data->skip) {
40 data->skip--;
41 return 0;
44 trace->entries[trace->nr_entries++] = addr;
46 return trace->nr_entries >= trace->max_entries;
49 void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
51 struct stack_trace_data data;
52 unsigned long sp;
54 data.trace = trace;
55 data.skip = trace->skip;
57 if (tsk != current) {
58 data.no_sched_functions = 1;
59 sp = tsk->thread.ksp;
60 } else {
61 data.no_sched_functions = 0;
62 sp = rdsp();
65 walk_stackframe(sp, save_trace, &data);
66 if (trace->nr_entries < trace->max_entries)
67 trace->entries[trace->nr_entries++] = ULONG_MAX;
70 void save_stack_trace(struct stack_trace *trace)
72 save_stack_trace_tsk(current, trace);
74 EXPORT_SYMBOL_GPL(save_stack_trace);
76 #endif /* CONFIG_STACKTRACE */