Linux Audio

Check our new training course

Loading...
v4.17
 1// SPDX-License-Identifier: GPL-2.0
 2// Copyright (C) 2005-2017 Andes Technology Corporation
 3
 4#include <linux/sched/debug.h>
 5#include <linux/sched/task_stack.h>
 6#include <linux/stacktrace.h>
 
 7
 8void save_stack_trace(struct stack_trace *trace)
 9{
10	save_stack_trace_tsk(current, trace);
11}
12EXPORT_SYMBOL_GPL(save_stack_trace);
13
14void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
15{
16	unsigned long *fpn;
17	int skip = trace->skip;
18	int savesched;
 
19
20	if (tsk == current) {
21		__asm__ __volatile__("\tori\t%0, $fp, #0\n":"=r"(fpn));
22		savesched = 1;
23	} else {
24		fpn = (unsigned long *)thread_saved_fp(tsk);
25		savesched = 0;
26	}
27
28	while (!kstack_end(fpn) && !((unsigned long)fpn & 0x3)
29	       && (fpn >= (unsigned long *)TASK_SIZE)) {
30		unsigned long lpp, fpp;
31
32		lpp = fpn[-1];
33		fpp = fpn[FP_OFFSET];
34		if (!__kernel_text_address(lpp))
35			break;
 
 
36
37		if (savesched || !in_sched_functions(lpp)) {
38			if (skip) {
39				skip--;
40			} else {
41				trace->entries[trace->nr_entries++] = lpp;
42				if (trace->nr_entries >= trace->max_entries)
43					break;
44			}
45		}
46		fpn = (unsigned long *)fpp;
47	}
48}
49EXPORT_SYMBOL_GPL(save_stack_trace_tsk);
v5.4
 1// SPDX-License-Identifier: GPL-2.0
 2// Copyright (C) 2005-2017 Andes Technology Corporation
 3
 4#include <linux/sched/debug.h>
 5#include <linux/sched/task_stack.h>
 6#include <linux/stacktrace.h>
 7#include <linux/ftrace.h>
 8
 9void save_stack_trace(struct stack_trace *trace)
10{
11	save_stack_trace_tsk(current, trace);
12}
13EXPORT_SYMBOL_GPL(save_stack_trace);
14
15void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
16{
17	unsigned long *fpn;
18	int skip = trace->skip;
19	int savesched;
20	int graph_idx = 0;
21
22	if (tsk == current) {
23		__asm__ __volatile__("\tori\t%0, $fp, #0\n":"=r"(fpn));
24		savesched = 1;
25	} else {
26		fpn = (unsigned long *)thread_saved_fp(tsk);
27		savesched = 0;
28	}
29
30	while (!kstack_end(fpn) && !((unsigned long)fpn & 0x3)
31	       && (fpn >= (unsigned long *)TASK_SIZE)) {
32		unsigned long lpp, fpp;
33
34		lpp = fpn[LP_OFFSET];
35		fpp = fpn[FP_OFFSET];
36		if (!__kernel_text_address(lpp))
37			break;
38		else
39			lpp = ftrace_graph_ret_addr(tsk, &graph_idx, lpp, NULL);
40
41		if (savesched || !in_sched_functions(lpp)) {
42			if (skip) {
43				skip--;
44			} else {
45				trace->entries[trace->nr_entries++] = lpp;
46				if (trace->nr_entries >= trace->max_entries)
47					break;
48			}
49		}
50		fpn = (unsigned long *)fpp;
51	}
52}
53EXPORT_SYMBOL_GPL(save_stack_trace_tsk);