Re: [PATCH v2 12/14] perf test: Allow infinite named_thread loops

[email protected]
Newsgroups org.kernel.vger.linux-perf-users
Message-ID <[email protected]>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The intentional infinite loop in test threads can be optimized away by the compiler, violating the requirement that they run forever.
--

--- Patch [12]: [PATCH v2 12/14] perf test: Allow infinite named_thread loops ---
commit 53c8a5e547e7365781e369ccbc9c9f225381027d
Author: James Clark <[email protected]>

perf test: Allow infinite named_thread loops

This commit modifies the named_threads workload in perf tests to run
infinitely when 0 is passed for the loop count. It also converts the loop
counter and work variable to unsigned integers to prevent undefined behavior
from signed overflow.

> diff --git a/tools/perf/tests/workloads/named_threads.c b/tools/perf/tests/workloads/named_threads.c
> index d051d41a3cfe4..6672c2f776840 100644
> --- a/tools/perf/tests/workloads/named_threads.c
> +++ b/tools/perf/tests/workloads/named_threads.c
[ ... ]
> @@ -19,7 +19,8 @@ typedef void *(*thread_fn_t)(void *);
>  noinline void *named_threads_thread##n(void *arg __maybe_unused)	\
>  {									\
>  	pthread_setname_np(pthread_self(), "thread" #n);		\
> -	for (int i = 0; i < iterations; i++)				\
> +	for (unsigned int i = 0;					\
> +	     i < (unsigned int) iterations || iterations == 0; i++)	\
>  		named_threads_work += 3;				\

[Severity: Medium]
Will this loop in DEFINE_THREAD() be optimized away by the compiler when
iterations == 0?

Because named_threads_work is not volatile and the loop lacks a compiler barrier
or cpu_relax(), the compiler might assume the loop terminates and eliminate it
entirely.

Could this cause the test threads to exit immediately instead of generating
continuous CPU cycles as intended?

>  									\
>  	return NULL;							\
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260821-james-cs-unformatted-per-thread-fix-v2-0-00c4fd0701b4@linaro.org?part=12
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.