Skip to content

Commit 8c0d120

Browse files
bjorn-rivosnamhyung
authored andcommitted
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>
1 parent 54afc56 commit 8c0d120

File tree

4 files changed

+78
-1
lines changed

4 files changed

+78
-1
lines changed

tools/perf/Makefile.config

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ $(call detected_var,SRCARCH)
3131
ifneq ($(NO_SYSCALL_TABLE),1)
3232
NO_SYSCALL_TABLE := 1
3333

34-
ifeq ($(SRCARCH),$(filter $(SRCARCH),x86 powerpc arm64 s390 mips loongarch))
34+
ifeq ($(SRCARCH),$(filter $(SRCARCH),x86 powerpc arm64 s390 mips loongarch riscv))
3535
NO_SYSCALL_TABLE := 0
3636
endif
3737

@@ -83,6 +83,10 @@ ifeq ($(ARCH),mips)
8383
LIBUNWIND_LIBS = -lunwind -lunwind-mips
8484
endif
8585

86+
ifeq ($(ARCH),riscv)
87+
CFLAGS += -I$(OUTPUT)arch/riscv/include/generated
88+
endif
89+
8690
# So far there's only x86 and arm libdw unwind support merged in perf.
8791
# Disable it on all other architectures in case libdw unwind
8892
# support is detected in system. Add supported architectures

tools/perf/arch/riscv/Makefile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,25 @@ endif
44
PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET := 1
55
PERF_HAVE_JITDUMP := 1
66
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)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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

tools/perf/util/syscalltbl.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ static const char *const *syscalltbl_native = syscalltbl_mips_n64;
4646
#include <asm/syscalls.c>
4747
const int syscalltbl_native_max_id = SYSCALLTBL_LOONGARCH_MAX_ID;
4848
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;
4953
#endif
5054

5155
struct syscall {

0 commit comments

Comments
 (0)