From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796044438; b=kLcwKWOpuS/6sg5V5vNX1lsdT249aVGkdboswqcLFqXJTS6t/An9QZ3Z1Nxq+3AQZKli hqq/6msLwFM4+ky/IM8Sd479xLjyn9d2CsYtydOl+WQYBf+GHBLmYzHf4mNLyHxHVpbS3 NRJ9il2A3WrqwWeqD33gNSvCQGiIbrJYJH64rpJZCFD61BWewrDYeaYmWAbxjk0toKMN5 JMGYqInCd1x+klNII3Xflicn0nUdoqLptrp3YqZJVLc5tNhP/gyWIKqUqX5d1YlHyPdje 5S5JsjvgzFaV19RE/W1SQZskiGDpjMgyvbuVys1TjtBV2mz6wyOMlfGlDGdsku9eKOw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796044438; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=Q/i58/fv1+E9nDIy4JdXegBFxYuMGq+bq0TPFauS3Vc=; b=CE1WP/+LwLZSW1Ff3F/lIKaFPq7Vv250e2usMoQ6e3sV4wzBAil/Mw0M2li4ByySH6nZ crhodyzB3x9g3IwnIZwxrgTSEkOJZkuAyFH52NwabWf2oUVVArhjG6c2tZa5Ets9iF08Z bYw/MKK46xKpThcEnUHUJ3t74fDDdBOmnzTgnet9Ym/ZQbXQ2eoeomHzNQszF2sCSkXNQ 9Ox98XpwRVAAjmSzJmRX0nvWXBZ2+peQn7OF7I3fDCaePK6Cl92FTP6G4ve8+zfyV21+t o2krRaduxjw7DVzT9Mfr3RDLBmbJx6P7kxU7WLqrza086u1gjzpXbT8OgxvL953SL3Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=diMQYcUH; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A3C4606A31C for ; Mon, 30 Nov 2026 13:13:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=diMQYcUH Received: by smtp.kernel.org (Postfix) with ESMTPSA id 792BA1F000C1; Mon, 30 Nov 2026 13:13:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796044437; bh=Q/i58/fv1+E9nDIy4JdXegBFxYuMGq+bq0TPFauS3Vc=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=diMQYcUHmBvWodGQ7q7jkmtpLNXP2zJYvA89CxMc6eNM+2o2sR7Q/iGiKLKA++jbx G6DSRXEmBYWeJ40mY1mq42vgbSoJkqFYVJZo0kXhmz1Mi2A806TWqihPQc0m8IPrbw Q7t3UkMcqNRdqsgA04rXiHOgVHirJJsEVbptWOfUW+iPm1djDI5BrvPpqfS9y/Ru5d wygdvqYKDYT8uoeffgF+ht0+QakKZTH0rgFkP1BxhsqofBq6+RXeXHm1umN4tuzTZz kI6eXOo7XnxYK3/64Fr0zJ8da+B+Tlrb75RoyTLdy+z6Zpj0AJp/eJMqU0j5C3LAU4 CRsC6hnM5dVjg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v5 18/19] perf test: cs-etm: Test multiple per-thread threads Reply-To: sashiko-reviews@lists.linux.dev To: "James Clark" Cc: linux-perf-users@vger.kernel.org In-Reply-To: <20261130-james-cs-unformatted-per-thread-fix-v5-18-f1bcc4d18c9b@linaro.org> References: <20261130-james-cs-unformatted-per-thread-fix-v5-0-f1bcc4d18c9b@linaro.org> <20261130-james-cs-unformatted-per-thread-fix-v5-18-f1bcc4d18c9b@linaro.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 13:13:55 +0000 X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 2 potential issues 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 b621845e4b0592b64332ebcf9f62c862f142a076 Author: James Clark perf test: cs-etm: Test multiple per-thread threads This commit adds a CoreSight shell test that attaches perf record in per-thread mode to a multi-threaded workload on systems with TRBE sinks and verifies that samples from all child threads are captured. > 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=3D$(mktemp -d /tmp/perf-cs-per-thread-multi-test.XXXXXX); th= en > + 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] Can cleanup_files() abort under set -e before removing $tmpdir? Later in the script, "wait $perf" runs before "unset perf". If perf record fails and exits with a non-zero status, "wait $perf" reaps the process and triggers an EXIT trap while $perf is still set. Because the script runs under "#!/bin/bash -e", the unguarded "kill -9 $perf" in cleanup_files() fails with ESRCH and exits the handler before "rm -rf "$tmpdir"" runs. Similarly, if $parent exits early, "kill -9 $parent" aborts cleanup_files() before killing $perf or removing $tmpdir. > + > +trap cleanup_files EXIT > +trap 'cleanup_files; exit 1' TERM INT > + > +# Multiple --per-thread events are only supported with 1:1 sinks/sources > +if ! ls /sys/bus/coresight/devices/trbe* > /dev/null 2>&1; then > + echo "No TRBE sinks, skipping" > + exit 2 > +fi > + > +# Launch 2 threads to run indefinitely > +nthreads=3D2 > +perf test -w named_threads $nthreads 0 & > +parent=3D$! > + > +# While parent still exists, wait for the 2 children to spawn > +while kill -0 "$parent" 2>/dev/null; do > + threads=3D(/proc/"$parent"/task/*) > + > + if (( ${#threads[@]} >=3D $(($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 --pi= d $parent > /dev/null 2>&1 & > +perf=3D$! > + > +sleep 1 > + > +kill $parent [Severity: Medium] Can "sleep 1" expire and kill $parent before perf record finishes initializing and enables events? perf record is started in the background, and its startup work (opening events disabled, starting the BPF sideband thread, and synthesizing auxtrace info, BPF events, and target threads) runs concurrently with "sleep 1" before evlist__enable() is reached. On a loaded system, or one with many CPUs or BPF programs, "kill $parent" can terminate the workload before tracing is enabled, causing missing thread samples. Running "sleep 1" as the perf record child workload or using wait_for_perf_to_start() from tools/perf/tests/shell/lib/waiting.sh would avoid this race. In addition, the /proc/$parent/task/* loop has no timeout and breaks as soon as clone() creates the task directories, before the child threads necessarily call pthread_setname_np(). If a child thread sets its comm name after __machine__synthesize_threads() reads /proc/$parent/task/ but before evlist__enable() enables the non-immediate dummy:u event, the PERF_RECORD_COMM event is dropped while dummy:u is still in PERF_EVENT_STATE_OFF, leaving samples attributed to "perf" instead of "thread1" or "thread2". --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130-james-cs-u= nformatted-per-thread-fix-v5-0-f1bcc4d18c9b@linaro.org?part=3D18