perf_callchain.c 1.1 KB

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