From: sashiko-bot@kernel.org
To: "Changbin Du" <changbin.du@gmail.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH] perf bench: Add atomic CAS benchmark
Date: Wed, 30 Sep 2026 09:25:53 +0000 [thread overview]
Message-ID: <20260930092553.819B61F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260930091617.4189736-1-changbin.du@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] perf bench: 32-bit integer overflow computing runtime in worker()
- [Low] perf bench: missing stdbool.h inclusion for false in worker()
--
commit 37bbeabb11e8b0698696e276ba97886862aa6887
Author: Changbin Du <changbin.du@intel.com>
perf bench: Add atomic CAS benchmark
This commit introduces a new atomic collection to perf bench for measuring
the performance of compare-and-swap (CAS) operations. It evaluates
multi-threaded contention to help identify latency and scalability patterns.
> diff --git a/tools/perf/bench/atomic.c b/tools/perf/bench/atomic.c
> new file mode 100644
> index 0000000000000..ce97025018ab3
> --- /dev/null
> +++ b/tools/perf/bench/atomic.c
[ ... ]
> +static void *worker(void *arg)
> +{
> + struct worker_stats *ws = (struct worker_stats *)arg;
> + struct timespec tstart, tend;
> + u64 i;
> +
> + pthread_barrier_wait(&start_barrier);
> +
> + clock_gettime(CLOCK_MONOTONIC, &tstart);
> + for (i = 0; i < iterations; i++) {
> + u64 old_val, new_val;
> +
> + do {
> + old_val = __atomic_load_n(&shared_counter,
> + __ATOMIC_RELAXED);
> + new_val = old_val + 1;
> + } while (!__atomic_compare_exchange_n(&shared_counter,
> + &old_val, new_val,
> + false,
[Severity: Low]
Does this file need to explicitly include <stdbool.h>?
The POSIX guidelines for perf tool compatibility with musl require files using
POSIX constants like false to directly include the headers where they are
declared. Relying on implicit inclusion from other headers can cause
compilation failures.
> + __ATOMIC_RELAXED,
> + __ATOMIC_RELAXED));
> + }
> + clock_gettime(CLOCK_MONOTONIC, &tend);
> +
> + ws->runtime_ns = (tend.tv_sec - tstart.tv_sec) * NSEC_PER_SEC +
[Severity: Medium]
Can this runtime calculation overflow on 32-bit architectures?
When compiling for 32-bit platforms where time_t is a 32-bit signed integer,
tv_sec is also a 32-bit signed integer. Since NSEC_PER_SEC is defined as
1000000000L (which is 32-bit signed on 32-bit platforms), the multiplication
is performed as a 32-bit signed integer operation.
If the time difference exceeds 2.14 seconds, the result wraps around before
being converted and assigned to the u64 runtime_ns field. Given the default
iterations take around 7.3 seconds based on the commit message, wouldn't this
guarantee an overflow during a native 32-bit run, leading to incorrect
benchmark results?
> + (tend.tv_nsec - tstart.tv_nsec);
> +
> + return NULL;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260930091617.4189736-1-changbin.du@gmail.com?part=1
next prev parent reply other threads:[~2026-09-30 9:25 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-30 9:16 [PATCH] perf bench: Add atomic CAS benchmark Changbin Du
2026-09-30 9:25 ` sashiko-bot [this message]
2026-10-05 22:30 ` Namhyung Kim
2026-10-07 5:27 ` Changbin Du
2026-10-07 21:35 ` Namhyung Kim
2026-10-08 7:44 ` David Laight
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=20260930092553.819B61F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=changbin.du@gmail.com \
--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