Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "James Clark" <james.clark@linaro.org>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v4 18/19] perf test: cs-etm: Test multiple per-thread threads
Date: Thu, 05 Nov 2026 14:00:57 +0000	[thread overview]
Message-ID: <sashiko-outbox-199183@kernel.org> (raw)
In-Reply-To: <20261105-james-cs-unformatted-per-thread-fix-v4-18-7759e0ce2449@linaro.org>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] perf test: cs-etm: unguarded kill in cleanup_files() aborts under set -e
- [Medium] perf test: cs-etm: unsynchronized perf record startup and thread wait loop
--

commit a1c04dea71b5f9bb657ac0b302a38c803f86b131
Author: James Clark <james.clark@linaro.org>

perf test: cs-etm: Test multiple per-thread threads

This commit adds a shell test for CoreSight per-thread tracing across
multiple child threads on systems with TRBE sinks. It spawns the
named_threads workload, attaches perf record in --per-thread mode, and
checks that perf script output includes samples from all child threads.

> diff --git a/tools/perf/tests/shell/coresight/per-thread-multi.sh b/tools/perf/tests/shell/coresight/per-thread-multi.sh
> new file mode 100755
> index 0000000000000..bace76cb6a510
> --- /dev/null
> +++ b/tools/perf/tests/shell/coresight/per-thread-multi.sh
> @@ -0,0 +1,76 @@
> +#!/bin/bash -e
> +# CoreSight per-thread multiple threads (exclusive)
> +
> +# SPDX-License-Identifier: GPL-2.0
> +
> +# If CoreSight is not available, skip the test
> +perf list pmu | grep -q cs_etm || exit 2
> +
> +if ! tmpdir=$(mktemp -d /tmp/perf-cs-per-thread-multi-test.XXXXXX); then
> +	echo "mktemp failed"
> +	exit 1
> +fi
> +
> +cleanup_files()
> +{
> +	if [[ $parent ]]; then
> +		kill -9 $parent
> +		wait $parent || true
> +	fi
> +	if [[ $perf ]]; then
> +		kill -9 $perf
> +		wait $perf || true
> +	fi
> +	rm -rf "$tmpdir"
> +	trap - EXIT TERM INT
> +}

[Severity: Medium]
As reported by Sashiko on v3 [1], because the script runs under
#!/bin/bash -e, errexit remains active inside cleanup_files(). Later in
the script:

    kill $parent
    wait $parent || true
    unset parent
    wait $perf
    unset perf

If the background perf record process fails and exits with a non-zero
status, wait $perf reaps the process and triggers an immediate shell exit
before unset perf runs, invoking cleanup_files() via the EXIT trap while
$perf is still set. Inside cleanup_files(), kill -9 $perf fails with ESRCH
because $perf has already exited and been reaped, aborting cleanup_files()
before rm -rf "$tmpdir" can remove /tmp/perf-cs-per-thread-multi-test.XXXXXX.

Similarly, if $parent exits unexpectedly before unset parent runs, kill
$parent fails and cleanup_files() aborts at kill -9 $parent before killing
$perf or removing $tmpdir.

Should kill -9 $parent and kill -9 $perf in cleanup_files() be guarded with
2>/dev/null || true?

[ ... ]

> +# Launch 2 threads to run indefinitely
> +nthreads=2
> +perf test -w named_threads $nthreads 0 &
> +parent=$!
> +
> +# While parent still exists, wait for the 2 children to spawn
> +while kill -0 "$parent" 2>/dev/null; do
> +  threads=(/proc/"$parent"/task/*)
> +
> +  if (( ${#threads[@]} >= $(($nthreads + 1)))); then
> +    break
> +  fi
> +
> +  sleep 0.1
> +done
> +
> +echo "Recording..."
> +perf record -o "$tmpdir/data" -e cs_etm//u --per-thread -Se -m,128K --pid $parent > /dev/null 2>&1 &
> +perf=$!
> +
> +sleep 1
> +
> +kill $parent

[Severity: Medium]
As reported by Sashiko on v3 [2], could this startup and thread wait sequence
cause flaky failures or hangs on loaded systems?

When perf record --pid $parent is started in the background, sleep 1 runs
immediately in parallel with perf record initialization. In
tools/perf/builtin-record.c, __cmd_record() opens cs_etm//u and dummy:u in
the disabled state in record__open(), performs synthesis in
record__synthesize() (including CoreSight sysfs reads, BPF synthesis, and
/proc task and mmap synthesis), and only enables the events at
evlist__enable(). If initialization takes most of or longer than the 1
second sleep window, kill $parent terminates the workload before
evlist__enable() or before both threads are sampled, causing the grep check
on "$tmpdir/script" to fail.

Additionally, the /proc/"$parent"/task/* polling loop has no timeout if the
children fail to spawn, and breaks as soon as clone() creates the task
directories, before the child threads have necessarily called
pthread_setname_np() in tools/perf/tests/workloads/named_threads.c. If
pthread_setname_np() runs after __machine__synthesize_threads() reads
/proc/$parent/task/$tid/status but before evlist__enable() enables dummy:u,
the PERF_RECORD_COMM event can be missed.

Would it be more reliable to use wait_for_threads() and
wait_for_perf_to_start() from tools/perf/tests/shell/lib/waiting.sh, or pass
sleep 1 as the perf record child workload so evlist__start_workload() runs
it only after evlist__enable()?

[1] https://lore.kernel.org/r/20261102-james-cs-unformatted-per-thread-fix-v3-18-dbcb0c281b9b@linaro.org
[2] https://lore.kernel.org/r/20261102-james-cs-unformatted-per-thread-fix-v3-18-dbcb0c281b9b@linaro.org

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261105-james-cs-unformatted-per-thread-fix-v4-0-7759e0ce2449@linaro.org?part=18

  reply	other threads:[~2026-11-05 14:00 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-05 11:44 [PATCH v4 00/19] perf cs-etm: Per-thread mode fixes and snapshot wrap support James Clark
2026-11-05 11:44 ` [PATCH v4 01/19] perf cs-etm: Fix nVHE per-thread decoding James Clark
2026-11-05 12:00   ` sashiko-bot
2026-11-05 11:44 ` [PATCH v4 02/19] perf cs-etm: Warn for invalid timestamp option James Clark
2026-11-05 12:05   ` sashiko-bot
2026-11-05 11:44 ` [PATCH v4 03/19] perf cs-etm: Turn on context packet timestamps in per-thread mode James Clark
2026-11-05 12:17   ` sashiko-bot
2026-11-05 11:44 ` [PATCH v4 04/19] perf cs-etm: Use per-CPU queues for " James Clark
2026-11-05 12:33   ` sashiko-bot
2026-11-05 11:44 ` [PATCH v4 05/19] perf test: cs-etm: Increase window size in disassembly test James Clark
2026-11-05 12:35   ` sashiko-bot
2026-11-05 11:44 ` [PATCH v4 06/19] perf cs-etm: Don't drop previous target for kernel samples James Clark
2026-11-05 12:51   ` sashiko-bot
2026-11-05 11:44 ` [PATCH v4 07/19] perf python: Expose sample instruction length James Clark
2026-11-05 12:54   ` sashiko-bot
2026-11-05 11:44 ` [PATCH v4 08/19] perf cs-etm: Use instruction length in disassembly script James Clark
2026-11-05 12:58   ` sashiko-bot
2026-11-05 11:44 ` [PATCH v4 09/19] perf cs-etm: Increase default timestamp generation period James Clark
2026-11-05 13:02   ` sashiko-bot
2026-11-05 11:44 ` [PATCH v4 10/19] perf auxtrace: Turn Intel BTS snapshot search into a generic one James Clark
2026-11-05 13:05   ` sashiko-bot
2026-11-05 11:44 ` [PATCH v4 11/19] perf arm-spe: Use generic snapshot search James Clark
2026-11-05 13:09   ` sashiko-bot
2026-11-05 11:45 ` [PATCH v4 12/19] perf auxtrace: intel-pt: Use common snapshot pointer fixup James Clark
2026-11-05 13:12   ` sashiko-bot
2026-11-05 11:45 ` [PATCH v4 13/19] perf cs-etm: Queue partial AUX records James Clark
2026-11-05 13:23   ` sashiko-bot
2026-11-05 11:45 ` [PATCH v4 14/19] perf cs-etm: Don't print missing buffers in snapshot mode James Clark
2026-11-05 13:25   ` sashiko-bot
2026-11-05 11:45 ` [PATCH v4 15/19] perf auxtrace: cs-etm: Capture wrapped snapshots James Clark
2026-11-05 13:30   ` sashiko-bot
2026-11-05 11:45 ` [PATCH v4 16/19] perf test: Allow infinite named_thread loops James Clark
2026-11-05 13:31   ` sashiko-bot
2026-11-05 11:45 ` [PATCH v4 17/19] perf test: cs-etm: Add test for per-thread mode James Clark
2026-11-05 13:44   ` sashiko-bot
2026-11-05 11:45 ` [PATCH v4 18/19] perf test: cs-etm: Test multiple per-thread threads James Clark
2026-11-05 14:00   ` sashiko-bot [this message]
2026-11-05 11:45 ` [PATCH v4 19/19] perf test: cs-etm: Increase snapshot size James Clark
2026-11-05 11:56   ` Leo Yan
2026-11-05 14:02   ` 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-199183@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=james.clark@linaro.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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