riscv: Add perf callchain support
Subsystems (2)
v2 cover riscv: Add perf callchain support
This patch set add 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.1-rc4:15ade5d2e7775667cf191cf2f94327a4889f8b9d
Changes since v1:
- simplify implementation and code convention
Mao Han (3):
riscv: Add perf callchain support
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 | 4 +- arch/riscv/kernel/perf_callchain.c | 113 ++++++++++++++++++++++++++ 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 | 3 + 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 +++++++++++++ 13 files changed, 482 insertions(+), 2 deletions(-) create mode 100644 arch/riscv/include/uapi/asm/perf_regs.h create mode 100644 arch/riscv/kernel/perf_callchain.c 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 · 7 lines
2.7.4 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH v2 1/3 riscv: Add perf callchain support
This patch add support for perf callchain sampling on riscv platform. The return address of leaf function is retrieved from pt_regs as it is not saved in the outmost frame.
--- arch/riscv/kernel/Makefile | 3 +- arch/riscv/kernel/perf_callchain.c | 113 +++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 arch/riscv/kernel/perf_callchain.c
arch/riscv/kernel/Makefile +2 -1
@@ -37,6 +37,7 @@ obj-$(CONFIG_MODULE_SECTIONS) += module-sections.o obj-$(CONFIG_FUNCTION_TRACER) += mcount.o ftrace.o obj-$(CONFIG_DYNAMIC_FTRACE) += mcount-dyn.o -obj-$(CONFIG_PERF_EVENTS) += perf_event.o +obj-$(CONFIG_PERF_EVENTS) += perf_event.o +obj-$(CONFIG_PERF_EVENTS) += perf_callchain.o clean:
arch/riscv/kernel/perf_callchain.c new file +113 -0
113 lines not on this page · raw message
Signature · 7 lines
2.7.4 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH v2 2/3 riscv: Add support for perf registers sampling
In reply to Mao HanThis 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
@@ -33,6 +33,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 RISCV_ISA_A if SMP
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
@@ -39,5 +39,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
PATCH v2 3/3 riscv: Add support for libdw
In reply to Mao HanThis patch add 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 | 3 + 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, 278 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 */ +/* 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
@@ -59,6 +59,10 @@ ifeq ($(SRCARCH),arm64) LIBUNWIND_LIBS = -lunwind -lunwind-aarch64 endif +ifeq ($(SRCARCH),riscv) + NO_PERF_REGS := 0 +endif + ifeq ($(ARCH),s390) NO_PERF_REGS := 0 NO_SYSCALL_TABLE := 0
@@ -77,7 +81,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)) +ifneq ($(SRCARCH),$(filter $(SRCARCH),x86 arm arm64 powerpc s390 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 +3 -0
@@ -0,0 +1,3 @@ +ifndef NO_DWARF +PERF_HAVE_DWARF_REGS := 1 +endif
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