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

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 <kim.phillips@arm.com>
Reviewed-by: Hendrik Brueckner <brueckner@linux.ibm.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
Cc: Thomas Richter <tmricht@linux.vnet.ibm.com>
Link: http://lkml.kernel.org/r/20180706163443.22626f5e9e10e5bab5e5c662@arm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Kim Phillips and committed by
Arnaldo Carvalho de Melo
2b588243 34b009cf

+83
+21
tools/perf/arch/arm64/Makefile
··· 4 4 endif 5 5 PERF_HAVE_JITDUMP := 1 6 6 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)
+62
tools/perf/arch/arm64/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 + 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