* [PATCH v2] perf test: Add AMD IBS sw filter test
@ 2025-05-24 0:27 Namhyung Kim
2025-05-24 9:47 ` Ravi Bangoria
0 siblings, 1 reply; 4+ messages in thread
From: Namhyung Kim @ 2025-05-24 0:27 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo, Ian Rogers, Kan Liang
Cc: Jiri Olsa, Adrian Hunter, Peter Zijlstra, Ingo Molnar, LKML,
linux-perf-users, Ravi Bangoria
The kernel v6.14 added 'swfilt' to support privilege filtering in
software so that IBS can be used by regular users. Add a test case in
x86 to verify the behavior.
$ sudo perf test -vv 'IBS software filter'
113: AMD IBS software filtering:
--- start ---
test child forked, pid 178826
check availability of IBS swfilt
run perf record with modifier and swfilt
[ perf record: Woken up 3 times to write data ]
[ perf record: Captured and wrote 0.000 MB /dev/null ]
[ perf record: Woken up 3 times to write data ]
[ perf record: Captured and wrote 0.000 MB /dev/null ]
[ perf record: Woken up 3 times to write data ]
[ perf record: Captured and wrote 0.000 MB /dev/null ]
[ perf record: Woken up 0 times to write data ]
[ perf record: Captured and wrote 0.000 MB /dev/null ]
check number of samples with swfilt
[ perf record: Woken up 3 times to write data ]
[ perf record: Captured and wrote 0.037 MB - ]
[ perf record: Woken up 3 times to write data ]
[ perf record: Captured and wrote 0.041 MB - ]
---- end(0) ----
113: AMD IBS software filtering : Ok
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/tests/shell/amd-ibs-swfilt.sh | 67 ++++++++++++++++++++++++
1 file changed, 67 insertions(+)
create mode 100755 tools/perf/tests/shell/amd-ibs-swfilt.sh
diff --git a/tools/perf/tests/shell/amd-ibs-swfilt.sh b/tools/perf/tests/shell/amd-ibs-swfilt.sh
new file mode 100755
index 0000000000000000..83937aa687ccd859
--- /dev/null
+++ b/tools/perf/tests/shell/amd-ibs-swfilt.sh
@@ -0,0 +1,67 @@
+#!/bin/sh
+# AMD IBS software filtering
+
+echo "check availability of IBS swfilt"
+
+# check if IBS PMU is available
+if [ ! -d /sys/bus/event_source/devices/ibs_op ]; then
+ echo "[SKIP] IBS PMU does not exist"
+ exit 2
+fi
+
+# check if IBS PMU has swfilt format
+if [ ! -f /sys/bus/event_source/devices/ibs_op/format/swfilt ]; then
+ echo "[SKIP] IBS PMU does not have swfilt"
+ exit 2
+fi
+
+echo "run perf record with modifier and swfilt"
+
+# setting any modifiers should fail
+perf record -B -e ibs_op//u -o /dev/null true 2> /dev/null
+if [ $? -eq 0 ]; then
+ echo "[FAIL] IBS PMU should not accept exclude_kernel"
+ exit 1
+fi
+
+# setting it with swfilt should be fine
+perf record -B -e ibs_op/swfilt/u -o /dev/null true
+if [ $? -ne 0 ]; then
+ echo "[FAIL] IBS op PMU cannot handle swfilt for exclude_kernel"
+ exit 1
+fi
+
+# setting it with swfilt=1 should be fine
+perf record -B -e ibs_op/swfilt=1/k -o /dev/null true
+if [ $? -ne 0 ]; then
+ echo "[FAIL] IBS op PMU cannot handle swfilt for exclude_user"
+ exit 1
+fi
+
+# check ibs_fetch PMU as well
+perf record -B -e ibs_fetch/swfilt/u -o /dev/null true
+if [ $? -ne 0 ]; then
+ echo "[FAIL] IBS fetch PMU cannot handle swfilt for exclude_kernel"
+ exit 1
+fi
+
+# check system wide recording
+perf record -aB --synth=no -e ibs_op/swfilt/k -o /dev/null true
+if [ $? -ne 0 ]; then
+ echo "[FAIL] IBS op PMU cannot handle swfilt in system-wide mode"
+ exit 1
+fi
+
+echo "check number of samples with swfilt"
+
+kernel_sample=$(perf record -e ibs_op/swfilt/u -o- true | perf script -i- -F misc | grep -c ^K)
+if [ ${kernel_sample} -ne 0 ]; then
+ echo "[FAIL] unexpected kernel samples: " ${kernel_sample}
+ exit 1
+fi
+
+user_sample=$(perf record -e ibs_fetch/swfilt/k -o- true | perf script -i- -F misc | grep -c ^U)
+if [ ${user_sample} -ne 0 ]; then
+ echo "[FAIL] unexpected user samples: " ${user_sample}
+ exit 1
+fi
--
2.49.0.1151.ga128411c76-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] perf test: Add AMD IBS sw filter test
2025-05-24 0:27 [PATCH v2] perf test: Add AMD IBS sw filter test Namhyung Kim
@ 2025-05-24 9:47 ` Ravi Bangoria
2025-05-27 20:51 ` Arnaldo Carvalho de Melo
0 siblings, 1 reply; 4+ messages in thread
From: Ravi Bangoria @ 2025-05-24 9:47 UTC (permalink / raw)
To: Namhyung Kim
Cc: Arnaldo Carvalho de Melo, Ian Rogers, Kan Liang, Jiri Olsa,
Adrian Hunter, Peter Zijlstra, Ingo Molnar, LKML,
linux-perf-users, Ravi Bangoria
Hi Namhyung,
On 24-May-25 5:57 AM, Namhyung Kim wrote:
> The kernel v6.14 added 'swfilt' to support privilege filtering in
> software so that IBS can be used by regular users. Add a test case in
> x86 to verify the behavior.
>
> $ sudo perf test -vv 'IBS software filter'
> 113: AMD IBS software filtering:
> --- start ---
> test child forked, pid 178826
> check availability of IBS swfilt
> run perf record with modifier and swfilt
> [ perf record: Woken up 3 times to write data ]
> [ perf record: Captured and wrote 0.000 MB /dev/null ]
> [ perf record: Woken up 3 times to write data ]
> [ perf record: Captured and wrote 0.000 MB /dev/null ]
> [ perf record: Woken up 3 times to write data ]
> [ perf record: Captured and wrote 0.000 MB /dev/null ]
> [ perf record: Woken up 0 times to write data ]
> [ perf record: Captured and wrote 0.000 MB /dev/null ]
> check number of samples with swfilt
> [ perf record: Woken up 3 times to write data ]
> [ perf record: Captured and wrote 0.037 MB - ]
> [ perf record: Woken up 3 times to write data ]
> [ perf record: Captured and wrote 0.041 MB - ]
> ---- end(0) ----
> 113: AMD IBS software filtering : Ok
>
> Cc: Ravi Bangoria <ravi.bangoria@amd.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Reviewed-by: Ravi Bangoria <ravi.bangoria@amd.com>
A minor nit below ...
> +echo "check number of samples with swfilt"
> +
> +kernel_sample=$(perf record -e ibs_op/swfilt/u -o- true | perf script -i- -F misc | grep -c ^K)
"true" barely runs in userspace. So, many a times this "perf record"
generates no samples :)
Thanks,
Ravi
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] perf test: Add AMD IBS sw filter test
2025-05-24 9:47 ` Ravi Bangoria
@ 2025-05-27 20:51 ` Arnaldo Carvalho de Melo
2025-05-28 18:35 ` Namhyung Kim
0 siblings, 1 reply; 4+ messages in thread
From: Arnaldo Carvalho de Melo @ 2025-05-27 20:51 UTC (permalink / raw)
To: Ravi Bangoria
Cc: Namhyung Kim, Ian Rogers, Kan Liang, Jiri Olsa, Adrian Hunter,
Peter Zijlstra, Ingo Molnar, LKML, linux-perf-users
On Sat, May 24, 2025 at 03:17:13PM +0530, Ravi Bangoria wrote:
> Hi Namhyung,
>
> On 24-May-25 5:57 AM, Namhyung Kim wrote:
> > The kernel v6.14 added 'swfilt' to support privilege filtering in
> > software so that IBS can be used by regular users. Add a test case in
> > x86 to verify the behavior.
> >
> > $ sudo perf test -vv 'IBS software filter'
> > 113: AMD IBS software filtering:
> > --- start ---
> > test child forked, pid 178826
> > check availability of IBS swfilt
> > run perf record with modifier and swfilt
> > [ perf record: Woken up 3 times to write data ]
> > [ perf record: Captured and wrote 0.000 MB /dev/null ]
> > [ perf record: Woken up 3 times to write data ]
> > [ perf record: Captured and wrote 0.000 MB /dev/null ]
> > [ perf record: Woken up 3 times to write data ]
> > [ perf record: Captured and wrote 0.000 MB /dev/null ]
> > [ perf record: Woken up 0 times to write data ]
> > [ perf record: Captured and wrote 0.000 MB /dev/null ]
> > check number of samples with swfilt
> > [ perf record: Woken up 3 times to write data ]
> > [ perf record: Captured and wrote 0.037 MB - ]
> > [ perf record: Woken up 3 times to write data ]
> > [ perf record: Captured and wrote 0.041 MB - ]
> > ---- end(0) ----
> > 113: AMD IBS software filtering : Ok
> >
> > Cc: Ravi Bangoria <ravi.bangoria@amd.com>
> > Signed-off-by: Namhyung Kim <namhyung@kernel.org>
>
> Reviewed-by: Ravi Bangoria <ravi.bangoria@amd.com>
>
> A minor nit below ...
>
> > +echo "check number of samples with swfilt"
> > +
> > +kernel_sample=$(perf record -e ibs_op/swfilt/u -o- true | perf script -i- -F misc | grep -c ^K)
>
> "true" barely runs in userspace. So, many a times this "perf record"
> generates no samples :)
Right, something else, maybe one of those workloads:
acme@number:~/git/perf-tools-next$ perf test --list-workloads
noploop
thloop
leafloop
sqrtloop
brstack
datasym
landlock
acme@number:~/git/perf-tools-next$
root@number:~# time perf record -e ibs_op/swfilt/u perf test -w sqrtloop
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.160 MB perf.data (3976 samples) ]
real 0m1.588s
user 0m1.407s
sys 0m0.161s
root@number:~# perf script | wc -l
3976
root@number:~#
But I'm applying the patch as is, we can replace the workload later.
- Arnaldo
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] perf test: Add AMD IBS sw filter test
2025-05-27 20:51 ` Arnaldo Carvalho de Melo
@ 2025-05-28 18:35 ` Namhyung Kim
0 siblings, 0 replies; 4+ messages in thread
From: Namhyung Kim @ 2025-05-28 18:35 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Ravi Bangoria, Ian Rogers, Kan Liang, Jiri Olsa, Adrian Hunter,
Peter Zijlstra, Ingo Molnar, LKML, linux-perf-users
On Tue, May 27, 2025 at 05:51:21PM -0300, Arnaldo Carvalho de Melo wrote:
> On Sat, May 24, 2025 at 03:17:13PM +0530, Ravi Bangoria wrote:
> > Hi Namhyung,
> >
> > On 24-May-25 5:57 AM, Namhyung Kim wrote:
> > > The kernel v6.14 added 'swfilt' to support privilege filtering in
> > > software so that IBS can be used by regular users. Add a test case in
> > > x86 to verify the behavior.
> > >
> > > $ sudo perf test -vv 'IBS software filter'
> > > 113: AMD IBS software filtering:
> > > --- start ---
> > > test child forked, pid 178826
> > > check availability of IBS swfilt
> > > run perf record with modifier and swfilt
> > > [ perf record: Woken up 3 times to write data ]
> > > [ perf record: Captured and wrote 0.000 MB /dev/null ]
> > > [ perf record: Woken up 3 times to write data ]
> > > [ perf record: Captured and wrote 0.000 MB /dev/null ]
> > > [ perf record: Woken up 3 times to write data ]
> > > [ perf record: Captured and wrote 0.000 MB /dev/null ]
> > > [ perf record: Woken up 0 times to write data ]
> > > [ perf record: Captured and wrote 0.000 MB /dev/null ]
> > > check number of samples with swfilt
> > > [ perf record: Woken up 3 times to write data ]
> > > [ perf record: Captured and wrote 0.037 MB - ]
> > > [ perf record: Woken up 3 times to write data ]
> > > [ perf record: Captured and wrote 0.041 MB - ]
> > > ---- end(0) ----
> > > 113: AMD IBS software filtering : Ok
> > >
> > > Cc: Ravi Bangoria <ravi.bangoria@amd.com>
> > > Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> >
> > Reviewed-by: Ravi Bangoria <ravi.bangoria@amd.com>
> >
> > A minor nit below ...
> >
> > > +echo "check number of samples with swfilt"
> > > +
> > > +kernel_sample=$(perf record -e ibs_op/swfilt/u -o- true | perf script -i- -F misc | grep -c ^K)
> >
> > "true" barely runs in userspace. So, many a times this "perf record"
> > generates no samples :)
>
> Right, something else, maybe one of those workloads:
>
> acme@number:~/git/perf-tools-next$ perf test --list-workloads
> noploop
> thloop
> leafloop
> sqrtloop
> brstack
> datasym
> landlock
> acme@number:~/git/perf-tools-next$
>
> root@number:~# time perf record -e ibs_op/swfilt/u perf test -w sqrtloop
> [ perf record: Woken up 1 times to write data ]
> [ perf record: Captured and wrote 0.160 MB perf.data (3976 samples) ]
>
> real 0m1.588s
> user 0m1.407s
> sys 0m0.161s
> root@number:~# perf script | wc -l
> 3976
> root@number:~#
>
> But I'm applying the patch as is, we can replace the workload later.
Thanks, I can add some workload to create both kernel and user traffic.
I think the current workloads run in user space mostly.
Thanks,
Namhyung
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-05-28 18:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-24 0:27 [PATCH v2] perf test: Add AMD IBS sw filter test Namhyung Kim
2025-05-24 9:47 ` Ravi Bangoria
2025-05-27 20:51 ` Arnaldo Carvalho de Melo
2025-05-28 18:35 ` 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).