Re: Please backport subset of 2f5d370dec3f ("perf test: Change all remaining #!/bin/sh to #!/bin/bash") for stat_bpf_counters.sh script to v6.12.y and older

From: Ian Rogers

Date: Fri Sep 18 2026 - 15:42:14 EST


On Fri, Sep 18, 2026 at 12:20 PM Salvatore Bonaccorso <carnil@xxxxxxxxxx> wrote:
>
> Hi,
>
> On Fri, Sep 18, 2026 at 09:08:48PM +0200, Salvatore Bonaccorso wrote:
> > Hi
> >
> > Recently for v5.15.221, v6.1.188, v6.6.157, v6.12.110, v6.18.52 and
> > v7.2.6, the commit b02027776ac5 ("perf tests: Fix flakiness in BPF
> > counters test on hybrid systems") was backported, but it introduced
> > bash specific syntax. For versions after 2f5d370dec3f ("perf test:
> > Change all remaining #!/bin/sh to #!/bin/bash") aka before v6.17-rc1
> > this is not a problem.
> >
> > The proposed patch is a stable series backports specific one, as one
> > cannot simply backport 2f5d370dec3f ("perf test: Change all remaining
> > #!/bin/sh to #!/bin/bash") without picking as well some other context
> > related changes to make it possible. So I was proposing to only change
> > shebang to #!/bin/bash in stable series were it is a problem, as in
> > the stat_bpf_counters.sh script.
>
> "Obviously" there was a typo in the commit message and a missing
> explanation, thus v2 of the proposed change as follows.
>
> Regards,
> Salvatore
>
> From 804ae26dab32c846467d7b7887d8f7dcd3348fa5 Mon Sep 17 00:00:00 2001
> From: Salvatore Bonaccorso <carnil@xxxxxxxxxx>
> Date: Fri, 18 Sep 2026 20:48:59 +0200
> Subject: [PATCH] perf tests: Change shebang for stat_bpf_counters.sh to
> #!/bin/bash
>
> When commit b02027776ac5 ("perf tests: Fix flakiness in BPF counters
> test on hybrid systems") was backported to several stable series
> (v5.15.221, v6.1.188, v6.6.157, v6.12.110, v6.18.52, v7.2.6) it
> introduced specific bash syntax. For versions after 2f5d370dec3f ("perf
> test: Change all remaining #!/bin/sh to #!/bin/bash") in v6.17-rc1 this
> is not a problem as the shebang was already changed to #!/bin/bash. For
> the older stable series this introduced invalid syntax if #!/bin/sh is
> not bash:
>
> $ sh -n tools/perf/tests/shell/stat_bpf_counters.sh
> tools/perf/tests/shell/stat_bpf_counters.sh: 12: Syntax error: "(" unexpected
>
> $ checkbashism tools/perf/tests/shell/stat_bpf_counters.sh
> possible bashism in tools/perf/tests/shell/stat_bpf_counters.sh line 52 (bash arrays, ${name[0|*|@]}):
> base_instructions=$(perf stat --no-big-num -e instructions:u -- "${workload[@]}" 2>&1 | \
> awk -v i=0 -v c=0 '/instructions/ { \
> if ($1 != "<not") { i++; c += $1 } \
> } END { if (i > 0) printf "%.0f", c; else print "<not" }')
> possible bashism in tools/perf/tests/shell/stat_bpf_counters.sh line 57 (bash arrays, ${name[0|*|@]}):
> bpf_instructions=$(perf stat --no-big-num --bpf-counters -e instructions:u \
> -- "${workload[@]}" 2>&1 | \
> awk -v i=0 -v c=0 '/instructions/ { \
> if ($1 != "<not") { i++; c += $1 } \
> } END { if (i > 0) printf "%.0f", c; else print "<not" }')
> possible bashism in tools/perf/tests/shell/stat_bpf_counters.sh line 68 (bash arrays, ${name[0|*|@]}):
> stat_output=$(perf stat --no-big-num \
> -e instructions/name=base_instructions/u,instructions/name=bpf_instructions/bu \
> -- "${workload[@]}" 2>&1)
>
> Change shebang for the stat_bpf_counters.sh script to #!/bin/bash.
>
> No upstream commit exists for this change as for versions post 6.17-rc1
> the scripts were converted to #!/bin/bash already.
>
> Signed-off-by: Salvatore Bonaccorso <carnil@xxxxxxxxxx>

Reviewed-by: Ian Rogers <irogers@xxxxxxxxxx>

This should have been caught by the perf tool build as that build runs
shellcheck on all tests when shellcheck is available. Maybe there
should be an action to run perf builds as part of the stable backports
when the tools/perf directory is touched.

Thanks,
Ian

> ---
> v2:
> - Fixed a typo in commit message: hanged -> changed
> - Explicit state to what shebang was changed for stat_bpf_counters.sh
> script.
>
> tools/perf/tests/shell/stat_bpf_counters.sh | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/perf/tests/shell/stat_bpf_counters.sh b/tools/perf/tests/shell/stat_bpf_counters.sh
> index 76d4a7f15a43..c4f71bfc0fc6 100755
> --- a/tools/perf/tests/shell/stat_bpf_counters.sh
> +++ b/tools/perf/tests/shell/stat_bpf_counters.sh
> @@ -1,4 +1,4 @@
> -#!/bin/sh
> +#!/bin/bash
> # perf stat --bpf-counters test
> # SPDX-License-Identifier: GPL-2.0
>
> --
> 2.55.0
>