linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] perf test: Skip 6.2 kernel for bpf-filter test
@ 2023-08-25 16:41 Namhyung Kim
  2023-08-25 16:41 ` [PATCH 2/3] perf test: Fix perf stat bpf counters test on Intel Namhyung Kim
  2023-08-25 16:41 ` [PATCH 3/3] perf test: Enhance perf stat cgroup BPF counter test Namhyung Kim
  0 siblings, 2 replies; 4+ messages in thread
From: Namhyung Kim @ 2023-08-25 16:41 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: Ian Rogers, Adrian Hunter, Peter Zijlstra, Ingo Molnar, LKML,
	linux-perf-users, bpf

The BPF sample filtering requires two kernel changes below:
 * bpf_cast_to_kernel_ctx() kfunc (added in v6.2)
 * setting perf_sample_data->sample_flags (finished in v6.3)

The perf tools can check bpf_cast_to_kernel_ctx() easily so it can
refuse BPF filters on those old kernels (v6.1 and earlier).  But
checking sample_flags appears to be difficult so current code won't
work on v6.2 kernel.  That's unfortunate but I don't know what's the
correct way to handle it.

For now, let's skip v6.2 kernels explicitly (if failed) in the test.

Fixes: 9575ecdd198a ("perf test: Add perf record sample filtering test")
Reported-by: Arnaldo Carvalho de Melo <acme@kernel.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/tests/shell/record_bpf_filter.sh | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tools/perf/tests/shell/record_bpf_filter.sh b/tools/perf/tests/shell/record_bpf_filter.sh
index e76ea861b92c..31c593966e8c 100755
--- a/tools/perf/tests/shell/record_bpf_filter.sh
+++ b/tools/perf/tests/shell/record_bpf_filter.sh
@@ -49,6 +49,12 @@ test_bpf_filter_basic() {
   fi
   if perf script -i "${perfdata}" -F ip | grep 'ffffffff[0-9a-f]*'
   then
+    if uname -r | grep -q ^6.2
+    then
+      echo "Basic bpf-filter test [Skipped unsupported kernel]"
+      err=2
+      return
+    fi
     echo "Basic bpf-filter test [Failed invalid output]"
     err=1
     return
-- 
2.42.0.rc1.204.g551eb34607-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] perf test: Fix perf stat bpf counters test on Intel
  2023-08-25 16:41 [PATCH 1/3] perf test: Skip 6.2 kernel for bpf-filter test Namhyung Kim
@ 2023-08-25 16:41 ` Namhyung Kim
  2023-08-25 16:47   ` Song Liu
  2023-08-25 16:41 ` [PATCH 3/3] perf test: Enhance perf stat cgroup BPF counter test Namhyung Kim
  1 sibling, 1 reply; 4+ messages in thread
From: Namhyung Kim @ 2023-08-25 16:41 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: Ian Rogers, Adrian Hunter, Peter Zijlstra, Ingo Molnar, LKML,
	linux-perf-users, bpf, stable, Song Liu

As of now, bpf counters (bperf) don't support event groups.  But the
default perf stat includes topdown metrics if supported (on recent Intel
machines) which require groups.  That makes perf stat exiting.

  $ sudo perf stat --bpf-counter true
  bpf managed perf events do not yet support groups.

Actually the test explicitly uses cycles event only, but it missed to
pass the option when it checks the availability of the command.

Fixes: 2c0cb9f56020d ("perf test: Add a shell test for 'perf stat --bpf-counters' new option")
Cc: stable@vger.kernel.org
Cc: Song Liu <song@kernel.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/tests/shell/stat_bpf_counters.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/tests/shell/stat_bpf_counters.sh b/tools/perf/tests/shell/stat_bpf_counters.sh
index 513cd1e58e0e..a87bb2814b4c 100755
--- a/tools/perf/tests/shell/stat_bpf_counters.sh
+++ b/tools/perf/tests/shell/stat_bpf_counters.sh
@@ -22,10 +22,10 @@ compare_number()
 }
 
 # skip if --bpf-counters is not supported
-if ! perf stat --bpf-counters true > /dev/null 2>&1; then
+if ! perf stat -e cycles --bpf-counters true > /dev/null 2>&1; then
 	if [ "$1" = "-v" ]; then
 		echo "Skipping: --bpf-counters not supported"
-		perf --no-pager stat --bpf-counters true || true
+		perf --no-pager stat -e cycles --bpf-counters true || true
 	fi
 	exit 2
 fi
-- 
2.42.0.rc1.204.g551eb34607-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] perf test: Enhance perf stat cgroup BPF counter test
  2023-08-25 16:41 [PATCH 1/3] perf test: Skip 6.2 kernel for bpf-filter test Namhyung Kim
  2023-08-25 16:41 ` [PATCH 2/3] perf test: Fix perf stat bpf counters test on Intel Namhyung Kim
@ 2023-08-25 16:41 ` Namhyung Kim
  1 sibling, 0 replies; 4+ messages in thread
From: Namhyung Kim @ 2023-08-25 16:41 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: Ian Rogers, Adrian Hunter, Peter Zijlstra, Ingo Molnar, LKML,
	linux-perf-users, bpf

It has system-wide test and cpu-list test but the cpu-list test fails
sometimes.  It runs sleep command on CPU1 and measure both user.slice
and system.slice cgroups by default (on systemd-based systems).

But if the system was idle enough, sometime the system.slice gets no
count and it makes the test failing.  Maybe that's because it only looks
at the CPU1, let's add CPU0 to increase the chance it finds some tasks.

Fixes: 7901086014bba ("perf test: Add a new test for perf stat cgroup BPF counter")
Reported-by: Arnaldo Carvalho de Melo <acme@kernel.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/tests/shell/stat_bpf_counters_cgrp.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/tests/shell/stat_bpf_counters_cgrp.sh b/tools/perf/tests/shell/stat_bpf_counters_cgrp.sh
index a74440a00b6b..e75d0780dc78 100755
--- a/tools/perf/tests/shell/stat_bpf_counters_cgrp.sh
+++ b/tools/perf/tests/shell/stat_bpf_counters_cgrp.sh
@@ -60,7 +60,7 @@ check_system_wide_counted()
 
 check_cpu_list_counted()
 {
-	check_cpu_list_counted_output=$(perf stat -C 1 --bpf-counters --for-each-cgroup ${test_cgroups} -e cpu-clock -x, taskset -c 1 sleep 1  2>&1)
+	check_cpu_list_counted_output=$(perf stat -C 0,1 --bpf-counters --for-each-cgroup ${test_cgroups} -e cpu-clock -x, taskset -c 1 sleep 1  2>&1)
 	if echo ${check_cpu_list_counted_output} | grep -q -F "<not "; then
 		echo "Some CPU events are not counted"
 		if [ "${verbose}" = "1" ]; then
-- 
2.42.0.rc1.204.g551eb34607-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/3] perf test: Fix perf stat bpf counters test on Intel
  2023-08-25 16:41 ` [PATCH 2/3] perf test: Fix perf stat bpf counters test on Intel Namhyung Kim
@ 2023-08-25 16:47   ` Song Liu
  0 siblings, 0 replies; 4+ messages in thread
From: Song Liu @ 2023-08-25 16:47 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Arnaldo Carvalho de Melo, Jiri Olsa, Ian Rogers, Adrian Hunter,
	Peter Zijlstra, Ingo Molnar, LKML, linux-perf-users, bpf, stable

On Fri, Aug 25, 2023 at 9:41 AM Namhyung Kim <namhyung@kernel.org> wrote:
>
> As of now, bpf counters (bperf) don't support event groups.  But the
> default perf stat includes topdown metrics if supported (on recent Intel
> machines) which require groups.  That makes perf stat exiting.
>
>   $ sudo perf stat --bpf-counter true
>   bpf managed perf events do not yet support groups.
>
> Actually the test explicitly uses cycles event only, but it missed to
> pass the option when it checks the availability of the command.
>
> Fixes: 2c0cb9f56020d ("perf test: Add a shell test for 'perf stat --bpf-counters' new option")
> Cc: stable@vger.kernel.org
> Cc: Song Liu <song@kernel.org>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Reviewed-by: Song Liu <song@kernel.org>

Thanks!
Song

> ---
>  tools/perf/tests/shell/stat_bpf_counters.sh | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/tests/shell/stat_bpf_counters.sh b/tools/perf/tests/shell/stat_bpf_counters.sh
> index 513cd1e58e0e..a87bb2814b4c 100755
> --- a/tools/perf/tests/shell/stat_bpf_counters.sh
> +++ b/tools/perf/tests/shell/stat_bpf_counters.sh
> @@ -22,10 +22,10 @@ compare_number()
>  }
>
>  # skip if --bpf-counters is not supported
> -if ! perf stat --bpf-counters true > /dev/null 2>&1; then
> +if ! perf stat -e cycles --bpf-counters true > /dev/null 2>&1; then
>         if [ "$1" = "-v" ]; then
>                 echo "Skipping: --bpf-counters not supported"
> -               perf --no-pager stat --bpf-counters true || true
> +               perf --no-pager stat -e cycles --bpf-counters true || true
>         fi
>         exit 2
>  fi
> --
> 2.42.0.rc1.204.g551eb34607-goog
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-08-25 16:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-25 16:41 [PATCH 1/3] perf test: Skip 6.2 kernel for bpf-filter test Namhyung Kim
2023-08-25 16:41 ` [PATCH 2/3] perf test: Fix perf stat bpf counters test on Intel Namhyung Kim
2023-08-25 16:47   ` Song Liu
2023-08-25 16:41 ` [PATCH 3/3] perf test: Enhance perf stat cgroup BPF counter test Namhyung Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).