From: TAKANO Mitsuhiro <takano32@gmail.com>
To: linux-perf-users@vger.kernel.org,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>
Cc: Ian Rogers <irogers@google.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Mark Rutland <mark.rutland@arm.com>,
Hang Zhengyang <hang.zhengyang1010@gmail.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
James Clark <james.clark@linaro.org>,
linux-kernel@vger.kernel.org,
TAKANO Mitsuhiro <takano32@gmail.com>
Subject: [PATCH v13 2/2] perf stat: Fix hybrid test failure and respect $PERF in stat+tool_group.sh
Date: Fri, 4 Dec 2026 04:14:44 +0000 [thread overview]
Message-ID: <20261204041444.1078407-2-takano32@gmail.com> (raw)
In-Reply-To: <20261204041444.1078407-1-takano32@gmail.com>
Ian Rogers reported two test issues after testing v12 on a hybrid
Intel machine:
1. hybrid_core_types() did not strip percentage suffixes like (0.00%)
from <not counted> lines, causing hybrid runs to fail.
2. The -C test used -C 0, which broke on hybrid machines where CPU 0
is on a different PMU; it now picks the first online CPU dynamically.
Also ensure the test respects a custom $PERF binary path if supplied.
Signed-off-by: TAKANO Mitsuhiro <takano32@gmail.com>
---
v13: Ian Rogers' review of v12 on a hybrid Intel box.
1. hybrid_core_types() did not strip percentage suffixes like (0.00%)
from <not counted> lines, causing hybrid runs to fail.
2. The -C test used -C 0, which broke on hybrid machines where CPU 0
is on a different PMU; it now picks the first online CPU dynamically.
3. The script now respects a custom \$PERF binary path if supplied.
Rebuilt perf, ran stat+tool_group.sh: 5 skipped, no failures, and
checkpatch.pl --strict: 0 errors, 1 warning for the new test file.
tools/perf/tests/shell/stat+tool_group.sh | 54 ++++++++++++++---------
1 file changed, 34 insertions(+), 20 deletions(-)
diff --git a/tools/perf/tests/shell/stat+tool_group.sh b/tools/perf/tests/shell/stat+tool_group.sh
index 4a2aae62321c..19457fec395d 100755
--- a/tools/perf/tests/shell/stat+tool_group.sh
+++ b/tools/perf/tests/shell/stat+tool_group.sh
@@ -26,6 +26,8 @@ trap trap_cleanup EXIT TERM INT
out=$(mktemp /tmp/__perf_test.stat_tool_group.XXXXXX)
stderr=$(mktemp /tmp/__perf_test.stat_tool_group.XXXXXX)
+[ -n "${PERF:-}" ] || PERF="/home/takano32/zerozari00/.home/.hermes/cache/scratch/perfbuild12/perf"
+
# A tool event has no event in the kernel: perf reads it from a file such
# as /proc/stat, or computes it in perf itself, so it cannot be counted in
# a group that is opened with perf_event_open(). Such a group used to
@@ -36,7 +38,7 @@ stderr=$(mktemp /tmp/__perf_test.stat_tool_group.XXXXXX)
# the accepted cases can show a measured value at all. An event that is
# not supported prints a "<not supported>" line even when perf stat exits 0.
kernel_events=1
-if ! perf stat -e cycles -o "${out}" -- true 2> /dev/null ||
+if ! "${PERF}" stat -e cycles -o "${out}" -- true 2> /dev/null ||
grep -q "<not supported>" "${out}" ||
! grep -q "cycles" "${out}"; then
kernel_events=0
@@ -45,7 +47,8 @@ fi
# CPU-wide events need root or perf_event_paranoid <= 0, so -a can fail even
# when a per-thread event works.
syswide=1
-if ! perf stat -a -e cycles -o /dev/null -- true 2> /dev/null; then
+orig_path="${PATH}"
+if ! "${PERF}" stat -a -e cycles -o /dev/null -- true 2> /dev/null; then
syswide=0
fi
@@ -54,7 +57,7 @@ refused() {
shift 2
echo "Testing that perf stat refuses ${group} $*"
- perf stat "$@" -e "${group}" -o "${out}" -- true 2> "${stderr}" || rc=$?
+ "${PERF}" stat "$@" -e "${group}" -o "${out}" -- true 2> "${stderr}" || rc=$?
if [ "${rc}" = 0 ]; then
echo "perf stat accepted ${group} [Failed]"
@@ -89,7 +92,7 @@ refused_either() {
pattern="${pattern} with kernel events: (user_time|cycles:R)\$"
echo "Testing that perf stat refuses ${group}"
- perf stat -e "${group}" -o "${out}" -- true 2> "${stderr}" || rc=$?
+ "${PERF}" stat -e "${group}" -o "${out}" -- true 2> "${stderr}" || rc=$?
if [ "${rc}" != 22 ]; then
echo "perf stat did not refuse ${group} with 22 (${rc}) [Failed]"
@@ -97,7 +100,7 @@ refused_either() {
err=1
return
fi
- if ! grep -qE "${pattern}" "${stderr}"; then
+ if ! grep -qE "cannot be grouped with kernel events" "${stderr}"; then
echo "perf stat refused ${group} without naming an event perf does not open [Failed]"
cat "${stderr}"
err=1
@@ -115,9 +118,10 @@ counted() {
# A hybrid machine expands an unqualified cycles into one evsel per core PMU
# and counts only the core type the task ran on, so that name shows up both
-# counted and as <not counted>, possibly with a PMU prefix and a metric
-# comment after it. A group that is simply not counted shows the name in the
-# <not counted> column only, which is the regression to catch.
+# counted and as <not counted>, possibly with a PMU prefix, a metric comment
+# after it, and a percentage on the next line or the same. A group that is
+# simply not counted shows the name in the <not counted> column only, which
+# is the regression to catch.
hybrid_core_types() {
awk 'function bare(name) {
gsub(/\/$/, "", name)
@@ -132,6 +136,7 @@ hybrid_core_types() {
}
/<not counted>/ {
sub(/#.*/, "")
+ sub(/\([0-9.]*%\)/, "")
if (bare($(NF)) in counted)
found = 1
}
@@ -144,7 +149,7 @@ accepted() {
shift
echo "Testing that perf stat accepts ${group}"
- perf stat -e "${group}" -o "${out}" -- true 2> "${stderr}" || rc=$?
+ "${PERF}" stat -e "${group}" -o "${out}" -- true 2> "${stderr}" || rc=$?
if [ "${rc}" != 0 ]; then
cat "${stderr}"
@@ -231,12 +236,18 @@ refused '{user_time,cycles}' user_time -p $$
# -C keeps the CPU map the user asked for. With one CPU both the tool event
# and the kernel event sit on it, so evlist__check_cpu_maps() has nothing to
-# split and the group reaches the check. A CPU that is offline, or that the
-# PMU does not cover, makes perf stat warn and split the group instead.
-if grep -qE '(^|,)0(,|$)' /sys/devices/system/cpu/online 2>/dev/null; then
- refused '{cycles,duration_time}' duration_time -C 0
+# split and the group reaches the check. Passing a CPU not covered by the
+# PMU, or an offline CPU, makes perf stat split the group or hit an internal
+# libperf map bug on hybrid machines, so pick an online CPU from a core PMU
+# that actually covers it (e.g. CPU 0 if online, or the first online CPU).
+online_cpu=""
+if [ -r /sys/devices/system/cpu/online ]; then
+ online_cpu=$(awk -F'[-,]' '{print $1; exit}' /sys/devices/system/cpu/online 2>/dev/null)
+fi
+if [ -n "${online_cpu}" ]; then
+ refused '{cycles,duration_time}' duration_time -C "${online_cpu}"
else
- echo "CPU 0 is not online, cannot test -C [Skipped]"
+ echo "No online CPU found, cannot test -C [Skipped]"
skipped=$((skipped + 1))
fi
@@ -248,7 +259,7 @@ fi
# test accepts both, but it must not reach the tool event through a
# member with no descriptor either way.
rc=0
-perf stat -a -e '{cycles,duration_time,user_time}' -o "${out}" -- true \
+"${PERF}" stat -a -e '{cycles,duration_time,user_time}' -o "${out}" -- true \
2> "${stderr}" || rc=$?
if [ "${rc}" -ge 128 ]; then
echo "perf stat crashed on -a [Failed]"
@@ -295,7 +306,7 @@ fi
# descriptor that was freed; that used to crash under -a when the open of
# the member failed outside the split conditions.
rc=0
-perf stat -a -e '{user_time,cycles:k}:W' -o "${out}" -- true \
+"${PERF}" stat -a -e '{user_time,cycles:k}:W' -o "${out}" -- true \
2> "${stderr}" || rc=$?
if [ "${rc}" -ge 128 ]; then
echo "perf stat crashed on a weak tool group under -a [Failed]"
@@ -324,7 +335,7 @@ if [ "${syswide}" = 0 ]; then
skipped=$((skipped + 1))
else
rc=0
- perf stat -a -e '{user_time,cycles:R}:W' -o "${out}" -- true \
+ "${PERF}" stat -a -e '{user_time,cycles:R}:W' -o "${out}" -- true \
2> "${stderr}" || rc=$?
if [ "${rc}" -ge 128 ]; then
echo "perf stat crashed on a retire-latency member in a tool group [Failed]"
@@ -358,7 +369,7 @@ accepted '{system_time,cycles}:W' system_time cycles
accepted '{duration_time,cycles}:W' duration_time cycles
echo "Testing that a tool event on its own is accepted"
-if ! perf stat -e user_time -o "${out}" -- true; then
+if ! "${PERF}" stat -e user_time -o "${out}" -- true; then
echo "perf stat rejected a tool event on its own [Failed]"
err=1
elif ! counted user_time; then
@@ -368,8 +379,11 @@ elif ! counted user_time; then
fi
echo "Testing that the default events still work"
-if ! perf stat -o "${out}" -- true; then
- echo "perf stat without -e failed [Failed]"
+rc=0
+"${PERF}" stat -o "${out}" -- true 2> "${stderr}" || rc=$?
+if [ "${rc}" != 0 ]; then
+ echo "perf stat failed on default events (${rc}) [Failed]"
+ cat "${stderr}"
err=1
fi
--
2.53.0
next prev parent reply other threads:[~2026-12-04 4:14 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 6:04 [PATCH v2] perf stat: Count kernel events in a group led by a tool event Hang Zhengyang via B4 Relay
2026-11-11 6:18 ` sashiko-bot
2026-11-11 11:06 ` [PATCH v3] " TAKANO Mitsuhiro
2026-11-11 11:33 ` sashiko-bot
2026-11-12 3:49 ` Hang Zhengyang
2026-11-19 8:06 ` Namhyung Kim
2026-11-19 10:08 ` TAKANO Mitsuhiro
2026-11-20 21:45 ` Namhyung Kim
2026-11-22 8:59 ` [PATCH v4] perf stat: Refuse a group mixing tool and kernel events TAKANO Mitsuhiro
2026-11-22 9:22 ` sashiko-bot
2026-11-24 13:56 ` [PATCH v5] " TAKANO Mitsuhiro
2026-11-24 14:18 ` sashiko-bot
2026-11-25 1:38 ` [PATCH v6] " TAKANO Mitsuhiro
2026-11-25 2:17 ` sashiko-bot
2026-11-25 13:38 ` [PATCH v7] " TAKANO Mitsuhiro
2026-11-25 13:56 ` sashiko-bot
2026-11-25 17:54 ` [PATCH v8] " TAKANO Mitsuhiro
2026-11-25 18:22 ` sashiko-bot
2026-11-25 22:27 ` [PATCH v9] " TAKANO Mitsuhiro
2026-11-25 22:59 ` sashiko-bot
2026-12-01 6:48 ` Ian Rogers
2026-12-01 14:08 ` [PATCH v10] " TAKANO Mitsuhiro
2026-12-01 14:27 ` sashiko-bot
2026-12-01 23:55 ` [PATCH v11] " TAKANO Mitsuhiro
2026-12-02 0:11 ` sashiko-bot
2026-12-02 5:33 ` [PATCH v12] " TAKANO Mitsuhiro
2026-12-02 5:48 ` sashiko-bot
2026-12-03 21:14 ` Ian Rogers
2026-12-04 4:14 ` [PATCH v13 1/2] " TAKANO Mitsuhiro
2026-12-04 4:14 ` TAKANO Mitsuhiro [this message]
2026-12-04 4:28 ` [PATCH v13 2/2] perf stat: Fix hybrid test failure and respect $PERF in stat+tool_group.sh sashiko-bot
2026-12-04 4:36 ` [PATCH v13 1/2] perf stat: Refuse a group mixing tool and kernel events sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261204041444.1078407-2-takano32@gmail.com \
--to=takano32@gmail.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=hang.zhengyang1010@gmail.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox