Skip to content

Commit b97aec0

Browse files
Donglin Pengrostedt
authored andcommitted
riscv: ftrace: Enable HAVE_FUNCTION_GRAPH_RETVAL
The previous patch ("function_graph: Support recording and printing the return value of function") has laid the groundwork for the for the funcgraph-retval, and this modification makes it available on the RISC-V platform. We introduce a new structure called fgraph_ret_regs for the RISC-V platform to hold return registers and the frame pointer. We then fill its content in the return_to_handler and pass its address to the function ftrace_return_to_handler to record the return value. Link: https://lore.kernel.org/linux-trace-kernel/a8d71b12259f90e7e63d0ea654fcac95b0232bbc.1680954589.git.pengdonglin@sangfor.com.cn Signed-off-by: Donglin Peng <[email protected]> Acked-by: Palmer Dabbelt <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 38638ff commit b97aec0

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

arch/riscv/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ config RISCV
146146
select HAVE_DYNAMIC_FTRACE_WITH_REGS if HAVE_DYNAMIC_FTRACE
147147
select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL
148148
select HAVE_FUNCTION_GRAPH_TRACER
149+
select HAVE_FUNCTION_GRAPH_RETVAL if HAVE_FUNCTION_GRAPH_TRACER
149150
select HAVE_FUNCTION_TRACER if !XIP_KERNEL && !PREEMPTION
150151

151152
config CLANG_SUPPORTS_DYNAMIC_FTRACE

arch/riscv/include/asm/ftrace.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,25 @@ int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec);
111111

112112
#endif /* CONFIG_DYNAMIC_FTRACE */
113113

114+
#ifndef __ASSEMBLY__
115+
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
116+
struct fgraph_ret_regs {
117+
unsigned long a1;
118+
unsigned long a0;
119+
unsigned long s0;
120+
unsigned long ra;
121+
};
122+
123+
static inline unsigned long fgraph_ret_regs_return_value(struct fgraph_ret_regs *ret_regs)
124+
{
125+
return ret_regs->a0;
126+
}
127+
128+
static inline unsigned long fgraph_ret_regs_frame_pointer(struct fgraph_ret_regs *ret_regs)
129+
{
130+
return ret_regs->s0;
131+
}
132+
#endif /* ifdef CONFIG_FUNCTION_GRAPH_TRACER */
133+
#endif
134+
114135
#endif /* _ASM_RISCV_FTRACE_H */

arch/riscv/kernel/mcount.S

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,8 @@ ENTRY(return_to_handler)
6565
* So alternatively we check the *old* frame pointer position, that is, the
6666
* value stored in -16(s0) on entry, and the s0 on return.
6767
*/
68-
#ifdef HAVE_FUNCTION_GRAPH_FP_TEST
69-
mv t6, s0
70-
#endif
7168
SAVE_RET_ABI_STATE
72-
#ifdef HAVE_FUNCTION_GRAPH_FP_TEST
73-
mv a0, t6
74-
#endif
69+
mv a0, sp
7570
call ftrace_return_to_handler
7671
mv a2, a0
7772
RESTORE_RET_ABI_STATE

0 commit comments

Comments
 (0)