Skip to content

Commit 4a73aff

Browse files
charlie-rivosacmel
authored andcommitted
perf tools: Create generic syscall table support
Currently each architecture in perf independently generates syscall headers. Adapt the work that has gone into unifying syscall header implementations in the kernel to work with perf tools. Introduce this framework with riscv at first. riscv previously relied on libaudit, but with this change, perf tools for riscv no longer needs this external dependency. Signed-off-by: Charlie Jenkins <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Christian Brauner <[email protected]> Cc: Guo Ren <[email protected]> Cc: Günther Noack <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: James Clark <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: John Garry <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Leo Yan <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Mickaël Salaün <[email protected]> Cc: Mike Leach <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Palmer Dabbelt <[email protected]> Cc: Paul Walmsley <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Will Deacon <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 6bfb4c5 commit 4a73aff

File tree

13 files changed

+588
-77
lines changed

13 files changed

+588
-77
lines changed

tools/build/Build.include

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
comma := ,
1414
squote := '
1515
pound := \#
16+
empty :=
17+
space := $(empty) $(empty)
1618

1719
###
1820
# Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o

tools/perf/Makefile.config

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ ifneq ($(NO_SYSCALL_TABLE),1)
3535
NO_SYSCALL_TABLE := 0
3636
endif
3737

38+
# architectures that use the generic syscall table scripts
39+
ifeq ($(SRCARCH),riscv)
40+
NO_SYSCALL_TABLE := 0
41+
CFLAGS += -DGENERIC_SYSCALL_TABLE
42+
CFLAGS += -I$(OUTPUT)arch/$(SRCARCH)/include/generated
43+
endif
44+
3845
ifneq ($(NO_SYSCALL_TABLE),1)
3946
CFLAGS += -DHAVE_SYSCALL_TABLE_SUPPORT
4047
endif
@@ -97,10 +104,6 @@ ifeq ($(ARCH),mips)
97104
endif
98105
endif
99106

100-
ifeq ($(ARCH),riscv)
101-
CFLAGS += -I$(OUTPUT)arch/riscv/include/generated
102-
endif
103-
104107
# So far there's only x86 and arm libdw unwind support merged in perf.
105108
# Disable it on all other architectures in case libdw unwind
106109
# support is detected in system. Add supported architectures

tools/perf/Makefile.perf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,10 @@ ifeq ($(filter feature-dump,$(MAKECMDGOALS)),feature-dump)
310310
FEATURE_TESTS := all
311311
endif
312312
endif
313+
# architectures that use the generic syscall table
314+
ifeq ($(SRCARCH),riscv)
315+
include $(srctree)/tools/perf/scripts/Makefile.syscalls
316+
endif
313317
include Makefile.config
314318
endif
315319

tools/perf/arch/riscv/Makefile

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,3 @@
11
# SPDX-License-Identifier: GPL-2.0
22
PERF_HAVE_JITDUMP := 1
33
HAVE_KVM_STAT_SUPPORT := 1
4-
5-
#
6-
# Syscall table generation for perf
7-
#
8-
9-
out := $(OUTPUT)arch/riscv/include/generated/asm
10-
header := $(out)/syscalls.c
11-
incpath := $(srctree)/tools
12-
sysdef := $(srctree)/tools/arch/riscv/include/uapi/asm/unistd.h
13-
sysprf := $(srctree)/tools/perf/arch/riscv/entry/syscalls/
14-
systbl := $(sysprf)/mksyscalltbl
15-
16-
# Create output directory if not already present
17-
$(shell [ -d '$(out)' ] || mkdir -p '$(out)')
18-
19-
$(header): $(sysdef) $(systbl)
20-
$(Q)$(SHELL) '$(systbl)' '$(CC)' '$(HOSTCC)' $(incpath) $(sysdef) > $@
21-
22-
clean::
23-
$(call QUIET_CLEAN, riscv) $(RM) $(header)
24-
25-
archheaders: $(header)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
syscall-y += syscalls_64.h
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
3+
syscall_abis_32 += riscv memfd_secret
4+
syscall_abis_64 += riscv rlimit memfd_secret

tools/perf/arch/riscv/entry/syscalls/mksyscalltbl

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#include <asm/bitsperlong.h>
3+
4+
#if __BITS_PER_LONG == 64
5+
#include <asm/syscalls_64.h>
6+
#else
7+
#include <asm/syscalls_32.h>
8+
#endif

tools/perf/check-headers.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ FILES=(
7171
"include/uapi/asm-generic/ioctls.h"
7272
"include/uapi/asm-generic/mman-common.h"
7373
"include/uapi/asm-generic/unistd.h"
74+
"scripts/syscall.tbl"
7475
)
7576

7677
declare -a SYNC_CHECK_FILES

tools/perf/scripts/Makefile.syscalls

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
# This Makefile generates headers in
3+
# tools/perf/arch/$(SRCARCH)/include/generated/asm from the architecture's
4+
# syscall table. This will either be from the generic syscall table, or from a
5+
# table that is specific to that architecture.
6+
7+
PHONY := all
8+
all:
9+
10+
obj := $(OUTPUT)arch/$(SRCARCH)/include/generated/asm
11+
12+
syscall_abis_32 := common,32
13+
syscall_abis_64 := common,64
14+
syscalltbl := $(srctree)/tools/scripts/syscall.tbl
15+
16+
# let architectures override $(syscall_abis_%) and $(syscalltbl)
17+
-include $(srctree)/tools/perf/arch/$(SRCARCH)/entry/syscalls/Makefile.syscalls
18+
include $(srctree)/tools/build/Build.include
19+
-include $(srctree)/tools/perf/arch/$(SRCARCH)/entry/syscalls/Kbuild
20+
21+
systbl := $(srctree)/tools/perf/scripts/syscalltbl.sh
22+
23+
syscall-y := $(addprefix $(obj)/, $(syscall-y))
24+
25+
# Remove stale wrappers when the corresponding files are removed from generic-y
26+
old-headers := $(wildcard $(obj)/*.h)
27+
unwanted := $(filter-out $(syscall-y),$(old-headers))
28+
29+
quiet_cmd_remove = REMOVE $(unwanted)
30+
cmd_remove = rm -f $(unwanted)
31+
32+
quiet_cmd_systbl = SYSTBL $@
33+
cmd_systbl = $(CONFIG_SHELL) $(systbl) \
34+
$(if $(systbl-args-$*),$(systbl-args-$*),$(systbl-args)) \
35+
--abis $(subst $(space),$(comma),$(strip $(syscall_abis_$*))) \
36+
$< $@
37+
38+
all: $(syscall-y)
39+
$(if $(unwanted),$(call cmd,remove))
40+
@:
41+
42+
$(obj)/syscalls_%.h: $(syscalltbl) $(systbl) FORCE
43+
$(call if_changed,systbl)
44+
45+
targets := $(syscall-y)
46+
47+
# Create output directory. Skip it if at least one old header exists
48+
# since we know the output directory already exists.
49+
ifeq ($(old-headers),)
50+
$(shell mkdir -p $(obj))
51+
endif
52+
53+
PHONY += FORCE
54+
55+
FORCE:
56+
57+
existing-targets := $(wildcard $(sort $(targets)))
58+
59+
-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
60+
61+
.PHONY: $(PHONY)

0 commit comments

Comments
 (0)