Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf, riscv: Wire up perf trace support for RISC-V

RISC-V does not currently support perf trace, since the system call
table is not generated.

Perform the copy/paste exercise, wiring up RISC-V system call table
generation.

Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
Tested-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Cc: Anup Patel <anup@brainfault.org>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: linux-riscv@lists.infradead.org
Cc: Atish Patra <atishp@rivosinc.com>
Cc: Paul Walmsley <paul.walmsley@sifive.com>
Link: https://lore.kernel.org/r/20241024190353.46737-1-bjorn@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Björn Töpel and committed by
Namhyung Kim
8c0d1202 54afc56d

+78 -1
+5 -1
tools/perf/Makefile.config
··· 31 31 ifneq ($(NO_SYSCALL_TABLE),1) 32 32 NO_SYSCALL_TABLE := 1 33 33 34 - ifeq ($(SRCARCH),$(filter $(SRCARCH),x86 powerpc arm64 s390 mips loongarch)) 34 + ifeq ($(SRCARCH),$(filter $(SRCARCH),x86 powerpc arm64 s390 mips loongarch riscv)) 35 35 NO_SYSCALL_TABLE := 0 36 36 endif 37 37 ··· 81 81 ifeq ($(ARCH),mips) 82 82 CFLAGS += -I$(OUTPUT)arch/mips/include/generated 83 83 LIBUNWIND_LIBS = -lunwind -lunwind-mips 84 + endif 85 + 86 + ifeq ($(ARCH),riscv) 87 + CFLAGS += -I$(OUTPUT)arch/riscv/include/generated 84 88 endif 85 89 86 90 # So far there's only x86 and arm libdw unwind support merged in perf.
+22
tools/perf/arch/riscv/Makefile
··· 4 4 PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET := 1 5 5 PERF_HAVE_JITDUMP := 1 6 6 HAVE_KVM_STAT_SUPPORT := 1 7 + 8 + # 9 + # Syscall table generation for perf 10 + # 11 + 12 + out := $(OUTPUT)arch/riscv/include/generated/asm 13 + header := $(out)/syscalls.c 14 + incpath := $(srctree)/tools 15 + sysdef := $(srctree)/tools/arch/riscv/include/uapi/asm/unistd.h 16 + sysprf := $(srctree)/tools/perf/arch/riscv/entry/syscalls/ 17 + systbl := $(sysprf)/mksyscalltbl 18 + 19 + # Create output directory if not already present 20 + $(shell [ -d '$(out)' ] || mkdir -p '$(out)') 21 + 22 + $(header): $(sysdef) $(systbl) 23 + $(Q)$(SHELL) '$(systbl)' '$(CC)' '$(HOSTCC)' $(incpath) $(sysdef) > $@ 24 + 25 + clean:: 26 + $(call QUIET_CLEAN, riscv) $(RM) $(header) 27 + 28 + archheaders: $(header)
+47
tools/perf/arch/riscv/entry/syscalls/mksyscalltbl
··· 1 + #!/bin/sh 2 + # SPDX-License-Identifier: GPL-2.0 3 + # 4 + # Generate system call table for perf. Derived from 5 + # powerpc script. 6 + # 7 + # Copyright IBM Corp. 2017 8 + # Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com> 9 + # Changed by: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> 10 + # Changed by: Kim Phillips <kim.phillips@arm.com> 11 + # Changed by: Björn Töpel <bjorn@rivosinc.com> 12 + 13 + gcc=$1 14 + hostcc=$2 15 + incpath=$3 16 + input=$4 17 + 18 + if ! test -r $input; then 19 + echo "Could not read input file" >&2 20 + exit 1 21 + fi 22 + 23 + create_sc_table() 24 + { 25 + local sc nr max_nr 26 + 27 + while read sc nr; do 28 + printf "%s\n" " [$nr] = \"$sc\"," 29 + max_nr=$nr 30 + done 31 + 32 + echo "#define SYSCALLTBL_RISCV_MAX_ID $max_nr" 33 + } 34 + 35 + create_table() 36 + { 37 + echo "#include \"$input\"" 38 + echo "static const char *const syscalltbl_riscv[] = {" 39 + create_sc_table 40 + echo "};" 41 + } 42 + 43 + $gcc -E -dM -x c -I $incpath/include/uapi $input \ 44 + |awk '$2 ~ "__NR" && $3 !~ "__NR3264_" { 45 + sub("^#define __NR(3264)?_", ""); 46 + print | "sort -k2 -n"}' \ 47 + |create_table
+4
tools/perf/util/syscalltbl.c
··· 46 46 #include <asm/syscalls.c> 47 47 const int syscalltbl_native_max_id = SYSCALLTBL_LOONGARCH_MAX_ID; 48 48 static const char *const *syscalltbl_native = syscalltbl_loongarch; 49 + #elif defined(__riscv) 50 + #include <asm/syscalls.c> 51 + const int syscalltbl_native_max_id = SYSCALLTBL_RISCV_MAX_ID; 52 + static const char *const *syscalltbl_native = syscalltbl_riscv; 49 53 #endif 50 54 51 55 struct syscall {