Skip to content

Commit 9a7e8ec

Browse files
ismhongpalmer-dabbelt
authored andcommitted
riscv: perf: Fix callchain parse error with kernel tracepoint events
For RISC-V, when tracing with tracepoint events, the IP and status are set to 0, preventing the perf code parsing the callchain and resolving the symbols correctly. ./ply 'tracepoint:kmem/kmem_cache_alloc { @[stack]=count(); }' @: { <STACKID4294967282> }: 1 The fix is to implement perf_arch_fetch_caller_regs for riscv, which fills several necessary registers used for callchain unwinding, including epc, sp, s0 and status. It's similar to commit b3eac02 ("arm: perf: Fix callchain parse error with kernel tracepoint events") and commit 5b09a09 ("arm64: perf: Fix callchain parse error with kernel tracepoint events"). With this patch, callchain can be parsed correctly as: ./ply 'tracepoint:kmem/kmem_cache_alloc { @[stack]=count(); }' @: { __traceiter_kmem_cache_alloc+68 __traceiter_kmem_cache_alloc+68 kmem_cache_alloc+354 __sigqueue_alloc+94 __send_signal_locked+646 send_signal_locked+154 do_send_sig_info+84 __kill_pgrp_info+130 kill_pgrp+60 isig+150 n_tty_receive_signal_char+36 n_tty_receive_buf_standard+2214 n_tty_receive_buf_common+280 n_tty_receive_buf2+26 tty_ldisc_receive_buf+34 tty_port_default_receive_buf+62 flush_to_ldisc+158 process_one_work+458 worker_thread+138 kthread+178 riscv_cpufeature_patch_func+832 }: 1 Signed-off-by: Ism Hong <[email protected]> Link: https://lore.kernel.org/r/[email protected] Fixes: 178e9fc ("perf: riscv: preliminary RISC-V support") Cc: [email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 8dc2a7e commit 9a7e8ec

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

arch/riscv/include/asm/perf_event.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,11 @@
1010

1111
#include <linux/perf_event.h>
1212
#define perf_arch_bpf_user_pt_regs(regs) (struct user_regs_struct *)regs
13+
14+
#define perf_arch_fetch_caller_regs(regs, __ip) { \
15+
(regs)->epc = (__ip); \
16+
(regs)->s0 = (unsigned long) __builtin_frame_address(0); \
17+
(regs)->sp = current_stack_pointer; \
18+
(regs)->status = SR_PP; \
19+
}
1320
#endif /* _ASM_RISCV_PERF_EVENT_H */

0 commit comments

Comments
 (0)