xref: /linux/arch/riscv/kernel/perf_callchain.c (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2019 Hangzhou C-SKY Microsystems co.,ltd. */
3 
4 #include <linux/perf_event.h>
5 #include <linux/uaccess.h>
6 
7 #include <asm/stacktrace.h>
8 
9 static bool fill_callchain(void *entry, unsigned long pc)
10 {
11 	return perf_callchain_store(entry, pc) == 0;
12 }
13 
14 /*
15  * This will be called when the target is in user mode
16  * This function will only be called when we use
17  * "PERF_SAMPLE_CALLCHAIN" in
18  * kernel/events/core.c:perf_prepare_sample()
19  *
20  * How to trigger perf_callchain_[user/kernel] :
21  * $ perf record -e cpu-clock --call-graph fp ./program
22  * $ perf report --call-graph
23  *
24  * On RISC-V platform, the program being sampled and the C library
25  * need to be compiled with -fno-omit-frame-pointer, otherwise
26  * the user stack will not contain function frame.
27  */
28 void perf_callchain_user(struct perf_callchain_entry_ctx *entry,
29 			 struct pt_regs *regs)
30 {
31 	arch_stack_walk_user(fill_callchain, entry, regs);
32 }
33 
34 void perf_callchain_kernel(struct perf_callchain_entry_ctx *entry,
35 			   struct pt_regs *regs)
36 {
37 	walk_stackframe(NULL, regs, fill_callchain, entry);
38 }
39