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 v3 09/19] perf test: Add named_threads workload
Date: Wed, 03 Jun 2026 10:26:22 +0000	[thread overview]
Message-ID: <20260603102622.8A04D1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260603-james-cs-context-tracking-fix-v3-9-c392945d9ed5@linaro.org>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] Data race and signed integer overflow on the global `named_threads_work` variable leading to Undefined Behavior.
- [Medium] Lack of synchronization barriers guarantees sequential execution instead of concurrent thread execution.
- [Medium] Background threads are leaked on the `pthread_create` error path.
--

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

perf test: Add named_threads workload

Add a workload that runs X threads executing a unique function to perform
multiplication in a loop. This is intended to test that processor trace
decoding handles concurrent threads correctly.

> diff --git a/tools/perf/tests/workloads/named_threads.c b/tools/perf/tests/workloads/named_threads.c
> new file mode 100644
> index 0000000000000..dc8070a98df4c
> --- /dev/null
> +++ b/tools/perf/tests/workloads/named_threads.c
> @@ -0,0 +1,109 @@
[ ... ]
> +static int iterations = 500;
> +int named_threads_work = 1234;
> +
> +typedef void *(*thread_fn_t)(void *);
> +
> +#define DEFINE_THREAD(n)						\
> +noinline void *named_threads_thread##n(void *arg __maybe_unused)	\
> +{									\
> +	pthread_setname_np(pthread_self(), "thread" #n);		\
> +	for (int i = 0; i < iterations; i++)				\
> +		named_threads_work *= 3;				\

[Severity: Medium]
Does this loop trigger undefined behavior due to data races and signed
integer overflow? 

Multiple threads concurrently modify the global named_threads_work without 
synchronization. Additionally, multiplying 1234 by 3 for 500 iterations 
will overflow the signed integer. 

Could modern C compilers optimize this loop out entirely due to the UB, 
preventing the generation of the processor trace samples this test relies 
on?

> +									\
> +	return NULL;							\
> +}
[ ... ]
> +static int named_threads(int argc, const char **argv)
> +{
[ ... ]
> +	for (int i = 0; i < nr_threads; i++) {
> +		int ret;
> +
> +		ret = pthread_create(&threads[i], NULL, thread_fns[i], NULL);

[Severity: Medium]
Will these threads actually run concurrently as intended?

The overhead of pthread_create is typically longer than the time it takes
for the thread to execute its workload, especially since the loop only 
executes 500 simple multiplications. 

Without a synchronization barrier (like pthread_barrier_wait), earlier 
threads might complete their loops and exit before the main thread finishes 
spawning the remaining threads, resulting in sequential execution rather 
than overlapping concurrent tasks.

> +		if (ret) {
> +			fprintf(stderr, "Error: failed to create thread%d: %s\n",
> +				i + 1, strerror(ret));
> +			return 1;

[Severity: Medium]
Does this error path leak previously created background threads?

If pthread_create fails for any thread index greater than 0, the function
returns 1 immediately. It doesn't join the successfully created threads from
earlier iterations. 

If perf test is run in non-forking mode (e.g., with --dont-fork), these 
leaked background threads could persist and interfere with subsequent tests.

> +		}
> +	}
> +
> +	for (int i = 0; i < nr_threads; i++)
> +		pthread_join(threads[i], NULL);
> +
> +	return err;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260603-james-cs-context-tracking-fix-v3-0-c392945d9ed5@linaro.org?part=9

  reply	other threads:[~2026-06-03 10:26 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-03 10:17 [PATCH v3 00/19] perf cs-etm: Queue context packets for frontend James Clark
2026-06-03 10:17 ` [PATCH v3 01/19] " James Clark
2026-06-03 10:32   ` sashiko-bot
2026-06-03 20:14   ` Amir Ayupov
2026-06-03 10:17 ` [PATCH v3 02/19] perf test: Add workload-ctl option James Clark
2026-06-03 10:17 ` [PATCH v3 03/19] perf test: Add a workload that forces context switches James Clark
2026-06-03 10:28   ` sashiko-bot
2026-06-03 10:17 ` [PATCH v3 04/19] perf test cs-etm: Test process attribution James Clark
2026-06-03 10:17 ` [PATCH v3 05/19] perf test: Add deterministic workload James Clark
2026-06-03 10:24   ` sashiko-bot
2026-06-03 10:17 ` [PATCH v3 06/19] perf test cs-etm: Replace unroll loop thread with deterministic decode test James Clark
2026-06-03 10:30   ` sashiko-bot
2026-06-03 10:17 ` [PATCH v3 07/19] perf test cs-etm: Remove asm_pure_loop test James Clark
2026-06-03 10:17 ` [PATCH v3 08/19] perf test cs-etm: Replace memcpy test with raw dump stress test James Clark
2026-06-03 10:17 ` [PATCH v3 09/19] perf test: Add named_threads workload James Clark
2026-06-03 10:26   ` sashiko-bot [this message]
2026-06-03 10:17 ` [PATCH v3 10/19] perf test cs-etm: Test decoding for concurrent threads test James Clark
2026-06-03 10:17 ` [PATCH v3 11/19] perf test cs-etm: Remove duplicate branch tests James Clark
2026-06-03 10:17 ` [PATCH v3 12/19] perf test cs-etm: Skip if not root James Clark
2026-06-03 10:17 ` [PATCH v3 13/19] perf test cs-etm: Reduce snapshot size James Clark
2026-06-03 10:17 ` [PATCH v3 14/19] perf test cs-etm: Speed up basic test James Clark
2026-06-03 10:17 ` [PATCH v3 15/19] perf test cs-etm: Remove unused Coresight workloads James Clark
2026-06-03 10:41   ` sashiko-bot
2026-06-03 10:17 ` [PATCH v3 16/19] perf test cs-etm: Make disassembly test use kcore James Clark
2026-06-03 10:36   ` sashiko-bot
2026-06-03 10:17 ` [PATCH v3 17/19] perf test cs-etm: Add all branch instructions to test James Clark
2026-06-03 10:17 ` [PATCH v3 18/19] perf test cs-etm: Speed up disassembly test James Clark
2026-06-03 10:17 ` [PATCH v3 19/19] perf test cs-etm: Move existing tests to coresight folder James Clark

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=20260603102622.8A04D1F00893@smtp.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