Skip to content

Commit 2b58824

Browse files
kim-phillips-armacmel
authored andcommitted
perf arm64: Generate system call table from asm/unistd.h
This should speed up accessing new system calls introduced with the kernel rather than waiting for libaudit updates to include them. Using the existing other arch scripts resulted in this error: tools/perf/arch/arm64/entry/syscalls//mksyscalltbl: 25: printf: __NR3264_ftruncate: expected numeric value because, unlike other arches, asm-generic's unistd.h does things like: #define __NR_ftruncate __NR3264_ftruncate Turning the scripts printf's %d into a %s resulted in this in the generated syscalls.c file: static const char *syscalltbl_arm64[] = { [__NR3264_ftruncate] = "ftruncate", So we use the host C compiler to fold the macros, and print them out from within a temporary C program, in order to get the correct output: static const char *syscalltbl_arm64[] = { [46] = "ftruncate", Committer notes: Testing this with a container with an old toolchain breaks because it ends up using the system's /usr/include/asm-generic/unistd.h, included from tools/arch/arm64/include/uapi/asm/unistd.h when what is desired is for it to include tools/include/uapi/asm-generic/unistd.h. Since all that tools/arch/arm64/include/uapi/asm/unistd.h is to set a define and then include asm-generic/unistd.h, do that directly and use tools/include/uapi/asm-generic/unistd.h as the file to get the syscall definitions to expand. Testing it: tools/perf/arch/arm64/entry/syscalls/mksyscalltbl /gcc-linaro-5.4.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc gcc tools/include/uapi/asm-generic/unistd.h Now works and generates in the syscall string table. Before it ended up as: $ tools/perf/arch/arm64/entry/syscalls/mksyscalltbl /gcc-linaro-5.4.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc gcc tools/arch/arm64/include/uapi/asm/unistd.h static const char *syscalltbl_arm64[] = { <stdin>: In function 'main': <stdin>:257:38: error: '__NR_getrandom' undeclared (first use in this function) <stdin>:257:38: note: each undeclared identifier is reported only once for each function it appears in <stdin>:258:41: error: '__NR_memfd_create' undeclared (first use in this function) <stdin>:259:32: error: '__NR_bpf' undeclared (first use in this function) <stdin>:260:37: error: '__NR_execveat' undeclared (first use in this function) tools/perf/arch/arm64/entry/syscalls/mksyscalltbl: 47: tools/perf/arch/arm64/entry/syscalls/mksyscalltbl: /tmp/create-table-60liya: Permission denied }; $ Signed-off-by: Kim Phillips <[email protected]> Reviewed-by: Hendrik Brueckner <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Michael Ellerman <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Ravi Bangoria <[email protected]> Cc: Thomas Richter <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 34b009c commit 2b58824

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

tools/perf/arch/arm64/Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,24 @@ PERF_HAVE_DWARF_REGS := 1
44
endif
55
PERF_HAVE_JITDUMP := 1
66
PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET := 1
7+
8+
#
9+
# Syscall table generation for perf
10+
#
11+
12+
out := $(OUTPUT)arch/arm64/include/generated/asm
13+
header := $(out)/syscalls.c
14+
sysdef := $(srctree)/tools/include/uapi/asm-generic/unistd.h
15+
sysprf := $(srctree)/tools/perf/arch/arm64/entry/syscalls/
16+
systbl := $(sysprf)/mksyscalltbl
17+
18+
# Create output directory if not already present
19+
_dummy := $(shell [ -d '$(out)' ] || mkdir -p '$(out)')
20+
21+
$(header): $(sysdef) $(systbl)
22+
$(Q)$(SHELL) '$(systbl)' '$(CC)' '$(HOSTCC)' $(sysdef) > $@
23+
24+
clean::
25+
$(call QUIET_CLEAN, arm64) $(RM) $(header)
26+
27+
archheaders: $(header)
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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 <[email protected]>
9+
# Changed by: Ravi Bangoria <[email protected]>
10+
# Changed by: Kim Phillips <[email protected]>
11+
12+
gcc=$1
13+
hostcc=$2
14+
input=$3
15+
16+
if ! test -r $input; then
17+
echo "Could not read input file" >&2
18+
exit 1
19+
fi
20+
21+
create_table_from_c()
22+
{
23+
local sc nr last_sc
24+
25+
create_table_exe=`mktemp /tmp/create-table-XXXXXX`
26+
27+
{
28+
29+
cat <<-_EoHEADER
30+
#include <stdio.h>
31+
#define __ARCH_WANT_RENAMEAT
32+
#include "$input"
33+
int main(int argc, char *argv[])
34+
{
35+
_EoHEADER
36+
37+
while read sc nr; do
38+
printf "%s\n" " printf(\"\\t[%d] = \\\"$sc\\\",\\n\", __NR_$sc);"
39+
last_sc=$sc
40+
done
41+
42+
printf "%s\n" " printf(\"#define SYSCALLTBL_ARM64_MAX_ID %d\\n\", __NR_$last_sc);"
43+
printf "}\n"
44+
45+
} | $hostcc -o $create_table_exe -x c -
46+
47+
$create_table_exe
48+
49+
rm -f $create_table_exe
50+
}
51+
52+
create_table()
53+
{
54+
echo "static const char *syscalltbl_arm64[] = {"
55+
create_table_from_c
56+
echo "};"
57+
}
58+
59+
$gcc -E -dM -x c $input \
60+
|sed -ne 's/^#define __NR_//p' \
61+
|sort -t' ' -k2 -nu \
62+
|create_table

0 commit comments

Comments
 (0)