From nobody Tue Dec 16 22:03:27 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 CFDE424EA89 for ; Wed, 19 Mar 2025 05:07:48 +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=1742360870; cv=none; b=bi/elz02x7h6EpJ48NvEaEMayrrTcfULMLVRluu6FWvE9x4Ph4afiAaREKtSGtB4pdiURfO2bBgoDkCXa+2lgdkkBKUpKzhSJuybhOpcuihrd9soW3h2ixYqzUrsNDqijZnWbDR0P3+o0hfk+p5/dr4404pH0PqhKRhAJyndulM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742360870; c=relaxed/simple; bh=echg6bhB2aBWSvnzX4SOEk+Z9aELKuECpxJgQ98XvbI=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=TUrb0ZENr4ZZVvuHZfcwWoDKnFcr5Aw0Ko8yO72S9GViCuC0Hkmy2xTa2GGhXqHHDRWkHhrsFER0ImEdYYxBPx6c4RdOXU9DIbc3SjeVt9Jncw1HwFpFvtrTZ60bItOFox2iT7ZEkbdMrWYHHo29DViAHAdMNBgJ3LrdzXVaV2Q= 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=tJXTOjg3; 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="tJXTOjg3" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e64124940abso5699582276.3 for ; Tue, 18 Mar 2025 22:07:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742360867; x=1742965667; darn=vger.kernel.org; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=abYRMOxViqYMp92GMDii3ruSxpFYmB3QwrQR3Z5L6HY=; b=tJXTOjg3NqXLXDMfxlpZ60GRbm6iOZPGsvE+eZ0grzlRvJeJTHRaQXpg2eI5Xx8w/B LJ+zNG3ucifIZmuQaVPQ8zOPPAAMssR5I1rzno3oBVVePiR8mgAKpmAke2GGnGrGPuvD OxSjxc7byYyLCSVF0uc6lyxYHvMAlwejv0edQZ4NMNTSlF40EXBeOQiiy9IDliaXLHCH WlUrNKUI6+IGshec0TvWmoC7NRaYUmJ7hRR7BS12kvgvzL+fgqN8HPvVGQYk+eowyUSM OYas09z2wQZP94BTOEi0yawhQcpWtV2sV7IIqYuh78Umu5IS7CSYmK668JRCBnFY+iUe KWXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742360867; x=1742965667; h=cc: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=abYRMOxViqYMp92GMDii3ruSxpFYmB3QwrQR3Z5L6HY=; b=T9+U9pPgAkxUeSousZDqZIJR7FASG0A3RS3mYT2RdmKDNu2gQ4dK5JKlbER1ZSPxP6 bl8+KI63gMdw3ZVeFhQhdBz1DKbOUbzLOfnMr67qscs1FxoWclDSMNMPkd26Kli6B6Lu AzVCmHXkLW4MFSmC5EmdWXFAJZeVUu/b6isQlvgQNN4AjkUeer7fgsGRbHKL7mjudUIu aMNflswPEb6/i9RrvA23w5ENbQA1YMxhBIpeXXbmxfk17jeV9HX/Hv98vatOv2TqzH4y OASYrmgYMFNU9oCmlY9WxB51TqOk8FBX6Hf2DfzP4o4j7H7Qom0oDIUI3+u842jjzvz5 HmeQ== X-Forwarded-Encrypted: i=1; AJvYcCVK7bBM5FqWvyQ+zFP36ns2MtvX9iupmGIlMrO8TniXdw49PsS5zSCXbTIOOHNl4qdFbhjMijLd1YbN5PA=@vger.kernel.org X-Gm-Message-State: AOJu0YxX4dU+msL7HoWmRpM+Bku7EaN3dKngij/wku7GfIFxfBo53a5x +Mx2PgBSZj+QWa0DrS7GYl/QEBouFGFHN/Ge/uQjyw4cBC9ltjz8RApgwOjPUQLRkyI8RhPz0aV y72i33Q== X-Google-Smtp-Source: AGHT+IGRmoWaZCuVB5ee3Iv2LzVEuNeEJLA9zgD9tzBFtuvqHm9F4Ignee+o0RWj2MTQlY6HLf9109e/Wj7N X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:8a11:10b5:af90:6031]) (user=irogers job=sendgmr) by 2002:a25:b323:0:b0:e5b:f74:f5a with SMTP id 3f1490d57ef6-e667b456dc4mr504276.8.1742360867177; Tue, 18 Mar 2025 22:07:47 -0700 (PDT) Date: Tue, 18 Mar 2025 22:07:28 -0700 In-Reply-To: <20250319050741.269828-1-irogers@google.com> Message-Id: <20250319050741.269828-2-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250319050741.269828-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.rc1.451.g8f38331e32-goog Subject: [PATCH v7 01/14] perf dso: Move libunwind dso_data variables into ifdef 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 Cc: Arnaldo Carvalho de Melo Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Reviewed-by: Arnaldo Carvalho de Melo Signed-off-by: Ian Rogers Reviewed-by: Namhyung Kim --- tools/perf/util/dso.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h index 846b74510038..2cc1f6593f9e 100644 --- a/tools/perf/util/dso.h +++ b/tools/perf/util/dso.h @@ -155,10 +155,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 }; =20 struct dso_bpf_prog { --=20 2.49.0.rc1.451.g8f38331e32-goog From nobody Tue Dec 16 22:03:27 2025 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 0A59F24EF63 for ; Wed, 19 Mar 2025 05:07:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742360872; cv=none; b=TQ1A5RJDsV2tk6rJyHTZi3eQyzw4mHhymffpOJ3R10bINtsK92KB7yhtda7NzFNSsiZF2RllLC/5+jnWdE4Km2CcFi9u2HbK20G1TXltv2kyiXvUVOjLFPYgajImCP7qbOwB1weQApGTwEugG+XQ+H+6iaK1xnsYB68MJyh833A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742360872; c=relaxed/simple; bh=frBSFQZ/Cps1/nItEHHyP8IDRMMrZoSwqR8Wpo+tIRw=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=VaGbMn0SXxFIANnm52vOE/Knak9zMyfVE9XPyxTcpkayFmhcRZi4sQsvOJVDXUq+v7Io2xdU+WLWnQ3HgNO+QIm9FfdBDdOyFRYtfLdgricoUbqwrz+Damh6eUSUGQgmUuUcN0q0cS2hIq9vhaVsma2nG8yXZPtLK/dlz0/toWU= 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=LUkGQ2H4; arc=none smtp.client-ip=209.85.128.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="LUkGQ2H4" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6f2737d115eso84463957b3.2 for ; Tue, 18 Mar 2025 22:07:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742360870; x=1742965670; darn=vger.kernel.org; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=XQUhpTPLVb6N2m+nc4ISL7gti6LwY0Os+AgxG8mcvpY=; b=LUkGQ2H4cjlVBGQGvaUwlgG2BcfTDkje+kpNdw6qlWJGGKr+boR7JSegZM15iUVjz4 MEBwHEamP6ipQKCr6kWPgqqe5d8gQ7pIDYUN67DlMBs3xh7f0z6v2L24naSOJndRGE8p IZ/eVzS6AAALcW+CsxtxIjld+DNm/BKCua2XLjrpJ9CH9Yzu9utH4p4fXROJKdLX2sle x0zSoXZ17zv17C5j0qubZc541z9KkjQO5Prt7gJ9k7g94psUr64iORBv1lcB9T59jzf9 rK4hU2zGVOzi9Tjvxg0SDlnK60R+XzsOqUZ23QJ1T7oHEouBQD1N7v2SZwyQfenyt3+h 4RIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742360870; x=1742965670; h=cc: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=XQUhpTPLVb6N2m+nc4ISL7gti6LwY0Os+AgxG8mcvpY=; b=lmLGCaX5OtSQ5gXri+6qyuoKvAv6tgeQPYAXuDf8Y0p2BT22iB6z8HgIg4HKrDaOxs 3dhgudzx0xVZwmrL6Jma2KKOiOJwCk1BITXC/JjVkZurBMU/exWxhPhR/qtLPVitn3iA gvXZwnc/tEHaqT7GOdk7LPD0lm+kdEN86OqHA5B0KJGQ0VasAODY9I0ZuHhgewDh7PP3 vJQnkqR6KhO8/ha5PpnFKdzI/Dnal4tJACrUz8L23tuv8UTmrGgpeDs0pmRK0eIZ0xL7 mKvm0eosQUzk/zWEd7no+YsqOEPO3hSBsdMUoaQJxGDrm1tqrI9gpBh0J8yULRTVctTi Rm6w== X-Forwarded-Encrypted: i=1; AJvYcCWkMX7cb3JB7mmaR5Teh/7L7f+HU3Y+B9zcaXX0KqhKCPu1J5Bwm6rTIHCin/7CzYcdPuH9tjiLMj4QidM=@vger.kernel.org X-Gm-Message-State: AOJu0YwG7PLX5Dc0CDw9cANaob/2Nf6hsXssHOb7o7W+4bycypO7peUL D7wHk7kldKojrMDy9mfY5TWlLRvbwrBUHpOS6UTxdysis/8vlz1b7rjXyr13LIjqMHRm418RuG7 CO0CPzA== X-Google-Smtp-Source: AGHT+IHOW262Yn1ggfPbRXiaD4JOO6KMlLE7LTu3k1LoYE6sevtUdiYlZtBYV3AOcRBRzOEXQI22siUbHecM X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:8a11:10b5:af90:6031]) (user=irogers job=sendgmr) by 2002:a05:690c:6912:b0:6f9:98c3:a191 with SMTP id 00721157ae682-7009bf44550mr5967b3.2.1742360869976; Tue, 18 Mar 2025 22:07:49 -0700 (PDT) Date: Tue, 18 Mar 2025 22:07:29 -0700 In-Reply-To: <20250319050741.269828-1-irogers@google.com> Message-Id: <20250319050741.269828-3-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250319050741.269828-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.rc1.451.g8f38331e32-goog Subject: [PATCH v7 02/14] perf dso: kernel-doc for enum dso_binary_type 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 Cc: Arnaldo Carvalho de Melo Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" There are many and non-obvious meanings to the dso_binary_type enum values. Add kernel-doc to speed interpretting their meanings. Acked-by: Arnaldo Carvalho de Melo Signed-off-by: Ian Rogers Reviewed-by: Namhyung Kim --- tools/perf/util/dso.h | 57 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h index 2cc1f6593f9e..53e3b9b337e5 100644 --- a/tools/perf/util/dso.h +++ b/tools/perf/util/dso.h @@ -20,31 +20,88 @@ struct perf_env; #define DSO__NAME_KALLSYMS "[kernel.kallsyms]" #define DSO__NAME_KCORE "[kernel.kcore]" =20 +/** + * enum dso_binary_type - The kind of DSO generally associated with a memo= ry + * region (struct map). + */ enum dso_binary_type { + /** @DSO_BINARY_TYPE__KALLSYMS: Symbols from /proc/kallsyms file. */ DSO_BINARY_TYPE__KALLSYMS =3D 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 f= ile. */ 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__GNU_DEBUGDATA: MiniDebuginfo where a compressed + * ELF file is placed in a .gnu_debugdata section. + */ DSO_BINARY_TYPE__GNU_DEBUGDATA, + /** @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, }; =20 --=20 2.49.0.rc1.451.g8f38331e32-goog From nobody Tue Dec 16 22:03:27 2025 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 7DD7924F5A0 for ; Wed, 19 Mar 2025 05:07:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742360875; cv=none; b=salYu9IqwVrpvuzseYoLs5zg76M3G1ojfUiqotzvpW2pGMlrDu26U73O4xtidBLcCgXKZU3oYzNUCK8nkQ4xSxCVzuqMIcGFXyDPA0yh3NkRjBlFcxIAsPPKKpyJ4sa39k2n1RoVnO7qGJTDBMpom4sCGlJdczdudN8GR9bEIU4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742360875; c=relaxed/simple; bh=V6Z1VaaZvWtk/tEXjKtJfP6Ld5lnXtv1c/u2guFja8I=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Z9Kf5+Gy6ApolyvIdNYM2V+tbiDNFexzkJuROM+1LMJ2QxKXYzdzbVd34KtLgutxh8uCa/txHCmz/y691SeaV7ZeetJSQs82dMw2BOCdOExYbJlnN9s0tThqqx+18qouhOrBs+4dAEf8KkhToQeP6gDD4jraMlUzOVZ+wa9zGr0= 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=Ko1tMgpT; arc=none smtp.client-ip=209.85.128.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="Ko1tMgpT" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6fee461837cso90900277b3.1 for ; Tue, 18 Mar 2025 22:07:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742360872; x=1742965672; 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=NFFalelwH8VoySEJuALgzWg3CwByqG22Rt5iA2R562U=; b=Ko1tMgpT2YtsU8LO5jJnpH+Owwr/0+KGz427sbxefTKdF0FHZZemRgV1cxECOyEXrH 5QrqAON3GYj/J3EWMI/z3iY3kTglgzPZ/BigQSsTM9Z0aQZoIP1dmqIm0pJFvVWZ1sKN r42wDUIML4IJMJQRMoDGABtQmwsmLetcONv3enZjc0+5OlZtVCX2nEvtxLfoj38XMa2d yatYdaLI/Fqh/MrMX95+0WNIGBTE6LoM2oTECZGqTLZLaHQZMXDBEIhaRYyfDG6jmdfX K2xFoXnl9OTqILGlT4G4gJ6KhOCLvEda+tW4z+P5r2O+9DG9Xa3kFNWsvt9+tzQyoI1l 2UbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742360872; x=1742965672; 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=NFFalelwH8VoySEJuALgzWg3CwByqG22Rt5iA2R562U=; b=AvU+4SRYMARecKe9X3YPzd46NnGyexca2QmGTgMoG7DNCaCp6ea5eqdTNecvk8nX6A DwEj32dmyu6l71BQVh4/AwauS2yhNxWiMnbf4ewYqBGnMJIbUErtkFZUujJM89Jm3abR DZePg/8qWGmodmV/5qT4h9ziJafxvROuZ6zdNXeAQHX/X8DVww59wATSlRznlqk5ZwzE jLBcfPdkzY5LIsD2Jm7ac6V2U0tAfJTEPxnFEH4qKYVHbJRTzbmKtWMsWVrt0fP1okJ9 Lsr4Yqq3v+otxZaAtLLnWSJgNm3cndRSoOwIO1Zq1h0f1qT4rfBsHUHPVZZfrPmVnyy8 sgWw== X-Forwarded-Encrypted: i=1; AJvYcCV9rsSyz8RzG3AaIqhKL3YjTPIVWr78SNHkrHuCHoYBZZsZ3w40YEWbfdZFtM1AnbyJruG5xavHG7py8do=@vger.kernel.org X-Gm-Message-State: AOJu0YzrJa32nGrxuYy8s5Oa1qlJxZy8XwUjrjug7r97COmg3qNj2SXo /2zrGAOdanN8IskGWUEIyqt3DPyeoIiX32yUVg/g7nRsLJNVezGkASdO2+LVuZF1hdT63fIVh1c WRNpJaw== X-Google-Smtp-Source: AGHT+IHKXcOcoX7oZFC1oFuGYiGGZ0j+MiBzxCOjCKBtTzivPnb3bP0kfvlmCNy9iQaR8bqAcvFNPd6Extds X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:8a11:10b5:af90:6031]) (user=irogers job=sendgmr) by 2002:a5b:a87:0:b0:e60:8793:89b3 with SMTP id 3f1490d57ef6-e667b456b9amr515276.8.1742360872036; Tue, 18 Mar 2025 22:07:52 -0700 (PDT) Date: Tue, 18 Mar 2025 22:07:30 -0700 In-Reply-To: <20250319050741.269828-1-irogers@google.com> Message-Id: <20250319050741.269828-4-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250319050741.269828-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.rc1.451.g8f38331e32-goog Subject: [PATCH v7 03/14] perf syscalltbl: Remove syscall_table.h 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" The definition of "static const char *const syscalltbl[] =3D {" 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. Signed-off-by: Ian Rogers Reviewed-by: Howard Chu Reviewed-by: Charlie Jenkins Reviewed-by: Namhyung Kim --- 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 diff --git a/tools/perf/arch/alpha/include/syscall_table.h b/tools/perf/arc= h/alpha/include/syscall_table.h deleted file mode 100644 index b53e31c15805..000000000000 --- a/tools/perf/arch/alpha/include/syscall_table.h +++ /dev/null @@ -1,2 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include diff --git a/tools/perf/arch/arc/include/syscall_table.h b/tools/perf/arch/= arc/include/syscall_table.h deleted file mode 100644 index 4c942821662d..000000000000 --- a/tools/perf/arch/arc/include/syscall_table.h +++ /dev/null @@ -1,2 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include diff --git a/tools/perf/arch/arm/include/syscall_table.h b/tools/perf/arch/= arm/include/syscall_table.h deleted file mode 100644 index 4c942821662d..000000000000 --- a/tools/perf/arch/arm/include/syscall_table.h +++ /dev/null @@ -1,2 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include diff --git a/tools/perf/arch/arm64/include/syscall_table.h b/tools/perf/arc= h/arm64/include/syscall_table.h deleted file mode 100644 index 7ff51b783000..000000000000 --- a/tools/perf/arch/arm64/include/syscall_table.h +++ /dev/null @@ -1,8 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include - -#if __BITS_PER_LONG =3D=3D 64 -#include -#else -#include -#endif diff --git a/tools/perf/arch/csky/include/syscall_table.h b/tools/perf/arch= /csky/include/syscall_table.h deleted file mode 100644 index 4c942821662d..000000000000 --- a/tools/perf/arch/csky/include/syscall_table.h +++ /dev/null @@ -1,2 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include diff --git a/tools/perf/arch/loongarch/include/syscall_table.h b/tools/perf= /arch/loongarch/include/syscall_table.h deleted file mode 100644 index 9d0646d3455c..000000000000 --- a/tools/perf/arch/loongarch/include/syscall_table.h +++ /dev/null @@ -1,2 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include diff --git a/tools/perf/arch/mips/include/syscall_table.h b/tools/perf/arch= /mips/include/syscall_table.h deleted file mode 100644 index b53e31c15805..000000000000 --- a/tools/perf/arch/mips/include/syscall_table.h +++ /dev/null @@ -1,2 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include diff --git a/tools/perf/arch/parisc/include/syscall_table.h b/tools/perf/ar= ch/parisc/include/syscall_table.h deleted file mode 100644 index 7ff51b783000..000000000000 --- a/tools/perf/arch/parisc/include/syscall_table.h +++ /dev/null @@ -1,8 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include - -#if __BITS_PER_LONG =3D=3D 64 -#include -#else -#include -#endif diff --git a/tools/perf/arch/powerpc/include/syscall_table.h b/tools/perf/a= rch/powerpc/include/syscall_table.h deleted file mode 100644 index 7ff51b783000..000000000000 --- a/tools/perf/arch/powerpc/include/syscall_table.h +++ /dev/null @@ -1,8 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include - -#if __BITS_PER_LONG =3D=3D 64 -#include -#else -#include -#endif diff --git a/tools/perf/arch/riscv/include/syscall_table.h b/tools/perf/arc= h/riscv/include/syscall_table.h deleted file mode 100644 index 7ff51b783000..000000000000 --- a/tools/perf/arch/riscv/include/syscall_table.h +++ /dev/null @@ -1,8 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include - -#if __BITS_PER_LONG =3D=3D 64 -#include -#else -#include -#endif diff --git a/tools/perf/arch/s390/include/syscall_table.h b/tools/perf/arch= /s390/include/syscall_table.h deleted file mode 100644 index b53e31c15805..000000000000 --- a/tools/perf/arch/s390/include/syscall_table.h +++ /dev/null @@ -1,2 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include diff --git a/tools/perf/arch/sh/include/syscall_table.h b/tools/perf/arch/s= h/include/syscall_table.h deleted file mode 100644 index 4c942821662d..000000000000 --- a/tools/perf/arch/sh/include/syscall_table.h +++ /dev/null @@ -1,2 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include diff --git a/tools/perf/arch/sparc/include/syscall_table.h b/tools/perf/arc= h/sparc/include/syscall_table.h deleted file mode 100644 index 7ff51b783000..000000000000 --- a/tools/perf/arch/sparc/include/syscall_table.h +++ /dev/null @@ -1,8 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include - -#if __BITS_PER_LONG =3D=3D 64 -#include -#else -#include -#endif diff --git a/tools/perf/arch/x86/include/syscall_table.h b/tools/perf/arch/= x86/include/syscall_table.h deleted file mode 100644 index 7ff51b783000..000000000000 --- a/tools/perf/arch/x86/include/syscall_table.h +++ /dev/null @@ -1,8 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include - -#if __BITS_PER_LONG =3D=3D 64 -#include -#else -#include -#endif diff --git a/tools/perf/arch/xtensa/include/syscall_table.h b/tools/perf/ar= ch/xtensa/include/syscall_table.h deleted file mode 100644 index 4c942821662d..000000000000 --- a/tools/perf/arch/xtensa/include/syscall_table.h +++ /dev/null @@ -1,2 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include diff --git a/tools/perf/util/syscalltbl.c b/tools/perf/util/syscalltbl.c index 928aca4cd6e9..2f76241494c8 100644 --- a/tools/perf/util/syscalltbl.c +++ b/tools/perf/util/syscalltbl.c @@ -7,13 +7,19 @@ =20 #include "syscalltbl.h" #include +#include #include #include =20 #include #include "string2.h" =20 -#include +#if __BITS_PER_LONG =3D=3D 64 + #include +#else + #include +#endif + const int syscalltbl_native_max_id =3D SYSCALLTBL_MAX_ID; static const char *const *syscalltbl_native =3D syscalltbl; =20 --=20 2.49.0.rc1.451.g8f38331e32-goog From nobody Tue Dec 16 22:03:27 2025 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 E781B2500BA for ; Wed, 19 Mar 2025 05:07:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742360880; cv=none; b=mE0WR01risGcWOpLaBwlCgbN85tWCo4KtUyNt0sE/vxUZ8yImcK5oUmF+NN5EoEeFXWwbV3iwZ3TrupI/UpdJneZLeAuPOYlPI5NFozeZNyFVu+MQuvybxfzrdmhJuqsYTBzDY/M/RtMqWBI5XqI6vK7ijD0y9D/RT9PmJ509nw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742360880; c=relaxed/simple; bh=um3SJglU94UOtGph5kPkY7hsQGJVI104ifL7D7mJo9g=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=nAHFEBYPgMUSmw6C2vSMAFG+xx0p7Q1boBlDgdfOojGfdgNfJomjFQkUTMIhbkTA1xr9zaRfPt/t0WkSUA0VdKKs0xvnABJ5FVCqipl3EpoDtTyGT4wH7dMCsot3JOYw0dsskjFkwWeudoFnEl55Y1NBfjPPRPuukghAl1qYEqo= 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=wzOO8har; arc=none smtp.client-ip=209.85.219.201 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="wzOO8har" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e3a0f608b88so8148269276.0 for ; Tue, 18 Mar 2025 22:07:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742360875; x=1742965675; 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=O1nK5uvxYAHiuhO7vp1MDxMA7qbFQ4SO2G8OmMvCRSM=; b=wzOO8harm9DG8/xxlXr59yVws8Yqa4Piptw5vrscxk+AKYEMWo1cLSzBYkTU5YB726 TRR4oSzKGr5heAqiBS5Nc4pNhGeqYxBsoKlwXVOXQUvBJHiFLek0D4/ovbDTySD7x3Ol SR/odvpuFySe8YLzhtbRtzikqu1422DL8j+9GBG5KKofj1VoeDvJ/A7v5oNf3VCSJzyA TOfQKIAC+sN13diUVXnAWmP16QZsMxp6R2xB3LNvvR9h3lEACHbX/KtG6GS28uh+3Cyb kF5CBVblMz3I2VjmxBg3iV57u6WEcZGwgQZQBqi3FntgV1Jl563c7XSnlfwwVXusJZTq o2WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742360875; x=1742965675; 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=O1nK5uvxYAHiuhO7vp1MDxMA7qbFQ4SO2G8OmMvCRSM=; b=awjvhtp5NFUw15SLxPWSUpYDTxejfobMpInRkbAW3/rkJPLD9rXwUxQjubur4q1bTH 8M2kocCHQOXc320M3dtCrCBATfUqm7L62FfmFZgnVQ2CF04pghJNKesXqHIYoUEOIVdW UiOJDh9/pRoC5RjBKThPSkoE36TAd6dBwMvb6qQNaIiQp9v9JxUTuk3umZXLor6ZB1Uc N8NulxBz50KkkM9lif4wiK81MI7hlNwBzgUwyyrnCiH+/BjPF9HYPuXAjP2Onr4v+1++ 5QyRPCj9IqeZ6Sek/Dskp5+iKK5YnselWtJCrPB/Ad3cij/0Hu2EfT+fe4BF5fDN8aCa aJ+A== X-Forwarded-Encrypted: i=1; AJvYcCW9xbh9+t7VJ5Un+600gL8xZxI4HIh01K/YbhG2DsHV+hZsL+lu8cE2EoGYVbkvH0zhZIhwcyzn3sEOXd4=@vger.kernel.org X-Gm-Message-State: AOJu0YzzM0f1yvM1fi7e87uZaqehquiff3WzF/nEi53OnaMzm/BhXpWo 9kMKUPg0qcFoqQNEAspNFpjSelrm2G04hAC7DTSqft0mod2KKdJiWNiLj/2a4Up8pmif6nAxXtD 2GJvFdQ== X-Google-Smtp-Source: AGHT+IFUeD1q1mcBgOYS6b/K4PBymwrwksBbIlprzmhn8jIvW3OyAPriR4x65RqgffXv43hJ4u3eA1io7qGZ X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:8a11:10b5:af90:6031]) (user=irogers job=sendgmr) by 2002:a25:b183:0:b0:e60:8c57:d650 with SMTP id 3f1490d57ef6-e667b42f1edmr499276.4.1742360874651; Tue, 18 Mar 2025 22:07:54 -0700 (PDT) Date: Tue, 18 Mar 2025 22:07:31 -0700 In-Reply-To: <20250319050741.269828-1-irogers@google.com> Message-Id: <20250319050741.269828-5-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250319050741.269828-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.rc1.451.g8f38331e32-goog Subject: [PATCH v7 04/14] perf trace: Reorganize syscalls 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" Identify 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. Signed-off-by: Ian Rogers Reviewed-by: Howard Chu Reviewed-by: Charlie Jenkins Reviewed-by: Namhyung Kim --- tools/perf/builtin-trace.c | 197 +++++++++++++++++++++++++------------ 1 file changed, 132 insertions(+), 65 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 092c5f6404ba..bdfd3d5128b7 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -66,6 +66,7 @@ #include "syscalltbl.h" #include "../perf.h" #include "trace_augment.h" +#include "dwarf-regs.h" =20 #include #include @@ -86,6 +87,7 @@ =20 #include #include +#include =20 #ifdef HAVE_LIBTRACEEVENT #include @@ -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); } =20 -/* - * is_exit: is this "exit" or "exit_group"? - * is_open: is this "open" or "openat"? To associate the fd returned in sy= s_exit with the pathname in sys_enter. - * args_size: sum of the sizes of the syscall arguments, anything after th= at 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; } =20 -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 =3D syscalltbl__name(trace->sctbl, id); + const char *name; int err; =20 - if (trace->syscalls.table =3D=3D NULL) { - trace->syscalls.table =3D calloc(trace->sctbl->syscalls.max_id + 1, size= of(*sc)); - if (trace->syscalls.table =3D=3D NULL) - return -ENOMEM; - } - sc =3D trace->syscalls.table + id; if (sc->nonexistent) return -EEXIST; =20 + if (sc->name) { + /* Info already read. */ + return 0; + } + + name =3D syscalltbl__name(trace->sctbl, sc->id); if (name =3D=3D NULL) { sc->nonexistent =3D true; return -EEXIST; @@ -2145,15 +2164,16 @@ static int trace__read_syscall_info(struct trace *t= race, int id) */ if (IS_ERR(sc->tp_format)) { sc->nonexistent =3D true; - return PTR_ERR(sc->tp_format); + err =3D PTR_ERR(sc->tp_format); + sc->tp_format =3D NULL; + return err; } =20 /* * 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; =20 sc->args =3D sc->tp_format->format.fields; @@ -2442,13 +2462,69 @@ static size_t syscall__scnprintf_args(struct syscal= l *sc, char *bf, size_t size, return printed; } =20 +static void syscall__init(struct syscall *sc, int e_machine, int id) +{ + memset(sc, 0, sizeof(*sc)); + sc->e_machine =3D e_machine; + sc->id =3D 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 =3D va, *b =3D vb; + + if (a->e_machine !=3D 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_mach= ine, int id) +{ + struct syscall key =3D { + .e_machine =3D e_machine, + .id =3D id, + }; + struct syscall *sc, *tmp; + + if (trace->syscalls.table) { + sc =3D bsearch(&key, trace->syscalls.table, trace->syscalls.table_size, + sizeof(struct syscall), syscall__cmp); + if (sc) + return sc; + } + + tmp =3D reallocarray(trace->syscalls.table, trace->syscalls.table_size + = 1, + sizeof(struct syscall)); + if (!tmp) + return NULL; + + trace->syscalls.table =3D tmp; + sc =3D &trace->syscalls.table[trace->syscalls.table_size++]; + syscall__init(sc, e_machine, id); + qsort(trace->syscalls.table, trace->syscalls.table_size, sizeof(struct sy= scall), + syscall__cmp); + sc =3D 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); =20 -static struct syscall *trace__syscall_info(struct trace *trace, - struct evsel *evsel, int id) +static struct syscall *trace__syscall_info(struct trace *trace, struct evs= el *evsel, + int e_machine, int id) { + struct syscall *sc; int err =3D 0; =20 if (id < 0) { @@ -2473,28 +2549,20 @@ static struct syscall *trace__syscall_info(struct t= race *trace, =20 err =3D -EINVAL; =20 - if (id > trace->sctbl->syscalls.max_id) { - goto out_cant_read; - } - - if ((trace->syscalls.table =3D=3D NULL || trace->syscalls.table[id].name = =3D=3D NULL) && - (err =3D trace__read_syscall_info(trace, id)) !=3D 0) - goto out_cant_read; - - if (trace->syscalls.table && trace->syscalls.table[id].nonexistent) - goto out_cant_read; + sc =3D trace__find_syscall(trace, e_machine, id); + if (sc) + err =3D syscall__read_info(sc, trace); =20 - 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 <=3D trace->sctbl->syscalls.max_id && trace->syscalls.table[id].n= ame !=3D 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; } =20 struct syscall_stats { @@ -2643,14 +2711,6 @@ static void *syscall__augmented_args(struct syscall = *sc, struct perf_sample *sam return NULL; } =20 -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 +2722,7 @@ static int trace__sys_enter(struct trace *trace, stru= ct evsel *evsel, int id =3D perf_evsel__sc_tp_uint(evsel, id, sample), err =3D -1; int augmented_args_size =3D 0; void *augmented_args =3D NULL; - struct syscall *sc =3D trace__syscall_info(trace, evsel, id); + struct syscall *sc =3D trace__syscall_info(trace, evsel, EM_HOST, id); struct thread_trace *ttrace; =20 if (sc =3D=3D NULL) @@ -2736,7 +2796,7 @@ static int trace__fprintf_sys_enter(struct trace *tra= ce, struct evsel *evsel, struct thread_trace *ttrace; struct thread *thread; int id =3D perf_evsel__sc_tp_uint(evsel, id, sample), err =3D -1; - struct syscall *sc =3D trace__syscall_info(trace, evsel, id); + struct syscall *sc =3D trace__syscall_info(trace, evsel, EM_HOST, id); char msg[1024]; void *args, *augmented_args =3D NULL; int augmented_args_size; @@ -2811,7 +2871,7 @@ static int trace__sys_exit(struct trace *trace, struc= t evsel *evsel, struct thread *thread; int id =3D perf_evsel__sc_tp_uint(evsel, id, sample), err =3D -1, callcha= in_ret =3D 0, printed =3D 0; int alignment =3D trace->args_alignment; - struct syscall *sc =3D trace__syscall_info(trace, evsel, id); + struct syscall *sc =3D trace__syscall_info(trace, evsel, EM_HOST, id); struct thread_trace *ttrace; =20 if (sc =3D=3D NULL) @@ -3164,7 +3224,7 @@ static int trace__event_handler(struct trace *trace, = struct evsel *evsel, =20 if (evsel =3D=3D trace->syscalls.events.bpf_output) { int id =3D perf_evsel__sc_tp_uint(evsel, id, sample); - struct syscall *sc =3D trace__syscall_info(trace, evsel, id); + struct syscall *sc =3D trace__syscall_info(trace, evsel, EM_HOST, id); =20 if (sc) { fprintf(trace->output, "%s(", sc->name); @@ -3673,7 +3733,7 @@ static struct bpf_program *trace__find_syscall_bpf_pr= og(struct trace *trace, str =20 static void trace__init_syscall_bpf_progs(struct trace *trace, int id) { - struct syscall *sc =3D trace__syscall_info(trace, NULL, id); + struct syscall *sc =3D trace__syscall_info(trace, NULL, EM_HOST, id); =20 if (sc =3D=3D NULL) return; @@ -3684,20 +3744,20 @@ static void trace__init_syscall_bpf_progs(struct tr= ace *trace, int id) =20 static int trace__bpf_prog_sys_enter_fd(struct trace *trace, int id) { - struct syscall *sc =3D trace__syscall_info(trace, NULL, id); + struct syscall *sc =3D trace__syscall_info(trace, NULL, EM_HOST, id); return sc ? bpf_program__fd(sc->bpf_prog.sys_enter) : bpf_program__fd(tra= ce->skel->progs.syscall_unaugmented); } =20 static int trace__bpf_prog_sys_exit_fd(struct trace *trace, int id) { - struct syscall *sc =3D trace__syscall_info(trace, NULL, id); + struct syscall *sc =3D trace__syscall_info(trace, NULL, EM_HOST, id); return sc ? bpf_program__fd(sc->bpf_prog.sys_exit) : bpf_program__fd(trac= e->skel->progs.syscall_unaugmented); } =20 static int trace__bpf_sys_enter_beauty_map(struct trace *trace, int key, u= nsigned int *beauty_array) { struct tep_format_field *field; - struct syscall *sc =3D trace__syscall_info(trace, NULL, key); + struct syscall *sc =3D trace__syscall_info(trace, NULL, EM_HOST, key); const struct btf_type *bt; char *struct_offset, *tmp, name[32]; bool can_augment =3D false; @@ -3779,13 +3839,14 @@ static int trace__bpf_sys_enter_beauty_map(struct t= race *trace, int key, unsigne return -1; } =20 -static struct bpf_program *trace__find_usable_bpf_prog_entry(struct trace = *trace, struct syscall *sc) +static struct bpf_program *trace__find_usable_bpf_prog_entry(struct trace = *trace, struct syscall *_sc) { + struct syscall sc =3D *_sc; /* Copy as trace__syscall_info may invalidate= pointer. */ struct tep_format_field *field, *candidate_field; /* * We're only interested in syscalls that have a pointer: */ - for (field =3D sc->args; field; field =3D field->next) { + for (field =3D sc.args; field; field =3D field->next) { if (field->flags & TEP_FIELD_IS_POINTER) goto try_to_find_pair; } @@ -3795,15 +3856,16 @@ static struct bpf_program *trace__find_usable_bpf_p= rog_entry(struct trace *trace try_to_find_pair: for (int i =3D 0; i < trace->sctbl->syscalls.nr_entries; ++i) { int id =3D syscalltbl__id_at_idx(trace->sctbl, i); - struct syscall *pair =3D trace__syscall_info(trace, NULL, id); + /* calling trace__syscall_info() may invalidate '_sc' */ + struct syscall *pair =3D trace__syscall_info(trace, NULL, sc.e_machine, = id); struct bpf_program *pair_prog; bool is_candidate =3D false; =20 - if (pair =3D=3D NULL || pair =3D=3D sc || + if (pair =3D=3D NULL || pair->id =3D=3D sc.id || pair->bpf_prog.sys_enter =3D=3D trace->skel->progs.syscall_unaugment= ed) continue; =20 - for (field =3D sc->args, candidate_field =3D pair->args; + for (field =3D sc.args, candidate_field =3D pair->args; field && candidate_field; field =3D field->next, candidate_field = =3D candidate_field->next) { bool is_pointer =3D field->flags & TEP_FIELD_IS_POINTER, candidate_is_pointer =3D candidate_field->flags & TEP_FIELD_IS_POI= NTER; @@ -3870,7 +3932,7 @@ static struct bpf_program *trace__find_usable_bpf_pro= g_entry(struct trace *trace goto next_candidate; } =20 - pr_debug("Reusing \"%s\" BPF sys_enter augmenter for \"%s\"\n", pair->na= me, sc->name); + pr_debug("Reusing \"%s\" BPF sys_enter augmenter for \"%s\"\n", pair->na= me, sc.name); return pair_prog; next_candidate: continue; @@ -3945,7 +4007,7 @@ static int trace__init_syscalls_bpf_prog_array_maps(s= truct trace *trace) */ for (int i =3D 0; i < trace->sctbl->syscalls.nr_entries; ++i) { int key =3D syscalltbl__id_at_idx(trace->sctbl, i); - struct syscall *sc =3D trace__syscall_info(trace, NULL, key); + struct syscall *sc =3D trace__syscall_info(trace, NULL, EM_HOST, key); struct bpf_program *pair_prog; int prog_fd; =20 @@ -3966,7 +4028,11 @@ static int trace__init_syscalls_bpf_prog_array_maps(= struct trace *trace) pair_prog =3D trace__find_usable_bpf_prog_entry(trace, sc); if (pair_prog =3D=3D NULL) continue; - + /* + * Get syscall info again as find usable entry above might + * modify the syscall table and shuffle it. + */ + sc =3D trace__syscall_info(trace, NULL, EM_HOST, key); sc->bpf_prog.sys_enter =3D pair_prog; =20 /* @@ -4761,7 +4827,10 @@ static size_t syscall__dump_stats(struct trace *trac= e, FILE *fp, pct =3D avg ? 100.0 * stddev_stats(&stats->stats) / avg : 0.0; avg /=3D NSEC_PER_MSEC; =20 - sc =3D &trace->syscalls.table[entry->syscall]; + sc =3D trace__syscall_info(trace, /*evsel=3D*/NULL, EM_HOST, entry->sys= call); + if (!sc) + continue; + printed +=3D fprintf(fp, " %-15s", sc->name); printed +=3D fprintf(fp, " %8" PRIu64 " %6" PRIu64 " %9.3f %9.3f %9.3f", n, stats->nr_failures, entry->msecs, min, avg); @@ -5218,12 +5287,10 @@ static int trace__config(const char *var, const cha= r *value, void *arg) =20 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 =3D 0; i <=3D trace->sctbl->syscalls.max_id; i++) + for (size_t i =3D 0; i < trace->syscalls.table_size; i++) syscall__exit(&trace->syscalls.table[i]); zfree(&trace->syscalls.table); } --=20 2.49.0.rc1.451.g8f38331e32-goog From nobody Tue Dec 16 22:03:27 2025 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 2C81D24E4B0 for ; Wed, 19 Mar 2025 05:07:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742360880; cv=none; b=Z2MmhPjoghGXQ/e+xNT+uMR3bh4CAmgwvrW+AZveQpFOOwVYq8xYl828ELuyeNf7ZyBjwivnN8+4RAy7SaPsOqy88HpD4KnGWnqqkvb99xSK8AAfeRQcnYOPPAS8QjV4GsDzoKQI7tNizP+lTsNPtfHvPdmVaoBUCn5M1YAvHHc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742360880; c=relaxed/simple; bh=uQeQE2okswahzV1RT6LjdQfZ0hvNgOVwFp5TlPS/Hr8=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=g8tQKQ520xbJ6QOI3BGQftDYhnB6jBwfQVGFTVdviYOt1f+A1IlCCCsK2l5G1U3N4Z2oG2hlp2GEw/2zaFutkaFQDLHNgvItYexd+1rxh81ZiDyNAWBypK+wuDwg7VudO4yiTlid++JPLwS/pCr45vCyXhSpsKRE0ASXnCUNK6c= 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=gtwdXhBf; arc=none smtp.client-ip=209.85.128.201 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="gtwdXhBf" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6fedcc61536so5373327b3.0 for ; Tue, 18 Mar 2025 22:07:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742360877; x=1742965677; 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=hCu3Vx7OmrvmpWlPHZUlvo0KIzrMgeMGs8eeWosVvZ8=; b=gtwdXhBfqBpsofRjkD6W8vyOAC0oNFJr4vqOP1T6V2MjvTxoUrE6U5mZuugLjlEVi9 ISsu/jdnoOv0mAaTqas6/66ML38nEHwExVNb1/6gJtehe2go9JBwW+tqk2rcc6kVfHiq dYc59DJ6Lw9VV0MiNaK8ajHifIxS7Tb4Eha7D5iNA1h6tLvnKo0bwtUeqy+cumkjcWAR njjMd4eP6jNC3us1gBPGmN7aUky4jLT6LT0tHVl8PDOfXmF4yH/K9In/wJ3esh1AOKEW utW280VuB4VaLs/t6T5OCTlT5foEGKPOQxF9zuHT/Dmxwjf9/zeyzSFkJMGvOjCDtzF5 WJTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742360877; x=1742965677; 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=hCu3Vx7OmrvmpWlPHZUlvo0KIzrMgeMGs8eeWosVvZ8=; b=BVARg64syrNsmrb8uyw43zkoSLOwkAzxkH/r6dFUGDztZDyytWe68dQxicKwYNMOAq NCrhMxpVOY56SZ+4I8hAnVF3ofNV0OkvDrw/Z+uSzhKte3I7bg0upR+llcpsQWm8YuX8 HECUm0ZJJB0eT/xV6jHgpnanMPwV78IZu6jzx7fJIrxQcytCuXPHnbUqPeRHO1zdULR2 569bsfjs9p/4IGcT+hJG/beEZiZnrwYs9QRzNqyBNXb6L1/Xl9Xl3UhbJio8VLI8jtDY UOJvwcIqGsVESSqmGE+4U9dCxwwqICR7Z/yCNYemW1YunHb7l0BxViaLwYJAKFc4sqDt yP3g== X-Forwarded-Encrypted: i=1; AJvYcCVI0adoRPmKktGiGTFxoHD1P/1wD9W4GnKCXl6s1cvYeW9wM7/b24eEApUYoPWRTVgzz0o5xUbQ4ScdTvc=@vger.kernel.org X-Gm-Message-State: AOJu0YxE7wPbe7M471Oeaqd17ssWXsiEKWQ5rkfD6+xoxmSXVnby5Rt+ 8ttaWn/k0OyiJFfzERUpWuyAHk8WMQrpd/S9+wRZcDwGINja8XEGANgp83Z7p3TgBPcZuzZqmBQ /yPzHTA== X-Google-Smtp-Source: AGHT+IFFuCfBJcXKbtLFy1Oq1UnQYe25pK9PgSHo3asgGuzg+QqZEsnz8KyEWhdkGx9fDGrtTzz67Y05pfJi X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:8a11:10b5:af90:6031]) (user=irogers job=sendgmr) by 2002:a05:6902:20ca:b0:e5b:1418:5733 with SMTP id 3f1490d57ef6-e667b40dd71mr812276.5.1742360877089; Tue, 18 Mar 2025 22:07:57 -0700 (PDT) Date: Tue, 18 Mar 2025 22:07:32 -0700 In-Reply-To: <20250319050741.269828-1-irogers@google.com> Message-Id: <20250319050741.269828-6-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250319050741.269828-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.rc1.451.g8f38331e32-goog Subject: [PATCH v7 05/14] perf syscalltbl: Remove struct syscalltbl 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" The 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. Signed-off-by: Ian Rogers Reviewed-by: Howard Chu Reviewed-by: Charlie Jenkins Reviewed-by: Namhyung Kim --- 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(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index bdfd3d5128b7..3017291242cf 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -149,7 +149,6 @@ enum summary_mode { =20 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, str= uct trace *trace) return 0; } =20 - name =3D syscalltbl__name(trace->sctbl, sc->id); + name =3D syscalltbl__name(sc->e_machine, sc->id); if (name =3D=3D NULL) { sc->nonexistent =3D true; return -EEXIST; @@ -2241,10 +2248,14 @@ static int trace__validate_ev_qualifier(struct trac= e *trace) =20 strlist__for_each_entry(pos, trace->ev_qualifier) { const char *sc =3D pos->s; - int id =3D syscalltbl__id(trace->sctbl, sc), match_next =3D -1; + /* + * TODO: Assume more than the validation/warnings are all for + * the same binary type as perf. + */ + int id =3D syscalltbl__id(EM_HOST, sc), match_next =3D -1; =20 if (id < 0) { - id =3D syscalltbl__strglobmatch_first(trace->sctbl, sc, &match_next); + id =3D syscalltbl__strglobmatch_first(EM_HOST, sc, &match_next); if (id >=3D 0) goto matches; =20 @@ -2264,7 +2275,7 @@ static int trace__validate_ev_qualifier(struct trace = *trace) continue; =20 while (1) { - id =3D syscalltbl__strglobmatch_next(trace->sctbl, sc, &match_next); + id =3D syscalltbl__strglobmatch_next(EM_HOST, sc, &match_next); if (id < 0) break; if (nr_allocated =3D=3D nr_used) { @@ -2722,6 +2733,7 @@ static int trace__sys_enter(struct trace *trace, stru= ct evsel *evsel, int id =3D perf_evsel__sc_tp_uint(evsel, id, sample), err =3D -1; int augmented_args_size =3D 0; void *augmented_args =3D NULL; + /* TODO: get e_machine from thread. */ struct syscall *sc =3D trace__syscall_info(trace, evsel, EM_HOST, id); struct thread_trace *ttrace; =20 @@ -2796,6 +2808,7 @@ static int trace__fprintf_sys_enter(struct trace *tra= ce, struct evsel *evsel, struct thread_trace *ttrace; struct thread *thread; int id =3D perf_evsel__sc_tp_uint(evsel, id, sample), err =3D -1; + /* TODO: get e_machine from thread. */ struct syscall *sc =3D trace__syscall_info(trace, evsel, EM_HOST, id); char msg[1024]; void *args, *augmented_args =3D NULL; @@ -2871,6 +2884,7 @@ static int trace__sys_exit(struct trace *trace, struc= t evsel *evsel, struct thread *thread; int id =3D perf_evsel__sc_tp_uint(evsel, id, sample), err =3D -1, callcha= in_ret =3D 0, printed =3D 0; int alignment =3D trace->args_alignment; + /* TODO: get e_machine from thread. */ struct syscall *sc =3D trace__syscall_info(trace, evsel, EM_HOST, id); struct thread_trace *ttrace; =20 @@ -3224,6 +3238,7 @@ static int trace__event_handler(struct trace *trace, = struct evsel *evsel, =20 if (evsel =3D=3D trace->syscalls.events.bpf_output) { int id =3D perf_evsel__sc_tp_uint(evsel, id, sample); + /* TODO: get e_machine from thread. */ struct syscall *sc =3D trace__syscall_info(trace, evsel, EM_HOST, id); =20 if (sc) { @@ -3731,9 +3746,9 @@ static struct bpf_program *trace__find_syscall_bpf_pr= og(struct trace *trace, str return trace->skel->progs.syscall_unaugmented; } =20 -static void trace__init_syscall_bpf_progs(struct trace *trace, int id) +static void trace__init_syscall_bpf_progs(struct trace *trace, int e_machi= ne, int id) { - struct syscall *sc =3D trace__syscall_info(trace, NULL, EM_HOST, id); + struct syscall *sc =3D trace__syscall_info(trace, NULL, e_machine, id); =20 if (sc =3D=3D NULL) return; @@ -3742,22 +3757,22 @@ static void trace__init_syscall_bpf_progs(struct tr= ace *trace, int id) sc->bpf_prog.sys_exit =3D trace__find_syscall_bpf_prog(trace, sc, sc->fm= t ? sc->fmt->bpf_prog_name.sys_exit : NULL, "exit"); } =20 -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 =3D trace__syscall_info(trace, NULL, EM_HOST, id); + struct syscall *sc =3D trace__syscall_info(trace, NULL, e_machine, id); return sc ? bpf_program__fd(sc->bpf_prog.sys_enter) : bpf_program__fd(tra= ce->skel->progs.syscall_unaugmented); } =20 -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 =3D trace__syscall_info(trace, NULL, EM_HOST, id); + struct syscall *sc =3D trace__syscall_info(trace, NULL, e_machine, id); return sc ? bpf_program__fd(sc->bpf_prog.sys_exit) : bpf_program__fd(trac= e->skel->progs.syscall_unaugmented); } =20 -static int trace__bpf_sys_enter_beauty_map(struct trace *trace, int key, u= nsigned int *beauty_array) +static int trace__bpf_sys_enter_beauty_map(struct trace *trace, int e_mach= ine, int key, unsigned int *beauty_array) { struct tep_format_field *field; - struct syscall *sc =3D trace__syscall_info(trace, NULL, EM_HOST, key); + struct syscall *sc =3D trace__syscall_info(trace, NULL, e_machine, key); const struct btf_type *bt; char *struct_offset, *tmp, name[32]; bool can_augment =3D false; @@ -3854,8 +3869,8 @@ static struct bpf_program *trace__find_usable_bpf_pro= g_entry(struct trace *trace return NULL; =20 try_to_find_pair: - for (int i =3D 0; i < trace->sctbl->syscalls.nr_entries; ++i) { - int id =3D syscalltbl__id_at_idx(trace->sctbl, i); + for (int i =3D 0, num_idx =3D syscalltbl__num_idx(sc.e_machine); i < num_= idx; ++i) { + int id =3D syscalltbl__id_at_idx(sc.e_machine, i); /* calling trace__syscall_info() may invalidate '_sc' */ struct syscall *pair =3D trace__syscall_info(trace, NULL, sc.e_machine, = id); struct bpf_program *pair_prog; @@ -3941,7 +3956,7 @@ static struct bpf_program *trace__find_usable_bpf_pro= g_entry(struct trace *trace return NULL; } =20 -static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace) +static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace, i= nt e_machine) { int map_enter_fd =3D bpf_map__fd(trace->skel->maps.syscalls_sys_enter); int map_exit_fd =3D bpf_map__fd(trace->skel->maps.syscalls_sys_exit); @@ -3949,27 +3964,27 @@ static int trace__init_syscalls_bpf_prog_array_maps= (struct trace *trace) int err =3D 0; unsigned int beauty_array[6]; =20 - for (int i =3D 0; i < trace->sctbl->syscalls.nr_entries; ++i) { - int prog_fd, key =3D syscalltbl__id_at_idx(trace->sctbl, i); + for (int i =3D 0, num_idx =3D syscalltbl__num_idx(e_machine); i < num_idx= ; ++i) { + int prog_fd, key =3D syscalltbl__id_at_idx(e_machine, i); =20 if (!trace__syscall_enabled(trace, key)) continue; =20 - trace__init_syscall_bpf_progs(trace, key); + trace__init_syscall_bpf_progs(trace, e_machine, key); =20 // It'll get at least the "!raw_syscalls:unaugmented" - prog_fd =3D trace__bpf_prog_sys_enter_fd(trace, key); + prog_fd =3D trace__bpf_prog_sys_enter_fd(trace, e_machine, key); err =3D bpf_map_update_elem(map_enter_fd, &key, &prog_fd, BPF_ANY); if (err) break; - prog_fd =3D trace__bpf_prog_sys_exit_fd(trace, key); + prog_fd =3D trace__bpf_prog_sys_exit_fd(trace, e_machine, key); err =3D bpf_map_update_elem(map_exit_fd, &key, &prog_fd, BPF_ANY); if (err) break; =20 /* 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 =3D trace__bpf_sys_enter_beauty_map(trace, key, (unsigned int *)beau= ty_array); + err =3D trace__bpf_sys_enter_beauty_map(trace, e_machine, key, (unsigned= int *)beauty_array); if (err) continue; err =3D bpf_map_update_elem(beauty_map_fd, &key, beauty_array, BPF_ANY); @@ -4005,9 +4020,9 @@ static int trace__init_syscalls_bpf_prog_array_maps(s= truct 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 =3D 0; i < trace->sctbl->syscalls.nr_entries; ++i) { - int key =3D syscalltbl__id_at_idx(trace->sctbl, i); - struct syscall *sc =3D trace__syscall_info(trace, NULL, EM_HOST, key); + for (int i =3D 0, num_idx =3D syscalltbl__num_idx(e_machine); i < num_idx= ; ++i) { + int key =3D syscalltbl__id_at_idx(e_machine, i); + struct syscall *sc =3D trace__syscall_info(trace, NULL, e_machine, key); struct bpf_program *pair_prog; int prog_fd; =20 @@ -4032,7 +4047,7 @@ static int trace__init_syscalls_bpf_prog_array_maps(s= truct trace *trace) * Get syscall info again as find usable entry above might * modify the syscall table and shuffle it. */ - sc =3D trace__syscall_info(trace, NULL, EM_HOST, key); + sc =3D trace__syscall_info(trace, NULL, e_machine, key); sc->bpf_prog.sys_enter =3D pair_prog; =20 /* @@ -4457,8 +4472,13 @@ static int trace__run(struct trace *trace, int argc,= const char **argv) goto out_error_mem; =20 #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 =20 if (trace->ev_qualifier_ids.nr > 0) { @@ -4483,7 +4503,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 =3D !trace__syscall_enabled(trace, syscalltbl__id= (trace->sctbl, "close")); + /* TODO: support for more than just perf binary machine type close. */ + trace->fd_path_disabled =3D !trace__syscall_enabled(trace, syscalltbl__id= (EM_HOST, "close")); =20 err =3D trace__expand_filters(trace, &evsel); if (err) @@ -4796,7 +4817,7 @@ static struct syscall_entry *syscall__sort_stats(stru= ct hashmap *syscall_stats) return entry; } =20 -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 =3D 0; @@ -4827,7 +4848,7 @@ static size_t syscall__dump_stats(struct trace *trace= , FILE *fp, pct =3D avg ? 100.0 * stddev_stats(&stats->stats) / avg : 0.0; avg /=3D NSEC_PER_MSEC; =20 - sc =3D trace__syscall_info(trace, /*evsel=3D*/NULL, EM_HOST, entry->sys= call); + sc =3D trace__syscall_info(trace, /*evsel=3D*/NULL, e_machine, entry->s= yscall); if (!sc) continue; =20 @@ -4854,14 +4875,14 @@ static size_t syscall__dump_stats(struct trace *tra= ce, FILE *fp, } =20 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); } =20 -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); } =20 static size_t trace__fprintf_thread(FILE *fp, struct thread *thread, struc= t trace *trace) @@ -4887,7 +4908,8 @@ static size_t trace__fprintf_thread(FILE *fp, struct = thread *thread, struct trac else if (fputc('\n', fp) !=3D EOF) ++printed; =20 - printed +=3D thread__dump_stats(ttrace, trace, fp); + /* TODO: get e_machine from thread. */ + printed +=3D thread__dump_stats(ttrace, trace, EM_HOST, fp); =20 return printed; } @@ -4948,7 +4970,8 @@ static size_t trace__fprintf_total_summary(struct tra= ce *trace, FILE *fp) else if (fputc('\n', fp) !=3D EOF) ++printed; =20 - printed +=3D system__dump_stats(trace, fp); + /* TODO: get all system e_machines. */ + printed +=3D system__dump_stats(trace, EM_HOST, fp); =20 return printed; } @@ -5140,8 +5163,9 @@ static int trace__parse_events_option(const struct op= tion *opt, const char *str, *sep =3D '\0'; =20 list =3D 0; - if (syscalltbl__id(trace->sctbl, s) >=3D 0 || - syscalltbl__strglobmatch_first(trace->sctbl, s, &idx) >=3D 0) { + /* TODO: support for more than just perf binary machine type syscalls. */ + if (syscalltbl__id(EM_HOST, s) >=3D 0 || + syscalltbl__strglobmatch_first(EM_HOST, s, &idx) >=3D 0) { list =3D 1; goto do_concat; } @@ -5294,7 +5318,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); } =20 @@ -5443,9 +5466,8 @@ int cmd_trace(int argc, const char **argv) sigaction(SIGCHLD, &sigchld_act, NULL); =20 trace.evlist =3D evlist__new(); - trace.sctbl =3D syscalltbl__new(); =20 - if (trace.evlist =3D=3D NULL || trace.sctbl =3D=3D NULL) { + if (trace.evlist =3D=3D NULL) { pr_err("Not enough memory to run!\n"); err =3D -ENOMEM; goto out; diff --git a/tools/perf/scripts/syscalltbl.sh b/tools/perf/scripts/syscallt= bl.sh index 1ce0d5aa8b50..a39b3013b103 100755 --- a/tools/perf/scripts/syscalltbl.sh +++ b/tools/perf/scripts/syscalltbl.sh @@ -50,37 +50,27 @@ fi infile=3D"$1" outfile=3D"$2" =20 -nxt=3D0 - -syscall_macro() { - nr=3D"$1" - name=3D"$2" - - echo " [$nr] =3D \"$name\"," -} - -emit() { - nr=3D"$1" - entry=3D"$2" - - syscall_macro "$nr" "$entry" -} - -echo "static const char *const syscalltbl[] =3D {" > $outfile - sorted_table=3D$(mktemp /tmp/syscalltbl.XXXXXX) grep -E "^[0-9]+[[:space:]]+$abis" "$infile" | sort -n > $sorted_table =20 -max_nr=3D0 +echo "static const char *const syscall_num_to_name[] =3D {" > $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=3D$nr + echo " [$nr] =3D \"$name\"," >> $outfile done < $sorted_table +echo "};" >> $outfile =20 -rm -f $sorted_table +echo "static const uint16_t syscall_sorted_names[] =3D {" >> $outfile =20 +# When sorting by name, add a suffix of 0s upto 20 characters so that syst= em +# 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 name nr; do + echo " $nr, /* $name */" >> $outfile +done < $sorted_table echo "};" >> $outfile =20 -echo "#define SYSCALLTBL_MAX_ID ${max_nr}" >> $outfile +rm -f $sorted_table diff --git a/tools/perf/util/syscalltbl.c b/tools/perf/util/syscalltbl.c index 2f76241494c8..760ac4d0869f 100644 --- a/tools/perf/util/syscalltbl.c +++ b/tools/perf/util/syscalltbl.c @@ -9,6 +9,7 @@ #include #include #include +#include #include =20 #include @@ -20,112 +21,66 @@ #include #endif =20 -const int syscalltbl_native_max_id =3D SYSCALLTBL_MAX_ID; -static const char *const *syscalltbl_native =3D syscalltbl; +const char *syscalltbl__name(int e_machine __maybe_unused, int id) +{ + if (id >=3D 0 && id <=3D (int)ARRAY_SIZE(syscall_num_to_name)) + return syscall_num_to_name[id]; + return NULL; +} =20 -struct syscall { - int id; +struct syscall_cmp_key { const char *name; + const char *const *tbl; }; =20 static int syscallcmpname(const void *vkey, const void *ventry) { - const char *key =3D vkey; - const struct syscall *entry =3D ventry; + const struct syscall_cmp_key *key =3D vkey; + const uint16_t *entry =3D ventry; =20 - return strcmp(key, entry->name); + return strcmp(key->name, key->tbl[*entry]); } =20 -static int syscallcmp(const void *va, const void *vb) +int syscalltbl__id(int e_machine __maybe_unused, const char *name) { - const struct syscall *a =3D va, *b =3D vb; - - return strcmp(a->name, b->name); + struct syscall_cmp_key key =3D { + .name =3D name, + .tbl =3D syscall_num_to_name, + }; + const int *id =3D bsearch(&key, syscall_sorted_names, + ARRAY_SIZE(syscall_sorted_names), + sizeof(syscall_sorted_names[0]), + syscallcmpname); + + return id ? *id : -1; } =20 -static int syscalltbl__init_native(struct syscalltbl *tbl) +int syscalltbl__num_idx(int e_machine __maybe_unused) { - int nr_entries =3D 0, i, j; - struct syscall *entries; - - for (i =3D 0; i <=3D syscalltbl_native_max_id; ++i) - if (syscalltbl_native[i]) - ++nr_entries; - - entries =3D tbl->syscalls.entries =3D malloc(sizeof(struct syscall) * nr_= entries); - if (tbl->syscalls.entries =3D=3D NULL) - return -1; - - for (i =3D 0, j =3D 0; i <=3D syscalltbl_native_max_id; ++i) { - if (syscalltbl_native[i]) { - entries[j].name =3D syscalltbl_native[i]; - entries[j].id =3D i; - ++j; - } - } - - qsort(tbl->syscalls.entries, nr_entries, sizeof(struct syscall), syscallc= mp); - tbl->syscalls.nr_entries =3D nr_entries; - tbl->syscalls.max_id =3D syscalltbl_native_max_id; - return 0; + return ARRAY_SIZE(syscall_sorted_names); } =20 -struct syscalltbl *syscalltbl__new(void) +int syscalltbl__id_at_idx(int e_machine __maybe_unused, int idx) { - struct syscalltbl *tbl =3D malloc(sizeof(*tbl)); - if (tbl) { - if (syscalltbl__init_native(tbl)) { - free(tbl); - return NULL; - } - } - return tbl; -} - -void syscalltbl__delete(struct syscalltbl *tbl) -{ - zfree(&tbl->syscalls.entries); - free(tbl); -} - -const char *syscalltbl__name(const struct syscalltbl *tbl __maybe_unused, = int id) -{ - return id <=3D syscalltbl_native_max_id ? syscalltbl_native[id]: NULL; -} - -int syscalltbl__id(struct syscalltbl *tbl, const char *name) -{ - struct syscall *sc =3D bsearch(name, tbl->syscalls.entries, - tbl->syscalls.nr_entries, sizeof(*sc), - syscallcmpname); - - return sc ? sc->id : -1; -} - -int syscalltbl__id_at_idx(struct syscalltbl *tbl, int idx) -{ - struct syscall *syscalls =3D tbl->syscalls.entries; - - return idx < tbl->syscalls.nr_entries ? syscalls[idx].id : -1; + return syscall_sorted_names[idx]; } =20 -int syscalltbl__strglobmatch_next(struct syscalltbl *tbl, const char *sysc= all_glob, int *idx) +int syscalltbl__strglobmatch_next(int e_machine __maybe_unused, const char= *syscall_glob, int *idx) { - int i; - struct syscall *syscalls =3D tbl->syscalls.entries; + for (int i =3D *idx + 1; i < (int)ARRAY_SIZE(syscall_sorted_names); ++i) { + const char *name =3D syscall_num_to_name[syscall_sorted_names[i]]; =20 - for (i =3D *idx + 1; i < tbl->syscalls.nr_entries; ++i) { - if (strglobmatch(syscalls[i].name, syscall_glob)) { + if (strglobmatch(name, syscall_glob)) { *idx =3D i; - return syscalls[i].id; + return syscall_sorted_names[i]; } } =20 return -1; } =20 -int syscalltbl__strglobmatch_first(struct syscalltbl *tbl, const char *sys= call_glob, int *idx) +int syscalltbl__strglobmatch_first(int e_machine, const char *syscall_glob= , int *idx) { *idx =3D -1; - return syscalltbl__strglobmatch_next(tbl, syscall_glob, idx); + return syscalltbl__strglobmatch_next(e_machine, syscall_glob, idx); } diff --git a/tools/perf/util/syscalltbl.h b/tools/perf/util/syscalltbl.h index 362411a6d849..2bb628eff367 100644 --- a/tools/perf/util/syscalltbl.h +++ b/tools/perf/util/syscalltbl.h @@ -2,22 +2,12 @@ #ifndef __PERF_SYSCALLTBL_H #define __PERF_SYSCALLTBL_H =20 -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); =20 -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 *sys= call_glob, int *idx); -int syscalltbl__strglobmatch_next(struct syscalltbl *tbl, const char *sysc= all_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); =20 #endif /* __PERF_SYSCALLTBL_H */ --=20 2.49.0.rc1.451.g8f38331e32-goog From nobody Tue Dec 16 22:03:27 2025 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 CB93A24FC1E for ; Wed, 19 Mar 2025 05:08:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742360882; cv=none; b=hsntcB8mBP6K5U3+lf2IRtq1o9xardIP2Zzy51lucvawKlNQZ/ZYk4zKoUzQVMoBpMtxaVTITSYR7t/ysU48N8dWUjHGSRIm3QbgHXCMhXZmKWhTGYaWC8RNv8PJM7/AaHfNT2Ix71esuP1TXPwCrqxC3SnBicZyaAflH/n3vUQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742360882; c=relaxed/simple; bh=wFMBAEiuyp+DrhyMSRVhZjVH94Yk9G67I1hQ9JkWjP4=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=lDrl5vw583J2ur5A2aUg9rZ3GBYOzXEMR35Edd80g2+Bt8qqHrRzHMJbTB+i2eOHp9Rp1C6cvWEtmDQWEEFij0m4qPT8jZ/5B1tgheAtFh4UXo0f4H7u9qM4CuQ5fzdIfQ67XsRP88g1mi4G4r/d9DKYCEfp3T2NydOHyS6Ekhk= 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=DOAxFlaU; arc=none smtp.client-ip=209.85.219.201 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="DOAxFlaU" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e63aad1e67dso10271285276.1 for ; Tue, 18 Mar 2025 22:08:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742360879; x=1742965679; 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=lKH0UkDR+38jlOCF0RORoz/lpVr/5XMrklIeecAtae0=; b=DOAxFlaU/uHp9ZpkECTMU67YUpQK4SZ2jz69Evj/34LcNoMxBXiHwZRAko7xrsCxEn bB0AbWeKi9Bkpjo4uLbMJAhpstlKn9+EYh4ipbrOYqhLB3OXQUaNg4Loeb2hIRCQghQI lJP7AOe6huVUSuw3VuHWPym9ta+iYWGs7idDPqTFZrDE3Ry94bWaoc2a+WVjwvRRkIPe 654khBbQHcLn2ekVKI7anOiaRolL4qOZiFPVeAQ5adVBMf37XRBxNLQNSiJJbEKOPWUs pScP3UcpExGe0aRSJDwZCfAfQwRojXJuMpmifCgj60LZcRYD34bhxjVttghxrsjDT4ji BD9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742360879; x=1742965679; 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=lKH0UkDR+38jlOCF0RORoz/lpVr/5XMrklIeecAtae0=; b=KzVxXj88HFPA23DRuA+n/f2sX9KTvvtinxkxHoSoh3CkTFoox+fYZCin02kfqLqzgd Isz/UN86Zu4sZeUy08UnspFQtQWW1Pk/qW3KcwzHFrOBcfCiHLSXQPFwurRfFqno3NRn tiB1PmWCNonbMNh1g9/TpnxWZvh61mWOyPESqbjyHb4wMhib5xJ3Su6yBXDb9WuxWEB6 LIU8KyAqMvSGs9z02i5n+G8O7PiWGMtvC2Dr8WW9efCy6uLYlbFnyZ3v1D6vBHJjw0UI 2SGjd5Ru8S/O6H3GKn8dFh9oOR+uK81iP15OK89JxNvLGxPnLBUe7NJ1HVGyBHpKhp/d wNNQ== X-Forwarded-Encrypted: i=1; AJvYcCXsXadgRcBcZmouvm/i526m6U4iE2PUvM3PNkf33/REcXSzPfWcaAPuMqtBFfX+1mKqIa8LRtNoAuY4EYE=@vger.kernel.org X-Gm-Message-State: AOJu0YwpoKls7jVwKvYO9C+DR3hLc5bR5wDK8gF47Km/TJjP414noGkY 5E3qcy2Q7TdlxfbjIJ80WyVwvDPw7oCBgAUstYtTXcDnN5UDZBtvMTjt671Xl/Qq0BzkGVKPaVq j/bBM0A== X-Google-Smtp-Source: AGHT+IHW5zIoZNQ/PFJ4nieCzozKPWCoO+ogY5Jq02jaNhLsphiocOSJqBwzeG9L8zyDxjhIToN0yhyiQJB3 X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:8a11:10b5:af90:6031]) (user=irogers job=sendgmr) by 2002:a25:c306:0:b0:e63:c603:37d2 with SMTP id 3f1490d57ef6-e667b44294fmr573276.7.1742360879473; Tue, 18 Mar 2025 22:07:59 -0700 (PDT) Date: Tue, 18 Mar 2025 22:07:33 -0700 In-Reply-To: <20250319050741.269828-1-irogers@google.com> Message-Id: <20250319050741.269828-7-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250319050741.269828-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.rc1.451.g8f38331e32-goog Subject: [PATCH v7 06/14] perf dso: Add support for reading the e_machine type for a dso 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" For 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. Signed-off-by: Ian Rogers Reviewed-by: Namhyung Kim --- tools/perf/util/dso.c | 89 ++++++++++++++++++++++++++++++++++++ tools/perf/util/dso.h | 3 ++ tools/perf/util/symbol-elf.c | 27 ----------- 3 files changed, 92 insertions(+), 27 deletions(-) diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index e0111049f6b0..8619b6eea62d 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c @@ -1194,6 +1194,68 @@ ssize_t dso__data_read_offset(struct dso *dso, struc= t machine *machine, return data_read_write_offset(dso, machine, offset, data, size, true); } =20 +uint16_t dso__e_machine(struct dso *dso, struct machine *machine) +{ + uint16_t e_machine =3D 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__GNU_DEBUGDATA: + 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; + } + + 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 =3D dso__data(dso)->fd; + if (fd >=3D 0) { + _Static_assert(offsetof(Elf32_Ehdr, e_machine) =3D=3D 18, "Unexpected of= fset"); + _Static_assert(offsetof(Elf64_Ehdr, e_machine) =3D=3D 18, "Unexpected of= fset"); + if (dso__needs_swap(dso) =3D=3D DSO_SWAP__UNSET) { + unsigned char eidata; + + if (pread(fd, &eidata, sizeof(eidata), EI_DATA) =3D=3D sizeof(eidata)) + dso__swap_init(dso, eidata); + } + if (dso__needs_swap(dso) !=3D DSO_SWAP__UNSET && + pread(fd, &e_machine, sizeof(e_machine), 18) =3D=3D sizeof(e_machine= )) + e_machine =3D DSO__SWAP(dso, uint16_t, e_machine); + } + mutex_unlock(dso__data_open_lock()); + return e_machine; +} + /** * dso__data_read_addr - Read data from dso address * @dso: dso object @@ -1549,6 +1611,33 @@ void dso__put(struct dso *dso) RC_CHK_PUT(dso); } =20 +int dso__swap_init(struct dso *dso, unsigned char eidata) +{ + static unsigned int const endian =3D 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 !=3D 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 !=3D 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 =3D *bid; diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h index 53e3b9b337e5..8c1e7cdbaefd 100644 --- a/tools/perf/util/dso.h +++ b/tools/perf/util/dso.h @@ -737,6 +737,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); =20 +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, @@ -826,6 +828,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); diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index 3fa92697c457..fbf6d0f73af9 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -1174,33 +1174,6 @@ int filename__read_debuglink(const char *filename, c= har *debuglink, =20 #endif =20 -static int dso__swap_init(struct dso *dso, unsigned char eidata) -{ - static unsigned int const endian =3D 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 !=3D 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 !=3D 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; --=20 2.49.0.rc1.451.g8f38331e32-goog From nobody Tue Dec 16 22:03:27 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 C3C632505D2 for ; Wed, 19 Mar 2025 05:08:02 +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=1742360885; cv=none; b=O3zSt5IWbj9K6h+E3RJ/svroh978QCqUdQkFNBmPc8t/0LBkbzU4ch6IrhpSZ3a+iVVFFhvKvGyw6QZv8Sp8iMnhiQPGCxGsidMWe3UjDGvWvtVDm11OMSPdoydn0ccXzu1srzX6JBvropLVAsi/MYAQAN0BPIJEI+dzJLY9jSU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742360885; c=relaxed/simple; bh=46X5snho+NC9xyHiugqSCdg1Jz8LKx2nORti21ecVVM=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=dhDYfXy9j7FiQKbsDqXBWOf3dIveIl7nWGXriuNENT9qbtONZsKrghLHg+S1c5RHGR1CfJopz4RzhCa+mZFOyj9RkZS9iSj4PkbEdWVlgqzL5Y2obo/R3Qx7FdamFwZBZp9Ll5r2ZuJuH1DPiNFiBi4aVcYFGzn1hPPjRFLqO2s= 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=Q1waJ9VI; 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="Q1waJ9VI" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e549de22484so9533337276.2 for ; Tue, 18 Mar 2025 22:08:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742360882; x=1742965682; 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=OrHbMMe03j2h6U4ZyDmCNi4vPHSyOLjKCo4G6hr5nEQ=; b=Q1waJ9VIrrw5XBGmFQ9Sjcu6SlYpSjWSPBRF4VQPW0Ig/ykFVspjxEREEsM4p4zJO+ r5EYPnNS3SfUQSJIZAVdRyKiHja0jNoQY6UpMV3iS9NysKHeyEEb9FhAkOQC8L/5fgcz 0ouSlGS6QFtiz/AjcQ3CZpp98pTXaoY8Jkv3nAhXjwQiLqFujHlrUBUeWCWUyRAuakqP zbFFiMweDr25NwH3qPVpLXg7ApfVAuyXMqas/cWYw1GD/EjRAhKrpDFSORWF6ffZwrHP 24u3APRb4k0+t62aiz8Vdqxg2giZBn0sWPjs9hno9H1XT9wqcJp17m3QuNrQsoen3HlW w0cQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742360882; x=1742965682; 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=OrHbMMe03j2h6U4ZyDmCNi4vPHSyOLjKCo4G6hr5nEQ=; b=EbTPtQuhvXEZ9y9LeHche40wJmPyVt837Mf0w3MkMWonain7aZN2cFxpV+4IXoEqoN kxcBW6xZ570jW05QcuN+arWWGeShKAd8hm21R8EHdMOJ4y6ivQlqIX1tEsrfOvPs3IYU RFfwmdYSwA5rcxJAD85/8PdsZJLXe7kDm2bjkuBWPf9AkwpmIvEbUMOYcDQszSLLW27L cJSiXo8X+pvw5OqDUx5NCkWVbevCPxWOvkF2nvRk5FIROQFdRrYHiBCEgVdFnvbtc2up d7epZocXHR/fa2puBtPiOUkUgk3HBbn08Y11Q3CBMSQHEx2cSUonK+hkUWNI/J3DESIe zscA== X-Forwarded-Encrypted: i=1; AJvYcCUGkgsQVUr3/qs4/m/jFkPzjjLqcnYu+pgNVZ3gHvoV9pCQ56emhFvQqkf3W5IfSJMC0uFzLN7ReThV5II=@vger.kernel.org X-Gm-Message-State: AOJu0YyhWaDfqS96f7ZFWHvNXnvHktk4f3glSOdGxSQrifnDzXFm5YBC nU9cityDsDG6DC5jokMtrKJxs8YufoI+xdzS+D86vtJlQjCOU75M46dIEZlrb3G6826TE9bO5Gm FEfoEQg== X-Google-Smtp-Source: AGHT+IFx9Z0x08GER++C8nD4jZUCyngaSw/7/gURiTevmG+iiTK/bE0OxP7IhHFOsqWZ82+12GwC/FPcL7kJ X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:8a11:10b5:af90:6031]) (user=irogers job=sendgmr) by 2002:a25:f609:0:b0:e63:72df:76f1 with SMTP id 3f1490d57ef6-e667b440409mr802276.6.1742360881675; Tue, 18 Mar 2025 22:08:01 -0700 (PDT) Date: Tue, 18 Mar 2025 22:07:34 -0700 In-Reply-To: <20250319050741.269828-1-irogers@google.com> Message-Id: <20250319050741.269828-8-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250319050741.269828-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.rc1.451.g8f38331e32-goog Subject: [PATCH v7 07/14] perf thread: Add support for reading the e_machine type for a thread 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" First 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. Signed-off-by: Ian Rogers Reviewed-by: Namhyung Kim --- 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(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 3017291242cf..1c080d95c1e2 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -2731,16 +2731,16 @@ static int trace__sys_enter(struct trace *trace, st= ruct evsel *evsel, int printed =3D 0; struct thread *thread; int id =3D perf_evsel__sc_tp_uint(evsel, id, sample), err =3D -1; - int augmented_args_size =3D 0; + int augmented_args_size =3D 0, e_machine; void *augmented_args =3D NULL; - /* TODO: get e_machine from thread. */ - struct syscall *sc =3D trace__syscall_info(trace, evsel, EM_HOST, id); + struct syscall *sc; struct thread_trace *ttrace; =20 - if (sc =3D=3D NULL) - return -1; - thread =3D machine__findnew_thread(trace->host, sample->pid, sample->tid); + e_machine =3D thread__e_machine(thread, trace->host); + sc =3D trace__syscall_info(trace, evsel, e_machine, id); + if (sc =3D=3D NULL) + goto out_put; ttrace =3D thread__trace(thread, trace); if (ttrace =3D=3D NULL) goto out_put; @@ -2808,17 +2808,18 @@ static int trace__fprintf_sys_enter(struct trace *t= race, struct evsel *evsel, struct thread_trace *ttrace; struct thread *thread; int id =3D perf_evsel__sc_tp_uint(evsel, id, sample), err =3D -1; - /* TODO: get e_machine from thread. */ - struct syscall *sc =3D trace__syscall_info(trace, evsel, EM_HOST, id); + struct syscall *sc; char msg[1024]; void *args, *augmented_args =3D NULL; - int augmented_args_size; + int augmented_args_size, e_machine; size_t printed =3D 0; =20 - if (sc =3D=3D NULL) - return -1; =20 thread =3D machine__findnew_thread(trace->host, sample->pid, sample->tid); + e_machine =3D thread__e_machine(thread, trace->host); + sc =3D trace__syscall_info(trace, evsel, e_machine, id); + if (sc =3D=3D NULL) + return -1; ttrace =3D thread__trace(thread, trace); /* * We need to get ttrace just to make sure it is there when syscall__scnp= rintf_args() @@ -2883,15 +2884,15 @@ static int trace__sys_exit(struct trace *trace, str= uct evsel *evsel, bool duration_calculated =3D false; struct thread *thread; int id =3D perf_evsel__sc_tp_uint(evsel, id, sample), err =3D -1, callcha= in_ret =3D 0, printed =3D 0; - int alignment =3D trace->args_alignment; - /* TODO: get e_machine from thread. */ - struct syscall *sc =3D trace__syscall_info(trace, evsel, EM_HOST, id); + int alignment =3D trace->args_alignment, e_machine; + struct syscall *sc; struct thread_trace *ttrace; =20 - if (sc =3D=3D NULL) - return -1; - thread =3D machine__findnew_thread(trace->host, sample->pid, sample->tid); + e_machine =3D thread__e_machine(thread, trace->host); + sc =3D trace__syscall_info(trace, evsel, e_machine, id); + if (sc =3D=3D NULL) + goto out_put; ttrace =3D thread__trace(thread, trace); if (ttrace =3D=3D NULL) goto out_put; @@ -3238,8 +3239,8 @@ static int trace__event_handler(struct trace *trace, = struct evsel *evsel, =20 if (evsel =3D=3D trace->syscalls.events.bpf_output) { int id =3D perf_evsel__sc_tp_uint(evsel, id, sample); - /* TODO: get e_machine from thread. */ - struct syscall *sc =3D trace__syscall_info(trace, evsel, EM_HOST, id); + int e_machine =3D thread ? thread__e_machine(thread, trace->host) : EM_H= OST; + struct syscall *sc =3D trace__syscall_info(trace, evsel, e_machine, id); =20 if (sc) { fprintf(trace->output, "%s(", sc->name); @@ -4889,6 +4890,7 @@ static size_t trace__fprintf_thread(FILE *fp, struct = thread *thread, struct trac { size_t printed =3D 0; struct thread_trace *ttrace =3D thread__priv(thread); + int e_machine =3D thread__e_machine(thread, trace->host); double ratio; =20 if (ttrace =3D=3D NULL) @@ -4908,8 +4910,7 @@ static size_t trace__fprintf_thread(FILE *fp, struct = thread *thread, struct trac else if (fputc('\n', fp) !=3D EOF) ++printed; =20 - /* TODO: get e_machine from thread. */ - printed +=3D thread__dump_stats(ttrace, trace, EM_HOST, fp); + printed +=3D thread__dump_stats(ttrace, trace, e_machine, fp); =20 return printed; } diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index 0ffdd52d86d7..89585f53c1d5 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c @@ -1,5 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 +#include #include +#include #include #include #include @@ -16,6 +18,7 @@ #include "symbol.h" #include "unwind.h" #include "callchain.h" +#include "dwarf-regs.h" =20 #include =20 @@ -51,6 +54,7 @@ struct thread *thread__new(pid_t pid, pid_t tid) thread__set_ppid(thread, -1); thread__set_cpu(thread, -1); thread__set_guest_cpu(thread, -1); + thread__set_e_machine(thread, EM_NONE); thread__set_lbr_stitch_enable(thread, false); INIT_LIST_HEAD(thread__namespaces_list(thread)); INIT_LIST_HEAD(thread__comm_list(thread)); @@ -423,6 +427,82 @@ void thread__find_cpumode_addr_location(struct thread = *thread, u64 addr, } } =20 +static uint16_t read_proc_e_machine_for_pid(pid_t pid) +{ + char path[6 /* "/proc/" */ + 11 /* max length of pid */ + 5 /* "/exe\0" *= /]; + int fd; + uint16_t e_machine =3D EM_NONE; + + snprintf(path, sizeof(path), "/proc/%d/exe", pid); + fd =3D open(path, O_RDONLY); + if (fd >=3D 0) { + _Static_assert(offsetof(Elf32_Ehdr, e_machine) =3D=3D 18, "Unexpected of= fset"); + _Static_assert(offsetof(Elf64_Ehdr, e_machine) =3D=3D 18, "Unexpected of= fset"); + if (pread(fd, &e_machine, sizeof(e_machine), 18) !=3D sizeof(e_machine)) + e_machine =3D EM_NONE; + close(fd); + } + return e_machine; +} + +static int thread__e_machine_callback(struct map *map, void *machine) +{ + struct dso *dso =3D map__dso(map); + + _Static_assert(0 =3D=3D EM_NONE, "Unexpected EM_NONE"); + if (!dso) + return EM_NONE; + + return dso__e_machine(dso, machine); +} + +uint16_t thread__e_machine(struct thread *thread, struct machine *machine) +{ + pid_t tid, pid; + uint16_t e_machine =3D RC_CHK_ACCESS(thread)->e_machine; + + if (e_machine !=3D EM_NONE) + return e_machine; + + tid =3D thread__tid(thread); + pid =3D thread__pid(thread); + if (pid !=3D tid) { + struct thread *parent =3D machine__findnew_thread(machine, pid, pid); + + if (parent) { + e_machine =3D thread__e_machine(parent, machine); + thread__set_e_machine(thread, e_machine); + return e_machine; + } + /* Something went wrong, fallback. */ + } + /* Reading on the PID thread. First try to find from the maps. */ + e_machine =3D maps__for_each_map(thread__maps(thread), + thread__e_machine_callback, + machine); + if (e_machine =3D=3D EM_NONE) { + /* Maps failed, perhaps we're live with map events disabled. */ + bool is_live =3D machine->machines =3D=3D NULL; + + if (!is_live) { + /* Check if the session has a data file. */ + struct perf_session *session =3D container_of(machine->machines, + struct perf_session, + machines); + + is_live =3D !!session->data; + } + /* Read from /proc/pid/exe if live. */ + if (is_live) + e_machine =3D read_proc_e_machine_for_pid(pid); + } + if (e_machine !=3D EM_NONE) + thread__set_e_machine(thread, e_machine); + else + e_machine =3D EM_HOST; + return e_machine; +} + struct thread *thread__main_thread(struct machine *machine, struct thread = *thread) { if (thread__pid(thread) =3D=3D thread__tid(thread)) diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h index 6cbf6eb2812e..cd574a896418 100644 --- a/tools/perf/util/thread.h +++ b/tools/perf/util/thread.h @@ -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(stru= ct thread *thread, int dep RC_CHK_ACCESS(thread)->filter_entry_depth =3D depth; } =20 +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 =3D e_machine; +} + + static inline bool thread__lbr_stitch_enable(const struct thread *thread) { return RC_CHK_ACCESS(thread)->lbr_stitch_enable; --=20 2.49.0.rc1.451.g8f38331e32-goog From nobody Tue Dec 16 22:03:27 2025 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 2D907250BF3 for ; Wed, 19 Mar 2025 05:08:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742360887; cv=none; b=snpCKVgaL+HJq0yOQsuldH3EYAorlHKSfoPpImmuZWZfINBXa+CwU8qRQ4+vJmptMIoZzFotTzKxiYdn1DsHT18N8UpZTgXsV1yiW0buSZt1kT13plJLqM4p6MBm8T+e/8aFJ+FWa+6V1A6y2I0ZjpixPR+sNOSkU7iAi88fzdA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742360887; c=relaxed/simple; bh=qA+1rn0lTZtkVVRz5dknjvMwBYG3fjJF4hzraRMd7UE=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Z5995HK5TkahS3WCjFa3gfvGyUY3fZz0NAoQOUHe8ZcRxVqnNjLkRa4OglEXYJXSV8RXi2IdG0G+po9K6e378diA9u6nTB1KINxnnzu1IgDp9Wn1v2gjRW0Sw7OMntFf+Z8rlalneJAWrahlKPi9bNWFbxq/Qt/1QfKxADLMkfI= 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=nP7ak2op; arc=none smtp.client-ip=209.85.128.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="nP7ak2op" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6fee461837cso90901947b3.1 for ; Tue, 18 Mar 2025 22:08:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742360884; x=1742965684; 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=nP7ak2opSR/uLfDv3WZR8xnsN18SPU8zt2vVSRtjf4eKFxokjbEiCkith3VG/6cyC1 CPCIs81EwkQDcYiS9tPeNtqu9ee9YHs/LxnI8szdvD6IW10FYRn7Sdii+9ICwKpY5WTw IiZjKTf+aMW2SyNDcJ5UHYC8X0FRjiRyTWJ7drEqigeHO9t5fqKPxyxVogkgT5Vr3+QA RfPXSyK9hmg6ElD7/CiBQtyWg46r6X5TAY2wcJCmHjWRabYFtVhZuXiHa0grvf4VeW4i 5Qx5Tpas0xDgqZTfT55A1aAq8zVYrU4d4ho/Gp8dnNiYKZTS/isOU8JOvCbGh64D6dMC GJdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742360884; x=1742965684; 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=aQa+d5pjbbO4bOyChGfy2JKbFln/iVYLQxWTOwsKukNei2mddLgImWkfY0n3XjplZ3 8cNYgXq1EEEZzu6WRTsN6oWiLKrLc4bMHgljrkckOMKaUw4Ch1b9Bzr1Ldd3n/S4B6zC /jfiHDPpmYg3chtrNNArjb5ps9H4beuqBdikUOjNBURqCwXQsGzHlCnbG7XWAk90wUDK Bro5FL0IXOD6OI8bSjVSgxU0iO/XjNUBAQsKguDbBxibswiGvd0Wj3O0WXkQDvecvFfj iWts8O/RztKNOhnaqpVnaApHBDRhkLdcNmOJPL12qslnQ2q0ms3VcmmXskTAXCMG62jA ML+Q== X-Forwarded-Encrypted: i=1; AJvYcCWjR9SOBIBMvL8LFX8RMC5VD3KF4FeoPjwVRBB+cG2bipVHaLLyNfCSbg7bcR/yhH4PHwSWLZYGYTkHY7c=@vger.kernel.org X-Gm-Message-State: AOJu0Yxms//CEnGCGQeCqnRDKWB6qICC4y2MD2CRw+AiH2n7fNzShnZU b2auxFiLxKrmjsqPIw/Bz9Gq1uDP2WTp+/zmHtWFl4heP1GJ9vX4tqXSZIM1y4rCSQAR6FDdvDd 59RTXLQ== X-Google-Smtp-Source: AGHT+IGc44u77yeoblmfKZi4hDIZy66Uo8gfvsW5pGD8d9f86tnE8cBwkN363tZeQaj9WwaYrjUTVN2252xA X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:8a11:10b5:af90:6031]) (user=irogers job=sendgmr) by 2002:a0d:c985:0:b0:6fd:41f6:62cb with SMTP id 00721157ae682-7009c027877mr5907b3.4.1742360884046; Tue, 18 Mar 2025 22:08:04 -0700 (PDT) Date: Tue, 18 Mar 2025 22:07:35 -0700 In-Reply-To: <20250319050741.269828-1-irogers@google.com> Message-Id: <20250319050741.269828-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: <20250319050741.269828-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.rc1.451.g8f38331e32-goog Subject: [PATCH v7 08/14] 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 Reviewed-by: Namhyung Kim --- 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" <; Wed, 19 Mar 2025 05:08:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742360889; cv=none; b=jD420rce3H0EvqT+SJirqLOHdnjbsgGnLTexfx8qH4CWkz4GrVZNLhyCFkcKHnpr5WTwyt52oltmVAM6HE/7BUUxfJcH+iV+tVxO0Eocg3JCGsNVU1P2PxxYc/KOdqjQm/D3+Rv2hV8PwxEwbnBJQmfXSjr6COMPWQlyWjidxMI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742360889; c=relaxed/simple; bh=/+amWOIQf4AYf0dNSCSGxeQx9lPAINUCD9cqk1hu0DU=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=sbD75Gva7ppUiqgkN8hK+tWvQ6vYkBpy3j4m2VcQRg2UYef+NWNcmJ1AgKLhM24FKdUtqS0AxuC51sQMuIHG7dpObDdpxQWXP90jUP7ZC7P2lCNMNypJU7jfggVubEu6U1kRXsDXdndNXLMFJ3Al+i2+w6/y6Akk1Iuucu35cmI= 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=DdlQAC9A; arc=none smtp.client-ip=209.85.128.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="DdlQAC9A" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6fed889e353so102180057b3.3 for ; Tue, 18 Mar 2025 22:08:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742360886; x=1742965686; darn=vger.kernel.org; h=content-transfer-encoding:to:from:subject:references:mime-version :message-id:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=jXG/G1oeYM9b/alKQuuagGTfIpZAhQmz/i2palTHGhI=; b=DdlQAC9Afs9/zQ16hm+nDFjASvk+0Fs7JfKks8Q3ZLd/m7KMfJBxBNsNzUI/AHoNao nph/263N42Abe3V5pvhCdd18gJZszlTGKiLihaFGBnRnX+vzKD5wNQaZOIGMkutRH0UJ 6kzS6bcMaHXNdzLjFIrzodbYS6x/miXpFquGAXxNR1UpwzXq4m/n2F9tb9p56VeD5Gmz cH1QGnpwv3qkwRGceoIoym2FhNx3Q/Jhx+ILkN/xk7OQY5W0f/p6ew7s+pf54HF8WGjl qlJhIFKPeUblW0louc6ynWPh6rgzJOny8tRgwJc5cNO58tr/RRepa64Kg7O/yq9dXlFl lpBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742360886; x=1742965686; h=content-transfer-encoding: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=jXG/G1oeYM9b/alKQuuagGTfIpZAhQmz/i2palTHGhI=; b=FZt2wNW4sMToZOij+3PyNz3+vXlz4qF4nsD6VAulBmEHrzMNNibOF63uHMY/e2o4sd gTDqtBM18Flg0xFmw3W/Ljsi3xcnuDXzg7nZnaqfommldsecwRxuUnuFQTAy4TSb25ax VYgnolwE1Ec4aIZ4qrvdp8yYa3nPiC2cRSJJQaXLEgiR2NLbdNtHNyAOx9hmDh6Tg81s yNkGv7HrZyknqA7TNzClNe/xWcgtJq3qyLfKxy8gGKpT2JLtW/7DH3YNUsvIDNRDSRvj X639RwzIkcIK42SArJPSO7tuLZ/VMh8lmRHcQl9joer3XNEKr75mAn5MOw0+BnXGvVUP ow/Q== X-Forwarded-Encrypted: i=1; AJvYcCVieXOEkSI65YRPEyg6Nt1zHNFvGZrgKuc1jj5nZW76eD4zKePyhVPMf3uQRny+Q+pnszKcW+qDAWVzFp4=@vger.kernel.org X-Gm-Message-State: AOJu0YwrL+3SQxW/6gmtohThd6ZMXs/bbrTJ0/BDtE73EGn7aqQa6mVI GnyH3KLRuygKJz5ehRU4SFrr7y90LFYCyjwwUOI+kkj52rcuV/EymNb30T97r69VlTbxSNsD6Y8 DC/ceag== X-Google-Smtp-Source: AGHT+IGfbivFYuMlSyVSguddaatmU/X+LBa+8+b7ZSnFdgYCi37H9xIH1R2JAv8LvsqW9+nMJDArTlk6qjei X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:8a11:10b5:af90:6031]) (user=irogers job=sendgmr) by 2002:a05:690c:6ac4:b0:6fe:d1b3:850a with SMTP id 00721157ae682-7009c142bb5mr13627b3.5.1742360886521; Tue, 18 Mar 2025 22:08:06 -0700 (PDT) Date: Tue, 18 Mar 2025 22:07:36 -0700 In-Reply-To: <20250319050741.269828-1-irogers@google.com> Message-Id: <20250319050741.269828-10-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250319050741.269828-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.rc1.451.g8f38331e32-goog Subject: [PATCH v7 09/14] perf syscalltbl: Use lookup table containing multiple architectures 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" 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. Before: ``` ? ( ): a.out/447296 ... [continued]: munmap()) = =3D 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|ERRQ= UEUE|NOSIGNAL|WAITFORONE|BATCH|SOCK_DEVMEM|ZEROCOPY|FASTOPEN|CMSG_CLOEXEC|0= x91f80000, addr: 0xe30, addr_len: 0xffce438c) =3D 1475198976 0.042 ( 0.003 ms): a.out/447296 lgetxattr(name: "", value: 0x3, size: = 34) =3D 4160344064 0.054 ( 0.003 ms): a.out/447296 dup2(oldfd: -134422744, newfd: 4) = =3D -1 ENOENT (No such file or directory) 0.060 ( 0.009 ms): a.out/447296 preadv(fd: 4294967196, vec: (struct io= vec){.iov_base =3D (void *)0x2e646c2f6374652f,.iov_len =3D (__kernel_size_t= )7307199665335594867,}, vlen: 557056, pos_h: 4160585708) =3D 3 0.074 ( 0.004 ms): a.out/447296 lgetxattr(name: "", value: 0x1, size: = 2) =3D 4160237568 0.080 ( 0.001 ms): a.out/447296 lstat(filename: "", statbuf: 0x193f6) = =3D 0 0.089 ( 0.007 ms): a.out/447296 preadv(fd: 4294967196, vec: (struct io= vec){.iov_base =3D (void *)0x3833692f62696c2f,.iov_len =3D (__kernel_size_t= )3276497845987585334,}, vlen: 557056, pos_h: 4160585708) =3D 3 0.097 ( 0.002 ms): a.out/447296 close(fd: 3) = =3D 512 0.103 ( 0.002 ms): a.out/447296 lgetxattr(name: "", value: 0x1, size: = 2050) =3D 4157935616 0.107 ( 0.007 ms): a.out/447296 lgetxattr(pathname: "", name: "", valu= e: 0x5, size: 2066) =3D 4158078976 0.116 ( 0.003 ms): a.out/447296 lgetxattr(pathname: "", name: "", valu= e: 0x1, size: 2066) =3D 4159639552 0.121 ( 0.003 ms): a.out/447296 lgetxattr(pathname: "", name: "", valu= e: 0x3, size: 2066) =3D 4160184320 0.129 ( 0.002 ms): a.out/447296 lgetxattr(pathname: "", name: "", valu= e: 0x3, size: 50) =3D 4160196608 0.138 ( 0.001 ms): a.out/447296 lstat(filename: "") = =3D 0 0.145 ( 0.002 ms): a.out/447296 mq_timedreceive(mqdes: 4291706800, u_m= sg_ptr: 0xf7f9ea48, msg_len: 134616640, u_msg_prio: 0xf7fd7fec, u_abs_timeo= ut: (struct __kernel_timespec){.tv_sec =3D (__kernel_time64_t)-578174027777= 317696,.tv_nsec =3D (long long int)4160349376,}) =3D 0 0.148 ( 0.001 ms): a.out/447296 mkdirat(dfd: -134617816, pathname: " = =EF=BF=BD=EF=BF=BD=EF=BF=BD =EF=BF=BD=EF=BF=BD=EF=BF=BD=E2=96=92=EF=BF=BD= =EF=BF=BD=EF=BF=BD=E2=96=92=EF=BF=BD=EF=BF=BD=EF=BF=BD", mode: IFREG|ISUID|= IRUSR|IWGRP|0xf7fd0000) =3D 447296 0.150 ( 0.001 ms): a.out/447296 process_vm_writev(pid: -134617812, lve= c: (struct iovec){.iov_base =3D (void *)0xf7f9e9c8f7f9e4c0,.iov_len =3D (__= kernel_size_t)4160349376,}, liovcnt: 4160588048, rvec: (struct iovec){}, ri= ovcnt: 4160585708, flags: 4291707352) =3D 0 0.197 ( 0.004 ms): a.out/447296 capget(header: 4160184320, dataptr: 81= 92) =3D 0 0.202 ( 0.002 ms): a.out/447296 capget(header: 1448669184, dataptr: 40= 96) =3D 0 0.208 ( 0.002 ms): a.out/447296 capget(header: 4160577536, dataptr: 81= 92) =3D 0 0.220 ( 0.001 ms): a.out/447296 getxattr(pathname: "", name: "c=EF=BF= =BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD", value: 0xf7f77e34, size:= 1) =3D 0 0.228 ( 0.005 ms): a.out/447296 fchmod(fd: -134729728, mode: IRUGO|IWU= GO|IFREG|IFIFO|ISVTX|IXUSR|0x10000) =3D 0 0.240 ( 0.009 ms): a.out/447296 preadv(fd: 4294967196, vec: 0x5658e008= , pos_h: 4160192052) =3D 3 0.250 ( 0.008 ms): a.out/447296 close(fd: 3) = =3D 1436 0.260 ( 0.018 ms): a.out/447296 stat(filename: "", statbuf: 0xffce32ac= ) =3D 1436 0.288 (1000.213 ms): a.out/447296 readlinkat(buf: 0xffce31d4, bufsiz: = 4291703244) =3D 0 ``` After: ``` ? ( ): a.out/442930 ... [continued]: execve()) = =3D 0 0.023 ( 0.002 ms): a.out/442930 brk() = =3D 0x57760000 0.052 ( 0.003 ms): a.out/442930 access(filename: 0xf7f5af28, mode: R) = =3D -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) =3D 3 0.078 ( 0.001 ms): a.out/442930 close(fd: 3) = =3D 0 0.087 ( 0.007 ms): a.out/442930 openat(dfd: CWD, filename: "/lib/i386-= linux-", flags: RDONLY|CLOEXEC|LARGEFILE) =3D 3 0.095 ( 0.002 ms): a.out/442930 read(fd: 3, buf: = 0xffbdbb70, count: 512) =3D 512 0.135 ( 0.001 ms): a.out/442930 close(fd: 3) = =3D 0 0.148 ( 0.001 ms): a.out/442930 set_tid_address(tidptr: 0xf7f2b528) = =3D 442930 (a.out) 0.150 ( 0.001 ms): a.out/442930 set_robust_list(head: 0xf7f2b52c, len:= 12) =3D 0.196 ( 0.004 ms): a.out/442930 mprotect(start: 0xf7f03000, len: 8192,= prot: READ) =3D 0 0.202 ( 0.002 ms): a.out/442930 mprotect(start: 0x5658e000, len: 4096,= prot: READ) =3D 0 0.207 ( 0.002 ms): a.out/442930 mprotect(start: 0xf7f63000, len: 8192,= prot: READ) =3D 0 0.230 ( 0.005 ms): a.out/442930 munmap(addr: 0xf7f10000, len: 103414) = =3D 0 0.244 ( 0.010 ms): a.out/442930 openat(dfd: CWD, filename: 0x5658d008)= =3D 3 0.255 ( 0.007 ms): a.out/442930 read(fd: 3, buf: = 0xffbdb67c, count: 4096) =3D 1436 0.264 ( 0.018 ms): a.out/442930 write(fd: 1, buf: , count:= 1436) =3D 1436 0.292 (1000.173 ms): a.out/442930 clock_nanosleep(rqtp: { .tv_sec: 178= 66546940376776704, .tv_nsec: 4159878336 }, rmtp: 0xffbdb59c) =3D 0 1000.478 ( ): a.out/442930 exit_group() = =3D ? ``` Signed-off-by: Ian Rogers Reviewed-by: Howard Chu Reviewed-by: Charlie Jenkins Reviewed-by: Namhyung Kim --- tools/perf/util/syscalltbl.c | 89 ++++++++++++++++++++++++++---------- 1 file changed, 64 insertions(+), 25 deletions(-) diff --git a/tools/perf/util/syscalltbl.c b/tools/perf/util/syscalltbl.c index 760ac4d0869f..4e6018e2e0b3 100644 --- a/tools/perf/util/syscalltbl.c +++ b/tools/perf/util/syscalltbl.c @@ -15,16 +15,39 @@ #include #include "string2.h" =20 -#if __BITS_PER_LONG =3D=3D 64 - #include -#else - #include -#endif +#include "trace/beauty/generated/syscalltbl.c" =20 -const char *syscalltbl__name(int e_machine __maybe_unused, int id) +static const struct syscalltbl *find_table(int e_machine) { - if (id >=3D 0 && id <=3D (int)ARRAY_SIZE(syscall_num_to_name)) - return syscall_num_to_name[id]; + static const struct syscalltbl *last_table; + static int last_table_machine =3D EM_NONE; + + /* Tables only exist for EM_SPARC. */ + if (e_machine =3D=3D EM_SPARCV9) + e_machine =3D EM_SPARC; + + if (last_table_machine =3D=3D e_machine && last_table !=3D NULL) + return last_table; + + for (size_t i =3D 0; i < ARRAY_SIZE(syscalltbls); i++) { + const struct syscalltbl *entry =3D &syscalltbls[i]; + + if (entry->e_machine !=3D e_machine && entry->e_machine !=3D EM_NONE) + continue; + + last_table =3D entry; + last_table_machine =3D e_machine; + return entry; + } + return NULL; +} + +const char *syscalltbl__name(int e_machine, int id) +{ + const struct syscalltbl *table =3D find_table(e_machine); + + if (table && id >=3D 0 && id < table->num_to_name_len) + return table->num_to_name[id]; return NULL; } =20 @@ -41,38 +64,54 @@ static int syscallcmpname(const void *vkey, const void = *ventry) return strcmp(key->name, key->tbl[*entry]); } =20 -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 =3D { - .name =3D name, - .tbl =3D syscall_num_to_name, - }; - const int *id =3D bsearch(&key, syscall_sorted_names, - ARRAY_SIZE(syscall_sorted_names), - sizeof(syscall_sorted_names[0]), - syscallcmpname); + const struct syscalltbl *table =3D find_table(e_machine); + struct syscall_cmp_key key; + const uint16_t *id; + + if (!table) + return -1; + + key.name =3D name; + key.tbl =3D table->num_to_name; + id =3D bsearch(&key, table->sorted_names, table->sorted_names_len, + sizeof(table->sorted_names[0]), syscallcmpname); =20 return id ? *id : -1; } =20 -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 =3D find_table(e_machine); + + if (!table) + return 0; + + return table->sorted_names_len; } =20 -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 =3D find_table(e_machine); + + if (!table) + return -1; + + assert(idx >=3D 0 && idx < table->sorted_names_len); + return table->sorted_names[idx]; } =20 -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 =3D *idx + 1; i < (int)ARRAY_SIZE(syscall_sorted_names); ++i) { - const char *name =3D syscall_num_to_name[syscall_sorted_names[i]]; + const struct syscalltbl *table =3D find_table(e_machine); + + for (int i =3D *idx + 1; table && i < table->sorted_names_len; ++i) { + const char *name =3D table->num_to_name[table->sorted_names[i]]; =20 if (strglobmatch(name, syscall_glob)) { *idx =3D i; - return syscall_sorted_names[i]; + return table->sorted_names[i]; } } =20 --=20 2.49.0.rc1.451.g8f38331e32-goog From nobody Tue Dec 16 22:03:27 2025 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 146752512CA for ; Wed, 19 Mar 2025 05:08:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742360892; cv=none; b=u1An0Yu4RQtsQMw1JRKSFua/aZ5t7rECp6+Dx65Yk9SLxBKaZU/trrJ8I9T8XyhMe5rc67kAya9M1gHpkTEmpyIModnOEFIqhyl90XpHHNhuWPDRkvFjb5yqGAmZ1r9kMHVIAeJOycZv/7TegbY12j7WNNmalo0gCK2tAbFOpIc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742360892; c=relaxed/simple; bh=nHC6TVLNTJS0rOrzKTofIKt0TlrHWwza/cs+AH5I4bA=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=X2Ap6HQFDZqLXc22KnZpickYMqNu71Z2iI2gNcGPf1uCFxeL4jN1TrKA9i2wKbSs2xQCTp8I4jtsF8roSIEKYhJ0d+2pHVfUxBmCDrPIVuJJaZYJqFzlu7OAK3pA5pL5jxYL+NNparoZ6Qbpaa4irrEM6BzPzJWknd7Fhs9gaqU= 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=adEE2uPj; arc=none smtp.client-ip=209.85.128.201 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="adEE2uPj" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6f2bc451902so91238727b3.3 for ; Tue, 18 Mar 2025 22:08:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742360889; x=1742965689; 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=91LKckxn206QSCaYEQn5crEKBGBeBMVmLqN08/7YChQ=; b=adEE2uPj0dSrHbdZ0JoWWd//AoTxSfq46zqVKnkqcDhWXY/wMApWviqjtENUYxHZC0 0udJrvJEeBD/lBiq/+6GocVqF0p6YebD758YrHC+jch6E2t/lY2ccfnRU8d0kjYeW561 HG2eXo3itWtR86MDkPDNExy6tzT/RfC9DQ09HFy4vDoZgtttBpg661SgXhfZWvPQyZnq 291Pgjd+6BYzhL/+FGIJhkb3tbvlJ0QPzulE2m3CLjb8WRF208ROLTULuAdxAGz82qH/ mzmwqU5iaCcVkmHAQ2YSS27jE6AyvhvQx4gguzwAE4XjpyRXYuFC5YshCWYga79qMPlG Py6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742360889; x=1742965689; 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=91LKckxn206QSCaYEQn5crEKBGBeBMVmLqN08/7YChQ=; b=B2EdgkX6nABArCyxcfZfJ8BwrTBoaJCGugxIbYSJzxx5Di3/erTPJrVQ0BWUw643xx 8CPyGwL7s3qP1kQb+1npGaVT6EqymNQfWqhoxjumbn07qyIABdtkVYRcT5mezlHzkq7o f/GvlOH0cQc5fJxgcM+X2YEU5ALV+Dog/XdVuUMibgcA47fu4GmYdqbYz05yVu/C3nvp sM79XkATv1Geb99jd7wawFjV/jF2tl0vKn0HzPnxG/KBUQ3BfbOWVtVFY9dLUEvX+gYc /WeDV3ceAcjz3k6oe79GGqJt+O0USawX9wvCFBinzq7NqHr45QSZj4ESzUTX5MnqsSij /wEA== X-Forwarded-Encrypted: i=1; AJvYcCWf61aOuYlvF0Qrlkv0yXrWkAm/TFWAV+F4Ja72bMl+b22ch066WEv97Ex4eHMzxjhMVrWAUX4+ePWRlkU=@vger.kernel.org X-Gm-Message-State: AOJu0YxHQyK2Jb7NmS54jV0u21m6avdn63B3y4hBzZIBDQoI2NEfhGkl /6EM+Yr0xAQKljxio2fo93hacDZI+u1eI2KvdnO/xypXW7/A0XNOqWybuHxv28DXvk5ml4lwGOm dEHzf2Q== X-Google-Smtp-Source: AGHT+IFHXmaHccCXeVJjGM4gMlucNwJvXb/MVQlLnZwg2cP8X9M7CzOFPea3GByyOHDkB8mDoEDWuXGbzM7P X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:8a11:10b5:af90:6031]) (user=irogers job=sendgmr) by 2002:a25:d30d:0:b0:e60:a52a:377a with SMTP id 3f1490d57ef6-e667b398f78mr547276.2.1742360888783; Tue, 18 Mar 2025 22:08:08 -0700 (PDT) Date: Tue, 18 Mar 2025 22:07:37 -0700 In-Reply-To: <20250319050741.269828-1-irogers@google.com> Message-Id: <20250319050741.269828-11-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250319050741.269828-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.rc1.451.g8f38331e32-goog Subject: [PATCH v7 10/14] perf build: Remove Makefile.syscalls 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" Now 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 and they'd written an alternate approach to support multiple architectures: https://lore.kernel.org/all/20250114-perf_syscall_arch_runtime-v1-1-5b304e4= 08e11@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/ Signed-off-by: Ian Rogers Reviewed-by: Howard Chu Reviewed-by: Charlie Jenkins Reviewed-by: Namhyung Kim --- 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.sysca= lls 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 diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index f949ec72f3d2..f3cd8de15d1a 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf @@ -339,7 +339,6 @@ ifeq ($(filter feature-dump,$(MAKECMDGOALS)),feature-du= mp) FEATURE_TESTS :=3D all endif endif -include $(srctree)/tools/perf/scripts/Makefile.syscalls include Makefile.config endif =20 diff --git a/tools/perf/arch/alpha/entry/syscalls/Kbuild b/tools/perf/arch/= alpha/entry/syscalls/Kbuild deleted file mode 100644 index 9a41e3572c3a..000000000000 --- a/tools/perf/arch/alpha/entry/syscalls/Kbuild +++ /dev/null @@ -1,2 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -syscall-y +=3D syscalls_64.h diff --git a/tools/perf/arch/alpha/entry/syscalls/Makefile.syscalls b/tools= /perf/arch/alpha/entry/syscalls/Makefile.syscalls deleted file mode 100644 index 690168aac34d..000000000000 --- a/tools/perf/arch/alpha/entry/syscalls/Makefile.syscalls +++ /dev/null @@ -1,5 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -syscall_abis_64 +=3D - -syscalltbl =3D $(srctree)/tools/perf/arch/alpha/entry/syscalls/syscall.tbl diff --git a/tools/perf/arch/arc/entry/syscalls/Kbuild b/tools/perf/arch/ar= c/entry/syscalls/Kbuild deleted file mode 100644 index 11707c481a24..000000000000 --- a/tools/perf/arch/arc/entry/syscalls/Kbuild +++ /dev/null @@ -1,2 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -syscall-y +=3D syscalls_32.h diff --git a/tools/perf/arch/arc/entry/syscalls/Makefile.syscalls b/tools/p= erf/arch/arc/entry/syscalls/Makefile.syscalls deleted file mode 100644 index 391d30ab7a83..000000000000 --- a/tools/perf/arch/arc/entry/syscalls/Makefile.syscalls +++ /dev/null @@ -1,3 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -syscall_abis_32 +=3D arc time32 renameat stat64 rlimit diff --git a/tools/perf/arch/arm/entry/syscalls/Kbuild b/tools/perf/arch/ar= m/entry/syscalls/Kbuild deleted file mode 100644 index 9d777540f089..000000000000 --- a/tools/perf/arch/arm/entry/syscalls/Kbuild +++ /dev/null @@ -1,4 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -syscall_abis_32 +=3D oabi -syscalltbl =3D $(srctree)/tools/perf/arch/arm/entry/syscalls/syscall.tbl diff --git a/tools/perf/arch/arm/entry/syscalls/Makefile.syscalls b/tools/p= erf/arch/arm/entry/syscalls/Makefile.syscalls deleted file mode 100644 index 11707c481a24..000000000000 --- a/tools/perf/arch/arm/entry/syscalls/Makefile.syscalls +++ /dev/null @@ -1,2 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -syscall-y +=3D syscalls_32.h diff --git a/tools/perf/arch/arm64/entry/syscalls/Kbuild b/tools/perf/arch/= arm64/entry/syscalls/Kbuild deleted file mode 100644 index 84c6599b4ea6..000000000000 --- a/tools/perf/arch/arm64/entry/syscalls/Kbuild +++ /dev/null @@ -1,3 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -syscall-y +=3D syscalls_32.h -syscall-y +=3D syscalls_64.h diff --git a/tools/perf/arch/arm64/entry/syscalls/Makefile.syscalls b/tools= /perf/arch/arm64/entry/syscalls/Makefile.syscalls deleted file mode 100644 index e7e78c2d1c02..000000000000 --- a/tools/perf/arch/arm64/entry/syscalls/Makefile.syscalls +++ /dev/null @@ -1,6 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -syscall_abis_32 +=3D -syscall_abis_64 +=3D renameat rlimit memfd_secret - -syscalltbl =3D $(srctree)/tools/perf/arch/arm64/entry/syscalls/syscall_%.t= bl diff --git a/tools/perf/arch/csky/entry/syscalls/Kbuild b/tools/perf/arch/c= sky/entry/syscalls/Kbuild deleted file mode 100644 index 11707c481a24..000000000000 --- a/tools/perf/arch/csky/entry/syscalls/Kbuild +++ /dev/null @@ -1,2 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -syscall-y +=3D syscalls_32.h diff --git a/tools/perf/arch/csky/entry/syscalls/Makefile.syscalls b/tools/= perf/arch/csky/entry/syscalls/Makefile.syscalls deleted file mode 100644 index ea2dd10d0571..000000000000 --- a/tools/perf/arch/csky/entry/syscalls/Makefile.syscalls +++ /dev/null @@ -1,3 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -syscall_abis_32 +=3D csky time32 stat64 rlimit diff --git a/tools/perf/arch/loongarch/entry/syscalls/Kbuild b/tools/perf/a= rch/loongarch/entry/syscalls/Kbuild deleted file mode 100644 index 9a41e3572c3a..000000000000 --- a/tools/perf/arch/loongarch/entry/syscalls/Kbuild +++ /dev/null @@ -1,2 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -syscall-y +=3D syscalls_64.h diff --git a/tools/perf/arch/loongarch/entry/syscalls/Makefile.syscalls b/t= ools/perf/arch/loongarch/entry/syscalls/Makefile.syscalls deleted file mode 100644 index 47d32da2aed8..000000000000 --- a/tools/perf/arch/loongarch/entry/syscalls/Makefile.syscalls +++ /dev/null @@ -1,3 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -syscall_abis_64 +=3D diff --git a/tools/perf/arch/mips/entry/syscalls/Kbuild b/tools/perf/arch/m= ips/entry/syscalls/Kbuild deleted file mode 100644 index 9a41e3572c3a..000000000000 --- a/tools/perf/arch/mips/entry/syscalls/Kbuild +++ /dev/null @@ -1,2 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -syscall-y +=3D syscalls_64.h diff --git a/tools/perf/arch/mips/entry/syscalls/Makefile.syscalls b/tools/= perf/arch/mips/entry/syscalls/Makefile.syscalls deleted file mode 100644 index 9ee914bdfb05..000000000000 --- a/tools/perf/arch/mips/entry/syscalls/Makefile.syscalls +++ /dev/null @@ -1,5 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -syscall_abis_64 +=3D n64 - -syscalltbl =3D $(srctree)/tools/perf/arch/mips/entry/syscalls/syscall_n64.= tbl diff --git a/tools/perf/arch/parisc/entry/syscalls/Kbuild b/tools/perf/arch= /parisc/entry/syscalls/Kbuild deleted file mode 100644 index 84c6599b4ea6..000000000000 --- a/tools/perf/arch/parisc/entry/syscalls/Kbuild +++ /dev/null @@ -1,3 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -syscall-y +=3D syscalls_32.h -syscall-y +=3D syscalls_64.h diff --git a/tools/perf/arch/parisc/entry/syscalls/Makefile.syscalls b/tool= s/perf/arch/parisc/entry/syscalls/Makefile.syscalls deleted file mode 100644 index ae326fecb83b..000000000000 --- a/tools/perf/arch/parisc/entry/syscalls/Makefile.syscalls +++ /dev/null @@ -1,6 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -syscall_abis_32 +=3D -syscall_abis_64 +=3D - -syscalltbl =3D $(srctree)/tools/perf/arch/parisc/entry/syscalls/syscall.tbl diff --git a/tools/perf/arch/powerpc/entry/syscalls/Kbuild b/tools/perf/arc= h/powerpc/entry/syscalls/Kbuild deleted file mode 100644 index 84c6599b4ea6..000000000000 --- a/tools/perf/arch/powerpc/entry/syscalls/Kbuild +++ /dev/null @@ -1,3 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -syscall-y +=3D syscalls_32.h -syscall-y +=3D syscalls_64.h diff --git a/tools/perf/arch/powerpc/entry/syscalls/Makefile.syscalls b/too= ls/perf/arch/powerpc/entry/syscalls/Makefile.syscalls deleted file mode 100644 index e35afbc57c79..000000000000 --- a/tools/perf/arch/powerpc/entry/syscalls/Makefile.syscalls +++ /dev/null @@ -1,6 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -syscall_abis_32 +=3D nospu -syscall_abis_64 +=3D nospu - -syscalltbl =3D $(srctree)/tools/perf/arch/powerpc/entry/syscalls/syscall.t= bl diff --git a/tools/perf/arch/riscv/entry/syscalls/Kbuild b/tools/perf/arch/= riscv/entry/syscalls/Kbuild deleted file mode 100644 index 9a41e3572c3a..000000000000 --- a/tools/perf/arch/riscv/entry/syscalls/Kbuild +++ /dev/null @@ -1,2 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -syscall-y +=3D syscalls_64.h diff --git a/tools/perf/arch/riscv/entry/syscalls/Makefile.syscalls b/tools= /perf/arch/riscv/entry/syscalls/Makefile.syscalls deleted file mode 100644 index 9668fd1faf60..000000000000 --- a/tools/perf/arch/riscv/entry/syscalls/Makefile.syscalls +++ /dev/null @@ -1,4 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -syscall_abis_32 +=3D riscv memfd_secret -syscall_abis_64 +=3D riscv rlimit memfd_secret diff --git a/tools/perf/arch/s390/entry/syscalls/Kbuild b/tools/perf/arch/s= 390/entry/syscalls/Kbuild deleted file mode 100644 index 9a41e3572c3a..000000000000 --- a/tools/perf/arch/s390/entry/syscalls/Kbuild +++ /dev/null @@ -1,2 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -syscall-y +=3D syscalls_64.h diff --git a/tools/perf/arch/s390/entry/syscalls/Makefile.syscalls b/tools/= perf/arch/s390/entry/syscalls/Makefile.syscalls deleted file mode 100644 index 9762d7abf17c..000000000000 --- a/tools/perf/arch/s390/entry/syscalls/Makefile.syscalls +++ /dev/null @@ -1,5 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -syscall_abis_64 +=3D renameat rlimit memfd_secret - -syscalltbl =3D $(srctree)/tools/perf/arch/s390/entry/syscalls/syscall.tbl diff --git a/tools/perf/arch/sh/entry/syscalls/Kbuild b/tools/perf/arch/sh/= entry/syscalls/Kbuild deleted file mode 100644 index 11707c481a24..000000000000 --- a/tools/perf/arch/sh/entry/syscalls/Kbuild +++ /dev/null @@ -1,2 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -syscall-y +=3D syscalls_32.h diff --git a/tools/perf/arch/sh/entry/syscalls/Makefile.syscalls b/tools/pe= rf/arch/sh/entry/syscalls/Makefile.syscalls deleted file mode 100644 index 25080390e4ed..000000000000 --- a/tools/perf/arch/sh/entry/syscalls/Makefile.syscalls +++ /dev/null @@ -1,4 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -syscall_abis_32 +=3D -syscalltbl =3D $(srctree)/tools/perf/arch/sh/entry/syscalls/syscall.tbl diff --git a/tools/perf/arch/sparc/entry/syscalls/Kbuild b/tools/perf/arch/= sparc/entry/syscalls/Kbuild deleted file mode 100644 index 84c6599b4ea6..000000000000 --- a/tools/perf/arch/sparc/entry/syscalls/Kbuild +++ /dev/null @@ -1,3 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -syscall-y +=3D syscalls_32.h -syscall-y +=3D syscalls_64.h diff --git a/tools/perf/arch/sparc/entry/syscalls/Makefile.syscalls b/tools= /perf/arch/sparc/entry/syscalls/Makefile.syscalls deleted file mode 100644 index 212c1800b644..000000000000 --- a/tools/perf/arch/sparc/entry/syscalls/Makefile.syscalls +++ /dev/null @@ -1,5 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -syscall_abis_32 +=3D -syscall_abis_64 +=3D -syscalltbl =3D $(srctree)/tools/perf/arch/sparc/entry/syscalls/syscall.tbl diff --git a/tools/perf/arch/x86/entry/syscalls/Kbuild b/tools/perf/arch/x8= 6/entry/syscalls/Kbuild deleted file mode 100644 index 84c6599b4ea6..000000000000 --- a/tools/perf/arch/x86/entry/syscalls/Kbuild +++ /dev/null @@ -1,3 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -syscall-y +=3D syscalls_32.h -syscall-y +=3D syscalls_64.h diff --git a/tools/perf/arch/x86/entry/syscalls/Makefile.syscalls b/tools/p= erf/arch/x86/entry/syscalls/Makefile.syscalls deleted file mode 100644 index db3d5d6d4e56..000000000000 --- a/tools/perf/arch/x86/entry/syscalls/Makefile.syscalls +++ /dev/null @@ -1,6 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -syscall_abis_32 +=3D i386 -syscall_abis_64 +=3D - -syscalltbl =3D $(srctree)/tools/perf/arch/x86/entry/syscalls/syscall_%.tbl diff --git a/tools/perf/arch/xtensa/entry/syscalls/Kbuild b/tools/perf/arch= /xtensa/entry/syscalls/Kbuild deleted file mode 100644 index 11707c481a24..000000000000 --- a/tools/perf/arch/xtensa/entry/syscalls/Kbuild +++ /dev/null @@ -1,2 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -syscall-y +=3D syscalls_32.h diff --git a/tools/perf/arch/xtensa/entry/syscalls/Makefile.syscalls b/tool= s/perf/arch/xtensa/entry/syscalls/Makefile.syscalls deleted file mode 100644 index d4aa2358460c..000000000000 --- a/tools/perf/arch/xtensa/entry/syscalls/Makefile.syscalls +++ /dev/null @@ -1,4 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -syscall_abis_32 +=3D -syscalltbl =3D $(srctree)/tools/perf/arch/xtensa/entry/syscalls/syscall.tbl diff --git a/tools/perf/scripts/Makefile.syscalls b/tools/perf/scripts/Make= file.syscalls deleted file mode 100644 index 8bf55333262e..000000000000 --- a/tools/perf/scripts/Makefile.syscalls +++ /dev/null @@ -1,61 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -# This Makefile generates headers in -# tools/perf/arch/$(SRCARCH)/include/generated/asm from the architecture's -# syscall table. This will either be from the generic syscall table, or fr= om a -# table that is specific to that architecture. - -PHONY :=3D all -all: - -obj :=3D $(OUTPUT)arch/$(SRCARCH)/include/generated/asm - -syscall_abis_32 :=3D common,32 -syscall_abis_64 :=3D common,64 -syscalltbl :=3D $(srctree)/tools/scripts/syscall.tbl - -# let architectures override $(syscall_abis_%) and $(syscalltbl) --include $(srctree)/tools/perf/arch/$(SRCARCH)/entry/syscalls/Makefile.sys= calls -include $(srctree)/tools/build/Build.include --include $(srctree)/tools/perf/arch/$(SRCARCH)/entry/syscalls/Kbuild - -systbl :=3D $(srctree)/tools/perf/scripts/syscalltbl.sh - -syscall-y :=3D $(addprefix $(obj)/, $(syscall-y)) - -# Remove stale wrappers when the corresponding files are removed from gene= ric-y -old-headers :=3D $(wildcard $(obj)/*.h) -unwanted :=3D $(filter-out $(syscall-y),$(old-headers)) - -quiet_cmd_remove =3D REMOVE $(unwanted) - cmd_remove =3D rm -f $(unwanted) - -quiet_cmd_systbl =3D SYSTBL $@ - cmd_systbl =3D $(CONFIG_SHELL) $(systbl) \ - $(if $(systbl-args-$*),$(systbl-args-$*),$(systbl-args)) \ - --abis $(subst $(space),$(comma),$(strip $(syscall_abis_$*))) \ - $< $@ - -all: $(syscall-y) - $(if $(unwanted),$(call cmd,remove)) - @: - -$(obj)/syscalls_%.h: $(syscalltbl) $(systbl) FORCE - $(call if_changed,systbl) - -targets :=3D $(syscall-y) - -# Create output directory. Skip it if at least one old header exists -# since we know the output directory already exists. -ifeq ($(old-headers),) -$(shell mkdir -p $(obj)) -endif - -PHONY +=3D FORCE - -FORCE: - -existing-targets :=3D $(wildcard $(sort $(targets))) - --include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) - -.PHONY: $(PHONY) diff --git a/tools/perf/scripts/syscalltbl.sh b/tools/perf/scripts/syscallt= bl.sh deleted file mode 100755 index a39b3013b103..000000000000 --- a/tools/perf/scripts/syscalltbl.sh +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0 -# -# Generate a syscall table header. -# -# Each line of the syscall table should have the following format: -# -# NR ABI NAME [NATIVE] [COMPAT] -# -# NR syscall number -# ABI ABI name -# NAME syscall name -# NATIVE native entry point (optional) -# COMPAT compat entry point (optional) - -set -e - -usage() { - echo >&2 "usage: $0 [--abis ABIS] INFILE OUTFILE" >&2 - echo >&2 - echo >&2 " INFILE input syscall table" - echo >&2 " OUTFILE output header file" - echo >&2 - echo >&2 "options:" - echo >&2 " --abis ABIS ABI(s) to handle (By default, all lines ar= e handled)" - exit 1 -} - -# default unless specified by options -abis=3D - -while [ $# -gt 0 ] -do - case $1 in - --abis) - abis=3D$(echo "($2)" | tr ',' '|') - shift 2;; - -*) - echo "$1: unknown option" >&2 - usage;; - *) - break;; - esac -done - -if [ $# -ne 2 ]; then - usage -fi - -infile=3D"$1" -outfile=3D"$2" - -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[] =3D {" > $outfile -# the params are: nr abi name entry compat -# use _ for intentionally unused variables according to SC2034 -while read nr _ name _ _; do - echo " [$nr] =3D \"$name\"," >> $outfile -done < $sorted_table -echo "};" >> $outfile - -echo "static const uint16_t syscall_sorted_names[] =3D {" >> $outfile - -# When sorting by name, add a suffix of 0s upto 20 characters so that syst= em -# 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 name nr; do - echo " $nr, /* $name */" >> $outfile -done < $sorted_table -echo "};" >> $outfile - -rm -f $sorted_table --=20 2.49.0.rc1.451.g8f38331e32-goog From nobody Tue Dec 16 22:03:27 2025 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 930AB25178C for ; Wed, 19 Mar 2025 05:08:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742360894; cv=none; b=gKSHK9ffp1Dkj+UdNIpOZB7fmCnSLr9rvYfm3kesd4c5vP2+c8wS3D5M0SxVfZqc8EOzN3ZXfHtE7bY49288zNBIo4hvWVxkhrjBj6pYSaJ+p+HoaFC28Zd+it99Oyp/Ie8hAD5jKmEAADXxRGPAOUAXiOhxGf4NrtA3zDcZuWQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742360894; c=relaxed/simple; bh=3uu7CB6A8C3yWHCi12pQmud6FUTrY1STEruRjCdoigM=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=qA3eghNMNE47qj7hGb6hu2she/+sTqSb3TxbiaICtJIKLpTGpCCbSEkvlBa56Z0bkk1f2WMCntGzAXYAPa6t/MIrhw1YSACvEhRXq3gHoJGacMy/hzJy1jsT58vgV5weSf/M8CRXnPz6co+N7VyxJjkTuLljSwyzOplB5YcEO6Q= 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=0SeleJNv; arc=none smtp.client-ip=209.85.128.201 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="0SeleJNv" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6fed889e353so102181107b3.3 for ; Tue, 18 Mar 2025 22:08:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742360891; x=1742965691; 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=ncdSM+lbXMb9xe65qVg6II6RWpGKh15ceN/q8SVr8Hw=; b=0SeleJNvxxWnXXSrOY/Xgfr6Zax5pF4XwRqQRai5S1/gVjgztBe1yxwoB0q2d6Ef00 pedwSaPGfjf18aydB51XZQ7zxDgfOGXSC7L++reIRvqm75+9oqrylEcdZ3Pr+8AH8dTR MzgD9o/IkscTFHUCjGiTLmKYBjaNrlSVmV2hkmhvNfAV57Sifmy2Zjt2KdtpApMyogl6 ogaHKTPiVsaJidy7hHRB6e6pYSRp5+5gVJ2bugvtJpgiQNdUnPN32OZQtRfC/HMESj5B e/uETKpygwoC2osce+jkhe5NiHJJhymcDVDXkcQ/j6WdALh7pBWf7QYD+mAOI7PyvY0K HtXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742360891; x=1742965691; 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=ncdSM+lbXMb9xe65qVg6II6RWpGKh15ceN/q8SVr8Hw=; b=ichb7b9A7QhkH/yQRulo43+inN/RspTUYIwBv5UFX99GQyMSHCQGaleVjDhrDmKiXf 602B9xKRpioOqpyY9SxQgF9wvmyltNLectNigjM4qdGPCuOrpZJR3aWiEIR9EkMPVjYs fQlKicjJbJoulGnEbY/lPlquD9jun87Ur7zPy70plawlEq9gTdViULfI0ZN9ujAqejSL jVFs6U4xy51tqLkaSL9nZxebTh4RAECX4L5lQFvBk1GMI/lPvxjzuAzN7NL8ExHf5e8z wb9zMaLeTbK4KGYetv9PRMwlkufzx0CMhRYO7QDIL/2T8ljxgRLJlFf5yPMIi5OmogoT 3ITw== X-Forwarded-Encrypted: i=1; AJvYcCVr0sO0+NWMAGQXfibP2xooXHMQvI0t2C9I4TXivIykm74kTTLYTFVBjS2QHxJdro47e6jG93u6X33/52Y=@vger.kernel.org X-Gm-Message-State: AOJu0YxHRNN7UGa/GMAY/f4lzBt4ljqu31dVebzISVeeFfPtMiiuOEkn fRkOtOMWFyNOQks5Sx1E2wlkrPaON+mZPqbu08bopXW3zjhykep1FXIFHAfEZW3Hl4TgAVmY22q 7wJMhyQ== X-Google-Smtp-Source: AGHT+IE7t62G3L9y/1w7Zr4bPbVHFfW94O8jbx7xn/oloQNZ3Xii0SOFszp47Hze8CWLQYL2UBnV/ggmaf2X X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:8a11:10b5:af90:6031]) (user=irogers job=sendgmr) by 2002:a05:690c:6501:b0:6ff:1fac:c4fd with SMTP id 00721157ae682-7009bf39905mr12697b3.2.1742360891193; Tue, 18 Mar 2025 22:08:11 -0700 (PDT) Date: Tue, 18 Mar 2025 22:07:38 -0700 In-Reply-To: <20250319050741.269828-1-irogers@google.com> Message-Id: <20250319050741.269828-12-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250319050741.269828-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.rc1.451.g8f38331e32-goog Subject: [PATCH v7 11/14] perf syscalltbl: Mask off ABI type for MIPS system calls 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" Arnd Bergmann described that MIPS system calls don't necessarily start from 0 as an ABI prefix is applied: https://lore.kernel.org/lkml/8ed7dfb2-1e4d-4aa4-a04b-0397a89365d1@app.fastm= ail.com/ When decoding the "id" (aka system call number) for MIPS ignore values greater-than 1000. Signed-off-by: Ian Rogers Reviewed-by: Namhyung Kim --- tools/perf/util/syscalltbl.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/perf/util/syscalltbl.c b/tools/perf/util/syscalltbl.c index 4e6018e2e0b3..67a8ec10e9e4 100644 --- a/tools/perf/util/syscalltbl.c +++ b/tools/perf/util/syscalltbl.c @@ -46,6 +46,14 @@ const char *syscalltbl__name(int e_machine, int id) { const struct syscalltbl *table =3D find_table(e_machine); =20 + if (e_machine =3D=3D 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 =3D id % 1000; + } if (table && id >=3D 0 && id < table->num_to_name_len) return table->num_to_name[id]; return NULL; --=20 2.49.0.rc1.451.g8f38331e32-goog From nobody Tue Dec 16 22:03:27 2025 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 DDF902517A7 for ; Wed, 19 Mar 2025 05:08:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742360898; cv=none; b=FiLeI9BYtuRVhkCdqDCKj28WIz4FOiKsRsVFaF6r3tNusTVKSYOeYcWM+G9/U8Uff8voRb+wvYJ5u2q4nEi03EGAphgWTjwmYWAKnatkLQEsHmvdssmXk1BX6NHvqTmc/Jt91YargXpYunzwev/KVn7CdUWaeFNxuqIEzVKt9zc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742360898; c=relaxed/simple; bh=GbxsG9MTzjhI/k4irKic5R/3koEfGE1mTaI8yVw4hYk=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=CFtSvkDymVBrp61+IAMXMvQKmNMXfPewUPJivMW0maXaDMekpZY8KRq/LbQQZzfJNvysBKfPyXWc9D5CONHTPSqqREQh4W9aqxFtb8zBPccwQiaH38h0clBbFoywl5VCb3gblEKHcFG8VczuLnWomEeCv8H4rBDg08Y/aWfgukc= 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=v0bA5oXx; arc=none smtp.client-ip=209.85.128.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="v0bA5oXx" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6fec6c91630so89806867b3.2 for ; Tue, 18 Mar 2025 22:08:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742360894; x=1742965694; 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=L7xBPeAI1ZGK/na4YhBc+S5M0v2o7F6+AZ1yRtBTaOg=; b=v0bA5oXxduq8hu5ZaHmP+Ec6uKeiavXOWxlt6YFB/Ra/mjds3esYOr7zmyPXrYxl1S mvNyb/WOnb/irLREtf9Ku1IcWE4XfoxrRDZdDkH0v79Aca+WakM8PF+Fd0tOrt6H1LV5 UFtb5HWSqNq9SN7/pyz09UVXcJtbascqW7v8p9pXtCEdyf19ahpIEYOZYVnL2dCRewsK l0Znc8wYHkUF3hzfUgzFiEgQhtWTtl9dTzlBN/zP2+h30suUiQ5ndCmd8Z6zbuMdMc6S 92woIVMHf5TdzomEHbE4FMPD7Co0v3c56SkAMkoeeaSeMmRmIdLmVusZpCquWKcVrIqi YKNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742360894; x=1742965694; 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=L7xBPeAI1ZGK/na4YhBc+S5M0v2o7F6+AZ1yRtBTaOg=; b=PmUwkDuZYcN7w2VxZc5BirVfBymKhuYmlYP9LU9RGLA5xiNEJaKoH7osVY+ew32SSP +ys6nXIZ6kL5WiCQ2z5288mYd+O8BbAZJPxSW4q3S6d290NlzxIlJcnPd/WiLcI175oH M5wgga2J/AJugsxmMAo8nD7BgXBc9zvfwqs764bpCYxlNTg9mBAIQRIZ2zVhoixKQJVN XWMvQHOfWTB6tDgjIokye8y5tZW2xzHCSBY8HahNWXi3XEOYVbP+Tv/Gy8TcGb06NQ5s ytNn6F9jXlHCad8hkuwZr8tgPp6xENkqFmpUccq8PE33mOmPMpSzEz0pEp9HEGe9Db6+ sT2w== X-Forwarded-Encrypted: i=1; AJvYcCUbLVhgiQQP7o3ptLtyNGeHlguItHR/Z+Y9LjJwVMWp7ISReueBr2IKLSo81A2ZmmsIlvTLKAx1iC122mg=@vger.kernel.org X-Gm-Message-State: AOJu0YwtIRhVajmyw3VpjpWnYOkjniokh8M6a0Egr3x/6dEUtvNag0AF +xMtzGQ5RJBEzCw/n1rjnW8leVrfkdRU7aW1B7FAhxcfrBQIQ+UWOXuY8sZxpkz5mZUNjLe9tHN H5j/nzA== X-Google-Smtp-Source: AGHT+IED/ZLlykbehWpsCbnxI7/VEXCzdceMElPMiVtqa8xKpgrgI1AFRxFexUYRexGCPPRyPnT6SSPwC/n+ X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:8a11:10b5:af90:6031]) (user=irogers job=sendgmr) by 2002:a05:6902:1824:b0:e5b:33c4:7279 with SMTP id 3f1490d57ef6-e667b432965mr506276.4.1742360893839; Tue, 18 Mar 2025 22:08:13 -0700 (PDT) Date: Tue, 18 Mar 2025 22:07:39 -0700 In-Reply-To: <20250319050741.269828-1-irogers@google.com> Message-Id: <20250319050741.269828-13-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250319050741.269828-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.rc1.451.g8f38331e32-goog Subject: [PATCH v7 12/14] perf trace: Make syscall table stable 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" Namhyung fixed the syscall table being reallocated and moving by reloading the system call pointer after a move: https://lore.kernel.org/lkml/Z9YHCzINiu4uBQ8B@google.com/ This could be brittle so this patch changes the syscall table to be an array of pointers of "struct syscall" that don't move. Remove unnecessary copies and searches with this change. Signed-off-by: Ian Rogers Reviewed-by: Namhyung Kim --- tools/perf/builtin-trace.c | 87 +++++++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 34 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 1c080d95c1e2..a5f31472980b 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -151,7 +151,7 @@ struct trace { struct perf_tool tool; struct { /** Sorted sycall numbers used by the trace. */ - struct syscall *table; + struct syscall **table; /** Size of table. */ size_t table_size; struct { @@ -2473,24 +2473,41 @@ static size_t syscall__scnprintf_args(struct syscal= l *sc, char *bf, size_t size, return printed; } =20 -static void syscall__init(struct syscall *sc, int e_machine, int id) +static struct syscall *syscall__new(int e_machine, int id) { - memset(sc, 0, sizeof(*sc)); + struct syscall *sc =3D zalloc(sizeof(*sc)); + + if (!sc) + return NULL; + sc->e_machine =3D e_machine; sc->id =3D id; + return sc; } =20 -static void syscall__exit(struct syscall *sc) +static void syscall__delete(struct syscall *sc) { if (!sc) return; =20 - zfree(&sc->arg_fmt); + free(sc->arg_fmt); + free(sc); +} + +static int syscall__bsearch_cmp(const void *key, const void *entry) +{ + const struct syscall *a =3D key, *b =3D *((const struct syscall **)entry); + + if (a->e_machine !=3D b->e_machine) + return a->e_machine - b->e_machine; + + return a->id - b->id; } =20 static int syscall__cmp(const void *va, const void *vb) { - const struct syscall *a =3D va, *b =3D vb; + const struct syscall *a =3D *((const struct syscall **)va); + const struct syscall *b =3D *((const struct syscall **)vb); =20 if (a->e_machine !=3D b->e_machine) return a->e_machine - b->e_machine; @@ -2504,27 +2521,33 @@ static struct syscall *trace__find_syscall(struct t= race *trace, int e_machine, i .e_machine =3D e_machine, .id =3D id, }; - struct syscall *sc, *tmp; + struct syscall *sc, **tmp; =20 if (trace->syscalls.table) { - sc =3D bsearch(&key, trace->syscalls.table, trace->syscalls.table_size, - sizeof(struct syscall), syscall__cmp); - if (sc) - return sc; + struct syscall **sc_entry =3D bsearch(&key, trace->syscalls.table, + trace->syscalls.table_size, + sizeof(trace->syscalls.table[0]), + syscall__bsearch_cmp); + + if (sc_entry) + return *sc_entry; } =20 + sc =3D syscall__new(e_machine, id); + if (!sc) + return NULL; + tmp =3D reallocarray(trace->syscalls.table, trace->syscalls.table_size + = 1, - sizeof(struct syscall)); - if (!tmp) + sizeof(trace->syscalls.table[0])); + if (!tmp) { + syscall__delete(sc); return NULL; + } =20 trace->syscalls.table =3D tmp; - sc =3D &trace->syscalls.table[trace->syscalls.table_size++]; - syscall__init(sc, e_machine, id); - qsort(trace->syscalls.table, trace->syscalls.table_size, sizeof(struct sy= scall), + trace->syscalls.table[trace->syscalls.table_size++] =3D sc; + qsort(trace->syscalls.table, trace->syscalls.table_size, sizeof(trace->sy= scalls.table[0]), syscall__cmp); - sc =3D bsearch(&key, trace->syscalls.table, trace->syscalls.table_size, - sizeof(struct syscall), syscall__cmp); return sc; } =20 @@ -3855,14 +3878,14 @@ static int trace__bpf_sys_enter_beauty_map(struct t= race *trace, int e_machine, i return -1; } =20 -static struct bpf_program *trace__find_usable_bpf_prog_entry(struct trace = *trace, struct syscall *_sc) +static struct bpf_program *trace__find_usable_bpf_prog_entry(struct trace = *trace, + struct syscall *sc) { - struct syscall sc =3D *_sc; /* Copy as trace__syscall_info may invalidate= pointer. */ struct tep_format_field *field, *candidate_field; /* * We're only interested in syscalls that have a pointer: */ - for (field =3D sc.args; field; field =3D field->next) { + for (field =3D sc->args; field; field =3D field->next) { if (field->flags & TEP_FIELD_IS_POINTER) goto try_to_find_pair; } @@ -3870,18 +3893,17 @@ static struct bpf_program *trace__find_usable_bpf_p= rog_entry(struct trace *trace return NULL; =20 try_to_find_pair: - for (int i =3D 0, num_idx =3D syscalltbl__num_idx(sc.e_machine); i < num_= idx; ++i) { - int id =3D syscalltbl__id_at_idx(sc.e_machine, i); - /* calling trace__syscall_info() may invalidate '_sc' */ - struct syscall *pair =3D trace__syscall_info(trace, NULL, sc.e_machine, = id); + for (int i =3D 0, num_idx =3D syscalltbl__num_idx(sc->e_machine); i < num= _idx; ++i) { + int id =3D syscalltbl__id_at_idx(sc->e_machine, i); + struct syscall *pair =3D trace__syscall_info(trace, NULL, sc->e_machine,= id); struct bpf_program *pair_prog; bool is_candidate =3D false; =20 - if (pair =3D=3D NULL || pair->id =3D=3D sc.id || + if (pair =3D=3D NULL || pair->id =3D=3D sc->id || pair->bpf_prog.sys_enter =3D=3D trace->skel->progs.syscall_unaugment= ed) continue; =20 - for (field =3D sc.args, candidate_field =3D pair->args; + for (field =3D sc->args, candidate_field =3D pair->args; field && candidate_field; field =3D field->next, candidate_field = =3D candidate_field->next) { bool is_pointer =3D field->flags & TEP_FIELD_IS_POINTER, candidate_is_pointer =3D candidate_field->flags & TEP_FIELD_IS_POI= NTER; @@ -3948,7 +3970,8 @@ static struct bpf_program *trace__find_usable_bpf_pro= g_entry(struct trace *trace goto next_candidate; } =20 - pr_debug("Reusing \"%s\" BPF sys_enter augmenter for \"%s\"\n", pair->na= me, sc.name); + pr_debug("Reusing \"%s\" BPF sys_enter augmenter for \"%s\"\n", pair->na= me, + sc->name); return pair_prog; next_candidate: continue; @@ -4044,11 +4067,7 @@ static int trace__init_syscalls_bpf_prog_array_maps(= struct trace *trace, int e_m pair_prog =3D trace__find_usable_bpf_prog_entry(trace, sc); if (pair_prog =3D=3D NULL) continue; - /* - * Get syscall info again as find usable entry above might - * modify the syscall table and shuffle it. - */ - sc =3D trace__syscall_info(trace, NULL, e_machine, key); + sc->bpf_prog.sys_enter =3D pair_prog; =20 /* @@ -5316,7 +5335,7 @@ static void trace__exit(struct trace *trace) zfree(&trace->ev_qualifier_ids.entries); if (trace->syscalls.table) { for (size_t i =3D 0; i < trace->syscalls.table_size; i++) - syscall__exit(&trace->syscalls.table[i]); + syscall__delete(trace->syscalls.table[i]); zfree(&trace->syscalls.table); } zfree(&trace->perfconfig_events); --=20 2.49.0.rc1.451.g8f38331e32-goog From nobody Tue Dec 16 22:03:27 2025 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 37E7B2528F9 for ; Wed, 19 Mar 2025 05:08:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742360898; cv=none; b=Qv79u4VdddGcxN1a205f1vqXp72MKRqNjv5BF2Lriwy6OQt2JpcDjCIPxKo8L0cCaKgCluKpUowHjqLJaTmMVOzMTeNxkpNvhACLwKDkokYDIkFNlq43lJleIiCONN/53gTuTHFgcSMlmxAoR6kpAvqP4hKFjkWeICYht7b269M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742360898; c=relaxed/simple; bh=tSOlzIg1yXOwUyw6zWCMnGwqLZhjjUkDbEkMOcp7FiY=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=dS9pwMtdbNatOAKdzSFsFsuCDQ41/CXdb+GZxcUQdWFFVgo7FE/TFvFg3+f3WJ/wFx+RAsL2T6kucikIERuxK9ZCPD/zgNY0NYu9zLurB02uaj6zR66zT1/GuVYxY51R5FUTVcNLmxkyglS1tlbD6+yMTjklAwjvJFkF29JF+Qk= 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=s714uWxu; arc=none smtp.client-ip=209.85.128.201 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="s714uWxu" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6feeba593dbso88554507b3.1 for ; Tue, 18 Mar 2025 22:08:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742360896; x=1742965696; 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=y38GESo485gGDIFJ1xMbGn6kWCzBk3/syJLY+zfYrVg=; b=s714uWxuhF3pTlhV44GX3YgG/HhG8jtQv+CQJQokWHeM++q0E5estCCtU2madufD53 SZMwWHm0DRiARV3I1U556Y3TLAiHwfB3Rs4fAg83bIuwhOnBjYIUbX8MkDM2FIomdT5R 63kFygiCzpda8COv65Lf3dTw515mN6wJzMAnQ0M/ihvnaHtZBa70+iiT5Cfnlit+QS2y jcTqw+w8ZPkwhzWFJuF7VBGhTx4dA7NM+7dOWquoBqdApGiTM5mRSzsu9ZNyf3i91I5U nOOjQT6tGoMMcg+FuA+gq6Q+hdGti89OwRoOOU9OvcoCI3SwPFkMDSN1dYppy2Ijkm2Y /kBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742360896; x=1742965696; 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=y38GESo485gGDIFJ1xMbGn6kWCzBk3/syJLY+zfYrVg=; b=tSKZtbkQ5P1++muU0N2r5cRxOzPzgw1a1J/6UG2sinzLglcs6iSdKOtzxdhTGJZfG0 iFdY1+sn5dum3ZEjNIrhMO7UAhHC18W65UkClwyDZiM2fvndQngX/5plB4QMy13PJJUY tBgYXgXW5tQHmANtj8+uzymlwm0V07b7zfERJExkLBJa6YOelGfaeDWa6s5XBDjw3phe P1uEKEd4obG5JUg4QkCJZFRCDBxAO6msNOSBWesp8g4ad47/I/7yTZQjIW3BcfTzTKly BfbfUSwkccqgyep1HGkgcDCXZefyfbOQspeAYqvR0SDPDSeHITP8SVjODsXnbEzYu6OM h9TQ== X-Forwarded-Encrypted: i=1; AJvYcCVcTK3TDrzi+cxDy3+IssUoHb2xnkqVZtZC0TOl9Jvq/X/ulaOwRBEiUxgtzkpm/c6o49dF5k0vThJq0bk=@vger.kernel.org X-Gm-Message-State: AOJu0YxQIV89ppX+LAGU834RuAJF378zHWqkNRRBr/Xog0bsxlhoAVEb 7055N8SE96l4AcEo8VApNXSIAAddvhGmoypyxpQI01wrbOyY/sIXsdozZSgjsj5a6PGE560FWUe dfk/0FA== X-Google-Smtp-Source: AGHT+IFPFakwCyr0uM1/sz8X8s9dtQflbQjZm9fJ42RkwL6er5xIYEKy4XS6bbEhodJ8Ew/JRCn4+wa1XjLm X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:8a11:10b5:af90:6031]) (user=irogers job=sendgmr) by 2002:a05:690c:d8e:b0:6fe:e77c:7741 with SMTP id 00721157ae682-7009c211810mr6127b3.8.1742360896116; Tue, 18 Mar 2025 22:08:16 -0700 (PDT) Date: Tue, 18 Mar 2025 22:07:40 -0700 In-Reply-To: <20250319050741.269828-1-irogers@google.com> Message-Id: <20250319050741.269828-14-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250319050741.269828-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.rc1.451.g8f38331e32-goog Subject: [PATCH v7 13/14] perf trace: Fix BTF memory leak 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" Add missing btf__free in trace__exit. Signed-off-by: Ian Rogers Reviewed-by: Namhyung Kim --- tools/perf/builtin-trace.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index a5f31472980b..1d4ad5d19b10 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -5339,6 +5339,10 @@ static void trace__exit(struct trace *trace) zfree(&trace->syscalls.table); } zfree(&trace->perfconfig_events); +#ifdef HAVE_LIBBPF_SUPPORT + btf__free(trace->btf); + trace->btf =3D NULL; +#endif } =20 #ifdef HAVE_BPF_SKEL --=20 2.49.0.rc1.451.g8f38331e32-goog From nobody Tue Dec 16 22:03:27 2025 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 6797525291F for ; Wed, 19 Mar 2025 05:08:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742360901; cv=none; b=s/DrYPCQv55BU+hlJRIIAkXt4dMis+sTE+dvm7v+VvhWD72ZZBrATBQ45S8wJczbAizee157Ixrx8W+QeIAb5m5C4RMX4uB4T+Wybk5+0cVg+diyUM5jAYLEbr1dh5MCyujBm30U9pEZFfMGzbw8aE0G5w3EmkzTxFlQ3rHciWg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742360901; c=relaxed/simple; bh=FwwCUQYWW0iPLjUpMdjojzAG65ocZ3jEUzcBFQsWjIY=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=a2QcaTiq+5SoW/REj5mu8f+uFrcq+xhW8X/kqwvsmEFqbWMsRcMt+4azHRIFjiHu9RhsKknFEQG5pKidHu4yDhyBGLrqElkF/N6pSsiNDb+ttVNHRVYe0gXyJTPC1tTIh4v8XOW0a/wlOPBzpXMdvPJz0L87CtHyv+lFweQbqIs= 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=mTs64ygf; arc=none smtp.client-ip=209.85.128.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="mTs64ygf" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6fed889e353so102182587b3.3 for ; Tue, 18 Mar 2025 22:08:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742360899; x=1742965699; 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=jGnh5R7F2nGjibuMN1IiOugHr5YAQ01+XconQh81ims=; b=mTs64ygfkHOpOUAgupDi4Vjty844ukF4nAIVX11Ymk/TgNL93v9sOI72KOUy3ovoFx 6lC2l8B2Mxg6ifGjYF2tRHE3BKppM8pYNlP8b/wvRHDP3FiHEL5V64M0vtW1NkOU7SWL vLtT28jgPlWb7M8PtjWtR2rJmuQIN1K3QNYTrZ8MMev9tg6ex6KeyTCb3vR8yXcz0uTj jnfOWCjNQZyvzgCP2mVuwKpWA8NpwRTj8puDdMIGPLZsekKpN1TBWnSwW9pb6Oa3nPBt Eq0UGGlD8h0K6c9Aesc4mLJqFL3X94OUGmiJhJ3C+1XWy2eHjwVMU6lf3LRWk7iHGJss ccbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742360899; x=1742965699; 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=jGnh5R7F2nGjibuMN1IiOugHr5YAQ01+XconQh81ims=; b=rKKKNC6eBriFEZrvDQDLC84bqu7gGeMwoP34dDOdFO2LrxjFiGIS30AQDYFKYc5hjH 9YYZxDQwPQ3Ade2iQIeVh3NsANNuiRw+H1+wmtUG9KsxJeqKWpwiK82g0L5vqa2/T9KM iq5qSdau79yF3j6it3BiD354pURQ3wDTNhP7ENjEFZV9df5FiTTpVlTPZADKl53EBBsa 0FAsa9+Z5fEF7k75Evd0W2JpOMs7XQMm0eWcohcHm7vXf11Pve+1jNTas6C9kxPQ8xc9 EjIqRZGxE7LWZMR5dgKSmSnGmQhgyxIlZywSNzXVVfBJ2jEHNcvhdFXX5q5MtHw4l8Hv vx8Q== X-Forwarded-Encrypted: i=1; AJvYcCWnW1yk32fMd0VbaY/aAj/npOvS1eeapyrxyqk/DZVBculQTASzI1/2O0xISKF12X2x8CDkcYhlt7ILoDE=@vger.kernel.org X-Gm-Message-State: AOJu0YwREIpGxTcX1EhenzrOxFqmJChlDs5TgygTrhSwoIf1KEwn27O4 nF+qrk3LHo69a4Ph34cvSe/vDHshl2nOFnIfL3C/D2cI1+55SaA/Gqb6ZCtrtBXIkySvq2Ydgg8 1dvdZlQ== X-Google-Smtp-Source: AGHT+IHv1nfcfv3Ye5fOTqwhfAPWbuVvzkQzn8h4pmksBhQF9eFLTiSxCvjG8QByREOpkefDEY1DbG6A3hXY X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:8a11:10b5:af90:6031]) (user=irogers job=sendgmr) by 2002:a25:dc03:0:b0:e63:699a:4e6b with SMTP id 3f1490d57ef6-e667b41463bmr514276.4.1742360898600; Tue, 18 Mar 2025 22:08:18 -0700 (PDT) Date: Tue, 18 Mar 2025 22:07:41 -0700 In-Reply-To: <20250319050741.269828-1-irogers@google.com> Message-Id: <20250319050741.269828-15-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250319050741.269828-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.rc1.451.g8f38331e32-goog Subject: [PATCH v7 14/14] perf trace: Fix evlist memory leak 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" Leak sanitizer was reporting a memory leak in the "perf record and replay" test. Add evlist__delete to trace__exit, also ensure trace__exit is called after trace__record. Signed-off-by: Ian Rogers Reviewed-by: Namhyung Kim --- tools/perf/builtin-trace.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 1d4ad5d19b10..a102748bd0c9 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -5339,6 +5339,8 @@ static void trace__exit(struct trace *trace) zfree(&trace->syscalls.table); } zfree(&trace->perfconfig_events); + evlist__delete(trace->evlist); + trace->evlist =3D NULL; #ifdef HAVE_LIBBPF_SUPPORT btf__free(trace->btf); trace->btf =3D NULL; @@ -5719,8 +5721,10 @@ int cmd_trace(int argc, const char **argv) } } =20 - if ((argc >=3D 1) && (strcmp(argv[0], "record") =3D=3D 0)) - return trace__record(&trace, argc-1, &argv[1]); + if ((argc >=3D 1) && (strcmp(argv[0], "record") =3D=3D 0)) { + err =3D trace__record(&trace, argc-1, &argv[1]); + goto out; + } =20 /* Using just --errno-summary will trigger --summary */ if (trace.errno_summary && !trace.summary && !trace.summary_only) --=20 2.49.0.rc1.451.g8f38331e32-goog