Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "TAKANO Mitsuhiro" <takano32@gmail.com>,
	linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v13 2/2] perf stat: Fix hybrid test failure and respect $PERF in stat+tool_group.sh
Date: Fri, 04 Dec 2026 04:28:30 +0000	[thread overview]
Message-ID: <sashiko-outbox-249088@kernel.org> (raw)
In-Reply-To: <20261204041444.1078407-2-takano32@gmail.com>

Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [Medium] perf: hardcoded local PERF fallback path breaks
  stat+tool_group.sh
- [Medium] perf: -C hybrid test still selects CPU 0 instead of a core
  PMU CPU
- [Medium] perf: hybrid_core_types() masks uncounted events via
  any-match logic
- [Low] perf: hybrid_core_types() omits percentage stripping on counted
  lines
- [Low] perf: refused_either() ignores pattern and weakens stderr
  assertion
- [Low] perf: unused orig_path variable left in stat+tool_group.sh
--

commit f4bf103458da72ae9c4983ff105e9599ecdb3196
Author: TAKANO Mitsuhiro <takano32@gmail.com>

perf stat: Fix hybrid test failure and respect $PERF in stat+tool_group.sh

This commit updates stat+tool_group.sh to strip percentage suffixes in
hybrid_core_types(), select an online CPU dynamically for the -C test,
and use a configurable PERF binary path.

> diff --git a/tools/perf/tests/shell/stat+tool_group.sh b/tools/perf/tests/shell/stat+tool_group.sh
> index 4a2aae62321c0..19457fec395d4 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"
> +

[Severity: Medium]
Should the fallback PERF path default to "perf" instead of a local build
directory?

perf test runs shell scripts via shell_test__run() without setting PERF,
relying on setup_path() putting the perf binary on PATH.  This hardcoded
path makes every perf stat call fail with status 127 on other machines,
and risks running an untrusted binary on multi-user hosts.

[ ... ]

> @@ -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

[Severity: Low]
Is orig_path leftover debugging code?  It is never referenced anywhere in
stat+tool_group.sh.

[ ... ]

> @@ -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

[Severity: Low]
Was dropping ${pattern} here intentional?  This leaves pattern unused and
stops verifying the error prefix and named event, contradicting the failure
message below it and going unmentioned in the commit message.

If hybrid PMU prefixes on cycles:R broke the match, allowing an optional
PMU prefix in pattern would preserve the check.

[ ... ]

> @@ -132,6 +136,7 @@ hybrid_core_types() {
>         }
>         /<not counted>/ {
>           sub(/#.*/, "")
> +         sub(/\([0-9.]*%\)/, "")

[Severity: Low]
Should percentage suffixes also be stripped in the FNR == NR pass above?

print_running_std() appends (%.2f%%) whenever run != ena on counted lines
too.  When a counted hybrid event is multiplexed without a # metric
comment, $(NF) becomes the percentage token instead of the event name, so
hybrid_core_types() fails to match the <not counted> line.

>           if (bare($(NF)) in counted)
>             found = 1
>         }

[Severity: Medium]
Can hybrid_core_types() mask an uncounted event in multi-event groups?

Setting found = 1 on any matching <not counted> line lets the awk script
succeed even if another <not counted> line has no counted counterpart.  If
cycles is hybrid-split while instructions is <not counted> on all core
types, accepted() marks the test skipped instead of failed.

[ ... ]

> @@ -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

[Severity: Medium]
Does this still pass -C 0 on hybrid Intel machines and fail the test?

The awk command only reads /sys/devices/system/cpu/online without checking
any PMU cpus mask, so online_cpu is still 0 on systems with ranges like
0-23.  Unlike the previous grep, which skipped range syntax, this now
actively runs -C 0.

pmu_read_sysfs() sorts core_pmus alphabetically, so {cycles,duration_time}
groups {cpu_atom/cycles/, duration_time}.  When CPU 0 belongs to cpu_core,
__perf_evlist__propagate_maps() intersects cpu_atom's CPUs with {0} to an
empty map and removes the leader.

evlist__check_cpu_maps() then detaches duration_time before
check_unopened_in_group() runs, so perf stat exits 0 instead of 22 and
refused() fails.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204041444.1078407-1-takano32@gmail.com?part=2

  reply	other threads:[~2026-12-04  4:28 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                       ` [PATCH v13 2/2] perf stat: Fix hybrid test failure and respect $PERF in stat+tool_group.sh TAKANO Mitsuhiro
2026-12-04  4:28                         ` sashiko-bot [this message]
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=sashiko-outbox-249088@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=takano32@gmail.com \
    /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