// SPDX-License-Identifier: GPL-2.01/* Copyright (C) 2019 Hangzhou C-SKY Microsystems co.,ltd. */23#include <linux/perf_event.h>4#include <linux/uaccess.h>56#include <asm/stacktrace.h>78static bool fill_callchain(void *entry, unsigned long pc)9{10return perf_callchain_store(entry, pc) == 0;11}1213/*14* This will be called when the target is in user mode15* This function will only be called when we use16* "PERF_SAMPLE_CALLCHAIN" in17* kernel/events/core.c:perf_prepare_sample()18*19* How to trigger perf_callchain_[user/kernel] :20* $ perf record -e cpu-clock --call-graph fp ./program21* $ perf report --call-graph22*23* On RISC-V platform, the program being sampled and the C library24* need to be compiled with -fno-omit-frame-pointer, otherwise25* the user stack will not contain function frame.26*/27void perf_callchain_user(struct perf_callchain_entry_ctx *entry,28struct pt_regs *regs)29{30if (perf_guest_state()) {31/* TODO: We don't support guest os callchain now */32return;33}3435arch_stack_walk_user(fill_callchain, entry, regs);36}3738void perf_callchain_kernel(struct perf_callchain_entry_ctx *entry,39struct pt_regs *regs)40{41if (perf_guest_state()) {42/* TODO: We don't support guest os callchain now */43return;44}4546walk_stackframe(NULL, regs, fill_callchain, entry);47}484950