From nobody Sun Feb 8 12:38:00 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B582189BB3; Tue, 4 Mar 2025 02:28:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741055319; cv=none; b=Ptwn31ISIbUpPfAjJyPxNJ4r9dU1GNhazlb7EhhYaZFl93wqEonNwWziJ9jkyu2RagKmHCnHwHCyiudGaBJm9wMcDGaY3TAjdYsV4RHr/Rjqcin0ix7/qR56tuUIZF3b0UkLvdfTzVYOy/GmYjDZMw/Bgt4IGMa3HNmOJTYtCW4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741055319; c=relaxed/simple; bh=nZ8ZCLcaVnVr2jRx2sOVDA3QIxlrVukP83MzQFyKq/E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nCocXH4iOLu+kqJImZeFjJ+wfizksDUWf/f3wAMvSAgGLnPNS6ezJc1xMWebKx4rKIR0Wkc5dwQK4FpBf61j0BTCu29o0xolZhPVIPBGC3fpDetF8YLcFEmkJTSXvkxglx5BdboTJ2PXBm5S872S7vI46gsn2P7Hs4MJZnBg9sM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZhWHGFC6; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZhWHGFC6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F48EC4CEEA; Tue, 4 Mar 2025 02:28:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741055318; bh=nZ8ZCLcaVnVr2jRx2sOVDA3QIxlrVukP83MzQFyKq/E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZhWHGFC6hdz9nQVlYOGdGbB7fNpV5qVC1Vgr3GnYhRbT++09E6fkAhqyQSDpwEkR8 LP7dOe/KhRIl12EPH/lixXsIfJ6zdfvKWOElJ3VnbXmI86sIaEQKpbtWzsJ/lG0ocB imelithCpuC72BCrU0/aHhIF9CElCl0KanCPV8lfYjTjvX9rI7Zh7jQyhWCcHC441M IYq7vMYGQjvH6R5mukvadhdgSbn3MQeXaKDhPEoenuEiINHbJuUyULijiLkmVj2b/n 1/QOVp/UM/5jCH/t/Otlrszpmrwh+HsO7LSr4q40Kc+8XmOYiKMt7pr74Y9PSlkYML nEQIBn//NNv1w== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH v2 1/6] perf test: Add --metric-only to perf stat output tests Date: Mon, 3 Mar 2025 18:28:32 -0800 Message-ID: <20250304022837.1877845-2-namhyung@kernel.org> X-Mailer: git-send-email 2.48.1.711.g2feabab25a-goog In-Reply-To: <20250304022837.1877845-1-namhyung@kernel.org> References: <20250304022837.1877845-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a test case for --metric-only for std, csv, json output mode using shadow IPC metric from instructions and cycles events. It should produce 'insn per cycle' metric. But currently JSON output has (none) 'GHz' as well. It looks like a bug but I don't have enough time to debug it for now so I made it pass. :( $ perf stat --metric-only -e instructions,cycles true Performance counter stats for 'true': 0.56 0.002127319 seconds time elapsed 0.002077000 seconds user 0.000000000 seconds sys $ perf stat -x, --metric-only -e instructions,cycles true 0.55,, $ perf stat -j --metric-only -e instructions,cycles true {"insn per cycle" : "0.53", "GHz" : "none"} $ perf test output -v 5: Test data source output : Ok 31: Sort output of hist entries : Ok 88: perf stat CSV output linter : Ok 90: perf stat JSON output linter : Ok 92: perf stat STD output linter : Ok Suggested-by: Ian Rogers Signed-off-by: Namhyung Kim Tested-by: Thomas Falcon --- tools/perf/tests/shell/lib/perf_json_output_lint.py | 7 +++++++ tools/perf/tests/shell/lib/stat_output.sh | 8 ++++++++ tools/perf/tests/shell/stat+csv_output.sh | 2 ++ tools/perf/tests/shell/stat+json_output.sh | 9 +++++++++ tools/perf/tests/shell/stat+std_output.sh | 8 ++++++++ 5 files changed, 34 insertions(+) diff --git a/tools/perf/tests/shell/lib/perf_json_output_lint.py b/tools/pe= rf/tests/shell/lib/perf_json_output_lint.py index b066d721f89735df..9e772a89ce381636 100644 --- a/tools/perf/tests/shell/lib/perf_json_output_lint.py +++ b/tools/perf/tests/shell/lib/perf_json_output_lint.py @@ -19,6 +19,7 @@ ap.add_argument('--per-cluster', action=3D'store_true') ap.add_argument('--per-die', action=3D'store_true') ap.add_argument('--per-node', action=3D'store_true') ap.add_argument('--per-socket', action=3D'store_true') +ap.add_argument('--metric-only', action=3D'store_true') ap.add_argument('--file', type=3Dargparse.FileType('r'), default=3Dsys.std= in) args =3D ap.parse_args() =20 @@ -64,6 +65,8 @@ Lines =3D args.file.readlines() 'socket': lambda x: True, 'thread': lambda x: True, 'unit': lambda x: True, + 'insn per cycle': lambda x: isfloat(x), + 'GHz': lambda x: True, # FIXME: it seems unintended for --metric-on= ly } input =3D '[\n' + ','.join(Lines) + '\n]' for item in json.loads(input): @@ -78,6 +81,8 @@ Lines =3D args.file.readlines() pass elif count - 1 in expected_items and 'metric-threshold' in item: pass + elif count in expected_items and 'insn per cycle' in item: + pass elif count not in expected_items: raise RuntimeError(f'wrong number of fields. counted {count} expec= ted {expected_items}' f' in \'{item}\'') @@ -95,6 +100,8 @@ Lines =3D args.file.readlines() expected_items =3D [6, 8] elif args.per_core or args.per_socket or args.per_node or args.per_die o= r args.per_cluster or args.per_cache: expected_items =3D [7, 9] + elif args.metric_only: + expected_items =3D [1, 2] else: # If no option is specified, don't check the number of items. expected_items =3D -1 diff --git a/tools/perf/tests/shell/lib/stat_output.sh b/tools/perf/tests/s= hell/lib/stat_output.sh index 9a176ceae4a3c3a2..4d4aac547f0109d1 100644 --- a/tools/perf/tests/shell/lib/stat_output.sh +++ b/tools/perf/tests/shell/lib/stat_output.sh @@ -148,6 +148,14 @@ check_per_socket() echo "[Success]" } =20 +check_metric_only() +{ + echo -n "Checking $1 output: metric only " + perf stat --metric-only $2 -e instructions,cycles true + commachecker --metric-only + echo "[Success]" +} + # The perf stat options for per-socket, per-core, per-die # and -A ( no_aggr mode ) uses the info fetched from this # directory: "/sys/devices/system/cpu/cpu*/topology". For diff --git a/tools/perf/tests/shell/stat+csv_output.sh b/tools/perf/tests/s= hell/stat+csv_output.sh index fc2d8cc6e5e0b1e5..7a6f6e1774028322 100755 --- a/tools/perf/tests/shell/stat+csv_output.sh +++ b/tools/perf/tests/shell/stat+csv_output.sh @@ -44,6 +44,7 @@ function commachecker() ;; "--per-die") exp=3D8 ;; "--per-cluster") exp=3D8 ;; "--per-cache") exp=3D8 + ;; "--metric-only") exp=3D2 esac =20 while read line @@ -75,6 +76,7 @@ check_interval "CSV" "$perf_cmd" check_event "CSV" "$perf_cmd" check_per_thread "CSV" "$perf_cmd" check_per_node "CSV" "$perf_cmd" +check_metric_only "CSV" "$perf_cmd" if [ $skip_test -ne 1 ] then check_system_wide_no_aggr "CSV" "$perf_cmd" diff --git a/tools/perf/tests/shell/stat+json_output.sh b/tools/perf/tests/= shell/stat+json_output.sh index 6b630d33c3287899..a4f257ea839e1368 100755 --- a/tools/perf/tests/shell/stat+json_output.sh +++ b/tools/perf/tests/shell/stat+json_output.sh @@ -173,6 +173,14 @@ check_per_socket() echo "[Success]" } =20 +check_metric_only() +{ + echo -n "Checking json output: metric only " + perf stat -j --metric-only -e instructions,cycles -o "${stat_output}" true + $PYTHON $pythonchecker --metric-only --file "${stat_output}" + echo "[Success]" +} + # The perf stat options for per-socket, per-core, per-die # and -A ( no_aggr mode ) uses the info fetched from this # directory: "/sys/devices/system/cpu/cpu*/topology". For @@ -207,6 +215,7 @@ check_interval check_event check_per_thread check_per_node +check_metric_only if [ $skip_test -ne 1 ] then check_system_wide_no_aggr diff --git a/tools/perf/tests/shell/stat+std_output.sh b/tools/perf/tests/s= hell/stat+std_output.sh index 0f7967be60afdc7d..6fee67693ba7a9be 100755 --- a/tools/perf/tests/shell/stat+std_output.sh +++ b/tools/perf/tests/shell/stat+std_output.sh @@ -30,6 +30,7 @@ trap trap_cleanup EXIT TERM INT function commachecker() { local prefix=3D1 + local -i metric_only=3D0 =20 case "$1" in "--interval") prefix=3D2 @@ -41,6 +42,7 @@ function commachecker() ;; "--per-die") prefix=3D3 ;; "--per-cache") prefix=3D3 ;; "--per-cluster") prefix=3D3 + ;; "--metric-only") metric_only=3D1 esac =20 while read line @@ -60,6 +62,9 @@ function commachecker() x=3D${main_body%#*} [ "$x" =3D "" ] && continue =20 + # Check metric only - if it has a non-empty result + [ $metric_only -eq 1 ] && return 0 + # Skip metrics without event name y=3D${main_body#*#} for i in "${!skip_metric[@]}"; do @@ -84,6 +89,8 @@ function commachecker() exit 1; } done < "${stat_output}" + + [ $metric_only -eq 1 ] && exit 1 return 0 } =20 @@ -95,6 +102,7 @@ check_system_wide "STD" "$perf_cmd" check_interval "STD" "$perf_cmd" check_per_thread "STD" "$perf_cmd" check_per_node "STD" "$perf_cmd" +check_metric_only "STD" "$perf_cmd" if [ $skip_test -ne 1 ] then check_system_wide_no_aggr "STD" "$perf_cmd" --=20 2.48.1.711.g2feabab25a-goog From nobody Sun Feb 8 12:38:00 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B993719E83E; Tue, 4 Mar 2025 02:28:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741055319; cv=none; b=N0qJQBhboD/sqc21z5dMHwrlX+d9/svRrOLbQBHlj01I0HNmSdmzzCCCfZo1EuAghYzacWh03EjLQhSDYfIyZVuwmLoqDXFf2HkKalIcIS3iwzMdgdkK1esMTiQBW0E/RY7/nyQCdwVa+Cm8p5rH5vmspXDhkxcxiX4J6GCrsCc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741055319; c=relaxed/simple; bh=nM37e+Q5uGyppMyuixp0WQG/9tKW9QwJMxGrmJqtW44=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cwxd+XuwLAP0airBnmGlxxBo3qZlv6S4MlMwAgFpDb1YabZyCLmMoZQNESzGYFYkM4mBv4B9RvGrUSHM004jq2pRBbYdAz6jCXm9v3PPqixeuQoW0z/t47ipSyAqctVciRfqmsCPKw6vteXfPrjB8/1K2LOQDV79ty3F9G88LWU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SVkU52Sw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SVkU52Sw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E5A59C4CEEB; Tue, 4 Mar 2025 02:28:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741055319; bh=nM37e+Q5uGyppMyuixp0WQG/9tKW9QwJMxGrmJqtW44=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SVkU52SwnhdDy7MpLrwBbMd2ZzWj69VfaQhE4kGr9YBNiqf+LV4M2ytDsc0i6wkmX M3hAqlAFwEhCGX6IcQssIPsWJCENrRW9jFEX9UcAdKGsF851ogS0CGC2zdAMJBu0a8 ATzC1iMXw1IkKaiB5mAO/+rSwCdAuojsGiAxEgtSCzU7DM2PaZeot70r2KdfhCEfi4 bE95AdBTMOqHpYYd9dz0bTlEiKo3vHtfN8e0H337QdCA4aLTbBYdc45+ULaKEWH2Jq Dq74LoyW6aUBH4qOVyf/ZBg95unl19DOPGC7q+v+iBkXFyOVtzArUJelCdX75stGf6 N4SRjmrZ/08qw== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Masami Hiramatsu Subject: [PATCH v2 2/6] perf test: Skip perf probe tests when running as non-root Date: Mon, 3 Mar 2025 18:28:33 -0800 Message-ID: <20250304022837.1877845-3-namhyung@kernel.org> X-Mailer: git-send-email 2.48.1.711.g2feabab25a-goog In-Reply-To: <20250304022837.1877845-1-namhyung@kernel.org> References: <20250304022837.1877845-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" perf trace requires root because it needs to use [ku]probes. Skip those test when it's not run as root. Before: $ perf test probe 47: Probe SDT events : Ok 104: test perf probe of function from different CU : FA= ILED! 115: perftool-testsuite_probe : FA= ILED! 117: Add vfs_getname probe to get syscall args filenames : FA= ILED! 118: probe libc's inet_pton & backtrace it with ping : FA= ILED! 119: Use vfs_getname probe to get syscall args filenames : FA= ILED! After: $ perf test probe 47: Probe SDT events : Ok 104: test perf probe of function from different CU : Sk= ip 115: perftool-testsuite_probe : Sk= ip 117: Add vfs_getname probe to get syscall args filenames : Sk= ip 118: probe libc's inet_pton & backtrace it with ping : Sk= ip 119: Use vfs_getname probe to get syscall args filenames : Sk= ip Cc: Masami Hiramatsu Signed-off-by: Namhyung Kim Tested-by: Thomas Falcon --- tools/perf/tests/shell/perftool-testsuite_probe.sh | 1 + tools/perf/tests/shell/probe_vfs_getname.sh | 1 + tools/perf/tests/shell/record+probe_libc_inet_pton.sh | 1 + .../tests/shell/record+script_probe_vfs_getname.sh | 1 + .../perf/tests/shell/test_uprobe_from_different_cu.sh | 11 +++++------ 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/tools/perf/tests/shell/perftool-testsuite_probe.sh b/tools/per= f/tests/shell/perftool-testsuite_probe.sh index 7b1bfd0f888fc30c..3863df16c19b9fa2 100755 --- a/tools/perf/tests/shell/perftool-testsuite_probe.sh +++ b/tools/perf/tests/shell/perftool-testsuite_probe.sh @@ -2,6 +2,7 @@ # perftool-testsuite_probe (exclusive) # SPDX-License-Identifier: GPL-2.0 =20 +[ "$(id -u)" =3D 0 ] || exit 2 test -d "$(dirname "$0")/base_probe" || exit 2 cd "$(dirname "$0")/base_probe" || exit 2 status=3D0 diff --git a/tools/perf/tests/shell/probe_vfs_getname.sh b/tools/perf/tests= /shell/probe_vfs_getname.sh index 0c5aacc446b3ef76..c51a32931af6313e 100755 --- a/tools/perf/tests/shell/probe_vfs_getname.sh +++ b/tools/perf/tests/shell/probe_vfs_getname.sh @@ -8,6 +8,7 @@ . "$(dirname $0)"/lib/probe.sh =20 skip_if_no_perf_probe || exit 2 +[ "$(id -u)" =3D 0 ] || exit 2 =20 # shellcheck source=3Dlib/probe_vfs_getname.sh . "$(dirname $0)"/lib/probe_vfs_getname.sh diff --git a/tools/perf/tests/shell/record+probe_libc_inet_pton.sh b/tools/= perf/tests/shell/record+probe_libc_inet_pton.sh index d5e5193cceb625fd..c4bab5b5cc59f0b3 100755 --- a/tools/perf/tests/shell/record+probe_libc_inet_pton.sh +++ b/tools/perf/tests/shell/record+probe_libc_inet_pton.sh @@ -105,6 +105,7 @@ delete_libc_inet_pton_event() { =20 # Check for IPv6 interface existence ip a sh lo | grep -F -q inet6 || exit 2 +[ "$(id -u)" =3D 0 ] || exit 2 =20 skip_if_no_perf_probe && \ add_libc_inet_pton_event && \ diff --git a/tools/perf/tests/shell/record+script_probe_vfs_getname.sh b/to= ols/perf/tests/shell/record+script_probe_vfs_getname.sh index 5940fdc1df37c502..fd5b10d469158b65 100755 --- a/tools/perf/tests/shell/record+script_probe_vfs_getname.sh +++ b/tools/perf/tests/shell/record+script_probe_vfs_getname.sh @@ -13,6 +13,7 @@ . "$(dirname "$0")/lib/probe.sh" =20 skip_if_no_perf_probe || exit 2 +[ "$(id -u)" =3D 0 ] || exit 2 =20 # shellcheck source=3Dlib/probe_vfs_getname.sh . "$(dirname "$0")/lib/probe_vfs_getname.sh" diff --git a/tools/perf/tests/shell/test_uprobe_from_different_cu.sh b/tool= s/perf/tests/shell/test_uprobe_from_different_cu.sh index 33387c329f92b6ed..7adf9755d6de240e 100755 --- a/tools/perf/tests/shell/test_uprobe_from_different_cu.sh +++ b/tools/perf/tests/shell/test_uprobe_from_different_cu.sh @@ -4,12 +4,11 @@ =20 set -e =20 -# Skip if there's no probe command. -if ! perf | grep probe -then - echo "Skip: probe command isn't present" - exit 2 -fi +# shellcheck source=3Dlib/probe.sh +. "$(dirname $0)"/lib/probe.sh + +skip_if_no_perf_probe || exit 2 +[ "$(id -u)" =3D=3D 0 ] || exit 2 =20 # skip if there's no gcc if ! [ -x "$(command -v gcc)" ]; then --=20 2.48.1.711.g2feabab25a-goog From nobody Sun Feb 8 12:38:00 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E7AC51B6CE3; Tue, 4 Mar 2025 02:28:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741055320; cv=none; b=htMTcuGFclLaK2mcPVSLZ0br8tPfqIvDtrRue4p/ye1hGvVCnScu4iRMgDIVQdDVHbGePDwN1Zr4/LDjYWGuT8yEpZxk6Q3hVkETZWniNNhjsuRG4JZMT95so6blW+YIUFQlabebeoEHCqWrfUT1mAqRYRetpjY9AFwPMlUNbxY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741055320; c=relaxed/simple; bh=v/m0g5WAqn0xy20K/5YA8hgY9gL9rBWO0n5tLPllelU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hKWOleH/Jy4djkFbbGuczFixzRR4i0tHDyfF5E6cBgxBOEk/4UbQvBNOf445L/mJD4dBZwYrzI1BRUdb6uRGAA11FPONkh+uM/JuUM+BGyg69Pb5q+j+XVuLxUsy7V3npM46zMc1t3cfZMoF1oYv6gCrYVSiPtp+4IZte7CuXBo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Z67uQwUS; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Z67uQwUS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71DC9C4CEE8; Tue, 4 Mar 2025 02:28:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741055319; bh=v/m0g5WAqn0xy20K/5YA8hgY9gL9rBWO0n5tLPllelU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z67uQwUStvTTTUz9xHh4XU1nlQVVxEd/7qnrrFb+8mR4YlauK3j2uQ9A/aQhDyvZV txH4bYRRSZGQ9q0HUppvSjMBEwYST+eC8K34ywcIk27nwblhAUbHZt5i/8kuTHCDXK 1PrTQebPnviHaUwWrs1izLzhWf/feveFeL2obV6DAsNoP+m9HRi8lxN8HyJKU4m4xs y7zUghTjGRj6cZpmvp2WuiRPr2Epzy9qVraggvRyfQxcMBRMxjjt9Rq/W7fePXD91p AR1GtU2YxmbFUsz+d0hXSbgCw0MIlPT/8mO7vDX4s1YF+a0Wms1bw6Zo0bbJlYTUnB EX/fx0lRPLnhQ== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Howard Chu Subject: [PATCH v2 3/6] perf test: Skip perf trace tests when running as non-root Date: Mon, 3 Mar 2025 18:28:34 -0800 Message-ID: <20250304022837.1877845-4-namhyung@kernel.org> X-Mailer: git-send-email 2.48.1.711.g2feabab25a-goog In-Reply-To: <20250304022837.1877845-1-namhyung@kernel.org> References: <20250304022837.1877845-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" perf trace requires root because it needs to use tracepoints and BPF. Skip those test when it's not run as root. Before: $ perf test trace 15: Parse sched tracepoints fields : Sk= ip (permissions) 80: perf ftrace tests : Sk= ip 105: perf trace enum augmentation tests : FA= ILED! 106: perf trace BTF general tests : FA= ILED! 107: perf trace exit race : FA= ILED! 118: probe libc's inet_pton & backtrace it with ping : Sk= ip 125: Check Arm CoreSight trace data recording and synthesized samples: Sk= ip 127: Check Arm SPE trace data recording and synthesized samples : Sk= ip 132: Check open filename arg using perf trace + vfs_getname : FA= ILED! After: $ perf test trace 15: Parse sched tracepoints fields : Sk= ip (permissions) 80: perf ftrace tests : Sk= ip 105: perf trace enum augmentation tests : Sk= ip 106: perf trace BTF general tests : Sk= ip 107: perf trace exit race : Sk= ip 118: probe libc's inet_pton & backtrace it with ping : Sk= ip 125: Check Arm CoreSight trace data recording and synthesized samples: Sk= ip 127: Check Arm SPE trace data recording and synthesized samples : Sk= ip 132: Check open filename arg using perf trace + vfs_getname : Sk= ip Cc: Howard Chu Signed-off-by: Namhyung Kim Tested-by: Thomas Falcon --- tools/perf/tests/shell/trace+probe_vfs_getname.sh | 1 + tools/perf/tests/shell/trace_btf_enum.sh | 1 + tools/perf/tests/shell/trace_btf_general.sh | 1 + tools/perf/tests/shell/trace_exit_race.sh | 1 + 4 files changed, 4 insertions(+) diff --git a/tools/perf/tests/shell/trace+probe_vfs_getname.sh b/tools/perf= /tests/shell/trace+probe_vfs_getname.sh index 708a13f006353611..60fccb62c5403ee9 100755 --- a/tools/perf/tests/shell/trace+probe_vfs_getname.sh +++ b/tools/perf/tests/shell/trace+probe_vfs_getname.sh @@ -15,6 +15,7 @@ =20 skip_if_no_perf_probe || exit 2 skip_if_no_perf_trace || exit 2 +[ "$(id -u)" =3D 0 ] || exit 2 =20 . "$(dirname $0)"/lib/probe_vfs_getname.sh =20 diff --git a/tools/perf/tests/shell/trace_btf_enum.sh b/tools/perf/tests/sh= ell/trace_btf_enum.sh index 8d1e6bbeac906843..60b3fa254cf6c7bc 100755 --- a/tools/perf/tests/shell/trace_btf_enum.sh +++ b/tools/perf/tests/shell/trace_btf_enum.sh @@ -13,6 +13,7 @@ TESTPROG=3D"perf test -w landlock" # shellcheck source=3Dlib/probe.sh . "$(dirname $0)"/lib/probe.sh skip_if_no_perf_trace || exit 2 +[ "$(id -u)" =3D 0 ] || exit 2 =20 check_vmlinux() { echo "Checking if vmlinux exists" diff --git a/tools/perf/tests/shell/trace_btf_general.sh b/tools/perf/tests= /shell/trace_btf_general.sh index e9ee727f3433eaba..a25d8744695e6fef 100755 --- a/tools/perf/tests/shell/trace_btf_general.sh +++ b/tools/perf/tests/shell/trace_btf_general.sh @@ -76,6 +76,7 @@ trace_config() { =20 skip_if_no_perf_trace || exit 2 check_vmlinux || exit 2 +[ "$(id -u)" =3D 0 ] || exit 2 =20 trace_config =20 diff --git a/tools/perf/tests/shell/trace_exit_race.sh b/tools/perf/tests/s= hell/trace_exit_race.sh index fbb0adc33a889516..1e247693e756d439 100755 --- a/tools/perf/tests/shell/trace_exit_race.sh +++ b/tools/perf/tests/shell/trace_exit_race.sh @@ -10,6 +10,7 @@ . "$(dirname $0)"/lib/probe.sh =20 skip_if_no_perf_trace || exit 2 +[ "$(id -u)" =3D 0 ] || exit 2 =20 if [ "$1" =3D "-v" ]; then verbose=3D"1" --=20 2.48.1.711.g2feabab25a-goog From nobody Sun Feb 8 12:38:00 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 755AE1C9EB1; Tue, 4 Mar 2025 02:28:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741055320; cv=none; b=qDTZiZ9BIrqadpKg1cgkHzVzl2mMZd1XhRdwTrVmkeCDQ/4MTw84g7KPx41s78LM6FJ5WPh3yknvRXYEJlzE/pPLUgBru5EZPj9h3MqOC41qMSSu2QleG21hXNdcWWeH88vt6fAaPwcFfjfgcvgMVB7zIGYRcSdnecOzIwQK3ZY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741055320; c=relaxed/simple; bh=2+lUnkmbSZWMXynR8WLp8OihqPqjBEgZ2igI4ntPbQY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h4KCSAKC+vAgSKlif4cfqvx4PdVYeEvy8VzY6eeTKo0xu8nNLhDQCN1XbGDOUpfeSgI16Apt+faPbChUg6n9JEliLN49DJMoufXj5BXpaJ8kMhhSEZTvbv1ctN1pAiGJJppbx5Aepk+cZMW2GPlIpQv4URsXqlLTRyBtcVZe4yo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YEE2O4Ei; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YEE2O4Ei" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EEE1AC4CEE4; Tue, 4 Mar 2025 02:28:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741055320; bh=2+lUnkmbSZWMXynR8WLp8OihqPqjBEgZ2igI4ntPbQY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YEE2O4Ei5bxGyEniOApmULtTbP8YS5/DcDg/ZZ5rpCbuvJPKwN1Wd3psb1DYwpaqJ M4W3K1lcEFi7Wb/qrEIILqixyyJ7qYu0Yyc9em/IfVAAVqN2lyMl/xBHtMmH4PIvhL o9D15xvYxcJ1tBcxyxsgS35hBCkAh5mJS3wJ0/DsYidtwra4noCdih1IQHpPH7dZzQ 8ZNzs046WO07MClq6jitU2YIZIg3SQXWYcqYAJoKcNp2hyDX1zLH6iY1eV5Ppff9Cr F17RA7M17nEkGPJphgqC5G7YodF8wl4SO9vUm0v6JnV5G1PwOWbz730qKO7+uosPRt voJQuVamPMRLw== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Howard Chu Subject: [PATCH v2 4/6] perf test: Add trace record and replay test Date: Mon, 3 Mar 2025 18:28:35 -0800 Message-ID: <20250304022837.1877845-5-namhyung@kernel.org> X-Mailer: git-send-email 2.48.1.711.g2feabab25a-goog In-Reply-To: <20250304022837.1877845-1-namhyung@kernel.org> References: <20250304022837.1877845-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It just check trace record and replay could display correct output. It uses 'sleep' process and sees there's a clock_nanosleep syscall. $ sudo perf test -vv replay 108: perf trace record and replay: --- start --- test child forked, pid 1563219 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.077 MB /tmp/temporary_file.w1ApA (242= samples) ] 0.686 (1000.068 ms): sleep/1563226 clock_nanosleep(rqtp: 0x7ffc20ffe= e10, rmtp: 0x7ffc20ffee50) =3D 0 ---- end(0) ---- 108: perf trace record and replay : Ok Cc: Howard Chu Signed-off-by: Namhyung Kim Tested-by: Thomas Falcon --- tools/perf/tests/shell/trace_record_replay.sh | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 tools/perf/tests/shell/trace_record_replay.sh diff --git a/tools/perf/tests/shell/trace_record_replay.sh b/tools/perf/tes= ts/shell/trace_record_replay.sh new file mode 100755 index 0000000000000000..6b4ed863c1ef8679 --- /dev/null +++ b/tools/perf/tests/shell/trace_record_replay.sh @@ -0,0 +1,21 @@ +#!/bin/sh +# perf trace record and replay +# SPDX-License-Identifier: GPL-2.0 + +# Check that perf trace works with record and replay + +# shellcheck source=3Dlib/probe.sh +. "$(dirname $0)"/lib/probe.sh + +skip_if_no_perf_trace || exit 2 +[ "$(id -u)" =3D 0 ] || exit 2 + +file=3D$(mktemp /tmp/temporary_file.XXXXX) + +perf trace record -o ${file} sleep 1 || exit 1 +if ! perf trace -i ${file} 2>&1 | grep nanosleep; then + echo "Failed: cannot find *nanosleep syscall" + exit 1 +fi + +rm -f ${file} --=20 2.48.1.711.g2feabab25a-goog From nobody Sun Feb 8 12:38:00 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D0051DDA3C; Tue, 4 Mar 2025 02:28:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741055321; cv=none; b=RH4AHqBr/YHta6eIpnczXDxGJM0VvGWE7fTM/OPq0h0Vdz/jTgeqaFDL2hGlM++mcDH8bjDtykUerPyunkVwNgpkmEqGfzwZNv8mVTU/QQGtQeTGtVbh71h12Ivskt7azh725gYwVVxh+9nrXYbjCZAwd/vMTek/9t2AYZZTqJY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741055321; c=relaxed/simple; bh=RzYrlM88omVGwDNYsMfqIjC0LNHDhGkdys42nQkzM6w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZVPu6HC4Cb3noAbujLl2MThmqnykQin5jyD7+8K2v/u0ONb5D98fedKkc4zlXYeVlEMXW0OnF+8Ef1bzEAcILGqN/38D/Wcatt1it6P4WLdpEzWDf9/ExR5FCwNnwbfRJiBB7ime+voyGL+5U4a3QmNpVpMnI6+JhKQpmNbBIxU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BAdbDFL9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BAdbDFL9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E8B4C4CEF0; Tue, 4 Mar 2025 02:28:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741055320; bh=RzYrlM88omVGwDNYsMfqIjC0LNHDhGkdys42nQkzM6w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BAdbDFL9cy9IOs0L1uQQyN/wVf7j7WMlZPH/K96R53X7xYnW0YaNPpe+BolbGHDtL jAyHdmryB9k1IJsm+fWIbNF7rk8mC8quVQV7CTYlwMQoaqPc4mdAbehoPPhOVBgVRg Wy90ZDj+r8hOk3Yd2TSTLy9e+vQzG08RW0UwMPT6avlvqJcZUfJXeRbb6SKBSVfXG6 3J/GD/7UZX+KFRBVzNN0EjmUk7JWGUivyHxw4vNGnf92StBTlE4VNTxIuS4BMcEBPp Yp0xPjPS4KpBGYY5Guw/5KN7UM+W+4AnuMOpjedL0M5f0iOyGH0sdXKa6cWZm7DSuQ b1DpmI6qo87iA== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Thomas Richter , Leo Yan Subject: [PATCH v2 5/6] perf test: Add timeout to datasym workload Date: Mon, 3 Mar 2025 18:28:36 -0800 Message-ID: <20250304022837.1877845-6-namhyung@kernel.org> X-Mailer: git-send-email 2.48.1.711.g2feabab25a-goog In-Reply-To: <20250304022837.1877845-1-namhyung@kernel.org> References: <20250304022837.1877845-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Unlike others it has an infinite loop that make it annoying to call. Make it finish after 1 second and handle command-line argument to change the setting. Cc: Thomas Richter Cc: Leo Yan Signed-off-by: Namhyung Kim Reviewed-by: Leo Yan Tested-by: Thomas Falcon Tested-by: Thomas Richter --- tools/perf/tests/workloads/datasym.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/tools/perf/tests/workloads/datasym.c b/tools/perf/tests/worklo= ads/datasym.c index 8e08fc75a973e5f7..8ddb2aa6a049e343 100644 --- a/tools/perf/tests/workloads/datasym.c +++ b/tools/perf/tests/workloads/datasym.c @@ -1,3 +1,6 @@ +#include +#include +#include #include #include "../tests.h" =20 @@ -12,9 +15,25 @@ static buf buf1 =3D { .reserved[0] =3D 1, }; =20 -static int datasym(int argc __maybe_unused, const char **argv __maybe_unus= ed) +static volatile sig_atomic_t done; + +static void sighandler(int sig __maybe_unused) +{ + done =3D 1; +} + +static int datasym(int argc, const char **argv) { - for (;;) { + int sec =3D 1; + + if (argc > 0) + sec =3D atoi(argv[0]); + + signal(SIGINT, sighandler); + signal(SIGALRM, sighandler); + alarm(sec); + + while (!done) { buf1.data1++; if (buf1.data1 =3D=3D 123) { /* --=20 2.48.1.711.g2feabab25a-goog From nobody Sun Feb 8 12:38:00 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 01BFA1F3FED; Tue, 4 Mar 2025 02:28:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741055323; cv=none; b=DwuZSF4Ddw2XRTjzMYaMtKMod0S9nIG1xQm6/cANVb2AO7eqip4w8M6D3pKcyqpvee6Y+eFdBSOrYTRNW6w7q2rPw2/+CquDo74Ufdh1yFORh8VoTVOnfUZVGauXCAL3j9zUh91e0TRmRuz8hOz7KacnR0KlXdBW0nYHLbR6NuE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741055323; c=relaxed/simple; bh=0hdoilLOGa6AOrQ12FPGta7eflB7cDeA1VkIKF6W4T8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QB83wxOiyGUz4mFT3EF7nhkVRLBds7OOo65nP2uwfPYtlc63UEUTZeW7zl3pmGD5eNm4HY7P/yaRbc2T92vdC/Swi/QfT56Fn6QnwTayU4aQV3fTEXD5K6VVuhTSVifJoLlWHbSfKI/H7XdS9Nt46jsFWkWYZOJZ9OzKC+y2hsI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DYbRyQQj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DYbRyQQj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 14241C4CEEC; Tue, 4 Mar 2025 02:28:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741055321; bh=0hdoilLOGa6AOrQ12FPGta7eflB7cDeA1VkIKF6W4T8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DYbRyQQj/mUwkLjRakZGzLwB51Aq6kKksQIL+lcYUKXvh9pq14VsJiFPgqOmnzOxN 4KksIn5QZa8so4nhsPZ949SxgXXzlu6i9heopNIGkLuqgu8EiI9KU+FJvkQN5ZTDgF BzLthqgKGgJR3PuDUlMA0kQdMJO49MxKxcrQTYih9NFLcPjcNdcVof/Ny8WkAf8nSy HOHgthgZ5FzEhyX7GIAlUQ/3np6u2J4jZNp2LaYeStudfXodjjIE1hluGLKPZTu50K NlU+cpajvUcZo0dE9wNZfeAr8MnxL8ucX//EpRD9r+vWwpqAgycHf+IrpsAyhkIYB1 MBXCEyUTipYhw== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Thomas Richter , Leo Yan Subject: [PATCH v2 6/6] perf test: Simplify data symbol test Date: Mon, 3 Mar 2025 18:28:37 -0800 Message-ID: <20250304022837.1877845-7-namhyung@kernel.org> X-Mailer: git-send-email 2.48.1.711.g2feabab25a-goog In-Reply-To: <20250304022837.1877845-1-namhyung@kernel.org> References: <20250304022837.1877845-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now the workload will end after 1 second. Just run it with perf instead of waiting for the background process. Cc: Thomas Richter Cc: Leo Yan Signed-off-by: Namhyung Kim Reviewed-by: Leo Yan Tested-by: Thomas Falcon Tested-by: Thomas Richter --- tools/perf/tests/shell/test_data_symbol.sh | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/tools/perf/tests/shell/test_data_symbol.sh b/tools/perf/tests/= shell/test_data_symbol.sh index c86da02350596b35..1792b7ad4066f8cd 100755 --- a/tools/perf/tests/shell/test_data_symbol.sh +++ b/tools/perf/tests/shell/test_data_symbol.sh @@ -5,8 +5,6 @@ # Leo Yan , 2022 =20 shelldir=3D$(dirname "$0") -# shellcheck source=3Dlib/waiting.sh -. "${shelldir}"/lib/waiting.sh =20 # shellcheck source=3Dlib/perf_has_symbol.sh . "${shelldir}"/lib/perf_has_symbol.sh @@ -60,19 +58,10 @@ echo "Recording workload..." # specific CPU and test in per-CPU mode. is_amd=3D$(grep -E -c 'vendor_id.*AuthenticAMD' /proc/cpuinfo) if (($is_amd >=3D 1)); then - perf mem record -vvv -o ${PERF_DATA} -C 0 -- taskset -c 0 $TEST_PROGRAM 2= >"${ERR_FILE}" & + perf mem record -vvv -o ${PERF_DATA} -C 0 -- taskset -c 0 $TEST_PROGRAM 2= >"${ERR_FILE}" else - perf mem record -vvv --all-user -o ${PERF_DATA} -- $TEST_PROGRAM 2>"${ERR= _FILE}" & + perf mem record -vvv --all-user -o ${PERF_DATA} -- $TEST_PROGRAM 2>"${ERR= _FILE}" fi =20 -PERFPID=3D$! - -wait_for_perf_to_start ${PERFPID} "${ERR_FILE}" - -sleep 1 - -kill $PERFPID -wait $PERFPID - check_result exit $? --=20 2.48.1.711.g2feabab25a-goog