From nobody Wed Dec 17 13:56:56 2025 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D4891CB51F for ; Tue, 18 Mar 2025 03:32:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742268737; cv=none; b=MMSCOeNzndvu00i/Is297R4bZZOsg7uj92i4oYGuML9uq+dngqYIcXkcFhWywtMzxlxJhSjRkcvnDbGLEVpKqnHU1XdD12zcXjpteL9qqsIqWWtzV/q8Y4ce56nI2od90L7YG91vWvKMighRgSLeAGd+kXuyl7eb3PqUm3FJiz4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742268737; c=relaxed/simple; bh=qA+1rn0lTZtkVVRz5dknjvMwBYG3fjJF4hzraRMd7UE=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=hO5SIy9LypTuJN4lZxYa1Dk8u4Lg+vRKoQZV67Xyynp8rGgoWxIFb4EuiIHpX9lvxzl0QM03PdEeHfE91V9sCGRfTDuqO3hwtQRv+874AsL5Krm99zJTuAoahvq27F4IayBnZcCVxPE7/4Xf8/EFhJklyB6TkpryWfqFc1kXG5U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=1uRV5/4d; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="1uRV5/4d" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e582bfcada6so9346130276.1 for ; Mon, 17 Mar 2025 20:32:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742268734; x=1742873534; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=HZEvb9rP0/Ou5uZ1kbtDkT305lhnhit7GPgOKo0wTf8=; b=1uRV5/4dS4UAeEcrb1zchHtFUOk7d4YVTmTdfAB/FD096e6p891Ra1pY0mBo6KKLok l4FarrsVbKe4jCfh/o6jozWlE6SXzb0g6vVrT7UOpKtNhorU3WMfUgu2KyPHHQzRlLl3 O4xw0G0nCp+BRL9jjM3zdYCAsYjslyVXk2ZqdTJxqBXr6TFfC5qVVDuivZ0Xd4iZhMZF X3HHe/FXgsIxsvTcvIPMjB6lZvL8IjF6ltD7BwmIesNOmLJDKaMqvn/60n/SGNAKDOtZ 1EYkJvBIt4YY5ng0ms8fydScJJtzRe2bWzdkiD2vOrTHL2gB43rM3N50BN84p8wpkKn/ sBkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742268734; x=1742873534; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=HZEvb9rP0/Ou5uZ1kbtDkT305lhnhit7GPgOKo0wTf8=; b=JhU2L0EJXllqJ34AiaJNE2S0xOnHjtAcaoysvcAbPisxUH3o7npBTt28GqxJTt/Kfx xhzpX29PKCEfM8UhS929AEGGZiPyGVgu17pR/e3Le/zBJValgH/uozFJwWXPttuCMMbn rsfYF0j+oQp6x74ky/PN6Walex2cDJluEg0zzQkWhBRa3aVr54NIzO5sOLFbvNnXZQCF Gxa28ga1vcYglJr41rZJkMGBol6q8Q8+mdfkwZilvvAqMvD1OPwhldlCA2Q5VqGZFeHn JX5mRgp7ZS1xlnFoIg6FHdNoMFYeHbCzz2ieDo2AN91DqXmKoyRyyWeXubl5WrjvWe+d 8QnA== X-Forwarded-Encrypted: i=1; AJvYcCXRcgcjMOuc6U68GeiU8UEFi7DEwgdR10HtRwe2f4ylAC7WGnhhmzBF1SPfyg8ZQnz61UpFSQVhYCWaRuw=@vger.kernel.org X-Gm-Message-State: AOJu0Yw1Qcv3bfk7ppXVgDgF/V/BoCtpANmWFzag4ogzVawLxe+Yr4ZN MJnvhKdQZgDzh4puAFmpT06UjceWBD+b8CQ3hf3WwynyYC4cMTOt2l4xa6Gll5KrzrT2E4raEGL ewrDSQg== X-Google-Smtp-Source: AGHT+IER6fnR9AvvAzl4yLV8Z9F4XaK0dfP3MnPgkW4XJ8tm86ClJfW9ouXzTMBqgm9jdWxbHmhtIlQjRsfi X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:ef29:15ce:a42a:b69f]) (user=irogers job=sendgmr) by 2002:a25:a4a9:0:b0:e5b:3241:79f7 with SMTP id 3f1490d57ef6-e63f64e00f2mr8113276.3.1742268733743; Mon, 17 Mar 2025 20:32:13 -0700 (PDT) Date: Mon, 17 Mar 2025 20:31:45 -0700 In-Reply-To: <20250318033150.119174-1-irogers@google.com> Message-Id: <20250318033150.119174-9-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250318033150.119174-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.rc1.451.g8f38331e32-goog Subject: [PATCH v6 08/13] perf trace beauty: Add syscalltbl.sh generating all system call tables From: Ian Rogers To: Ian Rogers , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , guoren , Paul Walmsley , Palmer Dabbelt , Albert Ou , Charlie Jenkins , Bibo Mao , Huacai Chen , Catalin Marinas , Jiri Slaby , "=?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?=" , Howard Chu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org, "linux-csky@vger.kernel.org" , linux-riscv@lists.infradead.org, Arnd Bergmann Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Rather 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/d47c35dd-9c52-48e7-a00d-135572f11fbb@app.fastm= ail.com/ and added in commit 9142be9e6443 ("x86/syscall: Mark exit[_group] syscall handlers __noreturn"). Signed-off-by: Ian Rogers Reviewed-by: Howard Chu Reviewed-by: Charlie Jenkins --- 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 diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index d0b50ccc9d7b..f949ec72f3d2 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf @@ -559,6 +559,14 @@ beauty_ioctl_outdir :=3D $(beauty_outdir)/ioctl # Create output directory if not already present $(shell [ -d '$(beauty_ioctl_outdir)' ] || mkdir -p '$(beauty_ioctl_outdir= )') =20 +syscall_array :=3D $(beauty_outdir)/syscalltbl.c +syscall_tbl :=3D $(srctree)/tools/perf/trace/beauty/syscalltbl.sh +syscall_tbl_data :=3D $(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 :=3D $(beauty_outdir)/fs_at_flags_array.c fs_at_flags_tbl :=3D $(srctree)/tools/perf/trace/beauty/fs_at_flags.sh =20 @@ -878,6 +886,7 @@ build-dir =3D $(or $(__build-dir),.) =20 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) \ diff --git a/tools/perf/trace/beauty/syscalltbl.sh b/tools/perf/trace/beaut= y/syscalltbl.sh new file mode 100755 index 000000000000..1199618dc178 --- /dev/null +++ b/tools/perf/trace/beauty/syscalltbl.sh @@ -0,0 +1,274 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# +# Generate all syscall tables. +# +# Each line of the syscall table should have the following format: +# +# NR ABI NAME [NATIVE] [COMPAT [noreturn]] +# +# NR syscall number +# ABI ABI name +# NAME syscall name +# NATIVE native entry point (optional) +# COMPAT compat entry point (optional) +# noreturn system call doesn't return (optional) +set -e + +usage() { + cat >&2 < + + path to kernel tools directory + output header file +EOF + exit 1 +} + +if [ $# -ne 2 ]; then + usage +fi +tools_dir=3D$1 +outfile=3D$2 + +build_tables() { + infile=3D"$1" + outfile=3D"$2" + abis=3D$(echo "($3)" | tr ',' '|') + e_machine=3D"$4" + + if [ ! -f "$infile" ] + then + echo "Missing file $infile" + exit 1 + fi + sorted_table=3D$(mktemp /tmp/syscalltbl.XXXXXX) + grep -E "^[0-9]+[[:space:]]+$abis" "$infile" | sort -n > "$sorted_table" + + echo "static const char *const syscall_num_to_name_${e_machine}[] =3D {" = >> "$outfile" + # the params are: nr abi name entry compat + # use _ for intentionally unused variables according to SC2034 + while read -r nr _ name _ _; do + echo " [$nr] =3D \"$name\"," >> "$outfile" + done < "$sorted_table" + echo "};" >> "$outfile" + + echo "static const uint16_t syscall_sorted_names_${e_machine}[] =3D {" >>= "$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 = =3D 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 -r name nr; do + echo " $nr, /* $name */" >> "$outfile" + done < "$sorted_table" + echo "};" >> "$outfile" + + rm -f "$sorted_table" +} + +rm -f "$outfile" +cat >> "$outfile" < +#include +#include +#include + +struct syscalltbl { + const char *const *num_to_name; + const uint16_t *sorted_names; + uint16_t e_machine; + uint16_t num_to_name_len; + uint16_t sorted_names_len; +}; + +#if defined(ALL_SYSCALLTBL) || defined(__alpha__) +EOF +build_tables "$tools_dir/perf/arch/alpha/entry/syscalls/syscall.tbl" "$out= file" common,64 EM_ALPHA +cat >> "$outfile" <> "$outfile" <> "$outfile" <> "$outfile" <> "$outfile" +build_tables "$tools_dir/perf/arch/parisc/entry/syscalls/syscall.tbl" "$ou= tfile" common,64 EM_PARISC +cat >> "$outfile" <> "$outfile" <> "$outfile" +build_tables "$tools_dir/scripts/syscall.tbl" "$outfile" common,64,riscv,r= limit,memfd_secret EM_RISCV +cat >> "$outfile" <> "$outfile" <> "$outfile" <> "$outfile" +build_tables "$tools_dir/perf/arch/sparc/entry/syscalls/syscall.tbl" "$out= file" common,64 EM_SPARC +cat >> "$outfile" <> "$outfile" <> "$outfile" <> "$outfile" +build_tables "$tools_dir/scripts/syscall.tbl" "$outfile" common,64 EM_NONE +echo "#endif //__BITS_PER_LONG !=3D 64" >> "$outfile" + +build_outer_table() { + e_machine=3D$1 + outfile=3D"$2" + cat >> "$outfile" <> "$outfile" <> "$outfile" <> "$outfile" <> "$outfile" <> "$outfile" <> "$outfile" <> "$outfile" <> "$outfile" <> "$outfile" <> "$outfile" <> "$outfile" <> "$outfile" <> "$outfile" <> "$outfile" <