riscv: Add perf callchain support
Subsystems (3)
v7 cover riscv: Add perf callchain support
This patchset adds perf callchain(FP/DWARF) support for RISC-V. It comes from the csky version callchain support with some slight modifications. The patchset base on Linux 5.3-rc6.
The patchset has some 'checkpatch.pl --strict' warnings:
WARNING: Use #include <linux/perf_regs.h> instead of <asm/perf_regs.h> #141: FILE: tools/perf/arch/riscv/include/perf_regs.h:9:
+#include <asm/perf_regs.h>
CHECK: Avoid CamelCase: <Dwfl_Thread>
#329: FILE: tools/perf/arch/riscv/util/unwind-libdw.c:9:
+bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg)
CHECK: Avoid CamelCase: <Dwarf_Word>
#333: FILE: tools/perf/arch/riscv/util/unwind-libdw.c:13:
+ Dwarf_Word dwarf_regs[32];
As all the other Linux architectures use asm/perf_regs.h directly and get these camelcases, I didn't try to fix them.
Changes since v6:
- add "WITH Linux-syscall-note" for uapi headers.
Changes since v5:
- use walk_stackframe from stacktrace.c to handle kernel callchain unwinding(fix invalid mem access)
Changes since v4:
- Add missing PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET verified with extra CFLAGS(-Wall -Werror)
Changes since v3:
- Add more strict check for unwind_frame_kernel
- update for kernel 5.3
Changes since v2:
- fix inconsistent comment
- force to build kernel with -fno-omit-frame-pointer if perf event is enabled
Changes since v1:
- simplify implementation and code convention
Mao Han (2):
riscv: Add support for perf registers sampling
riscv: Add support for libdw
arch/riscv/Kconfig | 2 + arch/riscv/include/uapi/asm/perf_regs.h | 42 ++++++++++++ arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/perf_regs.c | 44 ++++++++++++ tools/arch/riscv/include/uapi/asm/perf_regs.h | 42 ++++++++++++ tools/perf/Makefile.config | 6 +- tools/perf/arch/riscv/Build | 1 + tools/perf/arch/riscv/Makefile | 4 ++ tools/perf/arch/riscv/include/perf_regs.h | 96 +++++++++++++++++++++++++++ tools/perf/arch/riscv/util/Build | 2 + tools/perf/arch/riscv/util/dwarf-regs.c | 72 ++++++++++++++++++++ tools/perf/arch/riscv/util/unwind-libdw.c | 57 ++++++++++++++++ 12 files changed, 368 insertions(+), 1 deletion(-) create mode 100644 arch/riscv/include/uapi/asm/perf_regs.h create mode 100644 arch/riscv/kernel/perf_regs.c create mode 100644 tools/arch/riscv/include/uapi/asm/perf_regs.h create mode 100644 tools/perf/arch/riscv/Build create mode 100644 tools/perf/arch/riscv/Makefile create mode 100644 tools/perf/arch/riscv/include/perf_regs.h create mode 100644 tools/perf/arch/riscv/util/Build create mode 100644 tools/perf/arch/riscv/util/dwarf-regs.c create mode 100644 tools/perf/arch/riscv/util/unwind-libdw.c
Signature · 1 line
2.7.4
PATCH v7 1/2 riscv: Add support for perf registers sampling
This patch implements the perf registers sampling and validation API for riscv arch. The valid registers and their register ID are defined in perf_regs.h. Perf tool can backtrace in userspace with unwind library and the registers/user stack dump support.
--- arch/riscv/Kconfig | 2 ++ arch/riscv/include/uapi/asm/perf_regs.h | 42 +++++++++++++++++++++++++++++++ arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/perf_regs.c | 44 +++++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+) create mode 100644 arch/riscv/include/uapi/asm/perf_regs.h create mode 100644 arch/riscv/kernel/perf_regs.c
arch/riscv/Kconfig +2 -0
@@ -35,6 +35,8 @@ config RISCV select HAVE_DMA_CONTIGUOUS select HAVE_FUTEX_CMPXCHG if FUTEX select HAVE_PERF_EVENTS + select HAVE_PERF_REGS + select HAVE_PERF_USER_STACK_DUMP select HAVE_SYSCALL_TRACEPOINTS select IRQ_DOMAIN select SPARSE_IRQ
arch/riscv/include/uapi/asm/perf_regs.h new file +42 -0
42 lines not on this page · raw message
arch/riscv/kernel/Makefile +1 -0
@@ -40,5 +40,6 @@ obj-$(CONFIG_DYNAMIC_FTRACE) += mcount-dyn.o obj-$(CONFIG_PERF_EVENTS) += perf_event.o obj-$(CONFIG_PERF_EVENTS) += perf_callchain.o +obj-$(CONFIG_HAVE_PERF_REGS) += perf_regs.o clean:
arch/riscv/kernel/perf_regs.c new file +44 -0
44 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH V7 1/2] riscv: Add support for perf registers sampling
Quoted 5 lines · Mao Han
This patch implements the perf registers sampling and validation API for riscv arch. The valid registers and their register ID are defined in
perf_regs.h. Perf tool can backtrace in userspace with unwind library and the registers/user stack dump support.
Quoted 7 lines
Signed-off-by Mao Han <[email protected]>Cc Paul Walmsley <[email protected]>Cc Greentime Hu <[email protected]>Cc Palmer Dabbelt <[email protected]>Cc linux-riscv <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Guo Ren <[email protected]>
Thanks, queued for v5.4-rc1 with Greentime's Tested-by: (since the changes from v6 to v7 had no functional impact).
- Paul
PATCH v7 2/2 riscv: Add support for libdw
In reply to Mao HanThis patch adds support for DWARF register mappings and libdw registers initialization, which is used by perf callchain analyzing when --call-graph=dwarf is given.
--- tools/arch/riscv/include/uapi/asm/perf_regs.h | 42 ++++++++++++ tools/perf/Makefile.config | 6 +- tools/perf/arch/riscv/Build | 1 + tools/perf/arch/riscv/Makefile | 4 ++ tools/perf/arch/riscv/include/perf_regs.h | 96 +++++++++++++++++++++++++++ tools/perf/arch/riscv/util/Build | 2 + tools/perf/arch/riscv/util/dwarf-regs.c | 72 ++++++++++++++++++++ tools/perf/arch/riscv/util/unwind-libdw.c | 57 ++++++++++++++++ 8 files changed, 279 insertions(+), 1 deletion(-) create mode 100644 tools/arch/riscv/include/uapi/asm/perf_regs.h create mode 100644 tools/perf/arch/riscv/Build create mode 100644 tools/perf/arch/riscv/Makefile create mode 100644 tools/perf/arch/riscv/include/perf_regs.h create mode 100644 tools/perf/arch/riscv/util/Build create mode 100644 tools/perf/arch/riscv/util/dwarf-regs.c create mode 100644 tools/perf/arch/riscv/util/unwind-libdw.c
tools/arch/riscv/include/uapi/asm/perf_regs.h new file +42 -0
@@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* Copyright (C) 2019 Hangzhou C-SKY Microsystems co.,ltd. */ + +#ifndef _ASM_RISCV_PERF_REGS_H +#define _ASM_RISCV_PERF_REGS_H + +enum perf_event_riscv_regs { +PERF_REG_RISCV_PC , +PERF_REG_RISCV_RA , +PERF_REG_RISCV_SP , +PERF_REG_RISCV_GP , +PERF_REG_RISCV_TP , +PERF_REG_RISCV_T0 , +PERF_REG_RISCV_T1 , +PERF_REG_RISCV_T2 , +PERF_REG_RISCV_S0 , +PERF_REG_RISCV_S1 , +PERF_REG_RISCV_A0 , +PERF_REG_RISCV_A1 , +PERF_REG_RISCV_A2 , +PERF_REG_RISCV_A3 , +PERF_REG_RISCV_A4 , +PERF_REG_RISCV_A5 , +PERF_REG_RISCV_A6 , +PERF_REG_RISCV_A7 , +PERF_REG_RISCV_S2 , +PERF_REG_RISCV_S3 , +PERF_REG_RISCV_S4 , +PERF_REG_RISCV_S5 , +PERF_REG_RISCV_S6 , +PERF_REG_RISCV_S7 , +PERF_REG_RISCV_S8 , +PERF_REG_RISCV_S9 , +PERF_REG_RISCV_S10 , +PERF_REG_RISCV_S11 , +PERF_REG_RISCV_T3 , +PERF_REG_RISCV_T4 , +PERF_REG_RISCV_T5 , +PERF_REG_RISCV_T6 , +PERF_REG_RISCV_MAX , +}; +#endif /* _ASM_RISCV_PERF_REGS_H */
tools/perf/Makefile.config +5 -1
@@ -60,6 +60,10 @@ ifeq ($(SRCARCH),arm64) LIBUNWIND_LIBS = -lunwind -lunwind-aarch64 endif +ifeq ($(SRCARCH),riscv) + NO_PERF_REGS := 0 +endif + ifeq ($(SRCARCH),csky) NO_PERF_REGS := 0 endif
@@ -82,7 +86,7 @@ endif # Disable it on all other architectures in case libdw unwind # support is detected in system. Add supported architectures # to the check. -ifneq ($(SRCARCH),$(filter $(SRCARCH),x86 arm arm64 powerpc s390 csky)) +ifneq ($(SRCARCH),$(filter $(SRCARCH),x86 arm arm64 powerpc s390 csky riscv)) NO_LIBDW_DWARF_UNWIND := 1 endif
tools/perf/arch/riscv/Build new file +1 -0
@@ -0,0 +1 @@ +perf-y += util/
tools/perf/arch/riscv/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +ifndef NO_DWARF +PERF_HAVE_DWARF_REGS := 1 +endif +PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET := 1
tools/perf/arch/riscv/include/perf_regs.h new file +96 -0
96 lines not on this page · raw message
tools/perf/arch/riscv/util/Build new file +2 -0
@@ -0,0 +1,2 @@ +perf-$(CONFIG_DWARF) += dwarf-regs.o +perf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
tools/perf/arch/riscv/util/dwarf-regs.c new file +72 -0
72 lines not on this page · raw message
tools/perf/arch/riscv/util/unwind-libdw.c new file +57 -0
57 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH V7 2/2] riscv: Add support for libdw
Quoted 11 lines · Mao Han
This patch adds support for DWARF register mappings and libdw registers initialization, which is used by perf callchain analyzing when --call-graph=dwarf is given.
Signed-off-by Mao Han <[email protected]>Cc Paul Walmsley <[email protected]>Cc Greentime Hu <[email protected]>Cc Palmer Dabbelt <[email protected]>Cc linux-riscv <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Guo Ren <[email protected]>
Thanks, queued for v5.4-rc1 with Greentime's Tested-by: (since the changes from v6 to v7 had no functional impact).
- Paul