* [PATCH v3] perf test shell tpebs: Extra verbosity and hypervisor skip
@ 2025-01-30 17:01 Ian Rogers
2025-01-31 15:49 ` Falcon, Thomas
2025-02-04 17:26 ` Namhyung Kim
0 siblings, 2 replies; 3+ messages in thread
From: Ian Rogers @ 2025-01-30 17:01 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
Ian Rogers, Adrian Hunter, Kan Liang, James Clark, Weilin Wang,
linux-perf-users, linux-kernel, Thomas Falcon
When not running as root and with higher perf event paranoia values
the perf record forked by TPEBS can fail to attach to the process. Skip
the test in these scenarios.
Intel TPEBS test skips on non-Intel CPUs. On Intel CPUs under a
hypervisor the cache-misses event may not be present or precise. Skip
the test under this condition.
Refactor the output code to be placed in a file so that on a signal
the file can be dumped. This was necessary to catch the issue above as
the failing perf record command would fail without output.
Signed-off-by: Ian Rogers <irogers@google.com>
---
v3: Add/squash missed patches pointed out by "Falcon, Thomas"
<thomas.falcon@intel.com>
v2: Fix lost :R and use :p with record as it is ignored by perf stat.
---
.../perf/tests/shell/test_stat_intel_tpebs.sh | 89 ++++++++++++++++---
1 file changed, 76 insertions(+), 13 deletions(-)
diff --git a/tools/perf/tests/shell/test_stat_intel_tpebs.sh b/tools/perf/tests/shell/test_stat_intel_tpebs.sh
index f95fc64bf0a7..a330ecdb7ba5 100755
--- a/tools/perf/tests/shell/test_stat_intel_tpebs.sh
+++ b/tools/perf/tests/shell/test_stat_intel_tpebs.sh
@@ -3,20 +3,83 @@
# SPDX-License-Identifier: GPL-2.0
set -e
-grep -q GenuineIntel /proc/cpuinfo || { echo Skipping non-Intel; exit 2; }
-# Use this event for testing because it should exist in all platforms
-event=cache-misses:R
+ParanoidAndNotRoot() {
+ [ "$(id -u)" != 0 ] && [ "$(cat /proc/sys/kernel/perf_event_paranoid)" -gt $1 ]
+}
-# Hybrid platforms output like "cpu_atom/cache-misses/R", rather than as above
-alt_name=/cache-misses/R
+if ! grep -q GenuineIntel /proc/cpuinfo
+then
+ echo "Skipping non-Intel"
+ exit 2
+fi
-# Without this cmd option, default value or zero is returned
-#echo "Testing without --record-tpebs"
-#result=$(perf stat -e "$event" true 2>&1)
-#[[ "$result" =~ $event || "$result" =~ $alt_name ]] || exit 1
+if ParanoidAndNotRoot 0
+then
+ echo "Skipping paranoid >0 and not root"
+ exit 2
+fi
-# In platforms that do not support TPEBS, it should execute without error.
-echo "Testing with --record-tpebs"
-result=$(perf stat -e "$event" --record-tpebs -a sleep 0.01 2>&1)
-[[ "$result" =~ "perf record" && "$result" =~ $event || "$result" =~ $alt_name ]] || exit 1
+stat_output=$(mktemp /tmp/__perf_stat_tpebs_output.XXXXX)
+
+cleanup() {
+ rm -rf "${stat_output}"
+ trap - EXIT TERM INT
+}
+
+trap_cleanup() {
+ echo "Unexpected signal in ${FUNCNAME[1]}"
+ cat "${stat_output}"
+ cleanup
+ exit 1
+}
+trap trap_cleanup EXIT TERM INT
+
+# Event to be used in tests
+event=cache-misses
+
+if ! perf record -e "${event}:p" -a -o /dev/null sleep 0.01 > "${stat_output}" 2>&1
+then
+ echo "Missing ${event} support"
+ cleanup
+ exit 2
+fi
+
+test_with_record_tpebs() {
+ echo "Testing with --record-tpebs"
+ if ! perf stat -e "${event}:R" --record-tpebs -a sleep 0.01 > "${stat_output}" 2>&1
+ then
+ echo "Testing with --record-tpebs [Failed perf stat]"
+ cat "${stat_output}"
+ exit 1
+ fi
+
+ # Expected output:
+ # $ perf stat --record-tpebs -e cache-misses:R -a sleep 0.01
+ # Events enabled
+ # [ perf record: Woken up 2 times to write data ]
+ # [ perf record: Captured and wrote 0.056 MB - ]
+ #
+ # Performance counter stats for 'system wide':
+ #
+ # 0 cache-misses:R
+ #
+ # 0.013963299 seconds time elapsed
+ if ! grep "perf record" "${stat_output}"
+ then
+ echo "Testing with --record-tpebs [Failed missing perf record]"
+ cat "${stat_output}"
+ exit 1
+ fi
+ if ! grep "${event}:R" "${stat_output}" && ! grep "/${event}/R" "${stat_output}"
+ then
+ echo "Testing with --record-tpebs [Failed missing event name]"
+ cat "${stat_output}"
+ exit 1
+ fi
+ echo "Testing with --record-tpebs [Success]"
+}
+
+test_with_record_tpebs
+cleanup
+exit 0
--
2.48.1.262.g85cc9f2d1e-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v3] perf test shell tpebs: Extra verbosity and hypervisor skip
2025-01-30 17:01 [PATCH v3] perf test shell tpebs: Extra verbosity and hypervisor skip Ian Rogers
@ 2025-01-31 15:49 ` Falcon, Thomas
2025-02-04 17:26 ` Namhyung Kim
1 sibling, 0 replies; 3+ messages in thread
From: Falcon, Thomas @ 2025-01-31 15:49 UTC (permalink / raw)
To: james.clark@linaro.org, alexander.shishkin@linux.intel.com,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
peterz@infradead.org, acme@kernel.org, mingo@redhat.com,
mark.rutland@arm.com, Hunter, Adrian, namhyung@kernel.org,
jolsa@kernel.org, kan.liang@linux.intel.com, irogers@google.com,
Wang, Weilin
On Thu, 2025-01-30 at 09:01 -0800, Ian Rogers wrote:
> When not running as root and with higher perf event paranoia values
> the perf record forked by TPEBS can fail to attach to the process.
> Skip
> the test in these scenarios.
>
> Intel TPEBS test skips on non-Intel CPUs. On Intel CPUs under a
> hypervisor the cache-misses event may not be present or precise. Skip
> the test under this condition.
>
> Refactor the output code to be placed in a file so that on a signal
> the file can be dumped. This was necessary to catch the issue above
> as
> the failing perf record command would fail without output.
>
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
> v3: Add/squash missed patches pointed out by "Falcon, Thomas"
> <thomas.falcon@intel.com>
> v2: Fix lost :R and use :p with record as it is ignored by perf stat.
> ---
Works for me on an i9-12900 and Core Ultra 9 275HX .
Tested-by: Thomas Falcon <thomas.falcon@intel.com>
Thanks
> .../perf/tests/shell/test_stat_intel_tpebs.sh | 89 ++++++++++++++++-
> --
> 1 file changed, 76 insertions(+), 13 deletions(-)
>
> diff --git a/tools/perf/tests/shell/test_stat_intel_tpebs.sh
> b/tools/perf/tests/shell/test_stat_intel_tpebs.sh
> index f95fc64bf0a7..a330ecdb7ba5 100755
> --- a/tools/perf/tests/shell/test_stat_intel_tpebs.sh
> +++ b/tools/perf/tests/shell/test_stat_intel_tpebs.sh
> @@ -3,20 +3,83 @@
> # SPDX-License-Identifier: GPL-2.0
>
> set -e
> -grep -q GenuineIntel /proc/cpuinfo || { echo Skipping non-Intel;
> exit 2; }
>
> -# Use this event for testing because it should exist in all
> platforms
> -event=cache-misses:R
> +ParanoidAndNotRoot() {
> + [ "$(id -u)" != 0 ] && [ "$(cat
> /proc/sys/kernel/perf_event_paranoid)" -gt $1 ]
> +}
>
> -# Hybrid platforms output like "cpu_atom/cache-misses/R", rather
> than as above
> -alt_name=/cache-misses/R
> +if ! grep -q GenuineIntel /proc/cpuinfo
> +then
> + echo "Skipping non-Intel"
> + exit 2
> +fi
>
> -# Without this cmd option, default value or zero is returned
> -#echo "Testing without --record-tpebs"
> -#result=$(perf stat -e "$event" true 2>&1)
> -#[[ "$result" =~ $event || "$result" =~ $alt_name ]] || exit 1
> +if ParanoidAndNotRoot 0
> +then
> + echo "Skipping paranoid >0 and not root"
> + exit 2
> +fi
>
> -# In platforms that do not support TPEBS, it should execute without
> error.
> -echo "Testing with --record-tpebs"
> -result=$(perf stat -e "$event" --record-tpebs -a sleep 0.01 2>&1)
> -[[ "$result" =~ "perf record" && "$result" =~ $event || "$result" =~
> $alt_name ]] || exit 1
> +stat_output=$(mktemp /tmp/__perf_stat_tpebs_output.XXXXX)
> +
> +cleanup() {
> + rm -rf "${stat_output}"
> + trap - EXIT TERM INT
> +}
> +
> +trap_cleanup() {
> + echo "Unexpected signal in ${FUNCNAME[1]}"
> + cat "${stat_output}"
> + cleanup
> + exit 1
> +}
> +trap trap_cleanup EXIT TERM INT
> +
> +# Event to be used in tests
> +event=cache-misses
> +
> +if ! perf record -e "${event}:p" -a -o /dev/null sleep 0.01 >
> "${stat_output}" 2>&1
> +then
> + echo "Missing ${event} support"
> + cleanup
> + exit 2
> +fi
> +
> +test_with_record_tpebs() {
> + echo "Testing with --record-tpebs"
> + if ! perf stat -e "${event}:R" --record-tpebs -a sleep 0.01 >
> "${stat_output}" 2>&1
> + then
> + echo "Testing with --record-tpebs [Failed perf stat]"
> + cat "${stat_output}"
> + exit 1
> + fi
> +
> + # Expected output:
> + # $ perf stat --record-tpebs -e cache-misses:R -a sleep 0.01
> + # Events enabled
> + # [ perf record: Woken up 2 times to write data ]
> + # [ perf record: Captured and wrote 0.056 MB - ]
> + #
> + # Performance counter stats for 'system wide':
> + #
> + # 0 cache-misses:R
> + #
> + # 0.013963299 seconds time elapsed
> + if ! grep "perf record" "${stat_output}"
> + then
> + echo "Testing with --record-tpebs [Failed missing perf record]"
> + cat "${stat_output}"
> + exit 1
> + fi
> + if ! grep "${event}:R" "${stat_output}" && ! grep "/${event}/R"
> "${stat_output}"
> + then
> + echo "Testing with --record-tpebs [Failed missing event name]"
> + cat "${stat_output}"
> + exit 1
> + fi
> + echo "Testing with --record-tpebs [Success]"
> +}
> +
> +test_with_record_tpebs
> +cleanup
> +exit 0
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v3] perf test shell tpebs: Extra verbosity and hypervisor skip
2025-01-30 17:01 [PATCH v3] perf test shell tpebs: Extra verbosity and hypervisor skip Ian Rogers
2025-01-31 15:49 ` Falcon, Thomas
@ 2025-02-04 17:26 ` Namhyung Kim
1 sibling, 0 replies; 3+ messages in thread
From: Namhyung Kim @ 2025-02-04 17:26 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Adrian Hunter,
Kan Liang, James Clark, Weilin Wang, linux-perf-users,
linux-kernel, Thomas Falcon, Ian Rogers
On Thu, 30 Jan 2025 09:01:35 -0800, Ian Rogers wrote:
> When not running as root and with higher perf event paranoia values
> the perf record forked by TPEBS can fail to attach to the process. Skip
> the test in these scenarios.
>
> Intel TPEBS test skips on non-Intel CPUs. On Intel CPUs under a
> hypervisor the cache-misses event may not be present or precise. Skip
> the test under this condition.
>
> [...]
Applied to perf-tools-next, thanks!
Best regards,
Namhyung
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-02-04 17:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-30 17:01 [PATCH v3] perf test shell tpebs: Extra verbosity and hypervisor skip Ian Rogers
2025-01-31 15:49 ` Falcon, Thomas
2025-02-04 17:26 ` Namhyung Kim
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox