Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v1 08/12] perf tests: Fix flakiness in BPF counters test on hybrid systems
Date: Tue, 16 Jun 2026 01:35:55 +0000	[thread overview]
Message-ID: <20260616013556.323CF1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260616012744.4049193-9-irogers@google.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The script incorrectly uses `nproc` to pick a random CPU ID, which causes `taskset` to fail unconditionally on systems with restricted cpusets.
- [Medium] The percentage calculation using `expr $first_num \* 3 / 20` is vulnerable to a 32-bit signed integer overflow, causing false test failures on minimalist environments.
--

commit 3c1a23e10cc0581a3aebcf4bbcfca207d9638689
Author: Ian Rogers <irogers@google.com>
Subject: perf tests: Fix flakiness in BPF counters test on hybrid systems

This commit fixes flakiness in the BPF counters test by switching to a
deterministic `awk` workload pinned to a random CPU and restricted to
user-space instructions. It also tightens the comparison tolerance.

> diff --git a/tools/perf/tests/shell/stat_bpf_counters.sh b/tools/perf/tests/shell/stat_bpf_counters.sh
> index 35463358b273c..2f01608c95e37 100755
> --- a/tools/perf/tests/shell/stat_bpf_counters.sh
> +++ b/tools/perf/tests/shell/stat_bpf_counters.sh
> @@ -4,21 +4,25 @@
>  
>  set -e
>  
> -workload="perf test -w sqrtloop"
> +CPU=0
> +if command -v shuf >/dev/null 2>&1; then
> +	CPU=$(shuf -i 0-$(($(nproc) - 1)) -n 1 2>/dev/null || echo 0)
> +fi
> +workload=(taskset -c "$CPU" awk 'BEGIN { for (i=0; i<10000000; i++) sum+=i }')

[Severity: Medium]
On systems where the process is restricted to a subset of CPUs (e.g., CPUs 4
and 5 via cpusets), `nproc` will return 2. Will this select a CPU ID of 0 or 1,
causing `taskset -c "$CPU"` to fail unconditionally with an 'Invalid argument'
error?

If taskset fails immediately, it seems `perf stat` will only measure the brief
execution of the failed taskset command instead of the intended workload.

>  
> -# check whether $2 is within +/- 20% of $1
> +# check whether $2 is within +/- 15% of $1
>  compare_number()
>  {
>  	first_num=$1
>  	second_num=$2
>  
> -	# upper bound is first_num * 120%
> -	upper=$(expr $first_num + $first_num / 5 )
> -	# lower bound is first_num * 80%
> -	lower=$(expr $first_num - $first_num / 5 )
> +	# upper bound is first_num * 115%
> +	upper=$(expr $first_num + $first_num \* 3 / 20 )
> +	# lower bound is first_num * 85%
> +	lower=$(expr $first_num - $first_num \* 3 / 20 )

[Severity: Medium]
Will this percentage calculation cause an integer overflow on systems with
32-bit `expr` implementations (such as some BusyBox configurations)?

The newly introduced `awk` workload runs for 10 million iterations, executing
roughly 1.5 to 3 billion instructions. Since multiplication is performed before
division, `$first_num \* 3` will produce a value over 4.5 billion, overflowing
the 32-bit signed `INT_MAX` (2,147,483,647) and resulting in a negative bound.

Prior to this patch, division occurred first (`first_num / 5`), avoiding this
intermediate overflow.

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260616012744.4049193-1-irogers@google.com?part=8

  reply	other threads:[~2026-06-16  1:35 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-16  1:27 [PATCH v1 00/12] perf tests: Enhancements, speedups, and flakiness fixes Ian Rogers
2026-06-16  1:27 ` [PATCH v1 01/12] perf parse-events: Restrict core PMU bypass to --cputype option Ian Rogers
2026-06-16  1:44   ` sashiko-bot
2026-06-16  1:27 ` [PATCH v1 02/12] perf test: Truncate test description to fit terminal width Ian Rogers
2026-06-16  1:38   ` sashiko-bot
2026-06-16  1:27 ` [PATCH v1 03/12] perf tests workloads: Support sub-second durations in noploop and thloop Ian Rogers
2026-06-16  1:35   ` sashiko-bot
2026-06-16  1:27 ` [PATCH v1 04/12] perf tests: Add robust record retry helper and use subsecond workloads Ian Rogers
2026-06-16  1:38   ` sashiko-bot
2026-06-16  1:27 ` [PATCH v1 05/12] perf tests: Skip metrics validation if system-wide recording lacks permission Ian Rogers
2026-06-16  1:41   ` sashiko-bot
2026-06-16  1:27 ` [PATCH v1 06/12] perf tests: Fix Python JIT dump profiling test failure Ian Rogers
2026-06-16  1:39   ` sashiko-bot
2026-06-16  1:27 ` [PATCH v1 07/12] perf tests: Fix flakiness in trace record and replay test Ian Rogers
2026-06-16  1:42   ` sashiko-bot
2026-06-16  1:27 ` [PATCH v1 08/12] perf tests: Fix flakiness in BPF counters test on hybrid systems Ian Rogers
2026-06-16  1:35   ` sashiko-bot [this message]
2026-06-16  1:27 ` [PATCH v1 09/12] perf tests: Fix flakiness in branch stack sampling tests Ian Rogers
2026-06-16  1:27 ` [PATCH v1 10/12] perf tests: Speed up off-cpu profiling tests Ian Rogers
2026-06-16  1:41   ` sashiko-bot
2026-06-16  1:27 ` [PATCH v1 11/12] perf tests: Speed up lock contention analysis shell test Ian Rogers
2026-06-16  1:27 ` [PATCH v1 12/12] perf tests: Speed up metrics checking shell tests Ian Rogers
  -- strict thread matches above, loose matches on Subject: below --
2026-06-16  1:25 [PATCH v1 00/12] perf tests: Enhancements, speedups, and flakiness fixes Ian Rogers
2026-06-16  1:25 ` [PATCH v1 08/12] perf tests: Fix flakiness in BPF counters test on hybrid systems Ian Rogers

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=20260616013556.323CF1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=irogers@google.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