perf: Support multiple system call tables in the build
Subsystems (4)
Ian Rogers
reviewerv5 cover perf: Support multiple system call tables in the build
This work builds on the clean up of system call tables and removal of libaudit by Charlie Jenkins <[email protected]>.
The system call table in perf trace is used to map system call numbers to names and vice versa. Prior to these changes, a single table matching the perf binary's build was present. The table would be incorrect if tracing say a 32-bit binary from a 64-bit version of perf, the names and numbers wouldn't match.
Change the build so that a single system call file is built and the potentially multiple tables are identifiable from the ELF machine type of the process being examined. To determine the ELF machine type, the executable's maps are searched and the associated DSOs ELF headers are read. When this fails and when live, /proc/pid/exe's ELF header is read. Fallback to using the perf's binary type when unknown.
Remove some runtime types used by the system call tables and make equivalents generated at build time.
v5: Add byte swap to dso__e_machine and fix comment as suggested by
Namhyung.
v4: Add reading the e_machine from the thread's maps dsos, only read
from /proc/pid/exe on failure and when live as requested by Namhyung. Add patches to add dso comments and remove unused dso_data variables that are unused without libunwind.
v3: Add Charlie's reviewed-by tags. Incorporate feedback from Arnd
Bergmann <[email protected]> on additional optional column and MIPS system call numbering. Rebase past Namhyung's global system call statistics and add comments that they don't yet support an e_machine other than EM_HOST.
v2: Change the 1 element cache for the last table as suggested by
Howard Chu, add Howard's reviewed-by tags.
Add a comment and apology to Charlie for not doing better in guiding:
https://lore.kernel.org/all/20250114-perf_syscall_arch_runtime-v1-1-5b304e408e11@rivosinc.com/
After discussion on v1 and he agreed this patch series would be the better direction.
Ian Rogers (11):
perf dso: Move libunwind dso_data variables into ifdef perf dso: kernel-doc for enum dso_binary_type
perf syscalltbl: Remove syscall_table.h
perf trace: Reorganize syscalls
perf syscalltbl: Remove struct syscalltbl
perf dso: Add support for reading the e_machine type for a dso perf thread: Add support for reading the e_machine type for a thread perf trace beauty: Add syscalltbl.sh generating all system call tables perf syscalltbl: Use lookup table containing multiple architectures perf build: Remove Makefile.syscalls
perf syscalltbl: Mask off ABI type for MIPS system calls
tools/perf/Makefile.perf | 10 +- tools/perf/arch/alpha/entry/syscalls/Kbuild | 2 - .../alpha/entry/syscalls/Makefile.syscalls | 5 - tools/perf/arch/alpha/include/syscall_table.h | 2 - tools/perf/arch/arc/entry/syscalls/Kbuild | 2 - .../arch/arc/entry/syscalls/Makefile.syscalls | 3 - tools/perf/arch/arc/include/syscall_table.h | 2 - tools/perf/arch/arm/entry/syscalls/Kbuild | 4 - .../arch/arm/entry/syscalls/Makefile.syscalls | 2 - tools/perf/arch/arm/include/syscall_table.h | 2 - tools/perf/arch/arm64/entry/syscalls/Kbuild | 3 - .../arm64/entry/syscalls/Makefile.syscalls | 6 - tools/perf/arch/arm64/include/syscall_table.h | 8 - tools/perf/arch/csky/entry/syscalls/Kbuild | 2 - .../csky/entry/syscalls/Makefile.syscalls | 3 - tools/perf/arch/csky/include/syscall_table.h | 2 - .../perf/arch/loongarch/entry/syscalls/Kbuild | 2 - .../entry/syscalls/Makefile.syscalls | 3 - .../arch/loongarch/include/syscall_table.h | 2 - tools/perf/arch/mips/entry/syscalls/Kbuild | 2 - .../mips/entry/syscalls/Makefile.syscalls | 5 - tools/perf/arch/mips/include/syscall_table.h | 2 - tools/perf/arch/parisc/entry/syscalls/Kbuild | 3 - .../parisc/entry/syscalls/Makefile.syscalls | 6 - .../perf/arch/parisc/include/syscall_table.h | 8 - tools/perf/arch/powerpc/entry/syscalls/Kbuild | 3 - .../powerpc/entry/syscalls/Makefile.syscalls | 6 - .../perf/arch/powerpc/include/syscall_table.h | 8 - tools/perf/arch/riscv/entry/syscalls/Kbuild | 2 - .../riscv/entry/syscalls/Makefile.syscalls | 4 - tools/perf/arch/riscv/include/syscall_table.h | 8 - tools/perf/arch/s390/entry/syscalls/Kbuild | 2 - .../s390/entry/syscalls/Makefile.syscalls | 5 - tools/perf/arch/s390/include/syscall_table.h | 2 - tools/perf/arch/sh/entry/syscalls/Kbuild | 2 - .../arch/sh/entry/syscalls/Makefile.syscalls | 4 - tools/perf/arch/sh/include/syscall_table.h | 2 - tools/perf/arch/sparc/entry/syscalls/Kbuild | 3 - .../sparc/entry/syscalls/Makefile.syscalls | 5 - tools/perf/arch/sparc/include/syscall_table.h | 8 - tools/perf/arch/x86/entry/syscalls/Kbuild | 3 - .../arch/x86/entry/syscalls/Makefile.syscalls | 6 - tools/perf/arch/x86/include/syscall_table.h | 8 - tools/perf/arch/xtensa/entry/syscalls/Kbuild | 2 - .../xtensa/entry/syscalls/Makefile.syscalls | 4 - .../perf/arch/xtensa/include/syscall_table.h | 2 - tools/perf/builtin-trace.c | 290 +++++++++++------- tools/perf/scripts/Makefile.syscalls | 61 ---- tools/perf/scripts/syscalltbl.sh | 86 ------ tools/perf/trace/beauty/syscalltbl.sh | 274 +++++++++++++++++ tools/perf/util/dso.c | 88 ++++++ tools/perf/util/dso.h | 58 ++++ tools/perf/util/symbol-elf.c | 27 -- tools/perf/util/syscalltbl.c | 148 ++++----- tools/perf/util/syscalltbl.h | 22 +- tools/perf/util/thread.c | 80 +++++ tools/perf/util/thread.h | 14 +- 57 files changed, 792 insertions(+), 536 deletions(-) delete mode 100644 tools/perf/arch/alpha/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/alpha/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/alpha/include/syscall_table.h delete mode 100644 tools/perf/arch/arc/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/arc/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/arc/include/syscall_table.h delete mode 100644 tools/perf/arch/arm/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/arm/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/arm/include/syscall_table.h delete mode 100644 tools/perf/arch/arm64/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/arm64/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/arm64/include/syscall_table.h delete mode 100644 tools/perf/arch/csky/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/csky/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/csky/include/syscall_table.h delete mode 100644 tools/perf/arch/loongarch/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/loongarch/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/loongarch/include/syscall_table.h delete mode 100644 tools/perf/arch/mips/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/mips/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/mips/include/syscall_table.h delete mode 100644 tools/perf/arch/parisc/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/parisc/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/parisc/include/syscall_table.h delete mode 100644 tools/perf/arch/powerpc/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/powerpc/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/powerpc/include/syscall_table.h delete mode 100644 tools/perf/arch/riscv/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/riscv/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/riscv/include/syscall_table.h delete mode 100644 tools/perf/arch/s390/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/s390/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/s390/include/syscall_table.h delete mode 100644 tools/perf/arch/sh/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/sh/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/sh/include/syscall_table.h delete mode 100644 tools/perf/arch/sparc/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/sparc/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/sparc/include/syscall_table.h delete mode 100644 tools/perf/arch/x86/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/x86/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/x86/include/syscall_table.h delete mode 100644 tools/perf/arch/xtensa/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/xtensa/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/xtensa/include/syscall_table.h delete mode 100644 tools/perf/scripts/Makefile.syscalls delete mode 100755 tools/perf/scripts/syscalltbl.sh create mode 100755 tools/perf/trace/beauty/syscalltbl.sh
Signature · 1 line
2.49.0.rc0.332.g42c0ae87b1-goog
Ian Rogers
reviewerPATCH v5 1/11 perf dso: Move libunwind dso_data variables into ifdef
The variables elf_base_addr, debug_frame_offset, eh_frame_hdr_addr and eh_frame_hdr_offset are only accessed in unwind-libunwind-local.c which is conditionally built on having libunwind support. Make the variables conditional on libunwind support too.
--- tools/perf/util/dso.h | 2 ++ 1 file changed, 2 insertions(+)
tools/perf/util/dso.h +2 -0
@@ -154,10 +154,12 @@ struct dso_data {int status;u32 status_seen;u64 file_size; +#ifdef HAVE_LIBUNWIND_SUPPORT u64 elf_base_addr;u64 debug_frame_offset;u64 eh_frame_hdr_addr;u64 eh_frame_hdr_offset; +#endif };struct dso_bpf_prog {
Signature · 1 line
2.49.0.rc0.332.g42c0ae87b1-goog
Ian Rogers
reviewerPATCH v5 2/11 perf dso: kernel-doc for enum dso_binary_type
In reply to Ian RogersThere are many and non-obvious meanings to the dso_binary_type enum values. Add kernel-doc to speed interpretting their meanings.
--- tools/perf/util/dso.h | 53 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+)
tools/perf/util/dso.h +53 -0
@@ -20,30 +20,83 @@ struct perf_env;#define DSO__NAME_KALLSYMS "[kernel.kallsyms]"#define DSO__NAME_KCORE "[kernel.kcore]" +/** +* enum dso_binary_type - The kind of DSO generally associated with a memory +* region (struct map). +*/ enum dso_binary_type { +/** @DSO_BINARY_TYPE__KALLSYMS: Symbols from /proc/kallsyms file. */ DSO_BINARY_TYPE__KALLSYMS =0 , +/** @DSO_BINARY_TYPE__GUEST_KALLSYMS: Guest /proc/kallsyms file. */ DSO_BINARY_TYPE__GUEST_KALLSYMS , +/** @DSO_BINARY_TYPE__VMLINUX: Path to kernel /boot/vmlinux file. */ DSO_BINARY_TYPE__VMLINUX , +/** @DSO_BINARY_TYPE__GUEST_VMLINUX: Path to guest kernel /boot/vmlinux file. */ DSO_BINARY_TYPE__GUEST_VMLINUX , +/** @DSO_BINARY_TYPE__JAVA_JIT: Symbols from /tmp/perf.map file. */ DSO_BINARY_TYPE__JAVA_JIT , +/** +* @DSO_BINARY_TYPE__DEBUGLINK: Debug file readable from the file path +* in the .gnu_debuglink ELF section of the dso. +*/ DSO_BINARY_TYPE__DEBUGLINK , +/** +* @DSO_BINARY_TYPE__BUILD_ID_CACHE: File named after buildid located in +* the buildid cache with an elf filename. +*/ DSO_BINARY_TYPE__BUILD_ID_CACHE , +/** +* @DSO_BINARY_TYPE__BUILD_ID_CACHE_DEBUGINFO: File named after buildid +* located in the buildid cache with a debug filename. +*/ DSO_BINARY_TYPE__BUILD_ID_CACHE_DEBUGINFO , +/** +* @DSO_BINARY_TYPE__FEDORA_DEBUGINFO: Debug file in /usr/lib/debug +* with .debug suffix. +*/ DSO_BINARY_TYPE__FEDORA_DEBUGINFO , +/** @DSO_BINARY_TYPE__UBUNTU_DEBUGINFO: Debug file in /usr/lib/debug. */ DSO_BINARY_TYPE__UBUNTU_DEBUGINFO , +/** +* @DSO_BINARY_TYPE__MIXEDUP_UBUNTU_DEBUGINFO: dso__long_name debuginfo +* file in /usr/lib/debug/lib rather than the expected +* /usr/lib/debug/usr/lib. +*/ DSO_BINARY_TYPE__MIXEDUP_UBUNTU_DEBUGINFO , +/** +* @DSO_BINARY_TYPE__BUILDID_DEBUGINFO: File named after buildid located +* in /usr/lib/debug/.build-id/. +*/ DSO_BINARY_TYPE__BUILDID_DEBUGINFO , +/** @DSO_BINARY_TYPE__SYSTEM_PATH_DSO: A regular executable/shared-object file. */ DSO_BINARY_TYPE__SYSTEM_PATH_DSO , +/** @DSO_BINARY_TYPE__GUEST_KMODULE: Guest kernel module .ko file. */ DSO_BINARY_TYPE__GUEST_KMODULE , +/** @DSO_BINARY_TYPE__GUEST_KMODULE_COMP: Guest kernel module .ko.gz file. */ DSO_BINARY_TYPE__GUEST_KMODULE_COMP , +/** @DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE: Kernel module .ko file. */ DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE , +/** @DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP: Kernel module .ko.gz file. */ DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP , +/** @DSO_BINARY_TYPE__KCORE: /proc/kcore file. */ DSO_BINARY_TYPE__KCORE , +/** @DSO_BINARY_TYPE__GUEST_KCORE: Guest /proc/kcore file. */ DSO_BINARY_TYPE__GUEST_KCORE , +/** +* @DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO: Openembedded/Yocto -dbg +* package debug info. +*/ DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO , +/** @DSO_BINARY_TYPE__BPF_PROG_INFO: jitted BPF code. */ DSO_BINARY_TYPE__BPF_PROG_INFO , +/** @DSO_BINARY_TYPE__BPF_IMAGE: jitted BPF trampoline or dispatcher code. */ DSO_BINARY_TYPE__BPF_IMAGE , +/** +* @DSO_BINARY_TYPE__OOL: out of line code such as kprobe-replaced +* instructions or optimized kprobes or ftrace trampolines. +*/ DSO_BINARY_TYPE__OOL , +/** @DSO_BINARY_TYPE__NOT_FOUND: Unknown DSO kind. */ DSO_BINARY_TYPE__NOT_FOUND , };
Signature · 1 line
2.49.0.rc0.332.g42c0ae87b1-goog
Ian Rogers
reviewerPATCH v5 3/11 perf syscalltbl: Remove syscall_table.h
In reply to Ian RogersThe definition of "static const char *const syscalltbl[] = {" is done in a generated syscalls_32.h or syscalls_64.h that is architecture dependent. In order to include the appropriate file a syscall_table.h is found via the perf include path and it includes the syscalls_32.h or syscalls_64.h as appropriate.
To support having multiple syscall tables, one for 32-bit and one for 64-bit, or for different architectures, an include path cannot be used. Remove syscall_table.h because of this and inline what it does into syscalltbl.c.
For architectures without a syscall_table.h this will cause a failure to include either syscalls_32.h or syscalls_64.h rather than a failure to include syscall_table.h. For architectures that only included one or other, the behavior matches BITS_PER_LONG as previously done on architectures supporting both syscalls_32.h and syscalls_64.h.
--- tools/perf/arch/alpha/include/syscall_table.h | 2 -- tools/perf/arch/arc/include/syscall_table.h | 2 -- tools/perf/arch/arm/include/syscall_table.h | 2 -- tools/perf/arch/arm64/include/syscall_table.h | 8 -------- tools/perf/arch/csky/include/syscall_table.h | 2 -- tools/perf/arch/loongarch/include/syscall_table.h | 2 -- tools/perf/arch/mips/include/syscall_table.h | 2 -- tools/perf/arch/parisc/include/syscall_table.h | 8 -------- tools/perf/arch/powerpc/include/syscall_table.h | 8 -------- tools/perf/arch/riscv/include/syscall_table.h | 8 -------- tools/perf/arch/s390/include/syscall_table.h | 2 -- tools/perf/arch/sh/include/syscall_table.h | 2 -- tools/perf/arch/sparc/include/syscall_table.h | 8 -------- tools/perf/arch/x86/include/syscall_table.h | 8 -------- tools/perf/arch/xtensa/include/syscall_table.h | 2 -- tools/perf/util/syscalltbl.c | 8 +++++++- 16 files changed, 7 insertions(+), 67 deletions(-) delete mode 100644 tools/perf/arch/alpha/include/syscall_table.h delete mode 100644 tools/perf/arch/arc/include/syscall_table.h delete mode 100644 tools/perf/arch/arm/include/syscall_table.h delete mode 100644 tools/perf/arch/arm64/include/syscall_table.h delete mode 100644 tools/perf/arch/csky/include/syscall_table.h delete mode 100644 tools/perf/arch/loongarch/include/syscall_table.h delete mode 100644 tools/perf/arch/mips/include/syscall_table.h delete mode 100644 tools/perf/arch/parisc/include/syscall_table.h delete mode 100644 tools/perf/arch/powerpc/include/syscall_table.h delete mode 100644 tools/perf/arch/riscv/include/syscall_table.h delete mode 100644 tools/perf/arch/s390/include/syscall_table.h delete mode 100644 tools/perf/arch/sh/include/syscall_table.h delete mode 100644 tools/perf/arch/sparc/include/syscall_table.h delete mode 100644 tools/perf/arch/x86/include/syscall_table.h delete mode 100644 tools/perf/arch/xtensa/include/syscall_table.h
tools/perf/arch/alpha/include/syscall_table.h deleted +0 -2
@@ -1,2 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include <asm/syscalls_64.h>
tools/perf/arch/arc/include/syscall_table.h deleted +0 -2
@@ -1,2 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include <asm/syscalls_32.h>
tools/perf/arch/arm/include/syscall_table.h deleted +0 -2
@@ -1,2 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include <asm/syscalls_32.h>
tools/perf/arch/arm64/include/syscall_table.h deleted +0 -8
@@ -1,8 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include <asm/bitsperlong.h> - -#if __BITS_PER_LONG ==64 -#include <asm/syscalls_64.h> -#else -#include <asm/syscalls_32.h> -#endif
tools/perf/arch/csky/include/syscall_table.h deleted +0 -2
@@ -1,2 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include <asm/syscalls_32.h>
tools/perf/arch/loongarch/include/syscall_table.h deleted +0 -2
@@ -1,2 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include <asm/syscall_table_64.h>
tools/perf/arch/mips/include/syscall_table.h deleted +0 -2
@@ -1,2 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include <asm/syscalls_64.h>
tools/perf/arch/parisc/include/syscall_table.h deleted +0 -8
@@ -1,8 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include <asm/bitsperlong.h> - -#if __BITS_PER_LONG ==64 -#include <asm/syscalls_64.h> -#else -#include <asm/syscalls_32.h> -#endif
tools/perf/arch/powerpc/include/syscall_table.h deleted +0 -8
@@ -1,8 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include <asm/bitsperlong.h> - -#if __BITS_PER_LONG ==64 -#include <asm/syscalls_64.h> -#else -#include <asm/syscalls_32.h> -#endif
tools/perf/arch/riscv/include/syscall_table.h deleted +0 -8
@@ -1,8 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include <asm/bitsperlong.h> - -#if __BITS_PER_LONG ==64 -#include <asm/syscalls_64.h> -#else -#include <asm/syscalls_32.h> -#endif
tools/perf/arch/s390/include/syscall_table.h deleted +0 -2
@@ -1,2 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include <asm/syscalls_64.h>
tools/perf/arch/sh/include/syscall_table.h deleted +0 -2
@@ -1,2 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include <asm/syscalls_32.h>
tools/perf/arch/sparc/include/syscall_table.h deleted +0 -8
@@ -1,8 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include <asm/bitsperlong.h> - -#if __BITS_PER_LONG ==64 -#include <asm/syscalls_64.h> -#else -#include <asm/syscalls_32.h> -#endif
tools/perf/arch/x86/include/syscall_table.h deleted +0 -8
@@ -1,8 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include <asm/bitsperlong.h> - -#if __BITS_PER_LONG ==64 -#include <asm/syscalls_64.h> -#else -#include <asm/syscalls_32.h> -#endif
tools/perf/arch/xtensa/include/syscall_table.h deleted +0 -2
@@ -1,2 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include <asm/syscalls_32.h>
tools/perf/util/syscalltbl.c +7 -1
@@ -7,13 +7,19 @@#include "syscalltbl.h" #include <stdlib.h> +#include <asm/bitsperlong.h> #include <linux/compiler.h> #include <linux/zalloc.h> #include <string.h> #include "string2.h" -#include <syscall_table.h> +#if __BITS_PER_LONG ==64 +#include <asm/syscalls_64.h> +#else +#include <asm/syscalls_32.h> +#endif +const int syscalltbl_native_max_id =SYSCALLTBL_MAX_ID ;static const char *const *syscalltbl_native = syscalltbl;
Signature · 1 line
2.49.0.rc0.332.g42c0ae87b1-goog
Ian Rogers
reviewerPATCH v5 4/11 perf trace: Reorganize syscalls
In reply to Ian RogersIdentify struct syscall information in the syscalls table by a machine type and syscall number, not just system call number. Having the machine type means that 32-bit system calls can be differentiated from 64-bit ones on a machine capable of both. Having a table for all machine types and all system call numbers would be too large, so maintain a sorted array of system calls as they are encountered.
--- tools/perf/builtin-trace.c | 177 ++++++++++++++++++++++++------------- 1 file changed, 118 insertions(+), 59 deletions(-)
tools/perf/builtin-trace.c +118 -59
@@ -66,6 +66,7 @@#include "syscalltbl.h" #include "../perf.h" #include "trace_augment.h" +#include "dwarf-regs.h" #include <errno.h> #include <inttypes.h>
@@ -86,6 +87,7 @@#include <linux/ctype.h> #include <perf/mmap.h> +#include <tools/libc_compat.h> #ifdef HAVE_LIBTRACEEVENT #include <event-parse.h>
@@ -149,7 +151,10 @@ struct trace {struct perf_tool tool;struct syscalltbl *sctbl;struct { +/** Sorted sycall numbers used by the trace. */ struct syscall *table; +/** Size of table. */ +size_t table_size;struct {struct evsel *sys_enter, *sys_exit,
@@ -1454,22 +1459,37 @@ static const struct syscall_fmt *syscall_fmt__find_by_alias(const char *alias)return __syscall_fmt__find_by_alias (syscall_fmts, nmemb, alias); } -/* -* is_exit: is this "exit" or "exit_group"? -* is_open: is this "open" or "openat"? To associate the fd returned in sys_exit with the pathname in sys_enter. -* args_size: sum of the sizes of the syscall arguments, anything after that is augmented stuff: pathname for openat, etc. -* nonexistent: Just a hole in the syscall table, syscall id not allocated +/** +* struct syscall */ struct syscall { +/** @e_machine: The ELF machine associated with the entry. */ +int e_machine; +/** @id: id value from the tracepoint, the system call number. */ +int id;struct tep_event *tp_format;int nr_args; +/** +* @args_size: sum of the sizes of the syscall arguments, anything +* after that is augmented stuff: pathname for openat, etc. +*/ +int args_size;struct {struct bpf_program *sys_enter, *sys_exit; } bpf_prog; +/** @is_exit: is this "exit" or "exit_group"? */ bool is_exit; +/** +* @is_open: is this "open" or "openat"? To associate the fd returned in +* sys_exit with the pathname in sys_enter. +*/ bool is_open; +/** +* @nonexistent: Name lookup failed. Just a hole in the syscall table, +* syscall id not allocated. +*/ bool nonexistent;bool use_btf;struct tep_format_field *args;
@@ -2107,22 +2127,21 @@ static int syscall__set_arg_fmts(struct syscall *sc)return 0 ; } -static int trace__read_syscall_info (struct trace *trace,int id) +static int syscall__read_info (struct syscall *sc,struct trace *trace) {char tp_name[128 ]; -struct syscall *sc; -const char *name =syscalltbl__name (trace->sctbl, id); +const char *name;int err; -if (trace->syscalls.table ==NULL ) { - trace->syscalls.table =calloc (trace->sctbl->syscalls.max_id +1 ,sizeof (*sc)); -if (trace->syscalls.table ==NULL ) -return -ENOMEM ; - } - sc = trace->syscalls.table + id;if (sc->nonexistent)return -EEXIST ; +if (sc->name) { +/* Info already read. */ +return 0 ; + } + + name =syscalltbl__name (trace->sctbl, sc->id);if (name ==NULL ) { sc->nonexistent = true;return -EEXIST ;
@@ -2145,15 +2164,16 @@ static int trace__read_syscall_info(struct trace *trace, int id)*/ if (IS_ERR (sc->tp_format)) { sc->nonexistent = true; -return PTR_ERR (sc->tp_format); + err =PTR_ERR (sc->tp_format); + sc->tp_format =NULL ; +return err; }/* * The tracepoint format contains __syscall_nr field, so it's one more * than the actual number of syscall arguments. */ -if (syscall__alloc_arg_fmts (sc,IS_ERR (sc->tp_format) ? -RAW_SYSCALL_ARGS_NUM : sc->tp_format->format.nr_fields -1 )) +if (syscall__alloc_arg_fmts (sc, sc->tp_format->format.nr_fields -1 ))return -ENOMEM ; sc->args = sc->tp_format->format.fields;
@@ -2442,13 +2462,67 @@ static size_t syscall__scnprintf_args(struct syscall *sc, char *bf, size_t size,return printed; } +static void syscall__init (struct syscall *sc,int e_machine,int id) +{ +memset (sc,0 ,sizeof (*sc)); + sc->e_machine = e_machine; + sc->id = id; +} + +static void syscall__exit (struct syscall *sc) +{ +if (!sc) +return ; + +zfree (&sc->arg_fmt); +} + +static int syscall__cmp (const void *va,const void *vb) +{ +const struct syscall *a = va, *b = vb; + +if (a->e_machine != b->e_machine) +return a->e_machine - b->e_machine; + +return a->id - b->id; +} + +static struct syscall *trace__find_syscall (struct trace *trace,int e_machine,int id) +{ +struct syscall key = { + .e_machine = e_machine, + .id = id, + }; +struct syscall *sc, *tmp; + + sc =bsearch (&key, trace->syscalls.table, trace->syscalls.table_size, +sizeof (struct syscall ), syscall__cmp); +if (sc) +return sc; + + tmp =reallocarray (trace->syscalls.table, trace->syscalls.table_size +1 , +sizeof (struct syscall )); +if (!tmp) +return NULL ; + + trace->syscalls.table = tmp; + sc = &trace->syscalls.table[trace->syscalls.table_size++]; +syscall__init (sc, e_machine, id); +qsort (trace->syscalls.table, trace->syscalls.table_size,sizeof (struct syscall ), + syscall__cmp); + sc =bsearch (&key, trace->syscalls.table, trace->syscalls.table_size, +sizeof (struct syscall ), syscall__cmp); +return sc; +} +typedef int (*tracepoint_handler )(struct trace *trace,struct evsel *evsel,union perf_event *event,struct perf_sample *sample); -static struct syscall *trace__syscall_info (struct trace *trace, -struct evsel *evsel,int id) +static struct syscall *trace__syscall_info (struct trace *trace,struct evsel *evsel, +int e_machine,int id) { +struct syscall *sc;int err =0 ;if (id <0 ) {
@@ -2473,28 +2547,20 @@ static struct syscall *trace__syscall_info(struct trace *trace, err = -EINVAL ; -if (id > trace->sctbl->syscalls.max_id) { - goto out_cant_read; - } - -if ((trace->syscalls.table ==NULL || trace->syscalls.table[id].name ==NULL ) && - (err =trace__read_syscall_info (trace, id)) !=0 ) - goto out_cant_read; + sc =trace__find_syscall (trace, e_machine, id); +if (sc) + err =syscall__read_info (sc, trace); -if (trace->syscalls.table && trace->syscalls.table[id].nonexistent) - goto out_cant_read; - -return &trace->syscalls.table[id]; - -out_cant_read: -if (verbose >0 ) { +if (err && verbose >0 ) {char sbuf[STRERR_BUFSIZE ]; -fprintf (trace->output,"Problems reading syscall %d: %d (%s)" , id, -err,str_error_r (-err, sbuf,sizeof (sbuf))); -if (id <= trace->sctbl->syscalls.max_id && trace->syscalls.table[id].name !=NULL ) -fprintf (trace->output,"(%s)" , trace->syscalls.table[id].name); + +fprintf (trace->output,"Problems reading syscall %d: %d (%s)" , id, -err, +str_error_r (-err, sbuf,sizeof (sbuf))); +if (sc && sc->name) +fprintf (trace->output,"(%s)" , sc->name);fputs (" information\n" , trace->output); } -return NULL ; +return err ?NULL : sc; }struct syscall_stats {
@@ -2643,14 +2709,6 @@ static void *syscall__augmented_args(struct syscall *sc, struct perf_sample *samreturn NULL ; } -static void syscall__exit (struct syscall *sc) -{ -if (!sc) -return ; - -zfree (&sc->arg_fmt); -} -static int trace__sys_enter (struct trace *trace,struct evsel *evsel,union perf_event *event__maybe_unused ,struct perf_sample *sample)
@@ -2662,7 +2720,7 @@ static int trace__sys_enter(struct trace *trace, struct evsel *evsel,int id =perf_evsel__sc_tp_uint (evsel, id, sample), err =-1 ;int augmented_args_size =0 ;void *augmented_args =NULL ; -struct syscall *sc =trace__syscall_info (trace, evsel, id); +struct syscall *sc =trace__syscall_info (trace, evsel,EM_HOST , id);struct thread_trace *ttrace;if (sc ==NULL )
@@ -2736,7 +2794,7 @@ static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel,struct thread_trace *ttrace;struct thread *thread;int id =perf_evsel__sc_tp_uint (evsel, id, sample), err =-1 ; -struct syscall *sc =trace__syscall_info (trace, evsel, id); +struct syscall *sc =trace__syscall_info (trace, evsel,EM_HOST , id);char msg[1024 ];void *args, *augmented_args =NULL ;int augmented_args_size;
@@ -2811,7 +2869,7 @@ static int trace__sys_exit(struct trace *trace, struct evsel *evsel,struct thread *thread;int id =perf_evsel__sc_tp_uint (evsel, id, sample), err =-1 , callchain_ret =0 , printed =0 ;int alignment = trace->args_alignment; -struct syscall *sc =trace__syscall_info (trace, evsel, id); +struct syscall *sc =trace__syscall_info (trace, evsel,EM_HOST , id);struct thread_trace *ttrace;if (sc ==NULL )
@@ -3164,7 +3222,7 @@ static int trace__event_handler(struct trace *trace, struct evsel *evsel,if (evsel == trace->syscalls.events.bpf_output) {int id =perf_evsel__sc_tp_uint (evsel, id, sample); -struct syscall *sc =trace__syscall_info (trace, evsel, id); +struct syscall *sc =trace__syscall_info (trace, evsel,EM_HOST , id);if (sc) {fprintf (trace->output,"%s(" , sc->name);
@@ -3673,7 +3731,7 @@ static struct bpf_program *trace__find_syscall_bpf_prog(struct trace *trace, strstatic void trace__init_syscall_bpf_progs (struct trace *trace,int id) { -struct syscall *sc =trace__syscall_info (trace,NULL , id); +struct syscall *sc =trace__syscall_info (trace,NULL ,EM_HOST , id);if (sc ==NULL )return ;
@@ -3684,20 +3742,20 @@ static void trace__init_syscall_bpf_progs(struct trace *trace, int id)static int trace__bpf_prog_sys_enter_fd (struct trace *trace,int id) { -struct syscall *sc =trace__syscall_info (trace,NULL , id); +struct syscall *sc =trace__syscall_info (trace,NULL ,EM_HOST , id);return sc ?bpf_program__fd (sc->bpf_prog.sys_enter) :bpf_program__fd (trace->skel->progs.syscall_unaugmented); }static int trace__bpf_prog_sys_exit_fd (struct trace *trace,int id) { -struct syscall *sc =trace__syscall_info (trace,NULL , id); +struct syscall *sc =trace__syscall_info (trace,NULL ,EM_HOST , id);return sc ?bpf_program__fd (sc->bpf_prog.sys_exit) :bpf_program__fd (trace->skel->progs.syscall_unaugmented); }static int trace__bpf_sys_enter_beauty_map (struct trace *trace,int key,unsigned int *beauty_array) {struct tep_format_field *field; -struct syscall *sc =trace__syscall_info (trace,NULL , key); +struct syscall *sc =trace__syscall_info (trace,NULL ,EM_HOST , key);const struct btf_type *bt;char *struct_offset, *tmp, name[32 ];bool can_augment = false;
@@ -3795,7 +3853,7 @@ static struct bpf_program *trace__find_usable_bpf_prog_entry(struct trace *trace try_to_find_pair:for (int i =0 ; i < trace->sctbl->syscalls.nr_entries; ++i) {int id =syscalltbl__id_at_idx (trace->sctbl, i); -struct syscall *pair =trace__syscall_info (trace,NULL , id); +struct syscall *pair =trace__syscall_info (trace,NULL ,EM_HOST , id);struct bpf_program *pair_prog;bool is_candidate = false;
@@ -3945,7 +4003,7 @@ static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace)*/ for (int i =0 ; i < trace->sctbl->syscalls.nr_entries; ++i) {int key =syscalltbl__id_at_idx (trace->sctbl, i); -struct syscall *sc =trace__syscall_info (trace,NULL , key); +struct syscall *sc =trace__syscall_info (trace,NULL ,EM_HOST , key);struct bpf_program *pair_prog;int prog_fd;
@@ -4761,7 +4819,10 @@ static size_t syscall__dump_stats(struct trace *trace, FILE *fp, pct = avg ?100.0 *stddev_stats (&stats->stats) / avg :0.0 ; avg /=NSEC_PER_MSEC ; - sc = &trace->syscalls.table[entry->syscall]; + sc =trace__syscall_info (trace,/*evsel=*/ NULL ,EM_HOST , entry->syscall); +if (!sc) +continue ; + printed +=fprintf (fp," %-15s" , sc->name); printed +=fprintf (fp," %8" PRIu64" %6" PRIu64" %9.3f %9.3f %9.3f" , n, stats->nr_failures, entry->msecs, min, avg);
@@ -5218,12 +5279,10 @@ static int trace__config(const char *var, const char *value, void *arg)static void trace__exit (struct trace *trace) { -int i; -strlist__delete (trace->ev_qualifier);zfree (&trace->ev_qualifier_ids.entries);if (trace->syscalls.table) { -for (i =0 ; i <= trace->sctbl->syscalls.max_id; i++) +for (size_t i =0 ; i < trace->syscalls.table_size; i++)syscall__exit (&trace->syscalls.table[i]);zfree (&trace->syscalls.table); }
Signature · 1 line
2.49.0.rc0.332.g42c0ae87b1-goog
Ian Rogers
reviewerPATCH v5 5/11 perf syscalltbl: Remove struct syscalltbl
In reply to Ian RogersThe syscalltbl held entries of system call name and number pairs, generated from a native syscalltbl at start up. As there are gaps in the system call number there is a notion of index into the table. Going forward we want the system call table to be identifiable by a machine type, for example, i386 vs x86-64. Change the interface to the syscalltbl so (1) a (currently unused machine type of EM_HOST) is passed (2) the index to syscall number and system call name mapping is computed at build time.
Two tables are used for this, an array of system call number to name, an array of system call numbers sorted by the system call name. The sorted array doesn't store strings in part to save memory and relocations. The index notion is carried forward and is an index into the sorted array of system call numbers, the data structures are opaque (held only in syscalltbl.c), and so the number of indices for a machine type is exposed as a new API.
The arrays are computed in the syscalltbl.sh script and so no start-up time computation and storage is necessary.
--- tools/perf/builtin-trace.c | 106 +++++++++++++++++------------ tools/perf/scripts/syscalltbl.sh | 36 ++++------ tools/perf/util/syscalltbl.c | 113 ++++++++++--------------------- tools/perf/util/syscalltbl.h | 22 ++---- 4 files changed, 117 insertions(+), 160 deletions(-)
tools/perf/builtin-trace.c +64 -42
@@ -149,7 +149,6 @@ enum summary_mode {struct trace {struct perf_tool tool; -struct syscalltbl *sctbl;struct {/** Sorted sycall numbers used by the trace. */ struct syscall *table;
@@ -188,6 +187,14 @@ struct trace {pid_t *entries;struct bpf_map *map; } filter_pids; +/* +* TODO: The map is from an ID (aka system call number) to struct +* syscall_stats. If there is >1 e_machine, such as i386 and x86-64 +* processes, then the stats here will gather wrong the statistics for +* the non EM_HOST system calls. A fix would be to add the e_machine +* into the key, but this would make the code inconsistent with the +* per-thread version. +*/ struct hashmap *syscall_stats;double duration_filter;double runtime_ms;
@@ -2141,7 +2148,7 @@ static int syscall__read_info(struct syscall *sc, struct trace *trace)return 0 ; } - name =syscalltbl__name (trace->sctbl, sc->id); + name =syscalltbl__name (sc->e_machine, sc->id);if (name ==NULL ) { sc->nonexistent = true;return -EEXIST ;
@@ -2241,10 +2248,14 @@ static int trace__validate_ev_qualifier(struct trace *trace)strlist__for_each_entry (pos, trace->ev_qualifier) {const char *sc = pos->s; -int id =syscalltbl__id (trace->sctbl, sc), match_next =-1 ; +/* +* TODO: Assume more than the validation/warnings are all for +* the same binary type as perf. +*/ +int id =syscalltbl__id (EM_HOST , sc), match_next =-1 ;if (id <0 ) { - id =syscalltbl__strglobmatch_first (trace->sctbl, sc, &match_next); + id =syscalltbl__strglobmatch_first (EM_HOST , sc, &match_next);if (id >=0 ) goto matches;
@@ -2264,7 +2275,7 @@ static int trace__validate_ev_qualifier(struct trace *trace)continue ;while (1 ) { - id =syscalltbl__strglobmatch_next (trace->sctbl, sc, &match_next); + id =syscalltbl__strglobmatch_next (EM_HOST , sc, &match_next);if (id <0 )break ;if (nr_allocated == nr_used) {
@@ -2720,6 +2731,7 @@ static int trace__sys_enter(struct trace *trace, struct evsel *evsel,int id =perf_evsel__sc_tp_uint (evsel, id, sample), err =-1 ;int augmented_args_size =0 ;void *augmented_args =NULL ; +/* TODO: get e_machine from thread. */ struct syscall *sc =trace__syscall_info (trace, evsel,EM_HOST , id);struct thread_trace *ttrace;
@@ -2794,6 +2806,7 @@ static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel,struct thread_trace *ttrace;struct thread *thread;int id =perf_evsel__sc_tp_uint (evsel, id, sample), err =-1 ; +/* TODO: get e_machine from thread. */ struct syscall *sc =trace__syscall_info (trace, evsel,EM_HOST , id);char msg[1024 ];void *args, *augmented_args =NULL ;
@@ -2869,6 +2882,7 @@ static int trace__sys_exit(struct trace *trace, struct evsel *evsel,struct thread *thread;int id =perf_evsel__sc_tp_uint (evsel, id, sample), err =-1 , callchain_ret =0 , printed =0 ;int alignment = trace->args_alignment; +/* TODO: get e_machine from thread. */ struct syscall *sc =trace__syscall_info (trace, evsel,EM_HOST , id);struct thread_trace *ttrace;
@@ -3222,6 +3236,7 @@ static int trace__event_handler(struct trace *trace, struct evsel *evsel,if (evsel == trace->syscalls.events.bpf_output) {int id =perf_evsel__sc_tp_uint (evsel, id, sample); +/* TODO: get e_machine from thread. */ struct syscall *sc =trace__syscall_info (trace, evsel,EM_HOST , id);if (sc) {
@@ -3729,9 +3744,9 @@ static struct bpf_program *trace__find_syscall_bpf_prog(struct trace *trace, strreturn trace->skel->progs.syscall_unaugmented; } -static void trace__init_syscall_bpf_progs (struct trace *trace,int id) +static void trace__init_syscall_bpf_progs (struct trace *trace,int e_machine,int id) { -struct syscall *sc =trace__syscall_info (trace,NULL ,EM_HOST , id); +struct syscall *sc =trace__syscall_info (trace,NULL , e_machine, id);if (sc ==NULL )return ;
@@ -3740,22 +3755,22 @@ static void trace__init_syscall_bpf_progs(struct trace *trace, int id) sc->bpf_prog.sys_exit =trace__find_syscall_bpf_prog (trace, sc, sc->fmt ? sc->fmt->bpf_prog_name.sys_exit :NULL ,"exit" ); } -static int trace__bpf_prog_sys_enter_fd (struct trace *trace,int id) +static int trace__bpf_prog_sys_enter_fd (struct trace *trace,int e_machine,int id) { -struct syscall *sc =trace__syscall_info (trace,NULL ,EM_HOST , id); +struct syscall *sc =trace__syscall_info (trace,NULL , e_machine, id);return sc ?bpf_program__fd (sc->bpf_prog.sys_enter) :bpf_program__fd (trace->skel->progs.syscall_unaugmented); } -static int trace__bpf_prog_sys_exit_fd (struct trace *trace,int id) +static int trace__bpf_prog_sys_exit_fd (struct trace *trace,int e_machine,int id) { -struct syscall *sc =trace__syscall_info (trace,NULL ,EM_HOST , id); +struct syscall *sc =trace__syscall_info (trace,NULL , e_machine, id);return sc ?bpf_program__fd (sc->bpf_prog.sys_exit) :bpf_program__fd (trace->skel->progs.syscall_unaugmented); } -static int trace__bpf_sys_enter_beauty_map (struct trace *trace,int key,unsigned int *beauty_array) +static int trace__bpf_sys_enter_beauty_map (struct trace *trace,int e_machine,int key,unsigned int *beauty_array) {struct tep_format_field *field; -struct syscall *sc =trace__syscall_info (trace,NULL ,EM_HOST , key); +struct syscall *sc =trace__syscall_info (trace,NULL , e_machine, key);const struct btf_type *bt;char *struct_offset, *tmp, name[32 ];bool can_augment = false;
@@ -3851,9 +3866,9 @@ static struct bpf_program *trace__find_usable_bpf_prog_entry(struct trace *tracereturn NULL ; try_to_find_pair: -for (int i =0 ; i < trace->sctbl->syscalls.nr_entries; ++i) { -int id =syscalltbl__id_at_idx (trace->sctbl, i); -struct syscall *pair =trace__syscall_info (trace,NULL ,EM_HOST , id); +for (int i =0 , num_idx =syscalltbl__num_idx (sc->e_machine); i < num_idx; ++i) { +int id =syscalltbl__id_at_idx (sc->e_machine, i); +struct syscall *pair =trace__syscall_info (trace,NULL , sc->e_machine, id);struct bpf_program *pair_prog;bool is_candidate = false;
@@ -3937,7 +3952,7 @@ static struct bpf_program *trace__find_usable_bpf_prog_entry(struct trace *tracereturn NULL ; } -static int trace__init_syscalls_bpf_prog_array_maps (struct trace *trace) +static int trace__init_syscalls_bpf_prog_array_maps (struct trace *trace,int e_machine) {int map_enter_fd =bpf_map__fd (trace->skel->maps.syscalls_sys_enter);int map_exit_fd =bpf_map__fd (trace->skel->maps.syscalls_sys_exit);
@@ -3945,27 +3960,27 @@ static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace)int err =0 ;unsigned int beauty_array[6 ]; -for (int i =0 ; i < trace->sctbl->syscalls.nr_entries; ++i) { -int prog_fd, key =syscalltbl__id_at_idx (trace->sctbl, i); +for (int i =0 , num_idx =syscalltbl__num_idx (e_machine); i < num_idx; ++i) { +int prog_fd, key =syscalltbl__id_at_idx (e_machine, i);if (!trace__syscall_enabled (trace, key))continue ; -trace__init_syscall_bpf_progs (trace, key); +trace__init_syscall_bpf_progs (trace, e_machine, key);// It'll get at least the "!raw_syscalls:unaugmented" - prog_fd =trace__bpf_prog_sys_enter_fd (trace, key); + prog_fd =trace__bpf_prog_sys_enter_fd (trace, e_machine, key); err =bpf_map_update_elem (map_enter_fd, &key, &prog_fd,BPF_ANY );if (err)break ; - prog_fd =trace__bpf_prog_sys_exit_fd (trace, key); + prog_fd =trace__bpf_prog_sys_exit_fd (trace, e_machine, key); err =bpf_map_update_elem (map_exit_fd, &key, &prog_fd,BPF_ANY );if (err)break ;/* use beauty_map to tell BPF how many bytes to collect, set beauty_map's value here */ memset (beauty_array,0 ,sizeof (beauty_array)); - err =trace__bpf_sys_enter_beauty_map (trace, key, (unsigned int *)beauty_array); + err =trace__bpf_sys_enter_beauty_map (trace, e_machine, key, (unsigned int *)beauty_array);if (err)continue ; err =bpf_map_update_elem (beauty_map_fd, &key, beauty_array,BPF_ANY );
@@ -4001,9 +4016,9 @@ static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace)* first and second arg (this one on the raw_syscalls:sys_exit prog * array tail call, then that one will be used. */ -for (int i =0 ; i < trace->sctbl->syscalls.nr_entries; ++i) { -int key =syscalltbl__id_at_idx (trace->sctbl, i); -struct syscall *sc =trace__syscall_info (trace,NULL ,EM_HOST , key); +for (int i =0 , num_idx =syscalltbl__num_idx (e_machine); i < num_idx; ++i) { +int key =syscalltbl__id_at_idx (e_machine, i); +struct syscall *sc =trace__syscall_info (trace,NULL , e_machine, key);struct bpf_program *pair_prog;int prog_fd;
@@ -4449,8 +4464,13 @@ static int trace__run(struct trace *trace, int argc, const char **argv) goto out_error_mem;#ifdef HAVE_BPF_SKEL -if (trace->skel && trace->skel->progs.sys_enter) -trace__init_syscalls_bpf_prog_array_maps (trace); +if (trace->skel && trace->skel->progs.sys_enter) { +/* +* TODO: Initialize for all host binary machine types, not just +* those matching the perf binary. +*/ +trace__init_syscalls_bpf_prog_array_maps (trace,EM_HOST ); + }#endif if (trace->ev_qualifier_ids.nr >0 ) {
@@ -4475,7 +4495,8 @@ static int trace__run(struct trace *trace, int argc, const char **argv)* So just disable this beautifier (SCA_FD, SCA_FDAT) when 'close' is * not in use. */ - trace->fd_path_disabled = !trace__syscall_enabled (trace,syscalltbl__id (trace->sctbl,"close" )); +/* TODO: support for more than just perf binary machine type close. */ + trace->fd_path_disabled = !trace__syscall_enabled (trace,syscalltbl__id (EM_HOST ,"close" )); err =trace__expand_filters (trace, &evsel);if (err)
@@ -4788,7 +4809,7 @@ static struct syscall_entry *syscall__sort_stats(struct hashmap *syscall_stats)return entry; } -static size_t syscall__dump_stats (struct trace *trace,FILE *fp, +static size_t syscall__dump_stats (struct trace *trace,int e_machine,FILE *fp,struct hashmap *syscall_stats) {size_t printed =0 ;
@@ -4819,7 +4840,7 @@ static size_t syscall__dump_stats(struct trace *trace, FILE *fp, pct = avg ?100.0 *stddev_stats (&stats->stats) / avg :0.0 ; avg /=NSEC_PER_MSEC ; - sc =trace__syscall_info (trace,/*evsel=*/ NULL ,EM_HOST , entry->syscall); + sc =trace__syscall_info (trace,/*evsel=*/ NULL , e_machine, entry->syscall);if (!sc)continue ;
@@ -4846,14 +4867,14 @@ static size_t syscall__dump_stats(struct trace *trace, FILE *fp, }static size_t thread__dump_stats (struct thread_trace *ttrace, -struct trace *trace,FILE *fp) +struct trace *trace,int e_machine,FILE *fp) { -return syscall__dump_stats (trace, fp, ttrace->syscall_stats); +return syscall__dump_stats (trace, e_machine, fp, ttrace->syscall_stats); } -static size_t system__dump_stats (struct trace *trace,FILE *fp) +static size_t system__dump_stats (struct trace *trace,int e_machine,FILE *fp) { -return syscall__dump_stats (trace, fp, trace->syscall_stats); +return syscall__dump_stats (trace, e_machine, fp, trace->syscall_stats); }static size_t trace__fprintf_thread (FILE *fp,struct thread *thread,struct trace *trace)
@@ -4879,7 +4900,8 @@ static size_t trace__fprintf_thread(FILE *fp, struct thread *thread, struct tracelse if (fputc ('\n' , fp) !=EOF ) ++printed; - printed +=thread__dump_stats (ttrace, trace, fp); +/* TODO: get e_machine from thread. */ + printed +=thread__dump_stats (ttrace, trace,EM_HOST , fp);return printed; }
@@ -4940,7 +4962,8 @@ static size_t trace__fprintf_total_summary(struct trace *trace, FILE *fp)else if (fputc ('\n' , fp) !=EOF ) ++printed; - printed +=system__dump_stats (trace, fp); +/* TODO: get all system e_machines. */ + printed +=system__dump_stats (trace,EM_HOST , fp);return printed; }
@@ -5132,8 +5155,9 @@ static int trace__parse_events_option(const struct option *opt, const char *str, *sep ='\0' ; list =0 ; -if (syscalltbl__id (trace->sctbl, s) >=0 || -syscalltbl__strglobmatch_first (trace->sctbl, s, &idx) >=0 ) { +/* TODO: support for more than just perf binary machine type syscalls. */ +if (syscalltbl__id (EM_HOST , s) >=0 || +syscalltbl__strglobmatch_first (EM_HOST , s, &idx) >=0 ) { list =1 ; goto do_concat; }
@@ -5286,7 +5310,6 @@ static void trace__exit(struct trace *trace)syscall__exit (&trace->syscalls.table[i]);zfree (&trace->syscalls.table); } -syscalltbl__delete (trace->sctbl);zfree (&trace->perfconfig_events); }
@@ -5435,9 +5458,8 @@ int cmd_trace(int argc, const char **argv)sigaction (SIGCHLD , &sigchld_act,NULL ); trace.evlist =evlist__new (); - trace.sctbl =syscalltbl__new (); -if (trace.evlist ==NULL || trace.sctbl ==NULL ) { +if (trace.evlist ==NULL ) {pr_err ("Not enough memory to run!\n" ); err = -ENOMEM ; goto out;
tools/perf/scripts/syscalltbl.sh +13 -23
@@ -50,37 +50,27 @@ fi infile="$1" outfile="$2" -nxt=0 - -syscall_macro() { - nr="$1" - name="$2" - - echo " [$nr] = \"$name\"," -} - -emit() { - nr="$1" - entry="$2" - - syscall_macro "$nr" "$entry" -} - -echo "static const char *const syscalltbl[] = {" > $outfile - sorted_table=$(mktemp /tmp/syscalltbl.XXXXXX) grep -E "^[0-9]+[[:space:]]+$abis" "$infile" | sort -n > $sorted_table -max_nr=0 +echo "static const char *const syscall_num_to_name[] = {" > $outfile # the params are: nr abi name entry compat # use _ for intentionally unused variables according to SC2034 while read nr _ name _ _; do - emit "$nr" "$name" >> $outfile - max_nr=$nr + echo " [$nr] = \"$name\"," >> $outfile done < $sorted_table +echo "};" >> $outfile -rm -f $sorted_table +echo "static const uint16_t syscall_sorted_names[] = {" >> $outfile +# When sorting by name, add a suffix of 0s upto 20 characters so that system +# calls that differ with a numerical suffix don't sort before those +# without. This default behavior of sort differs from that of strcmp used at +# runtime. Use sed to strip the trailing 0s suffix afterwards. +grep -E "^[0-9]+[[:space:]]+$abis" "$infile" | awk '{printf $3; for (i = length($3); i < 20; i++) { printf "0"; }; print " " $1}'| sort | sed 's/\([a-zA-Z1-9]\+\)0\+ \([0-9]\+\)/\1 \2/' > $sorted_table +while read name nr; do + echo " $nr, /* $name */" >> $outfile +done < $sorted_table echo "};" >> $outfile -echo "#define SYSCALLTBL_MAX_ID ${max_nr}" >> $outfile +rm -f $sorted_table
tools/perf/util/syscalltbl.c +34 -79
152 lines not on this page · raw message
tools/perf/util/syscalltbl.h +6 -16
@@ -2,22 +2,12 @@#ifndef __PERF_SYSCALLTBL_H#define __PERF_SYSCALLTBL_H -struct syscalltbl { -struct { -int max_id; -int nr_entries; -void *entries; - } syscalls; -}; +const char *syscalltbl__name (int e_machine,int id); +int syscalltbl__id (int e_machine,const char *name); +int syscalltbl__num_idx (int e_machine); +int syscalltbl__id_at_idx (int e_machine,int idx); -struct syscalltbl *syscalltbl__new (void ); -void syscalltbl__delete (struct syscalltbl *tbl); - -const char *syscalltbl__name (const struct syscalltbl *tbl,int id); -int syscalltbl__id (struct syscalltbl *tbl,const char *name); -int syscalltbl__id_at_idx (struct syscalltbl *tbl,int idx); - -int syscalltbl__strglobmatch_first (struct syscalltbl *tbl,const char *syscall_glob,int *idx); -int syscalltbl__strglobmatch_next (struct syscalltbl *tbl,const char *syscall_glob,int *idx); +int syscalltbl__strglobmatch_first (int e_machine,const char *syscall_glob,int *idx); +int syscalltbl__strglobmatch_next (int e_machine,const char *syscall_glob,int *idx);#endif /* __PERF_SYSCALLTBL_H */
Signature · 1 line
2.49.0.rc0.332.g42c0ae87b1-goog
Ian Rogers
reviewerPATCH v5 6/11 perf dso: Add support for reading the e_machine type for a dso
In reply to Ian RogersFor ELF file dsos read the e_machine from the ELF header. For kernel types assume the e_machine matches the perf tool. In other cases return EM_NONE.
When reading from the ELF header use DSO__SWAP that may need dso->needs_swap initializing. Factor out dso__swap_init to allow this.
--- tools/perf/util/dso.c | 88 ++++++++++++++++++++++++++++++++++++ tools/perf/util/dso.h | 3 ++ tools/perf/util/symbol-elf.c | 27 ----------- 3 files changed, 91 insertions(+), 27 deletions(-)
tools/perf/util/dso.c +88 -0
@@ -1170,6 +1170,67 @@ ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine,return data_read_write_offset (dso, machine, offset, data, size, true); } +uint16_t dso__e_machine (struct dso *dso,struct machine *machine) +{ +uint16_t e_machine =EM_NONE ; +int fd; + +switch (dso__binary_type (dso)) { +case DSO_BINARY_TYPE__KALLSYMS : +case DSO_BINARY_TYPE__GUEST_KALLSYMS : +case DSO_BINARY_TYPE__VMLINUX : +case DSO_BINARY_TYPE__GUEST_VMLINUX : +case DSO_BINARY_TYPE__GUEST_KMODULE : +case DSO_BINARY_TYPE__GUEST_KMODULE_COMP : +case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE : +case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP : +case DSO_BINARY_TYPE__KCORE : +case DSO_BINARY_TYPE__GUEST_KCORE : +case DSO_BINARY_TYPE__BPF_PROG_INFO : +case DSO_BINARY_TYPE__BPF_IMAGE : +case DSO_BINARY_TYPE__OOL : +case DSO_BINARY_TYPE__JAVA_JIT : +return EM_HOST ; +case DSO_BINARY_TYPE__DEBUGLINK : +case DSO_BINARY_TYPE__BUILD_ID_CACHE : +case DSO_BINARY_TYPE__BUILD_ID_CACHE_DEBUGINFO : +case DSO_BINARY_TYPE__SYSTEM_PATH_DSO : +case DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO : +case DSO_BINARY_TYPE__FEDORA_DEBUGINFO : +case DSO_BINARY_TYPE__UBUNTU_DEBUGINFO : +case DSO_BINARY_TYPE__MIXEDUP_UBUNTU_DEBUGINFO : +case DSO_BINARY_TYPE__BUILDID_DEBUGINFO : +break ; +case DSO_BINARY_TYPE__NOT_FOUND : +default : +return EM_NONE ; + } + +pthread_mutex_lock (&dso__data_open_lock); + +/* +* dso__data(dso)->fd might be closed if other thread opened another +* file (dso) due to open file limit (RLIMIT_NOFILE). +*/ +try_to_open_dso (dso, machine); + fd =dso__data (dso)->fd; +if (fd >=0 ) { +_Static_assert (offsetof(Elf32_Ehdr , e_machine) ==18 ,"Unexpected offset" ); +_Static_assert (offsetof(Elf64_Ehdr , e_machine) ==18 ,"Unexpected offset" ); +if (dso__needs_swap (dso) ==DSO_SWAP__UNSET ) { +unsigned char eidata; + +if (pread (fd, &eidata,sizeof (eidata),EI_DATA ) ==sizeof (eidata)) +dso__swap_init (dso, eidata); + } +if (dso__needs_swap (dso) !=DSO_SWAP__UNSET && +pread (fd, &e_machine,sizeof (e_machine),18 ) ==sizeof (e_machine)) + e_machine =DSO__SWAP (dso, uint16_t, e_machine); + } +pthread_mutex_unlock (&dso__data_open_lock); +return e_machine; +} +/** * dso__data_read_addr - Read data from dso address * @dso: dso object
@@ -1525,6 +1586,33 @@ void dso__put(struct dso *dso)RC_CHK_PUT (dso); } +int dso__swap_init (struct dso *dso,unsigned char eidata) +{ +static unsigned int const endian =1 ; + +dso__set_needs_swap (dso,DSO_SWAP__NO ); + +switch (eidata) { +case ELFDATA2LSB : +/* We are big endian, DSO is little endian. */ +if (*(unsigned char const *)&endian !=1 ) +dso__set_needs_swap (dso,DSO_SWAP__YES ); +break ; + +case ELFDATA2MSB : +/* We are little endian, DSO is big endian. */ +if (*(unsigned char const *)&endian !=0 ) +dso__set_needs_swap (dso,DSO_SWAP__YES ); +break ; + +default : +pr_err ("unrecognized DSO data encoding %d\n" , eidata); +return -EINVAL ; + } + +return 0 ; +} +void dso__set_build_id (struct dso *dso,struct build_id *bid) {RC_CHK_ACCESS (dso)->bid = *bid;
tools/perf/util/dso.h +3 -0
@@ -730,6 +730,8 @@ bool dso__sorted_by_name(const struct dso *dso);void dso__set_sorted_by_name (struct dso *dso);void dso__sort_by_name (struct dso *dso); +int dso__swap_init (struct dso *dso,unsigned char eidata); +void dso__set_build_id (struct dso *dso,struct build_id *bid);bool dso__build_id_equal (const struct dso *dso,struct build_id *bid); void dso__read_running_kernel_build_id(struct dso *dso,
@@ -818,6 +820,7 @@ int dso__data_file_size(struct dso *dso, struct machine *machine);off_t dso__data_size (struct dso *dso,struct machine *machine);ssize_t dso__data_read_offset (struct dso *dso,struct machine *machine,u64 offset,u8 *data,ssize_t size); +uint16_t dso__e_machine (struct dso *dso,struct machine *machine);ssize_t dso__data_read_addr (struct dso *dso,struct map *map,struct machine *machine,u64 addr,u8 *data,ssize_t size);
tools/perf/util/symbol-elf.c +0 -27
@@ -1173,33 +1173,6 @@ int filename__read_debuglink(const char *filename, char *debuglink,#endif -static int dso__swap_init (struct dso *dso,unsigned char eidata) -{ -static unsigned int const endian =1 ; - -dso__set_needs_swap (dso,DSO_SWAP__NO ); - -switch (eidata) { -case ELFDATA2LSB : -/* We are big endian, DSO is little endian. */ -if (*(unsigned char const *)&endian !=1 ) -dso__set_needs_swap (dso,DSO_SWAP__YES ); -break ; - -case ELFDATA2MSB : -/* We are little endian, DSO is big endian. */ -if (*(unsigned char const *)&endian !=0 ) -dso__set_needs_swap (dso,DSO_SWAP__YES ); -break ; - -default : -pr_err ("unrecognized DSO data encoding %d\n" , eidata); -return -EINVAL ; - } - -return 0 ; -} -bool symsrc__possibly_runtime (struct symsrc *ss) {return ss->dynsym || ss->opdsec;
Signature · 1 line
2.49.0.rc0.332.g42c0ae87b1-goog
Ian Rogers
reviewerPATCH v5 7/11 perf thread: Add support for reading the e_machine type for a thread
In reply to Ian RogersFirst try to read the e_machine from the dsos associated with the thread's maps. If live use the executable from /proc/pid/exe and read the e_machine from the ELF header. On failure use EM_HOST. Change builtin-trace syscall functions to pass e_machine from the thread rather than EM_HOST, so that in later patches when syscalltbl can use the e_machine the system calls are specific to the architecture.
--- tools/perf/builtin-trace.c | 43 ++++++++++---------- tools/perf/util/thread.c | 80 ++++++++++++++++++++++++++++++++++++++ tools/perf/util/thread.h | 14 ++++++- 3 files changed, 115 insertions(+), 22 deletions(-)
tools/perf/builtin-trace.c +22 -21
@@ -2729,16 +2729,16 @@ static int trace__sys_enter(struct trace *trace, struct evsel *evsel,int printed =0 ;struct thread *thread;int id =perf_evsel__sc_tp_uint (evsel, id, sample), err =-1 ; -int augmented_args_size =0 ; +int augmented_args_size =0 , e_machine;void *augmented_args =NULL ; -/* TODO: get e_machine from thread. */ -struct syscall *sc =trace__syscall_info (trace, evsel,EM_HOST , id); +struct syscall *sc;struct thread_trace *ttrace; -if (sc ==NULL ) -return -1 ; - thread =machine__findnew_thread (trace->host, sample->pid, sample->tid); + e_machine =thread__e_machine (thread, trace->host); + sc =trace__syscall_info (trace, evsel, e_machine, id); +if (sc ==NULL ) + goto out_put; ttrace =thread__trace (thread, trace);if (ttrace ==NULL ) goto out_put;
@@ -2806,17 +2806,18 @@ static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel,struct thread_trace *ttrace;struct thread *thread;int id =perf_evsel__sc_tp_uint (evsel, id, sample), err =-1 ; -/* TODO: get e_machine from thread. */ -struct syscall *sc =trace__syscall_info (trace, evsel,EM_HOST , id); +struct syscall *sc;char msg[1024 ];void *args, *augmented_args =NULL ; -int augmented_args_size; +int augmented_args_size, e_machine;size_t printed =0 ; -if (sc ==NULL ) -return -1 ; thread =machine__findnew_thread (trace->host, sample->pid, sample->tid); + e_machine =thread__e_machine (thread, trace->host); + sc =trace__syscall_info (trace, evsel, e_machine, id); +if (sc ==NULL ) +return -1 ; ttrace =thread__trace (thread, trace);/* * We need to get ttrace just to make sure it is there when syscall__scnprintf_args()
@@ -2881,15 +2882,15 @@ static int trace__sys_exit(struct trace *trace, struct evsel *evsel,bool duration_calculated = false;struct thread *thread;int id =perf_evsel__sc_tp_uint (evsel, id, sample), err =-1 , callchain_ret =0 , printed =0 ; -int alignment = trace->args_alignment; -/* TODO: get e_machine from thread. */ -struct syscall *sc =trace__syscall_info (trace, evsel,EM_HOST , id); +int alignment = trace->args_alignment, e_machine; +struct syscall *sc;struct thread_trace *ttrace; -if (sc ==NULL ) -return -1 ; - thread =machine__findnew_thread (trace->host, sample->pid, sample->tid); + e_machine =thread__e_machine (thread, trace->host); + sc =trace__syscall_info (trace, evsel, e_machine, id); +if (sc ==NULL ) + goto out_put; ttrace =thread__trace (thread, trace);if (ttrace ==NULL ) goto out_put;
@@ -3236,8 +3237,8 @@ static int trace__event_handler(struct trace *trace, struct evsel *evsel,if (evsel == trace->syscalls.events.bpf_output) {int id =perf_evsel__sc_tp_uint (evsel, id, sample); -/* TODO: get e_machine from thread. */ -struct syscall *sc =trace__syscall_info (trace, evsel,EM_HOST , id); +int e_machine = thread ?thread__e_machine (thread, trace->host) :EM_HOST ; +struct syscall *sc =trace__syscall_info (trace, evsel, e_machine, id);if (sc) {fprintf (trace->output,"%s(" , sc->name);
@@ -4881,6 +4882,7 @@ static size_t trace__fprintf_thread(FILE *fp, struct thread *thread, struct trac {size_t printed =0 ;struct thread_trace *ttrace =thread__priv (thread); +int e_machine =thread__e_machine (thread, trace->host);double ratio;if (ttrace ==NULL )
@@ -4900,8 +4902,7 @@ static size_t trace__fprintf_thread(FILE *fp, struct thread *thread, struct tracelse if (fputc ('\n' , fp) !=EOF ) ++printed; -/* TODO: get e_machine from thread. */ - printed +=thread__dump_stats (ttrace, trace,EM_HOST , fp); + printed +=thread__dump_stats (ttrace, trace, e_machine, fp);return printed; }
tools/perf/util/thread.c +80 -0
103 lines not on this page · raw message
tools/perf/util/thread.h +13 -1
@@ -60,7 +60,11 @@ DECLARE_RC_STRUCT(thread) {struct srccode_state srccode_state;bool filter;int filter_entry_depth; - +/** +* @e_machine: The ELF EM_* associated with the thread. EM_NONE if not +* computed. +*/ +uint16_t e_machine;/* LBR call stack stitch */ bool lbr_stitch_enable;struct lbr_stitch *lbr_stitch;
@@ -302,6 +306,14 @@ static inline void thread__set_filter_entry_depth(struct thread *thread, int depRC_CHK_ACCESS (thread)->filter_entry_depth = depth; } +uint16_t thread__e_machine (struct thread *thread,struct machine *machine); + +static inline void thread__set_e_machine (struct thread *thread,uint16_t e_machine) +{ +RC_CHK_ACCESS (thread)->e_machine = e_machine; +} + +static inline bool thread__lbr_stitch_enable (const struct thread *thread) {return RC_CHK_ACCESS (thread)->lbr_stitch_enable;
Signature · 1 line
2.49.0.rc0.332.g42c0ae87b1-goog
Ian Rogers
reviewerPATCH v5 8/11 perf trace beauty: Add syscalltbl.sh generating all system call tables
In reply to Ian RogersRather than generating individual syscall header files generate a single trace/beauty/generated/syscalltbl.c. In a syscalltbls array have references to each architectures tables along with the corresponding e_machine. When the 32-bit or 64-bit table is ambiguous, match the perf binary's type. For ARM32 don't use the arm64 32-bit table which is smaller. EM_NONE is present for is no machine matches.
Conditionally compile the tables, only having the appropriate 32 and 64-bit table. If ALL_SYSCALLTBL is defined all tables can be compiled.
Add comment for noreturn column suggested by Arnd Bergmann:
https://lore.kernel.org/lkml/[email protected]/
and added in commit 9142be9e6443 ("x86/syscall: Mark exit[_group] syscall handlers __noreturn").
--- tools/perf/Makefile.perf | 9 + tools/perf/trace/beauty/syscalltbl.sh | 274 ++++++++++++++++++++++++++ 2 files changed, 283 insertions(+) create mode 100755 tools/perf/trace/beauty/syscalltbl.sh
tools/perf/Makefile.perf +9 -0
@@ -559,6 +559,14 @@ beauty_ioctl_outdir := $(beauty_outdir)/ioctl # Create output directory if not already present $(shell [ -d '$(beauty_ioctl_outdir)' ] || mkdir -p '$(beauty_ioctl_outdir)') +syscall_array := $(beauty_outdir)/syscalltbl.c +syscall_tbl := $(srctree)/tools/perf/trace/beauty/syscalltbl.sh +syscall_tbl_data := $(srctree)/tools/scripts/syscall.tbl \ + $(wildcard $(srctree)/tools/perf/arch/*/entry/syscalls/syscall*.tbl) + +$(syscall_array): $(syscall_tbl) $(syscall_tbl_data) + $(Q)$(SHELL) '$(syscall_tbl)' $(srctree)/tools $@ + fs_at_flags_array := $(beauty_outdir)/fs_at_flags_array.c fs_at_flags_tbl := $(srctree)/tools/perf/trace/beauty/fs_at_flags.sh
@@ -878,6 +886,7 @@ build-dir = $(or $(__build-dir),.) prepare: $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h archheaders \ arm64-sysreg-defs \ + $(syscall_array) \ $(fs_at_flags_array) \ $(clone_flags_array) \ $(drm_ioctl_array) \
tools/perf/trace/beauty/syscalltbl.sh new file +274 -0
274 lines not on this page · raw message
Signature · 1 line
2.49.0.rc0.332.g42c0ae87b1-goog
Ian Rogers
reviewerPATCH v5 9/11 perf syscalltbl: Use lookup table containing multiple architectures
In reply to Ian RogersSwitch to use the lookup table containing all architectures rather than tables matching the perf binary.
This fixes perf trace when executed on a 32-bit i386 binary on an x86-64 machine. Note in the following the system call names of the 32-bit i386 binary as seen by an x86-64 perf.
Before:
```
? ( ): a.out/447296 ... [continued]: munmap()) = 0
0.024 ( 0.001 ms): a.out/447296 recvfrom(ubuf: 0x2, size: 4160585708, flags: DONTROUTE|CTRUNC|TRUNC|DONTWAIT|EOR|WAITALL|FIN|SYN|CONFIRM|RST|ERRQUEUE|NOSIGNAL|WAITFORONE|BATCH|SOCK_DEVMEM|ZEROCOPY|FASTOPEN|CMSG_CLOEXEC|0x91f80000, addr: 0xe30, addr_len: 0xffce438c) = 1475198976
0.042 ( 0.003 ms): a.out/447296 lgetxattr(name: "", value: 0x3, size: 34) = 4160344064
0.054 ( 0.003 ms): a.out/447296 dup2(oldfd: -134422744, newfd: 4) = -1 ENOENT (No such file or directory)
0.060 ( 0.009 ms): a.out/447296 preadv(fd: 4294967196, vec: (struct iovec){.iov_base = (void *)0x2e646c2f6374652f,.iov_len = (__kernel_size_t)7307199665335594867,}, vlen: 557056, pos_h: 4160585708) = 3
0.074 ( 0.004 ms): a.out/447296 lgetxattr(name: "", value: 0x1, size: 2) = 4160237568
0.080 ( 0.001 ms): a.out/447296 lstat(filename: "", statbuf: 0x193f6) = 0
0.089 ( 0.007 ms): a.out/447296 preadv(fd: 4294967196, vec: (struct iovec){.iov_base = (void *)0x3833692f62696c2f,.iov_len = (__kernel_size_t)3276497845987585334,}, vlen: 557056, pos_h: 4160585708) = 3
0.097 ( 0.002 ms): a.out/447296 close(fd: 3</proc/447296/status>) = 512
0.103 ( 0.002 ms): a.out/447296 lgetxattr(name: "", value: 0x1, size: 2050) = 4157935616
0.107 ( 0.007 ms): a.out/447296 lgetxattr(pathname: "", name: "", value: 0x5, size: 2066) = 4158078976
0.116 ( 0.003 ms): a.out/447296 lgetxattr(pathname: "", name: "", value: 0x1, size: 2066) = 4159639552
0.121 ( 0.003 ms): a.out/447296 lgetxattr(pathname: "", name: "", value: 0x3, size: 2066) = 4160184320
0.129 ( 0.002 ms): a.out/447296 lgetxattr(pathname: "", name: "", value: 0x3, size: 50) = 4160196608
0.138 ( 0.001 ms): a.out/447296 lstat(filename: "") = 0
0.145 ( 0.002 ms): a.out/447296 mq_timedreceive(mqdes: 4291706800, u_msg_ptr: 0xf7f9ea48, msg_len: 134616640, u_msg_prio: 0xf7fd7fec, u_abs_timeout: (struct __kernel_timespec){.tv_sec = (__kernel_time64_t)-578174027777317696,.tv_nsec = (long long int)4160349376,}) = 0
0.148 ( 0.001 ms): a.out/447296 mkdirat(dfd: -134617816, pathname: " ��� ���▒���▒���", mode: IFREG|ISUID|IRUSR|IWGRP|0xf7fd0000) = 447296
0.150 ( 0.001 ms): a.out/447296 process_vm_writev(pid: -134617812, lvec: (struct iovec){.iov_base = (void *)0xf7f9e9c8f7f9e4c0,.iov_len = (__kernel_size_t)4160349376,}, liovcnt: 4160588048, rvec: (struct iovec){}, riovcnt: 4160585708, flags: 4291707352) = 0
0.197 ( 0.004 ms): a.out/447296 capget(header: 4160184320, dataptr: 8192) = 0
0.202 ( 0.002 ms): a.out/447296 capget(header: 1448669184, dataptr: 4096) = 0
0.208 ( 0.002 ms): a.out/447296 capget(header: 4160577536, dataptr: 8192) = 0
0.220 ( 0.001 ms): a.out/447296 getxattr(pathname: "", name: "c������", value: 0xf7f77e34, size: 1) = 0
0.228 ( 0.005 ms): a.out/447296 fchmod(fd: -134729728, mode: IRUGO|IWUGO|IFREG|IFIFO|ISVTX|IXUSR|0x10000) = 0
0.240 ( 0.009 ms): a.out/447296 preadv(fd: 4294967196, vec: 0x5658e008, pos_h: 4160192052) = 3
0.250 ( 0.008 ms): a.out/447296 close(fd: 3</proc/447296/status>) = 1436
0.260 ( 0.018 ms): a.out/447296 stat(filename: "", statbuf: 0xffce32ac) = 1436
0.288 (1000.213 ms): a.out/447296 readlinkat(buf: 0xffce31d4, bufsiz: 4291703244) = 0
```After:
```
? ( ): a.out/442930 ... [continued]: execve()) = 0
0.023 ( 0.002 ms): a.out/442930 brk() = 0x57760000
0.052 ( 0.003 ms): a.out/442930 access(filename: 0xf7f5af28, mode: R) = -1 ENOENT (No such file or directory)
0.059 ( 0.009 ms): a.out/442930 openat(dfd: CWD, filename: "/etc/ld.so.cache", flags: RDONLY|CLOEXEC|LARGEFILE) = 3
0.078 ( 0.001 ms): a.out/442930 close(fd: 3</proc/442930/status>) = 0
0.087 ( 0.007 ms): a.out/442930 openat(dfd: CWD, filename: "/lib/i386-linux-", flags: RDONLY|CLOEXEC|LARGEFILE) = 3
0.095 ( 0.002 ms): a.out/442930 read(fd: 3</proc/442930/status>, buf: 0xffbdbb70, count: 512) = 512
0.135 ( 0.001 ms): a.out/442930 close(fd: 3</proc/442930/status>) = 0
0.148 ( 0.001 ms): a.out/442930 set_tid_address(tidptr: 0xf7f2b528) = 442930 (a.out)
0.150 ( 0.001 ms): a.out/442930 set_robust_list(head: 0xf7f2b52c, len: 12) =
0.196 ( 0.004 ms): a.out/442930 mprotect(start: 0xf7f03000, len: 8192, prot: READ) = 0
0.202 ( 0.002 ms): a.out/442930 mprotect(start: 0x5658e000, len: 4096, prot: READ) = 0
0.207 ( 0.002 ms): a.out/442930 mprotect(start: 0xf7f63000, len: 8192, prot: READ) = 0
0.230 ( 0.005 ms): a.out/442930 munmap(addr: 0xf7f10000, len: 103414) = 0
0.244 ( 0.010 ms): a.out/442930 openat(dfd: CWD, filename: 0x5658d008) = 3
0.255 ( 0.007 ms): a.out/442930 read(fd: 3</proc/442930/status>, buf: 0xffbdb67c, count: 4096) = 1436
0.264 ( 0.018 ms): a.out/442930 write(fd: 1</dev/pts/4>, buf: , count: 1436) = 1436
0.292 (1000.173 ms): a.out/442930 clock_nanosleep(rqtp: { .tv_sec: 17866546940376776704, .tv_nsec: 4159878336 }, rmtp: 0xffbdb59c) = 0
1000.478 ( ): a.out/442930 exit_group() = ?
```--- tools/perf/util/syscalltbl.c | 89 ++++++++++++++++++++++++++---------- 1 file changed, 64 insertions(+), 25 deletions(-)
tools/perf/util/syscalltbl.c +64 -25
@@ -15,16 +15,39 @@#include <string.h> #include "string2.h" -#if __BITS_PER_LONG ==64 -#include <asm/syscalls_64.h> -#else -#include <asm/syscalls_32.h> -#endif +#include "trace/beauty/generated/syscalltbl.c" -const char *syscalltbl__name (int e_machine__maybe_unused ,int id) +static const struct syscalltbl *find_table (int e_machine) { -if (id >=0 && id <= (int )ARRAY_SIZE (syscall_num_to_name)) -return syscall_num_to_name[id]; +static const struct syscalltbl *last_table; +static int last_table_machine =EM_NONE ; + +/* Tables only exist for EM_SPARC. */ +if (e_machine ==EM_SPARCV9 ) + e_machine =EM_SPARC ; + +if (last_table_machine == e_machine && last_table !=NULL ) +return last_table; + +for (size_t i =0 ; i <ARRAY_SIZE (syscalltbls); i++) { +const struct syscalltbl *entry = &syscalltbls[i]; + +if (entry->e_machine != e_machine && entry->e_machine !=EM_NONE ) +continue ; + + last_table = entry; + last_table_machine = e_machine; +return entry; + } +return NULL ; +} + +const char *syscalltbl__name (int e_machine,int id) +{ +const struct syscalltbl *table =find_table (e_machine); + +if (table && id >=0 && id < table->num_to_name_len) +return table->num_to_name[id];return NULL ; }
@@ -41,38 +64,54 @@ static int syscallcmpname(const void *vkey, const void *ventry)return strcmp (key->name, key->tbl[*entry]); } -int syscalltbl__id (int e_machine__maybe_unused ,const char *name) +int syscalltbl__id (int e_machine,const char *name) { -struct syscall_cmp_key key = { - .name = name, - .tbl = syscall_num_to_name, - }; -const int *id =bsearch (&key, syscall_sorted_names, -ARRAY_SIZE (syscall_sorted_names), -sizeof (syscall_sorted_names[0 ]), - syscallcmpname); +const struct syscalltbl *table =find_table (e_machine); +struct syscall_cmp_key key; +const int *id; + +if (!table) +return -1 ; + + key.name = name; + key.tbl = table->num_to_name; + id =bsearch (&key, table->sorted_names, table->sorted_names_len, +sizeof (table->sorted_names[0 ]), syscallcmpname);return id ? *id :-1 ; } -int syscalltbl__num_idx (int e_machine__maybe_unused ) +int syscalltbl__num_idx (int e_machine) { -return ARRAY_SIZE (syscall_sorted_names); +const struct syscalltbl *table =find_table (e_machine); + +if (!table) +return 0 ; + +return table->sorted_names_len; } -int syscalltbl__id_at_idx (int e_machine__maybe_unused ,int idx) +int syscalltbl__id_at_idx (int e_machine,int idx) { -return syscall_sorted_names[idx]; +const struct syscalltbl *table =find_table (e_machine); + +if (!table) +return -1 ; + +assert (idx >=0 && idx < table->sorted_names_len); +return table->sorted_names[idx]; } -int syscalltbl__strglobmatch_next (int e_machine__maybe_unused ,const char *syscall_glob,int *idx) +int syscalltbl__strglobmatch_next (int e_machine,const char *syscall_glob,int *idx) { -for (int i = *idx +1 ; i < (int )ARRAY_SIZE (syscall_sorted_names); ++i) { -const char *name = syscall_num_to_name[syscall_sorted_names[i]]; +const struct syscalltbl *table =find_table (e_machine); + +for (int i = *idx +1 ; table && i < table->sorted_names_len; ++i) { +const char *name = table->num_to_name[table->sorted_names[i]];if (strglobmatch (name, syscall_glob)) { *idx = i; -return syscall_sorted_names[i]; +return table->sorted_names[i]; } }
Signature · 1 line
2.49.0.rc0.332.g42c0ae87b1-goog
Ian Rogers
reviewerPATCH v5 10/11 perf build: Remove Makefile.syscalls
In reply to Ian RogersNow a single beauty file is generated and used by all architectures, remove the per-architecture Makefiles, Kbuild files and previous generator script.
Note: there was conversation with Charlie Jenkins <[email protected]> and they'd written an alternate approach to support multiple architectures:
https://lore.kernel.org/all/20250114-perf_syscall_arch_runtime-v1-1-5b304e408e11@rivosinc.com/
It would have been better to have helped Charlie fix their series (my apologies) but they agreed that the approach taken here was likely best for longer term maintainability:
https://lore.kernel.org/lkml/Z6Jk_UN9i69QGqUj@ghost/
--- tools/perf/Makefile.perf | 1 - tools/perf/arch/alpha/entry/syscalls/Kbuild | 2 - .../alpha/entry/syscalls/Makefile.syscalls | 5 -- tools/perf/arch/arc/entry/syscalls/Kbuild | 2 - .../arch/arc/entry/syscalls/Makefile.syscalls | 3 - tools/perf/arch/arm/entry/syscalls/Kbuild | 4 - .../arch/arm/entry/syscalls/Makefile.syscalls | 2 - tools/perf/arch/arm64/entry/syscalls/Kbuild | 3 - .../arm64/entry/syscalls/Makefile.syscalls | 6 -- tools/perf/arch/csky/entry/syscalls/Kbuild | 2 - .../csky/entry/syscalls/Makefile.syscalls | 3 - .../perf/arch/loongarch/entry/syscalls/Kbuild | 2 - .../entry/syscalls/Makefile.syscalls | 3 - tools/perf/arch/mips/entry/syscalls/Kbuild | 2 - .../mips/entry/syscalls/Makefile.syscalls | 5 -- tools/perf/arch/parisc/entry/syscalls/Kbuild | 3 - .../parisc/entry/syscalls/Makefile.syscalls | 6 -- tools/perf/arch/powerpc/entry/syscalls/Kbuild | 3 - .../powerpc/entry/syscalls/Makefile.syscalls | 6 -- tools/perf/arch/riscv/entry/syscalls/Kbuild | 2 - .../riscv/entry/syscalls/Makefile.syscalls | 4 - tools/perf/arch/s390/entry/syscalls/Kbuild | 2 - .../s390/entry/syscalls/Makefile.syscalls | 5 -- tools/perf/arch/sh/entry/syscalls/Kbuild | 2 - .../arch/sh/entry/syscalls/Makefile.syscalls | 4 - tools/perf/arch/sparc/entry/syscalls/Kbuild | 3 - .../sparc/entry/syscalls/Makefile.syscalls | 5 -- tools/perf/arch/x86/entry/syscalls/Kbuild | 3 - .../arch/x86/entry/syscalls/Makefile.syscalls | 6 -- tools/perf/arch/xtensa/entry/syscalls/Kbuild | 2 - .../xtensa/entry/syscalls/Makefile.syscalls | 4 - tools/perf/scripts/Makefile.syscalls | 61 --------------- tools/perf/scripts/syscalltbl.sh | 76 ------------------- 33 files changed, 242 deletions(-) delete mode 100644 tools/perf/arch/alpha/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/alpha/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/arc/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/arc/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/arm/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/arm/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/arm64/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/arm64/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/csky/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/csky/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/loongarch/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/loongarch/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/mips/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/mips/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/parisc/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/parisc/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/powerpc/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/powerpc/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/riscv/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/riscv/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/s390/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/s390/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/sh/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/sh/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/sparc/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/sparc/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/x86/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/x86/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/xtensa/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/xtensa/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/scripts/Makefile.syscalls delete mode 100755 tools/perf/scripts/syscalltbl.sh
tools/perf/Makefile.perf +0 -1
@@ -339,7 +339,6 @@ ifeq ($(filter feature-dump,$(MAKECMDGOALS)),feature-dump) FEATURE_TESTS := all endif endif -include $(srctree)/tools/perf/scripts/Makefile.syscalls include Makefile.config endif
tools/perf/arch/alpha/entry/syscalls/Kbuild deleted +0 -2
@@ -1,2 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -syscall-y += syscalls_64.h
tools/perf/arch/alpha/entry/syscalls/Makefile.syscalls deleted +0 -5
@@ -1,5 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -syscall_abis_64 += - -syscalltbl = $(srctree)/tools/perf/arch/alpha/entry/syscalls/syscall.tbl
tools/perf/arch/arc/entry/syscalls/Kbuild deleted +0 -2
@@ -1,2 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -syscall-y += syscalls_32.h
tools/perf/arch/arc/entry/syscalls/Makefile.syscalls deleted +0 -3
@@ -1,3 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -syscall_abis_32 += arc time32 renameat stat64 rlimit
tools/perf/arch/arm/entry/syscalls/Kbuild deleted +0 -4
@@ -1,4 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -syscall_abis_32 += oabi -syscalltbl = $(srctree)/tools/perf/arch/arm/entry/syscalls/syscall.tbl
tools/perf/arch/arm/entry/syscalls/Makefile.syscalls deleted +0 -2
@@ -1,2 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -syscall-y += syscalls_32.h
tools/perf/arch/arm64/entry/syscalls/Kbuild deleted +0 -3
@@ -1,3 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -syscall-y += syscalls_32.h -syscall-y += syscalls_64.h
tools/perf/arch/arm64/entry/syscalls/Makefile.syscalls deleted +0 -6
@@ -1,6 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -syscall_abis_32 += -syscall_abis_64 += renameat rlimit memfd_secret - -syscalltbl = $(srctree)/tools/perf/arch/arm64/entry/syscalls/syscall_%.tbl
tools/perf/arch/csky/entry/syscalls/Kbuild deleted +0 -2
@@ -1,2 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -syscall-y += syscalls_32.h
tools/perf/arch/csky/entry/syscalls/Makefile.syscalls deleted +0 -3
@@ -1,3 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -syscall_abis_32 += csky time32 stat64 rlimit
tools/perf/arch/loongarch/entry/syscalls/Kbuild deleted +0 -2
@@ -1,2 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -syscall-y += syscalls_64.h
tools/perf/arch/loongarch/entry/syscalls/Makefile.syscalls deleted +0 -3
@@ -1,3 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -syscall_abis_64 +=
tools/perf/arch/mips/entry/syscalls/Kbuild deleted +0 -2
@@ -1,2 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -syscall-y += syscalls_64.h
tools/perf/arch/mips/entry/syscalls/Makefile.syscalls deleted +0 -5
@@ -1,5 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -syscall_abis_64 += n64 - -syscalltbl = $(srctree)/tools/perf/arch/mips/entry/syscalls/syscall_n64.tbl
tools/perf/arch/parisc/entry/syscalls/Kbuild deleted +0 -3
@@ -1,3 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -syscall-y += syscalls_32.h -syscall-y += syscalls_64.h
tools/perf/arch/parisc/entry/syscalls/Makefile.syscalls deleted +0 -6
@@ -1,6 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -syscall_abis_32 += -syscall_abis_64 += - -syscalltbl = $(srctree)/tools/perf/arch/parisc/entry/syscalls/syscall.tbl
tools/perf/arch/powerpc/entry/syscalls/Kbuild deleted +0 -3
@@ -1,3 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -syscall-y += syscalls_32.h -syscall-y += syscalls_64.h
tools/perf/arch/powerpc/entry/syscalls/Makefile.syscalls deleted +0 -6
@@ -1,6 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -syscall_abis_32 += nospu -syscall_abis_64 += nospu - -syscalltbl = $(srctree)/tools/perf/arch/powerpc/entry/syscalls/syscall.tbl
tools/perf/arch/riscv/entry/syscalls/Kbuild deleted +0 -2
@@ -1,2 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -syscall-y += syscalls_64.h
tools/perf/arch/riscv/entry/syscalls/Makefile.syscalls deleted +0 -4
@@ -1,4 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -syscall_abis_32 += riscv memfd_secret -syscall_abis_64 += riscv rlimit memfd_secret
tools/perf/arch/s390/entry/syscalls/Kbuild deleted +0 -2
@@ -1,2 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -syscall-y += syscalls_64.h
tools/perf/arch/s390/entry/syscalls/Makefile.syscalls deleted +0 -5
@@ -1,5 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -syscall_abis_64 += renameat rlimit memfd_secret - -syscalltbl = $(srctree)/tools/perf/arch/s390/entry/syscalls/syscall.tbl
tools/perf/arch/sh/entry/syscalls/Kbuild deleted +0 -2
@@ -1,2 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -syscall-y += syscalls_32.h
tools/perf/arch/sh/entry/syscalls/Makefile.syscalls deleted +0 -4
@@ -1,4 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -syscall_abis_32 += -syscalltbl = $(srctree)/tools/perf/arch/sh/entry/syscalls/syscall.tbl
tools/perf/arch/sparc/entry/syscalls/Kbuild deleted +0 -3
@@ -1,3 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -syscall-y += syscalls_32.h -syscall-y += syscalls_64.h
tools/perf/arch/sparc/entry/syscalls/Makefile.syscalls deleted +0 -5
@@ -1,5 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -syscall_abis_32 += -syscall_abis_64 += -syscalltbl = $(srctree)/tools/perf/arch/sparc/entry/syscalls/syscall.tbl
tools/perf/arch/x86/entry/syscalls/Kbuild deleted +0 -3
@@ -1,3 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -syscall-y += syscalls_32.h -syscall-y += syscalls_64.h
tools/perf/arch/x86/entry/syscalls/Makefile.syscalls deleted +0 -6
@@ -1,6 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -syscall_abis_32 += i386 -syscall_abis_64 += - -syscalltbl = $(srctree)/tools/perf/arch/x86/entry/syscalls/syscall_%.tbl
tools/perf/arch/xtensa/entry/syscalls/Kbuild deleted +0 -2
@@ -1,2 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -syscall-y += syscalls_32.h
tools/perf/arch/xtensa/entry/syscalls/Makefile.syscalls deleted +0 -4
@@ -1,4 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -syscall_abis_32 += -syscalltbl = $(srctree)/tools/perf/arch/xtensa/entry/syscalls/syscall.tbl
tools/perf/scripts/Makefile.syscalls deleted +0 -61
61 lines not on this page · raw message
tools/perf/scripts/syscalltbl.sh deleted +0 -76
76 lines not on this page · raw message
Signature · 1 line
2.49.0.rc0.332.g42c0ae87b1-goog
Ian Rogers
reviewerPATCH v5 11/11 perf syscalltbl: Mask off ABI type for MIPS system calls
In reply to Ian RogersArnd Bergmann described that MIPS system calls don't necessarily start from 0 as an ABI prefix is applied:
https://lore.kernel.org/lkml/[email protected]/
When decoding the "id" (aka system call number) for MIPS ignore values greater-than 1000.
--- tools/perf/util/syscalltbl.c | 8 ++++++++ 1 file changed, 8 insertions(+)
tools/perf/util/syscalltbl.c +8 -0
@@ -46,6 +46,14 @@ const char *syscalltbl__name(int e_machine, int id) {const struct syscalltbl *table =find_table (e_machine); +if (e_machine ==EM_MIPS && id >1000 ) { +/* +* MIPS may encode the N32/64/O32 type in the high part of +* syscall number. Mask this off if present. See the values of +* __NR_N32_Linux, __NR_64_Linux, __NR_O32_Linux and __NR_Linux. +*/ + id = id %1000 ; + }if (table && id >=0 && id < table->num_to_name_len)return table->num_to_name[id];return NULL ;
Signature · 1 line
2.49.0.rc0.332.g42c0ae87b1-goog
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v5 06/11] perf dso: Add support for reading the e_machine type for a dso
In reply to Ian RogersQuoted 7 lines · Ian Rogers
For ELF file dsos read the
e_machinefrom the ELF header. For kernel types assume thee_machinematches the perf tool. In other cases returnEM_NONE.When reading from the ELF header use
DSO__SWAPthat may needdso->needs_swapinitializing. Factor outdso__swap_initto allow this.
Quoted 6 lines
Signed-off-by Ian Rogers <[email protected]>--- tools/perf/util/dso.c | 88 ++++++++++++++++++++++++++++++++++++ tools/perf/util/dso.h | 3 ++ tools/perf/util/symbol-elf.c | 27 ----------- 3 files changed, 91 insertions(+), 27 deletions(-)
This one, due to this having already been merged:
commit b10f74308e1305275e69ddde711ec817cc69e306 (perf-tools-next/perf-tools-next)
Author: Stephen Brennan <[email protected]> Date: Fri Mar 7 15:22:03 2025 -0800
perf symbol: Support .gnu_debugdata for symbols
Needs this so that we read the e_machine from the ELF file:
tools/perf/util/dso.c +1 -0
@@ -1203,6 +1203,7 @@ uint16_t dso__e_machine(struct dso *dso, struct machine *machine)case DSO_BINARY_TYPE__UBUNTU_DEBUGINFO :case DSO_BINARY_TYPE__MIXEDUP_UBUNTU_DEBUGINFO :case DSO_BINARY_TYPE__BUILDID_DEBUGINFO : +case DSO_BINARY_TYPE__GNU_DEBUGDATA :break ;case DSO_BINARY_TYPE__NOT_FOUND :default :
---
Continuing the review and test.
- Arnaldo
Quoted 168 lines
tools/perf/util/dso.c +88
-0@@ -1170,6 +1170,67 @@ ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine,return data_read_write_offset (dso, machine, offset, data, size, true); } +uint16_t dso__e_machine (struct dso *dso,struct machine *machine) +{ +uint16_t e_machine =EM_NONE ; +int fd; + +switch (dso__binary_type (dso)) { +case DSO_BINARY_TYPE__KALLSYMS : +case DSO_BINARY_TYPE__GUEST_KALLSYMS : +case DSO_BINARY_TYPE__VMLINUX : +case DSO_BINARY_TYPE__GUEST_VMLINUX : +case DSO_BINARY_TYPE__GUEST_KMODULE : +case DSO_BINARY_TYPE__GUEST_KMODULE_COMP : +case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE : +case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP : +case DSO_BINARY_TYPE__KCORE : +case DSO_BINARY_TYPE__GUEST_KCORE : +case DSO_BINARY_TYPE__BPF_PROG_INFO : +case DSO_BINARY_TYPE__BPF_IMAGE : +case DSO_BINARY_TYPE__OOL : +case DSO_BINARY_TYPE__JAVA_JIT : +return EM_HOST ; +case DSO_BINARY_TYPE__DEBUGLINK : +case DSO_BINARY_TYPE__BUILD_ID_CACHE : +case DSO_BINARY_TYPE__BUILD_ID_CACHE_DEBUGINFO : +case DSO_BINARY_TYPE__SYSTEM_PATH_DSO : +case DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO : +case DSO_BINARY_TYPE__FEDORA_DEBUGINFO : +case DSO_BINARY_TYPE__UBUNTU_DEBUGINFO : +case DSO_BINARY_TYPE__MIXEDUP_UBUNTU_DEBUGINFO : +case DSO_BINARY_TYPE__BUILDID_DEBUGINFO : +break ; +case DSO_BINARY_TYPE__NOT_FOUND : +default : +return EM_NONE ; + } + +pthread_mutex_lock (&dso__data_open_lock); + +/* +* dso__data(dso)->fd might be closed if other thread opened another +* file (dso) due to open file limit (RLIMIT_NOFILE). +*/ +try_to_open_dso (dso, machine); + fd =dso__data (dso)->fd; +if (fd >=0 ) { +_Static_assert (offsetof(Elf32_Ehdr , e_machine) ==18 ,"Unexpected offset" ); +_Static_assert (offsetof(Elf64_Ehdr , e_machine) ==18 ,"Unexpected offset" ); +if (dso__needs_swap (dso) ==DSO_SWAP__UNSET ) { +unsigned char eidata; + +if (pread (fd, &eidata,sizeof (eidata),EI_DATA ) ==sizeof (eidata)) +dso__swap_init (dso, eidata); + } +if (dso__needs_swap (dso) !=DSO_SWAP__UNSET && +pread (fd, &e_machine,sizeof (e_machine),18 ) ==sizeof (e_machine)) + e_machine =DSO__SWAP (dso, uint16_t, e_machine); + } +pthread_mutex_unlock (&dso__data_open_lock); +return e_machine; +} +/** * dso__data_read_addr - Read data from dso address * @dso: dso object @@ -1525,6 +1586,33 @@ void dso__put(struct dso *dso)RC_CHK_PUT (dso); } +int dso__swap_init (struct dso *dso,unsigned char eidata) +{ +static unsigned int const endian =1 ; + +dso__set_needs_swap (dso,DSO_SWAP__NO ); + +switch (eidata) { +case ELFDATA2LSB : +/* We are big endian, DSO is little endian. */ +if (*(unsigned char const *)&endian !=1 ) +dso__set_needs_swap (dso,DSO_SWAP__YES ); +break ; + +case ELFDATA2MSB : +/* We are little endian, DSO is big endian. */ +if (*(unsigned char const *)&endian !=0 ) +dso__set_needs_swap (dso,DSO_SWAP__YES ); +break ; + +default : +pr_err ("unrecognized DSO data encoding %d\n" , eidata); +return -EINVAL ; + } + +return 0 ; +} +void dso__set_build_id (struct dso *dso,struct build_id *bid) {RC_CHK_ACCESS (dso)->bid = *bid;tools/perf/util/dso.h +3
-0@@ -730,6 +730,8 @@ bool dso__sorted_by_name(const struct dso *dso);void dso__set_sorted_by_name (struct dso *dso);void dso__sort_by_name (struct dso *dso); +int dso__swap_init (struct dso *dso,unsigned char eidata); +void dso__set_build_id (struct dso *dso,struct build_id *bid);bool dso__build_id_equal (const struct dso *dso,struct build_id *bid); void dso__read_running_kernel_build_id(struct dso *dso,@@ -818,6 +820,7 @@ int dso__data_file_size(struct dso *dso, struct machine *machine);off_t dso__data_size (struct dso *dso,struct machine *machine);ssize_t dso__data_read_offset (struct dso *dso,struct machine *machine,u64 offset,u8 *data,ssize_t size); +uint16_t dso__e_machine (struct dso *dso,struct machine *machine);ssize_t dso__data_read_addr (struct dso *dso,struct map *map,struct machine *machine,u64 addr,u8 *data,ssize_t size);tools/perf/util/symbol-elf.c +0
-27@@ -1173,33 +1173,6 @@ int filename__read_debuglink(const char *filename, char *debuglink,#endif -static int dso__swap_init (struct dso *dso,unsigned char eidata) -{ -static unsigned int const endian =1 ; - -dso__set_needs_swap (dso,DSO_SWAP__NO ); - -switch (eidata) { -case ELFDATA2LSB : -/* We are big endian, DSO is little endian. */ -if (*(unsigned char const *)&endian !=1 ) -dso__set_needs_swap (dso,DSO_SWAP__YES ); -break ; - -case ELFDATA2MSB : -/* We are little endian, DSO is big endian. */ -if (*(unsigned char const *)&endian !=0 ) -dso__set_needs_swap (dso,DSO_SWAP__YES ); -break ; - -default : -pr_err ("unrecognized DSO data encoding %d\n" , eidata); -return -EINVAL ; - } - -return 0 ; -} -bool symsrc__possibly_runtime (struct symsrc *ss) {return ss->dynsym || ss->opdsec;Signature · 1 line
2.49.0.rc0.332.g42c0ae87b1-goog
Namhyung Kim
maintainerQuoted 9 lines · Ian Rogers
This work builds on the clean up of system call tables and removal of libaudit by Charlie Jenkins <[email protected]>.
The system call table in perf trace is used to map system call numbers to names and vice versa. Prior to these changes, a single table matching the perf binary's build was present. The table would be incorrect if tracing say a 32-bit binary from a 64-bit version of perf, the names and numbers wouldn't match.
Quoted 6 lines
Change the build so that a single system call file is built and the potentially multiple tables are identifiable from the ELF machine type of the process being examined. To determine the ELF machine type, the executable's maps are searched and the associated DSOs ELF headers are read. When this fails and when live, /proc/pid/exe's ELF header is read. Fallback to using the perf's binary type when unknown.
Now it works well for me!
$ sudo ./perf trace a32.out
? ( ): a32.out/1267727 ... [continued]: execve()) = 0
? ( ): a32.out/1267727 ... [continued]: brk()) = 0x57f33000
0.062 ( 0.003 ms): a32.out/1267727 access(filename: 0xf7f170cc, mode: R) = -1 ENOENT (No such file or directory)
0.070 ( 0.011 ms): a32.out/1267727 openat(dfd: CWD, filename: 0xf7f1347f, flags: RDONLY|CLOEXEC|LARGEFILE) = 3
0.070 ( 0.023 ms): a32.out/1267727 ... [continued]: close()) = 0
0.103 ( 0.009 ms): a32.out/1267727 openat(dfd: CWD, filename: 0xf7ee43e0, flags: RDONLY|CLOEXEC|LARGEFILE) = 3
0.113 ( 0.002 ms): a32.out/1267727 read(fd: 3, buf: 0xff854990, count: 512) = 512
0.113 ( 0.049 ms): a32.out/1267727 ... [continued]: close()) = 0
0.113 ( 0.060 ms): a32.out/1267727 ... [continued]: set_tid_address()) = 1267727 (a32.out)
0.175 ( 0.001 ms): a32.out/1267727 set_robust_list(head: 0xf7ee556c, len: 12) =
0.222 ( 0.005 ms): a32.out/1267727 mprotect(start: 0xf7ebc000, len: 8192, prot: READ) = 0
0.230 ( 0.004 ms): a32.out/1267727 mprotect(start: 0x565b1000, len: 4096, prot: READ) = 0
0.237 ( 0.003 ms): a32.out/1267727 mprotect(start: 0xf7f1f000, len: 8192, prot: READ) = 0
0.258 ( 0.006 ms): a32.out/1267727 munmap(addr: 0xf7ec9000, len: 108298) = 0
0.258 ( 0.027 ms): a32.out/1267727 ... [continued]: brk()) = 0x57f33000
0.258 ( 0.031 ms): a32.out/1267727 ... [continued]: brk()) = 0x57f54000
0.258 ( 0.033 ms): a32.out/1267727 ... [continued]: brk()) = 0x57f55000
0.296 ( 0.008 ms): a32.out/1267727 openat(dfd: CWD, filename: 0x565b000a) = 3
0.316 ( 0.002 ms): a32.out/1267727 read(fd: 3, buf: 0xff8544a8, count: 4096) = 211
0.319 ( 0.001 ms): a32.out/1267727 read(fd: 3, buf: 0x57f332e0, count: 4096) = 0
0.319 ( 0.005 ms): a32.out/1267727 ... [continued]: close()) = 0
0.319 ( 0.010 ms): a32.out/1267727 ... [continued]: brk()) = 0x57f54000
0.337 ( ): a32.out/1267727 exit_group() = ?Thanks,
Namhyung
Quoted 149 lines
Remove some runtime types used by the system call tables and make equivalents generated at build time.
v5: Add byte swap to
dso__e_machineand fix comment as suggested by
Namhyung.v4: Add reading the
e_machinefrom the thread's maps dsos, only read
from/proc/pid/exeon failure and when live as requested by Namhyung. Add patches to add dso comments and remove unuseddso_datavariables that are unused without libunwind.v3: Add Charlie's reviewed-by tags. Incorporate feedback from Arnd
Bergmann <[email protected]> on additional optional column and MIPS system call numbering. Rebase past Namhyung's global system call statistics and add comments that they don't yet support ane_machineother thanEM_HOST.v2: Change the 1 element cache for the last table as suggested by
Howard Chu, add Howard's reviewed-by tags.
Add a comment and apology to Charlie for not doing better in guiding:
https://lore.kernel.org/all/20250114-perf_syscall_arch_runtime-v1-1-5b304e408e11@rivosinc.com/
After discussion on v1 and he agreed this patch series would be the better direction.Ian Rogers (11):
perf dso: Move libunwinddso_datavariables into ifdef perf dso: kernel-doc for enumdso_binary_type
perf syscalltbl: Removesyscall_table.h
perf trace: Reorganize syscalls
perf syscalltbl: Remove struct syscalltbl
perf dso: Add support for reading thee_machinetype for a dso perf thread: Add support for reading thee_machinetype for a thread perf trace beauty: Addsyscalltbl.shgenerating all system call tables perf syscalltbl: Use lookup table containing multiple architectures perf build: Remove Makefile.syscalls
perf syscalltbl: Mask off ABI type for MIPS system callstools/perf/Makefile.perf | 10 +- tools/perf/arch/alpha/entry/syscalls/Kbuild | 2 - .../alpha/entry/syscalls/Makefile.syscalls | 5 - tools/perf/arch/alpha/include/syscall_table.h | 2 - tools/perf/arch/arc/entry/syscalls/Kbuild | 2 - .../arch/arc/entry/syscalls/Makefile.syscalls | 3 - tools/perf/arch/arc/include/syscall_table.h | 2 - tools/perf/arch/arm/entry/syscalls/Kbuild | 4 - .../arch/arm/entry/syscalls/Makefile.syscalls | 2 - tools/perf/arch/arm/include/syscall_table.h | 2 - tools/perf/arch/arm64/entry/syscalls/Kbuild | 3 - .../arm64/entry/syscalls/Makefile.syscalls | 6 - tools/perf/arch/arm64/include/syscall_table.h | 8 - tools/perf/arch/csky/entry/syscalls/Kbuild | 2 - .../csky/entry/syscalls/Makefile.syscalls | 3 - tools/perf/arch/csky/include/syscall_table.h | 2 - .../perf/arch/loongarch/entry/syscalls/Kbuild | 2 - .../entry/syscalls/Makefile.syscalls | 3 - .../arch/loongarch/include/syscall_table.h | 2 - tools/perf/arch/mips/entry/syscalls/Kbuild | 2 - .../mips/entry/syscalls/Makefile.syscalls | 5 - tools/perf/arch/mips/include/syscall_table.h | 2 - tools/perf/arch/parisc/entry/syscalls/Kbuild | 3 - .../parisc/entry/syscalls/Makefile.syscalls | 6 - .../perf/arch/parisc/include/syscall_table.h | 8 - tools/perf/arch/powerpc/entry/syscalls/Kbuild | 3 - .../powerpc/entry/syscalls/Makefile.syscalls | 6 - .../perf/arch/powerpc/include/syscall_table.h | 8 - tools/perf/arch/riscv/entry/syscalls/Kbuild | 2 - .../riscv/entry/syscalls/Makefile.syscalls | 4 - tools/perf/arch/riscv/include/syscall_table.h | 8 - tools/perf/arch/s390/entry/syscalls/Kbuild | 2 - .../s390/entry/syscalls/Makefile.syscalls | 5 - tools/perf/arch/s390/include/syscall_table.h | 2 - tools/perf/arch/sh/entry/syscalls/Kbuild | 2 - .../arch/sh/entry/syscalls/Makefile.syscalls | 4 - tools/perf/arch/sh/include/syscall_table.h | 2 - tools/perf/arch/sparc/entry/syscalls/Kbuild | 3 - .../sparc/entry/syscalls/Makefile.syscalls | 5 - tools/perf/arch/sparc/include/syscall_table.h | 8 - tools/perf/arch/x86/entry/syscalls/Kbuild | 3 - .../arch/x86/entry/syscalls/Makefile.syscalls | 6 - tools/perf/arch/x86/include/syscall_table.h | 8 - tools/perf/arch/xtensa/entry/syscalls/Kbuild | 2 - .../xtensa/entry/syscalls/Makefile.syscalls | 4 - .../perf/arch/xtensa/include/syscall_table.h | 2 - tools/perf/builtin-trace.c | 290 +++++++++++------- tools/perf/scripts/Makefile.syscalls | 61 ---- tools/perf/scripts/syscalltbl.sh | 86 ------ tools/perf/trace/beauty/syscalltbl.sh | 274 +++++++++++++++++ tools/perf/util/dso.c | 88 ++++++ tools/perf/util/dso.h | 58 ++++ tools/perf/util/symbol-elf.c | 27 -- tools/perf/util/syscalltbl.c | 148 ++++----- tools/perf/util/syscalltbl.h | 22 +- tools/perf/util/thread.c | 80 +++++ tools/perf/util/thread.h | 14 +- 57 files changed, 792 insertions(+), 536 deletions(-) delete mode 100644 tools/perf/arch/alpha/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/alpha/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/alpha/include/syscall_table.h delete mode 100644 tools/perf/arch/arc/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/arc/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/arc/include/syscall_table.h delete mode 100644 tools/perf/arch/arm/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/arm/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/arm/include/syscall_table.h delete mode 100644 tools/perf/arch/arm64/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/arm64/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/arm64/include/syscall_table.h delete mode 100644 tools/perf/arch/csky/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/csky/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/csky/include/syscall_table.h delete mode 100644 tools/perf/arch/loongarch/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/loongarch/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/loongarch/include/syscall_table.h delete mode 100644 tools/perf/arch/mips/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/mips/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/mips/include/syscall_table.h delete mode 100644 tools/perf/arch/parisc/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/parisc/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/parisc/include/syscall_table.h delete mode 100644 tools/perf/arch/powerpc/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/powerpc/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/powerpc/include/syscall_table.h delete mode 100644 tools/perf/arch/riscv/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/riscv/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/riscv/include/syscall_table.h delete mode 100644 tools/perf/arch/s390/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/s390/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/s390/include/syscall_table.h delete mode 100644 tools/perf/arch/sh/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/sh/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/sh/include/syscall_table.h delete mode 100644 tools/perf/arch/sparc/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/sparc/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/sparc/include/syscall_table.h delete mode 100644 tools/perf/arch/x86/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/x86/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/x86/include/syscall_table.h delete mode 100644 tools/perf/arch/xtensa/entry/syscalls/Kbuild delete mode 100644 tools/perf/arch/xtensa/entry/syscalls/Makefile.syscalls delete mode 100644 tools/perf/arch/xtensa/include/syscall_table.h delete mode 100644 tools/perf/scripts/Makefile.syscalls delete mode 100755 tools/perf/scripts/syscalltbl.sh create mode 100755 tools/perf/trace/beauty/syscalltbl.shSignature · 1 line
2.49.0.rc0.332.g42c0ae87b1-goog
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v5 09/11] perf syscalltbl: Use lookup table containing multiple architectures
In reply to Ian RogersQuoted 7 lines · Ian Rogers
Switch to use the lookup table containing all architectures rather than tables matching the perf binary.
This fixes perf trace when executed on a 32-bit i386 binary on an x86-64 machine. Note in the following the system call names of the 32-bit i386 binary as seen by an x86-64 perf.
Reproduced the results here:
root@number:/home/acme/c# file faccessat2 faccessat2: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, BuildID[sha1]=8dafcc1549658d57248dce883e8ec7eea3d6e8a5, for GNU/Linux 3.2.0, not stripped root@number:/home/acme/c#
root@number:/home/acme/c# strace ./faccessat2 |& head
execve("./faccessat2", ["./faccessat2"], 0x7ffce63265e0 /* 39 vars */) = 0
[ Process PID=2552445 runs in 32 bit mode. ]
brk(NULL) = 0x849a000
mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xf7fb3000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 3
statx(3, "", AT_STATX_SYNC_AS_STAT|AT_NO_AUTOMOUNT|AT_EMPTY_PATH, STATX_BASIC_STATS, {stx_mask=STATX_ALL|STATX_MNT_ID|STATX_SUBVOL, stx_attributes=0, stx_mode=S_IFREG|0644, stx_size=85091, ...}) = 0
mmap2(NULL, 85091, PROT_READ, MAP_PRIVATE, 3, 0) = 0xf7f9e000
close(3) = 0
openat(AT_FDCWD, "/lib/libc.so.6", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 3
root@number:/home/acme/c#Before:
root@number:/home/acme/c# perf trace ./faccessat2 |& head
faccessat2(123, (null), X_OK, AT_EACCESS | AT_SYMLINK_NOFOLLOW) = -1
? ( ): faccessat2/2552543 ... [continued]: munmap()) = 0
0.024 ( 0.002 ms): faccessat2/2552543 recvfrom(ubuf: 0x2, size: 4159848428, flags: DONTROUTE|CTRUNC|TRUNC|DONTWAIT|EOR|WAITALL|FIN|SYN|CONFIRM|RST|ERRQUEUE|SOCK_DEVMEM|ZEROCOPY|FASTOPEN|CMSG_CLOEXEC|0x91f20000, addr: 0xe30, addr_len: 0xffcda98c) = 138993664
0.047 ( 0.006 ms): faccessat2/2552543 lgetxattr(name: "", value: 0x3, size: 34) = 4159602688
0.063 ( 0.003 ms): faccessat2/2552543 dup2(oldfd: -135160188, newfd: 4) = -1 ENOENT (No such file or directory)
0.071 ( 0.023 ms): faccessat2/2552543 preadv(fd: 4294967196, vec: 0xf7f16420, vlen: 557056, pos_h: 4159848428) = 3
0.098 ( 0.004 ms): faccessat2/2552543 lgetxattr(name: "", value: 0x1, size: 2) = 4159516672
0.104 ( 0.001 ms): faccessat2/2552543 lstat(filename: "", statbuf: 0x14c63) = 0
0.114 ( 0.004 ms): faccessat2/2552543 preadv(fd: 4294967196, vec: 0xf7ee8380, vlen: 557056, pos_h: 4159848428) = 3
0.118 ( 0.002 ms): faccessat2/2552543 close(fd: 3) = 512
root@number:/home/acme/c# After:
root@number:/home/acme/c# perf trace ./faccessat2 |& head
faccessat2(123, (null), X_OK, AT_EACCESS | AT_SYMLINK_NOFOLLOW) = -1
sh: line 1: perf-read-vdso32: command not found
? ( ): faccessat2/2556897 ... [continued]: execve()) = 0
0.028 ( 0.002 ms): faccessat2/2556897 brk() = 0x8fe4000
0.068 ( 0.003 ms): faccessat2/2556897 access(filename: 0xf7ff2e84, mode: R) = -1 ENOENT (No such file or directory)
0.080 ( 0.005 ms): faccessat2/2556897 openat(dfd: CWD, filename: "/etc/ld.so.cache", flags: RDONLY|CLOEXEC|LARGEFILE) = 3
0.094 ( 0.001 ms): faccessat2/2556897 close(fd: 3) = 0
0.103 ( 0.003 ms): faccessat2/2556897 openat(dfd: CWD, filename: "/lib/libc.so.6", flags: RDONLY|CLOEXEC|LARGEFILE) = 3
0.108 ( 0.002 ms): faccessat2/2556897 read(fd: 3, buf: 0xffdd84b0, count: 512) = 512
0.216 ( 0.001 ms): faccessat2/2556897 close(fd: 3) = 0
root@number:/home/acme/c#And interestingly the openat syscall got its contents obtained via the BPF augmenter... better to test this more thoroughly, but I think it should come after this series lands.
- Arnaldo
Arnaldo Carvalho de Melo
maintainerQuoted 10 lines · Namhyung Kim
Quoted 9 lines · Ian Rogers
This work builds on the clean up of system call tables and removal of libaudit by Charlie Jenkins <[email protected]>.
The system call table in perf trace is used to map system call numbers to names and vice versa. Prior to these changes, a single table matching the perf binary's build was present. The table would be incorrect if tracing say a 32-bit binary from a 64-bit version of perf, the names and numbers wouldn't match.
Quoted 8 lines
Quoted 6 lines
Change the build so that a single system call file is built and the potentially multiple tables are identifiable from the ELF machine type of the process being examined. To determine the ELF machine type, the executable's maps are searched and the associated DSOs ELF headers are read. When this fails and when live, /proc/pid/exe's ELF header is read. Fallback to using the perf's binary type when unknown.
Now it works well for me!
Its working for me on x86_64 as well, I'm doing some more tests, the container builds and will do 32-bit tracing on 64-bit ARM (rpi5 aarch64) and then report results here, should be later today as the default kernel for the rpi5 doesn't come with CONFIG_FTRACE_SYSCALLS=y and BTF, so building one with it.
- Arnaldo
Namhyung Kim
maintainerRe: [PATCH v5 09/11] perf syscalltbl: Use lookup table containing multiple architectures
In reply to Arnaldo Carvalho de MeloQuoted 58 lines · Arnaldo Carvalho de Melo
Quoted 7 lines · Ian Rogers
Switch to use the lookup table containing all architectures rather than tables matching the perf binary.
This fixes perf trace when executed on a 32-bit i386 binary on an x86-64 machine. Note in the following the system call names of the 32-bit i386 binary as seen by an x86-64 perf.
Reproduced the results here:
root@number:/home/acme/c# file faccessat2 faccessat2: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, BuildID[sha1]=8dafcc1549658d57248dce883e8ec7eea3d6e8a5, for GNU/Linux 3.2.0, not stripped root@number:/home/acme/c#root@number:/home/acme/c# strace ./faccessat2 |& head execve("./faccessat2", ["./faccessat2"], 0x7ffce63265e0 /* 39 vars */) = 0 [ Process PID=2552445 runs in 32 bit mode. ] brk(NULL) = 0x849a000 mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xf7fb3000 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 3 statx(3, "", AT_STATX_SYNC_AS_STAT|AT_NO_AUTOMOUNT|AT_EMPTY_PATH, STATX_BASIC_STATS, {stx_mask=STATX_ALL|STATX_MNT_ID|STATX_SUBVOL, stx_attributes=0, stx_mode=S_IFREG|0644, stx_size=85091, ...}) = 0 mmap2(NULL, 85091, PROT_READ, MAP_PRIVATE, 3, 0) = 0xf7f9e000 close(3) = 0 openat(AT_FDCWD, "/lib/libc.so.6", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 3 root@number:/home/acme/c#Before:
root@number:/home/acme/c# perf trace ./faccessat2 |& head faccessat2(123, (null), X_OK, AT_EACCESS | AT_SYMLINK_NOFOLLOW) = -1 ? ( ): faccessat2/2552543 ... [continued]: munmap()) = 0 0.024 ( 0.002 ms): faccessat2/2552543 recvfrom(ubuf: 0x2, size: 4159848428, flags: DONTROUTE|CTRUNC|TRUNC|DONTWAIT|EOR|WAITALL|FIN|SYN|CONFIRM|RST|ERRQUEUE|SOCK_DEVMEM|ZEROCOPY|FASTOPEN|CMSG_CLOEXEC|0x91f20000, addr: 0xe30, addr_len: 0xffcda98c) = 138993664 0.047 ( 0.006 ms): faccessat2/2552543 lgetxattr(name: "", value: 0x3, size: 34) = 4159602688 0.063 ( 0.003 ms): faccessat2/2552543 dup2(oldfd: -135160188, newfd: 4) = -1 ENOENT (No such file or directory) 0.071 ( 0.023 ms): faccessat2/2552543 preadv(fd: 4294967196, vec: 0xf7f16420, vlen: 557056, pos_h: 4159848428) = 3 0.098 ( 0.004 ms): faccessat2/2552543 lgetxattr(name: "", value: 0x1, size: 2) = 4159516672 0.104 ( 0.001 ms): faccessat2/2552543 lstat(filename: "", statbuf: 0x14c63) = 0 0.114 ( 0.004 ms): faccessat2/2552543 preadv(fd: 4294967196, vec: 0xf7ee8380, vlen: 557056, pos_h: 4159848428) = 3 0.118 ( 0.002 ms): faccessat2/2552543 close(fd: 3) = 512 root@number:/home/acme/c#After:
root@number:/home/acme/c# perf trace ./faccessat2 |& head faccessat2(123, (null), X_OK, AT_EACCESS | AT_SYMLINK_NOFOLLOW) = -1 sh: line 1: perf-read-vdso32: command not found ? ( ): faccessat2/2556897 ... [continued]: execve()) = 0 0.028 ( 0.002 ms): faccessat2/2556897 brk() = 0x8fe4000 0.068 ( 0.003 ms): faccessat2/2556897 access(filename: 0xf7ff2e84, mode: R) = -1 ENOENT (No such file or directory) 0.080 ( 0.005 ms): faccessat2/2556897 openat(dfd: CWD, filename: "/etc/ld.so.cache", flags: RDONLY|CLOEXEC|LARGEFILE) = 3 0.094 ( 0.001 ms): faccessat2/2556897 close(fd: 3) = 0 0.103 ( 0.003 ms): faccessat2/2556897 openat(dfd: CWD, filename: "/lib/libc.so.6", flags: RDONLY|CLOEXEC|LARGEFILE) = 3 0.108 ( 0.002 ms): faccessat2/2556897 read(fd: 3, buf: 0xffdd84b0, count: 512) = 512 0.216 ( 0.001 ms): faccessat2/2556897 close(fd: 3) = 0 root@number:/home/acme/c#
Quoted 3 lines
And interestingly the openat syscall got its contents obtained via the BPF augmenter... better to test this more thoroughly, but I think it should come after this series lands.
Right, I don't see the filename in openat() in my tests.
openat() is 295 on i386 and that's preadv() on x86_64 so BPF won't try to augment the argument. I wonder how it can get the filename. But anyway we can take a look later.
Thanks,
Namhyung
Arnaldo Carvalho de Melo
maintainerQuoted 18 lines · Arnaldo Carvalho de Melo
Quoted 17 lines · Namhyung Kim
Quoted 15 lines · Ian Rogers
This work builds on the clean up of system call tables and removal of libaudit by Charlie Jenkins <[email protected]>.
The system call table in perf trace is used to map system call numbers to names and vice versa. Prior to these changes, a single table matching the perf binary's build was present. The table would be incorrect if tracing say a 32-bit binary from a 64-bit version of perf, the names and numbers wouldn't match.
Change the build so that a single system call file is built and the potentially multiple tables are identifiable from the ELF machine type of the process being examined. To determine the ELF machine type, the executable's maps are searched and the associated DSOs ELF headers are read. When this fails and when live, /proc/pid/exe's ELF header is read. Fallback to using the perf's binary type when unknown.
Quoted 7 lines
Quoted 1 line
Now it works well for me!
Its working for me on
x86_64as well, I'm doing some more tests, the container builds and will do 32-bit tracing on 64-bit ARM (rpi5 aarch64) and then report results here, should be later today as the default kernel for the rpi5 doesn't come withCONFIG_FTRACE_SYSCALLS=yand BTF, so building one with it.
Still building, but noticed this on x86_64:
105: perf trace enum augmentation tests : FAILED! 106: perf trace BTF general tests : FAILED! 107: perf trace exit race : Ok 108: perf trace record and replay : FAILED!
The first doesn´t help that much with verbose mode, haven't checked if before this series it was failing :-\
root@x1:~# perf test -vvv 105 105: perf trace enum augmentation tests: --- start --- test child forked, pid 19411 Checking if vmlinux exists Tracing syscall landlock_add_rule ---- end(-1) ---- 105: perf trace enum augmentation tests : FAILED! root@x1:~#
Ditto for 106:
root@x1:~# perf test -vv 106 106: perf trace BTF general tests: --- start --- test child forked, pid 19467 Checking if vmlinux BTF exists Testing perf trace's string augmentation Testing perf trace's buffer augmentation Buffer augmentation test failed ---- end(-1) ---- 106: perf trace BTF general tests : FAILED! root@x1:~#
108 works when its the only test:
root@x1:~# perf test 108 108: perf trace record and replay : Ok root@x1:~# perf test 108 108: perf trace record and replay : Ok root@x1:~# perf test 108 108: perf trace record and replay : Ok root@x1:~#
I'll try to check what is happening with the first two later today.
- Arnaldo
Arnaldo Carvalho de Melo
maintainerQuoted 11 lines · Arnaldo Carvalho de Melo
Still building, but noticed this on
x86_64:105: perf trace enum augmentation tests : FAILED! 106: perf trace BTF general tests : FAILED! 107: perf trace exit race : Ok 108: perf trace record and replay : FAILED!The first doesn´t help that much with verbose mode, haven't checked if before this series it was failing :-\
Quoted 9 lines
root@x1:~# perf test -vvv 105 105: perf trace enum augmentation tests: --- start --- test child forked, pid 19411 Checking if vmlinux exists Tracing syscall landlock_add_rule ---- end(-1) ---- 105: perf trace enum augmentation tests : FAILED! root@x1:~#
So:
root@x1:~# perf trace -e landlock_add_rule perf test -w landlock root@x1:~#
But:
root@x1:~# perf trace perf test -w landlock |& grep landlock_add_rule
26.120 ( 0.002 ms): perf/19791 landlock_add_rule(ruleset_fd: 11, rule_type: LANDLOCK_RULE_PATH_BENEATH, rule_attr: 0x7ffde75e2680, flags: 45) = -1 EINVAL (Invalid argument)
26.124 ( 0.001 ms): perf/19791 landlock_add_rule(ruleset_fd: 11, rule_type: LANDLOCK_RULE_NET_PORT, rule_attr: 0x7ffde75e2690, flags: 45) = -1 EINVAL (Invalid argument)
root@x1:~# -e is having some trouble, when no event is specified, then it works.
Something in the changes made to:
static int trace__parse_events_option(const struct option *opt, const char *str,
int unset __maybe_unused)
- Arnaldo
More data:
root@x1:~# perf trace -vvv -e landlock_add_rule perf test -w landlock
Using CPUID GenuineIntel-6-BA-3
Opening: cpu/cycles/
------------------------------------------------------------
perf_event_attr:
type 0 (PERF_TYPE_HARDWARE)
config 0xa00000000 (cpu_atom/PERF_COUNT_HW_CPU_CYCLES/)
disabled 1
------------------------------------------------------------
sys_perf_event_open: pid 0 cpu -1 group_fd -1 flags 0x8 = 27
Opening: cpu/cycles/
------------------------------------------------------------
perf_event_attr:
type 0 (PERF_TYPE_HARDWARE)
config 0x400000000 (cpu_core/PERF_COUNT_HW_CPU_CYCLES/)
disabled 1
------------------------------------------------------------
sys_perf_event_open: pid 0 cpu -1 group_fd -1 flags 0x8 = 28
Opening: raw_syscalls:sys_enter
------------------------------------------------------------
perf_event_attr:
type 2 (PERF_TYPE_TRACEPOINT)
size 136
config 0x197 (raw_syscalls:sys_enter)
{ sample_period, sample_freq } 1
sample_type IP|TID|TIME|ID|CPU|PERIOD|RAW
read_format ID|LOST
disabled 1
inherit 1
mmap 1
comm 1
enable_on_exec 1
task 1
sample_id_all 1
mmap2 1
comm_exec 1
ksymbol 1
bpf_event 1
{ wakeup_events, wakeup_watermark } 1
------------------------------------------------------------
sys_perf_event_open: pid 19786 cpu 0 group_fd -1 flags 0x8 = 29
sys_perf_event_open: pid 19786 cpu 1 group_fd -1 flags 0x8 = 30
sys_perf_event_open: pid 19786 cpu 2 group_fd -1 flags 0x8 = 31
sys_perf_event_open: pid 19786 cpu 3 group_fd -1 flags 0x8 = 33
sys_perf_event_open: pid 19786 cpu 4 group_fd -1 flags 0x8 = 34
sys_perf_event_open: pid 19786 cpu 5 group_fd -1 flags 0x8 = 35
sys_perf_event_open: pid 19786 cpu 6 group_fd -1 flags 0x8 = 36
sys_perf_event_open: pid 19786 cpu 7 group_fd -1 flags 0x8 = 37
sys_perf_event_open: pid 19786 cpu 8 group_fd -1 flags 0x8 = 38
sys_perf_event_open: pid 19786 cpu 9 group_fd -1 flags 0x8 = 39
sys_perf_event_open: pid 19786 cpu 10 group_fd -1 flags 0x8 = 40
sys_perf_event_open: pid 19786 cpu 11 group_fd -1 flags 0x8 = 41
Opening: raw_syscalls:sys_exit
------------------------------------------------------------
perf_event_attr:
type 2 (PERF_TYPE_TRACEPOINT)
size 136
config 0x196 (raw_syscalls:sys_exit)
{ sample_period, sample_freq } 1
sample_type IP|TID|TIME|ID|CPU|PERIOD|RAW
read_format ID|LOST
disabled 1
inherit 1
enable_on_exec 1
sample_id_all 1
{ wakeup_events, wakeup_watermark } 1
------------------------------------------------------------
sys_perf_event_open: pid 19786 cpu 0 group_fd -1 flags 0x8 = 42
sys_perf_event_open: pid 19786 cpu 1 group_fd -1 flags 0x8 = 43
sys_perf_event_open: pid 19786 cpu 2 group_fd -1 flags 0x8 = 44
sys_perf_event_open: pid 19786 cpu 3 group_fd -1 flags 0x8 = 45
sys_perf_event_open: pid 19786 cpu 4 group_fd -1 flags 0x8 = 46
sys_perf_event_open: pid 19786 cpu 5 group_fd -1 flags 0x8 = 47
sys_perf_event_open: pid 19786 cpu 6 group_fd -1 flags 0x8 = 48
sys_perf_event_open: pid 19786 cpu 7 group_fd -1 flags 0x8 = 49
sys_perf_event_open: pid 19786 cpu 8 group_fd -1 flags 0x8 = 50
sys_perf_event_open: pid 19786 cpu 9 group_fd -1 flags 0x8 = 51
sys_perf_event_open: pid 19786 cpu 10 group_fd -1 flags 0x8 = 52
sys_perf_event_open: pid 19786 cpu 11 group_fd -1 flags 0x8 = 53
Opening: __augmented_syscalls__
------------------------------------------------------------
perf_event_attr:
type 1 (PERF_TYPE_SOFTWARE)
size 136
config 0xa (PERF_COUNT_SW_BPF_OUTPUT)
{ sample_period, sample_freq } 1
sample_type IP|TID|TIME|ID|CPU|PERIOD|RAW
read_format ID|LOST
disabled 1
enable_on_exec 1
sample_id_all 1
{ wakeup_events, wakeup_watermark } 1
------------------------------------------------------------
sys_perf_event_open: pid 19786 cpu 0 group_fd -1 flags 0x8 = 54
sys_perf_event_open: pid 19786 cpu 1 group_fd -1 flags 0x8 = 55
sys_perf_event_open: pid 19786 cpu 2 group_fd -1 flags 0x8 = 56
sys_perf_event_open: pid 19786 cpu 3 group_fd -1 flags 0x8 = 57
sys_perf_event_open: pid 19786 cpu 4 group_fd -1 flags 0x8 = 58
sys_perf_event_open: pid 19786 cpu 5 group_fd -1 flags 0x8 = 59
sys_perf_event_open: pid 19786 cpu 6 group_fd -1 flags 0x8 = 60
sys_perf_event_open: pid 19786 cpu 7 group_fd -1 flags 0x8 = 61
sys_perf_event_open: pid 19786 cpu 8 group_fd -1 flags 0x8 = 62
sys_perf_event_open: pid 19786 cpu 9 group_fd -1 flags 0x8 = 63
sys_perf_event_open: pid 19786 cpu 10 group_fd -1 flags 0x8 = 64
sys_perf_event_open: pid 19786 cpu 11 group_fd -1 flags 0x8 = 65
Problems reading syscall 156: 2 (No such file or directory)(_sysctl) information
Problems reading syscall 183: 2 (No such file or directory)(afs_syscall) information
Problems reading syscall 174: 2 (No such file or directory)(create_module) information
Problems reading syscall 214: 2 (No such file or directory)(epoll_ctl_old) information
Problems reading syscall 215: 2 (No such file or directory)(epoll_wait_old) information
Problems reading syscall 177: 2 (No such file or directory)(get_kernel_syms) information
Problems reading syscall 211: 2 (No such file or directory)(get_thread_area) information
Problems reading syscall 181: 2 (No such file or directory)(getpmsg) information
vmlinux BTF loaded
Problems reading syscall 212: 2 (No such file or directory)(lookup_dcookie) information
Problems reading syscall 180: 2 (No such file or directory)(nfsservctl) information
Problems reading syscall 182: 2 (No such file or directory)(putpmsg) information
Problems reading syscall 178: 2 (No such file or directory)(query_module) information
Problems reading syscall 185: 2 (No such file or directory)(security) information
Problems reading syscall 205: 2 (No such file or directory)(set_thread_area) information
Problems reading syscall 184: 2 (No such file or directory)(tuxcall) information
Problems reading syscall 134: 2 (No such file or directory)(uselib) information
Problems reading syscall 236: 2 (No such file or directory)(vserver) information
event qualifier tracepoint filter: id == 29098429
mmap size 528384B
libperf: mmap_per_cpu: nr cpu values 12 nr threads 1
libperf: idx 0: mmapping fd 29
<SNIP>
root@x1:~#root@x1:~# cat /sys/kernel/tracing/events/syscalls/sys_enter_landlock_add_rule/id
1449
root@x1:~# perf trace -e landlock_add_rule perf test -w landlock
root@x1:~# strace -e landlock_add_rule perf test -w landlock
landlock_add_rule(11, LANDLOCK_RULE_PATH_BENEATH, {allowed_access=LANDLOCK_ACCESS_FS_READ_FILE, parent_fd=14}, 0x2d) = -1 EINVAL (Invalid argument)
landlock_add_rule(11, LANDLOCK_RULE_NET_PORT, {allowed_access=LANDLOCK_ACCESS_NET_CONNECT_TCP, port=19}, 0x2d) = -1 EINVAL (Invalid argument)
+++ exited with 0 +++
root@x1:~# root@x1:~# vim /tmp/build/perf-tools-next/trace/beauty/generated/syscalltbl.c
<SNIP>
static const char *const syscall_num_to_name_EM_X86_64[] = {
[0] = "read",
[1] = "write",
[2] = "open",
<SNIP>
[442] = "mount_setattr",
[443] = "quotactl_fd",
[444] = "landlock_create_ruleset",
[445] = "landlock_add_rule",
[446] = "landlock_restrict_self",
[447] = "memfd_secret",
[448] = "process_mrelease",
[449] = "futex_waitv",
[450] = "set_mempolicy_home_node",
<SNIP>
};
static const uint16_t syscall_sorted_names_EM_X86_64[] = {
156, /* _sysctl */
43, /* accept */
288, /* accept4 */
<SNIP>
246, /* kexec_load */
250, /* keyctl */
62, /* kill */
445, /* landlock_add_rule */
444, /* landlock_create_ruleset */
446, /* landlock_restrict_self */
94, /* lchown */
192, /* lgetxattr */
<SNIP>
};<SNIP>
#if defined(ALL_SYSCALLTBL) || defined(__i386__) || defined(__x86_64__)
{
.num_to_name = syscall_num_to_name_EM_386,
.sorted_names = syscall_sorted_names_EM_386,
.e_machine = EM_386,
.num_to_name_len = ARRAY_SIZE(syscall_num_to_name_EM_386),
.sorted_names_len = ARRAY_SIZE(syscall_sorted_names_EM_386),
},
{
.num_to_name = syscall_num_to_name_EM_X86_64,
.sorted_names = syscall_sorted_names_EM_X86_64,
.e_machine = EM_X86_64,
.num_to_name_len = ARRAY_SIZE(syscall_num_to_name_EM_X86_64),
.sorted_names_len = ARRAY_SIZE(syscall_sorted_names_EM_X86_64),
},#endif // defined(ALL_SYSCALLTBL) || defined(__i386__) || defined(__x86_64__)
<SNIP>
Namhyung Kim
maintainerQuoted 34 lines · Arnaldo Carvalho de Melo
Quoted 11 lines · Arnaldo Carvalho de Melo
Still building, but noticed this on
x86_64:105: perf trace enum augmentation tests : FAILED! 106: perf trace BTF general tests : FAILED! 107: perf trace exit race : Ok 108: perf trace record and replay : FAILED!The first doesn´t help that much with verbose mode, haven't checked if before this series it was failing :-\
Quoted 9 lines
root@x1:~# perf test -vvv 105 105: perf trace enum augmentation tests: --- start --- test child forked, pid 19411 Checking if vmlinux exists Tracing syscall landlock_add_rule ---- end(-1) ---- 105: perf trace enum augmentation tests : FAILED! root@x1:~#So:
root@x1:~# perf trace -e landlock_add_rule perf test -w landlock root@x1:~#But:
root@x1:~# perf trace perf test -w landlock |& grep landlock_add_rule 26.120 ( 0.002 ms): perf/19791 landlock_add_rule(ruleset_fd: 11, rule_type: LANDLOCK_RULE_PATH_BENEATH, rule_attr: 0x7ffde75e2680, flags: 45) = -1 EINVAL (Invalid argument) 26.124 ( 0.001 ms): perf/19791 landlock_add_rule(ruleset_fd: 11, rule_type: LANDLOCK_RULE_NET_PORT, rule_attr: 0x7ffde75e2690, flags: 45) = -1 EINVAL (Invalid argument) root@x1:~#
Quoted 6 lines
-e is having some trouble, when no event is specified, then it works.
Something in the changes made to:
static int trace__parse_events_option(const struct option *opt, const char *str,
int unset__maybe_unused)
Thanks for the test, I think this should fix it:
Thanks,
Namhyung
---8<---
tools/perf/util/syscalltbl.c +1 -1
@@ -76,7 +76,7 @@ int syscalltbl__id(int e_machine, const char *name) {const struct syscalltbl *table =find_table (e_machine);struct syscall_cmp_key key; -const int *id; +const uint16_t *id;if (!table)return -1 ;
Arnaldo Carvalho de Melo
maintainerQuoted 35 lines · Namhyung Kim
Quoted 34 lines · Arnaldo Carvalho de Melo
Quoted 11 lines · Arnaldo Carvalho de Melo
Still building, but noticed this on
x86_64:105: perf trace enum augmentation tests : FAILED! 106: perf trace BTF general tests : FAILED! 107: perf trace exit race : Ok 108: perf trace record and replay : FAILED!The first doesn´t help that much with verbose mode, haven't checked if before this series it was failing :-\
Quoted 9 lines
root@x1:~# perf test -vvv 105 105: perf trace enum augmentation tests: --- start --- test child forked, pid 19411 Checking if vmlinux exists Tracing syscall landlock_add_rule ---- end(-1) ---- 105: perf trace enum augmentation tests : FAILED! root@x1:~#So:
root@x1:~# perf trace -e landlock_add_rule perf test -w landlock root@x1:~#But:
root@x1:~# perf trace perf test -w landlock |& grep landlock_add_rule 26.120 ( 0.002 ms): perf/19791 landlock_add_rule(ruleset_fd: 11, rule_type: LANDLOCK_RULE_PATH_BENEATH, rule_attr: 0x7ffde75e2680, flags: 45) = -1 EINVAL (Invalid argument) 26.124 ( 0.001 ms): perf/19791 landlock_add_rule(ruleset_fd: 11, rule_type: LANDLOCK_RULE_NET_PORT, rule_attr: 0x7ffde75e2690, flags: 45) = -1 EINVAL (Invalid argument) root@x1:~#
Quoted 9 lines
Quoted 6 lines
-e is having some trouble, when no event is specified, then it works.
Something in the changes made to:
static int trace__parse_events_option(const struct option *opt, const char *str,
int unset__maybe_unused)Thanks for the test, I think this should fix it:
Well, not really:
root@number:~# perf trace -e landlock_add_rule perf test -w landlock perf: Segmentation fault Obtained 10 stack frames. perf() [0x5be761] perf() [0x5be7f9] /lib64/libc.so.6(+0x40fd0) [0x7fe005c4efd0] perf() [0x491bc1] perf() [0x497090] perf() [0x4973ab] perf() [0x413483] /lib64/libc.so.6(+0x2a088) [0x7fe005c38088] /lib64/libc.so.6(__libc_start_main+0x8b) [0x7fe005c3814b] perf() [0x413ad5] Segmentation fault (core dumped) root@number:~#
Time for me to test another patch from Ian, the one symbolizing the above backtrace...
- Arnaldo
Quoted 16 lines
---8<---
tools/perf/util/syscalltbl.c +1
-1@@ -76,7 +76,7 @@ int syscalltbl__id(int e_machine, const char *name) {const struct syscalltbl *table =find_table (e_machine);struct syscall_cmp_key key; -const int *id; +const uint16_t *id;if (!table)return -1 ;
Arnaldo Carvalho de Melo
maintainerQuoted 97 lines · Arnaldo Carvalho de Melo
Quoted 35 lines · Namhyung Kim
Quoted 34 lines · Arnaldo Carvalho de Melo
Quoted 11 lines · Arnaldo Carvalho de Melo
Still building, but noticed this on
x86_64:105: perf trace enum augmentation tests : FAILED! 106: perf trace BTF general tests : FAILED! 107: perf trace exit race : Ok 108: perf trace record and replay : FAILED!The first doesn´t help that much with verbose mode, haven't checked if before this series it was failing :-\
Quoted 9 lines
root@x1:~# perf test -vvv 105 105: perf trace enum augmentation tests: --- start --- test child forked, pid 19411 Checking if vmlinux exists Tracing syscall landlock_add_rule ---- end(-1) ---- 105: perf trace enum augmentation tests : FAILED! root@x1:~#So:
root@x1:~# perf trace -e landlock_add_rule perf test -w landlock root@x1:~#But:
root@x1:~# perf trace perf test -w landlock |& grep landlock_add_rule 26.120 ( 0.002 ms): perf/19791 landlock_add_rule(ruleset_fd: 11, rule_type: LANDLOCK_RULE_PATH_BENEATH, rule_attr: 0x7ffde75e2680, flags: 45) = -1 EINVAL (Invalid argument) 26.124 ( 0.001 ms): perf/19791 landlock_add_rule(ruleset_fd: 11, rule_type: LANDLOCK_RULE_NET_PORT, rule_attr: 0x7ffde75e2690, flags: 45) = -1 EINVAL (Invalid argument) root@x1:~#Quoted 9 lines
Quoted 6 lines
-e is having some trouble, when no event is specified, then it works.
Something in the changes made to:
static int trace__parse_events_option(const struct option *opt, const char *str,
int unset__maybe_unused)Thanks for the test, I think this should fix it:
Well, not really:
root@number:~# perf trace -e landlock_add_rule perf test -w landlock perf: Segmentation fault Obtained 10 stack frames. perf() [0x5be761] perf() [0x5be7f9] /lib64/libc.so.6(+0x40fd0) [0x7fe005c4efd0] perf() [0x491bc1] perf() [0x497090] perf() [0x4973ab] perf() [0x413483] /lib64/libc.so.6(+0x2a088) [0x7fe005c38088] /lib64/libc.so.6(__libc_start_main+0x8b) [0x7fe005c3814b] perf() [0x413ad5] Segmentation fault (core dumped) root@number:~#Time for me to test another patch from Ian, the one symbolizing the above backtrace...
Worked, but didn't help as much, with gdb:
(gdb) run trace -e
landlock_add_ruleperf test -w landlock
Starting program:/root/bin/perftrace -elandlock_add_ruleperf test -w landlockThis GDB supports auto-downloading debuginfo from the following URLs:
<https://debuginfod.fedoraproject.org/>
Enable debuginfod for this session? (y or [n]) y
Debuginfod has been enabled.
To make this setting permanent, add 'set debuginfod enabled on' to .gdbinit. Downloading 53.88 K separate debug info for system-supplied DSO at0x7ffff7fc6000Downloading 458.26 K separate debug info for/lib64/libtracefs.so.1[Thread debugging usinglibthread_dbenabled]
Using hostlibthread_dblibrary "/lib64/libthread_db.so.1". [Detaching after fork from child process 39141]Program received signal SIGSEGV, Segmentation fault.
0x00000000004d0e56intrace__find_usable_bpf_prog_entry(trace=0x7fffffffa510, sc=0x10fb7b0) at builtin-trace.c:3882
3882 boolis_pointer=field->flags&TEP_FIELD_IS_POINTER,
(gdb) p field
$1 = (structtep_format_field*)0x64656e6769736e75
(gdb) bt#0 0x00000000004d0e56 in trace__find_usable_bpf_prog_entry (trace=0x7fffffffa510, sc=0x10fb7b0) at builtin-trace.c:3882 #1 0x00000000004cf3de in trace__init_syscalls_bpf_prog_array_maps (trace=0x7fffffffa510, e_machine=62) at builtin-trace.c:4040 #2 0x00000000004bf626 in trace__run (trace=0x7fffffffa510, argc=4, argv=0x7fffffffde40) at builtin-trace.c:4473 #3 0x00000000004bb7a9 in cmd_trace (argc=4, argv=0x7fffffffde40) at builtin-trace.c:5741 #4 0x00000000004d873f in run_builtin (p=0xf83d48 <commands+648>, argc=7, argv=0x7fffffffde40) at perf.c:351 #5 0x00000000004d7df3 in handle_internal_command (argc=7, argv=0x7fffffffde40) at perf.c:404 #6 0x00000000004d860f in run_argv (argcp=0x7fffffffdc7c, argv=0x7fffffffdc70) at perf.c:448 #7 0x00000000004d7a4f in main (argc=7, argv=0x7fffffffde40) at perf.c:556
Quoted 12 lines
(gdb) list -10
3867 return NULL;
3868
3869try_to_find_pair:
3870 for (int i = 0,num_idx=syscalltbl__num_idx(sc->e_machine); i <num_idx; ++i) {
3871 int id =syscalltbl__id_at_idx(sc->e_machine, i);
3872 struct syscall *pair =trace__syscall_info(trace, NULL, sc->e_machine, id);
3873 structbpf_program*pair_prog;
3874 boolis_candidate= false;
3875
3876 if (pair == NULL || pair == sc ||
(gdb)
Humm
(gdb) p i
$1 = 147
(gdb) p num_idx
$2 = 379
(gdb) p id
$3 = 192
(gdb) p pair
$4 = (struct syscall *) 0x10fe8f0
(gdb) p *pair
$5 = {e_machine = 62, id = 192, tp_format = 0x10f6c00, nr_args = 3, args_size = 48, bpf_prog = {sys_enter = 0x0, sys_exit = 0x0}, is_exit = false, is_open = false, nonexistent = false,
use_btf = false, args = 0x10f9480, name = 0x814406 "lgetxattr", fmt = 0x0, arg_fmt = 0x10fa0a0}
(gdb) p sc
$6 = (struct syscall *) 0x10fb7b0
(gdb) p sc->args
$7 = (struct tep_format_field *) 0x64656e6769736e75
(gdb) p *pair
$8 = {e_machine = 62, id = 192, tp_format = 0x10f6c00, nr_args = 3, args_size = 48, bpf_prog = {sys_enter = 0x0, sys_exit = 0x0}, is_exit = false, is_open = false, nonexistent = false,
use_btf = false, args = 0x10f9480, name = 0x814406 "lgetxattr", fmt = 0x0, arg_fmt = 0x10fa0a0}
(gdb)
it finds the pair, but then its sc->args has a bogus pointer... I'll see where this isn't being initialized...
- Arnaldo
Arnaldo Carvalho de Melo
maintainerQuoted 2 lines · Arnaldo Carvalho de Melo
it finds the pair, but then its
sc->argshas a bogus pointer... I'll see where this isn't being initialized...
Breakpoint 4, trace__find_usable_bpf_prog_entry (trace=0x7fffffffa510, sc=0x1046f10) at builtin-trace.c:3874
3874 bool is_candidate = false;
(gdb) n
3876 if (pair == NULL || pair == sc ||
(gdb) p pair
$7 = (struct syscall *) 0x1083c50
(gdb) p pair->name
$8 = 0x81478e "accept4"
(gdb) n
3877 pair->bpf_prog.sys_enter == trace->skel->progs.syscall_unaugmented)
(gdb) p i
$9 = 1
(gdb) n
3876 if (pair == NULL || pair == sc ||
(gdb) n
3880 printf("sc=%p\n", sc); fflush(stdout);
(gdb) n
sc=0x1046f10
3881 printf("sc->name=%p\n", sc->name); fflush(stdout);
(gdb) n
sc->name=0x6c66202c786c3830
3882 printf("sc->nr_args=%d, sc->args=%p\n", sc->nr_args, sc->args); fflush(stdout);
(gdb) p sc->nr_args
$10 = 1935635045
(gdb) p sc->args
$11 = (struct tep_format_field *) 0x257830203a6e656c
(gdb) p *sc
$12 = {e_machine = 540697702, id = 807761968, tp_format = 0x657075202c786c38, nr_args = 1935635045, args_size = 1634427759, bpf_prog = {sys_enter = 0x257830203a726464,
sys_exit = 0x7075202c786c3830}, is_exit = 101, is_open = 101, nonexistent = 114, use_btf = 95, args = 0x257830203a6e656c,
name = 0x6c66202c786c3830 <error: Cannot access memory at address 0x6c66202c786c3830>, fmt = 0x257830203a736761, arg_fmt = 0x786c3830}
(gdb)
Ok, ran out of time, but if I simple avoid the second loop in:
static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace, int e_machine)
I.e. the one that starts with:
/*
* Now lets do a second pass looking for enabled syscalls without
* an augmenter that have a signature that is a superset of another
* syscall with an augmenter so that we can auto-reuse it.
This:
tools/perf/builtin-trace.c +2 -0
@@ -3989,6 +3989,8 @@ static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace, int e_m goto out; } +return 0 ; +/* * Now lets do a second pass looking for enabled syscalls without * an augmenter that have a signature that is a superset of another
⬢ [acme@toolbox perf-tools-next]$
Then all works, we don't reuse any BPF program, but then that is an heuristic anyway, that is tried becuase landlock_add_rule has a pointer argument:
root@number:~# perf trace -e landlock_add_rule perf test -w landlock
0.000 ( 0.003 ms): perf/71034 landlock_add_rule(ruleset_fd: 11, rule_type: LANDLOCK_RULE_PATH_BENEATH, rule_attr: 0x7fff6f2bb550, flags: 45) = -1 EINVAL (Invalid argument)
0.004 ( 0.001 ms): perf/71034 landlock_add_rule(ruleset_fd: 11, rule_type: LANDLOCK_RULE_NET_PORT, rule_attr: 0x7fff6f2bb540, flags: 45) = -1 EINVAL (Invalid argument)
root@number:~# perf test enum
105: perf trace enum augmentation tests : Ok
root@number:~#So its some sort of syncronization on the various new tables, sorted by name, etc that then when iterating over the syscalls ends up using a sc that is not initialized.
- Arnaldo
Namhyung Kim
maintainerQuoted 77 lines · Arnaldo Carvalho de Melo
Quoted 2 lines · Arnaldo Carvalho de Melo
it finds the pair, but then its
sc->argshas a bogus pointer... I'll see where this isn't being initialized...Breakpoint 4,
trace__find_usable_bpf_prog_entry(trace=0x7fffffffa510, sc=0x1046f10) at builtin-trace.c:3874
3874 boolis_candidate= false;
(gdb) n
3876 if (pair == NULL || pair == sc ||
(gdb) p pair
$7 = (struct syscall *)0x1083c50
(gdb) ppair->name
$8 =0x81478e"accept4"
(gdb) n
3877pair->bpf_prog.sys_enter==trace->skel->progs.syscall_unaugmented)
(gdb) p i
$9 = 1
(gdb) n
3876 if (pair == NULL || pair == sc ||
(gdb) n
3880printf("sc=%p\n", sc); fflush(stdout);
(gdb) n
sc=0x1046f10
3881printf("sc->name=%p\n", sc->name); fflush(stdout);
(gdb) n
sc->name=0x6c66202c786c3830
3882printf("sc->nr_args=%d, sc->args=%p\n", sc->nr_args, sc->args); fflush(stdout);
(gdb) psc->nr_args
$10 = 1935635045
(gdb) psc->args
$11 = (structtep_format_field*)0x257830203a6e656c
(gdb) p *sc
$12 = {e_machine= 540697702, id = 807761968,tp_format=0x657075202c786c38,nr_args= 1935635045,args_size= 1634427759,bpf_prog= {sys_enter=0x257830203a726464,sys_exit = 0x7075202c786c3830}, is_exit = 101, is_open = 101, nonexistent = 114, use_btf = 95, args = 0x257830203a6e656c,name =
0x6c66202c786c3830<error: Cannot access memory at address0x6c66202c786c3830>, fmt =0x257830203a736761,arg_fmt=0x786c3830}
(gdb)Ok, ran out of time, but if I simple avoid the second loop in:
static int
trace__init_syscalls_bpf_prog_array_maps(struct trace *trace, int e_machine)I.e. the one that starts with:
/*
* Now lets do a second pass looking for enabled syscalls without
* an augmenter that have a signature that is a superset of another
* syscall with an augmenter so that we can auto-reuse it.This:
tools/perf/builtin-trace.c +2
-0@@ -3989,6 +3989,8 @@ static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace, int e_m goto out; } +return 0 ; +/* * Now lets do a second pass looking for enabled syscalls without * an augmenter that have a signature that is a superset of another ⬢ [acme@toolbox perf-tools-next]$
Then all works, we don't reuse any BPF program, but then that is an heuristic anyway, that is tried becuase
landlock_add_rulehas a pointer argument:root@number:~# perf trace -e landlock_add_rule perf test -w landlock 0.000 ( 0.003 ms): perf/71034 landlock_add_rule(ruleset_fd: 11, rule_type: LANDLOCK_RULE_PATH_BENEATH, rule_attr: 0x7fff6f2bb550, flags: 45) = -1 EINVAL (Invalid argument) 0.004 ( 0.001 ms): perf/71034 landlock_add_rule(ruleset_fd: 11, rule_type: LANDLOCK_RULE_NET_PORT, rule_attr: 0x7fff6f2bb540, flags: 45) = -1 EINVAL (Invalid argument) root@number:~# perf test enum 105: perf trace enum augmentation tests : Ok root@number:~#
Quoted 3 lines
So its some sort of syncronization on the various new tables, sorted by name, etc that then when iterating over the syscalls ends up using a sc that is not initialized.
Right, I've realized that calling trace__syscall_info() can invalidate the existing sc since it calls trace__find_syscall() which reallocates and resorts the syscall table. That's why it was ok when no filter was used since it'd allocate the whole table in the first pass. Otherwise it looks for a pair syscall while holding the original sc but calling the function would invalidate the sc.
What about this (on top of my earlier fix)?
Thanks,
Namhyung
---8<---
tools/perf/builtin-trace.c +22 -10
@@ -2506,10 +2506,12 @@ static struct syscall *trace__find_syscall(struct trace *trace, int e_machine, i };struct syscall *sc, *tmp; - sc =bsearch (&key, trace->syscalls.table, trace->syscalls.table_size, -sizeof (struct syscall ), syscall__cmp); -if (sc) -return sc; +if (trace->syscalls.table) { + sc =bsearch (&key, trace->syscalls.table, trace->syscalls.table_size, +sizeof (struct syscall ), syscall__cmp); +if (sc) +return sc; + } tmp =reallocarray (trace->syscalls.table, trace->syscalls.table_size +1 ,sizeof (struct syscall ));
@@ -3855,6 +3857,10 @@ static int trace__bpf_sys_enter_beauty_map(struct trace *trace, int e_machine, istatic struct bpf_program *trace__find_usable_bpf_prog_entry (struct trace *trace,struct syscall *sc) { +int orig_id = sc->id; +const char *orig_name = sc->name; +int e_machine = sc->e_machine; +struct tep_format_field *args = sc->args;struct tep_format_field *field, *candidate_field;/* * We're only interested in syscalls that have a pointer:
@@ -3866,18 +3872,19 @@ static struct bpf_program *trace__find_usable_bpf_prog_entry(struct trace *tracereturn NULL ; +/* calling trace__syscall_info() may invalidate 'sc' */ try_to_find_pair: -for (int i =0 , num_idx =syscalltbl__num_idx (sc->e_machine); i < num_idx; ++i) { -int id =syscalltbl__id_at_idx (sc->e_machine, i); -struct syscall *pair =trace__syscall_info (trace,NULL , sc->e_machine, id); +for (int i =0 , num_idx =syscalltbl__num_idx (e_machine); i < num_idx; ++i) { +int id =syscalltbl__id_at_idx (e_machine, i); +struct syscall *pair =trace__syscall_info (trace,NULL , e_machine, id);struct bpf_program *pair_prog;bool is_candidate = false; -if (pair ==NULL || pair == sc || +if (pair ==NULL || pair->id == orig_id || pair->bpf_prog.sys_enter == trace->skel->progs.syscall_unaugmented)continue ; -for (field = sc->args, candidate_field = pair->args; +for (field = args, candidate_field = pair->args; field && candidate_field; field = field->next, candidate_field = candidate_field->next) {bool is_pointer = field->flags &TEP_FIELD_IS_POINTER , candidate_is_pointer = candidate_field->flags &TEP_FIELD_IS_POINTER ;
@@ -3944,7 +3951,7 @@ static struct bpf_program *trace__find_usable_bpf_prog_entry(struct trace *trace goto next_candidate; } -pr_debug ("Reusing \"%s\" BPF sys_enter augmenter for \"%s\"\n" , pair->name, sc->name); +pr_debug ("Reusing \"%s\" BPF sys_enter augmenter for \"%s\"\n" , pair->name, orig_name);return pair_prog; next_candidate:continue ;
@@ -4041,6 +4048,11 @@ static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace, int e_mif (pair_prog ==NULL )continue ; +/* +* Get syscall info again as find usable entry above might +* modify the syscall table and shuffle it. +*/ + sc =trace__syscall_info (trace,NULL , e_machine, key); sc->bpf_prog.sys_enter = pair_prog;/*
Quoted 90 lines · Namhyung Kim
Quoted 77 lines · Arnaldo Carvalho de Melo
Quoted 2 lines · Arnaldo Carvalho de Melo
it finds the pair, but then its
sc->argshas a bogus pointer... I'll see where this isn't being initialized...Breakpoint 4,
trace__find_usable_bpf_prog_entry(trace=0x7fffffffa510, sc=0x1046f10) at builtin-trace.c:3874
3874 boolis_candidate= false;
(gdb) n
3876 if (pair == NULL || pair == sc ||
(gdb) p pair
$7 = (struct syscall *)0x1083c50
(gdb) ppair->name
$8 =0x81478e"accept4"
(gdb) n
3877pair->bpf_prog.sys_enter==trace->skel->progs.syscall_unaugmented)
(gdb) p i
$9 = 1
(gdb) n
3876 if (pair == NULL || pair == sc ||
(gdb) n
3880printf("sc=%p\n", sc); fflush(stdout);
(gdb) n
sc=0x1046f10
3881printf("sc->name=%p\n", sc->name); fflush(stdout);
(gdb) n
sc->name=0x6c66202c786c3830
3882printf("sc->nr_args=%d, sc->args=%p\n", sc->nr_args, sc->args); fflush(stdout);
(gdb) psc->nr_args
$10 = 1935635045
(gdb) psc->args
$11 = (structtep_format_field*)0x257830203a6e656c
(gdb) p *sc
$12 = {e_machine= 540697702, id = 807761968,tp_format=0x657075202c786c38,nr_args= 1935635045,args_size= 1634427759,bpf_prog= {sys_enter=0x257830203a726464,sys_exit = 0x7075202c786c3830}, is_exit = 101, is_open = 101, nonexistent = 114, use_btf = 95, args = 0x257830203a6e656c,name =
0x6c66202c786c3830<error: Cannot access memory at address0x6c66202c786c3830>, fmt =0x257830203a736761,arg_fmt=0x786c3830}
(gdb)Ok, ran out of time, but if I simple avoid the second loop in:
static int
trace__init_syscalls_bpf_prog_array_maps(struct trace *trace, int e_machine)I.e. the one that starts with:
/*
* Now lets do a second pass looking for enabled syscalls without
* an augmenter that have a signature that is a superset of another
* syscall with an augmenter so that we can auto-reuse it.This:
tools/perf/builtin-trace.c +2
-0@@ -3989,6 +3989,8 @@ static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace, int e_m goto out; } +return 0 ; +/* * Now lets do a second pass looking for enabled syscalls without * an augmenter that have a signature that is a superset of another ⬢ [acme@toolbox perf-tools-next]$
Then all works, we don't reuse any BPF program, but then that is an heuristic anyway, that is tried becuase
landlock_add_rulehas a pointer argument:root@number:~# perf trace -e landlock_add_rule perf test -w landlock 0.000 ( 0.003 ms): perf/71034 landlock_add_rule(ruleset_fd: 11, rule_type: LANDLOCK_RULE_PATH_BENEATH, rule_attr: 0x7fff6f2bb550, flags: 45) = -1 EINVAL (Invalid argument) 0.004 ( 0.001 ms): perf/71034 landlock_add_rule(ruleset_fd: 11, rule_type: LANDLOCK_RULE_NET_PORT, rule_attr: 0x7fff6f2bb540, flags: 45) = -1 EINVAL (Invalid argument) root@number:~# perf test enum 105: perf trace enum augmentation tests : Ok root@number:~#Quoted 3 lines
So its some sort of syncronization on the various new tables, sorted by name, etc that then when iterating over the syscalls ends up using a sc that is not initialized.
Right, I've realized that calling
trace__syscall_info()can invalidate the existing sc since it callstrace__find_syscall()which reallocates and resorts the syscall table. That's why it was ok when no filter was used since it'd allocate the whole table in the first pass. Otherwise it looks for a pair syscall while holding the original sc but calling the function would invalidate the sc.
Quoted 1 line
What about this (on top of my earlier fix)?
LGTM.
Thanks,
Ian
Quoted 84 lines
Thanks,
Namhyung---8<---
tools/perf/builtin-trace.c +22
-10@@ -2506,10 +2506,12 @@ static struct syscall *trace__find_syscall(struct trace *trace, int e_machine, i };struct syscall *sc, *tmp; - sc =bsearch (&key, trace->syscalls.table, trace->syscalls.table_size, -sizeof (struct syscall ), syscall__cmp); -if (sc) -return sc; +if (trace->syscalls.table) { + sc =bsearch (&key, trace->syscalls.table, trace->syscalls.table_size, +sizeof (struct syscall ), syscall__cmp); +if (sc) +return sc; + } tmp =reallocarray (trace->syscalls.table, trace->syscalls.table_size +1 ,sizeof (struct syscall ));@@ -3855,6 +3857,10 @@ static int trace__bpf_sys_enter_beauty_map(struct trace *trace, int e_machine, istatic struct bpf_program *trace__find_usable_bpf_prog_entry (struct trace *trace,struct syscall *sc) { +int orig_id = sc->id; +const char *orig_name = sc->name; +int e_machine = sc->e_machine; +struct tep_format_field *args = sc->args;struct tep_format_field *field, *candidate_field;/* * We're only interested in syscalls that have a pointer: @@ -3866,18 +3872,19 @@ static struct bpf_program *trace__find_usable_bpf_prog_entry(struct trace *tracereturn NULL ; +/* calling trace__syscall_info() may invalidate 'sc' */ try_to_find_pair: -for (int i =0 , num_idx =syscalltbl__num_idx (sc->e_machine); i < num_idx; ++i) { -int id =syscalltbl__id_at_idx (sc->e_machine, i); -struct syscall *pair =trace__syscall_info (trace,NULL , sc->e_machine, id); +for (int i =0 , num_idx =syscalltbl__num_idx (e_machine); i < num_idx; ++i) { +int id =syscalltbl__id_at_idx (e_machine, i); +struct syscall *pair =trace__syscall_info (trace,NULL , e_machine, id);struct bpf_program *pair_prog;bool is_candidate = false; -if (pair ==NULL || pair == sc || +if (pair ==NULL || pair->id == orig_id || pair->bpf_prog.sys_enter == trace->skel->progs.syscall_unaugmented)continue ; -for (field = sc->args, candidate_field = pair->args; +for (field = args, candidate_field = pair->args; field && candidate_field; field = field->next, candidate_field = candidate_field->next) {bool is_pointer = field->flags &TEP_FIELD_IS_POINTER , candidate_is_pointer = candidate_field->flags &TEP_FIELD_IS_POINTER ;@@ -3944,7 +3951,7 @@ static struct bpf_program *trace__find_usable_bpf_prog_entry(struct trace *trace goto next_candidate; } -pr_debug ("Reusing \"%s\" BPF sys_enter augmenter for \"%s\"\n" , pair->name, sc->name); +pr_debug ("Reusing \"%s\" BPF sys_enter augmenter for \"%s\"\n" , pair->name, orig_name);return pair_prog; next_candidate:continue ;@@ -4041,6 +4048,11 @@ static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace, int e_mif (pair_prog ==NULL )continue ; +/* +* Get syscall info again as find usable entry above might +* modify the syscall table and shuffle it. +*/ + sc =trace__syscall_info (trace,NULL , e_machine, key); sc->bpf_prog.sys_enter = pair_prog;/*
Arnaldo Carvalho de Melo
maintainerQuoted 14 lines · Arnaldo Carvalho de Melo
Quoted 13 lines · Namhyung Kim
Quoted 12 lines · Arnaldo Carvalho de Melo
Quoted 11 lines · Arnaldo Carvalho de Melo
Still building, but noticed this on
x86_64:105: perf trace enum augmentation tests : FAILED! 106: perf trace BTF general tests : FAILED! 107: perf trace exit race : Ok 108: perf trace record and replay : FAILED!The first doesn´t help that much with verbose mode, haven't checked if before this series it was failing :-\
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
root@x1:~# perf test -vvv 105 105: perf trace enum augmentation tests: --- start --- test child forked, pid 19411 Checking if vmlinux exists Tracing syscall landlock_add_rule ---- end(-1) ---- 105: perf trace enum augmentation tests : FAILED! root@x1:~#
This one is now ok:
0.004 ( 0.000 ms): perf/200342 landlock_add_rule(ruleset_fd: 11, rule_type: LANDLOCK_RULE_NET_PORT, rule_attr: 0x7ffd649bd0d0, flags: 45) = -1 EINVAL (Invalid argument) root@number:~# perf test enum 105: perf trace enum augmentation tests : Ok root@number:~#
now looking at:
root@number:~# perf test -vvvvvvvvv 106 106: perf trace BTF general tests: --- start --- test child forked, pid 200467 Checking if vmlinux BTF exists Testing perf trace's string augmentation String augmentation test failed ---- end(-1) ---- 106: perf trace BTF general tests : FAILED! root@number:~#
No clue from the test, reading its source code now to see where it is failing to try and reproduce the problem.
- Arnaldo
Arnaldo Carvalho de Melo
maintainerQuoted 45 lines · Arnaldo Carvalho de Melo
Quoted 14 lines · Arnaldo Carvalho de Melo
Quoted 13 lines · Namhyung Kim
Quoted 12 lines · Arnaldo Carvalho de Melo
Quoted 11 lines · Arnaldo Carvalho de Melo
Still building, but noticed this on
x86_64:105: perf trace enum augmentation tests : FAILED! 106: perf trace BTF general tests : FAILED! 107: perf trace exit race : Ok 108: perf trace record and replay : FAILED!The first doesn´t help that much with verbose mode, haven't checked if before this series it was failing :-\
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
root@x1:~# perf test -vvv 105 105: perf trace enum augmentation tests: --- start --- test child forked, pid 19411 Checking if vmlinux exists Tracing syscall landlock_add_rule ---- end(-1) ---- 105: perf trace enum augmentation tests : FAILED! root@x1:~#This one is now ok:
0.004 ( 0.000 ms): perf/200342 landlock_add_rule(ruleset_fd: 11, rule_type: LANDLOCK_RULE_NET_PORT, rule_attr: 0x7ffd649bd0d0, flags: 45) = -1 EINVAL (Invalid argument) root@number:~# perf test enum 105: perf trace enum augmentation tests : Ok root@number:~#now looking at:
root@number:~# perf test -vvvvvvvvv 106 106: perf trace BTF general tests: --- start --- test child forked, pid 200467 Checking if vmlinux BTF exists Testing perf trace's string augmentation String augmentation test failed ---- end(-1) ---- 106: perf trace BTF general tests : FAILED! root@number:~#
Quoted 2 lines
No clue from the test, reading its source code now to see where it is failing to try and reproduce the problem.
root@number:~# rm -f /tmp/1234567 ; touch /tmp/1234567 ; perf trace -e renameat* --max-events=1 -- mv /tmp/1234567 /tmp/abcdefg
? ( ): mv/200698 ... [continued]: renameat2()) = -1 EEXIST (File exists)
root@number:~# At this point it works:
⬢ [acme@toolbox perf-tools-next]$ git log -1 commit 58f4f294b358861adaee68dfd19da1060058ec27 (HEAD)
Author: James Clark <[email protected]> Date: Mon Jan 6 16:42:58 2025 +0000
perf test trace_btf_general: Fix shellcheck warning
root@number:~# rm -f /tmp/1234567 ; touch /tmp/1234567 ; perf trace -e renameat* --max-events=1 -- mv /tmp/1234567 /tmp/abcdefg
0.000 ( 0.006 ms): mv/218282 renameat2(olddfd: CWD, oldname: "/tmp/1234567", newdfd: CWD, newname: "/tmp/abcdefg", flags: NOREPLACE) = -1 EEXIST (File exists)
root@number:~#Seems like some transient problem on this test machine, didn't manage to bisect and now everything seems to work:
Well, not always :-\
root@number:~# perf test 105 106 107 108 105: perf trace enum augmentation tests : Ok 106: perf trace BTF general tests : Ok 107: perf trace exit race : Ok 108: perf trace record and replay : Ok root@number:~# perf test 105 106 107 108 105: perf trace enum augmentation tests : Ok 106: perf trace BTF general tests : Ok 107: perf trace exit race : Ok 108: perf trace record and replay : Ok root@number:~# perf test 105 106 107 108 105: perf trace enum augmentation tests : FAILED! 106: perf trace BTF general tests : FAILED! 107: perf trace exit race : Ok 108: perf trace record and replay : Ok root@number:~# perf test 105 106 107 108 105: perf trace enum augmentation tests : FAILED! 106: perf trace BTF general tests : FAILED! 107: perf trace exit race : Ok 108: perf trace record and replay : Ok root@number:~# perf test 105 106 107 108 105: perf trace enum augmentation tests : FAILED! 106: perf trace BTF general tests : FAILED! 107: perf trace exit race : Ok 108: perf trace record and replay : Ok root@number:~# perf test 105 106 107 108 105: perf trace enum augmentation tests : FAILED! 106: perf trace BTF general tests : FAILED! 107: perf trace exit race : Ok 108: perf trace record and replay : Ok root@number:~# perf test 105 106 107 108 105: perf trace enum augmentation tests : Ok 106: perf trace BTF general tests : FAILED! 107: perf trace exit race : Ok 108: perf trace record and replay : Ok root@number:~# for test in 105 106 107 108 ; do perf test $test ; done 105: perf trace enum augmentation tests : FAILED! 106: perf trace BTF general tests : FAILED! 107: perf trace exit race : Ok 108: perf trace record and replay : Ok root@number:~# for test in 105 106 107 108 ; do perf test $test ; done 105: perf trace enum augmentation tests : FAILED! 106: perf trace BTF general tests : FAILED! 107: perf trace exit race : Ok 108: perf trace record and replay : Ok root@number:~#
So, overall, I think this should land and we should continue trying to figure out how to find out about the above failure cases, probably the perf trace cases, since they do set up BPF programs, etc should be done serially?
Doesn't seem to be the case:
root@number:~# for test in 105 106 107 108 ; do perf test --sequential $test ; done 105: perf trace enum augmentation tests : FAILED! 106: perf trace BTF general tests : Ok 107: perf trace exit race : Ok 108: perf trace record and replay : Ok root@number:~# for test in 105 106 107 108 ; do perf test --sequential $test ; done 105: perf trace enum augmentation tests : FAILED! 106: perf trace BTF general tests : Ok 107: perf trace exit race : Ok 108: perf trace record and replay : Ok root@number:~# perf test --sequential 105 106 107 108 105: perf trace enum augmentation tests : FAILED! 106: perf trace BTF general tests : Ok 107: perf trace exit race : Ok 108: perf trace record and replay : Ok root@number:~#
But then if that is the case it needs some love and care to deal with other BPF users in the system, being more graceful in the face of errors.
- Arnaldo