* [PATCH 0/3] perf test: Extend branch stack sampling test for arm64 BRBE
@ 2025-08-13 13:38 James Clark
2025-08-13 13:38 ` [PATCH 1/3] perf test: Refactor brstack test James Clark
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: James Clark @ 2025-08-13 13:38 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
Ian Rogers, Adrian Hunter, Anshuman Khandual, Mark Rutland,
Rob Herring (Arm), Adam Young, Will Deacon, German Gomez
Cc: linux-perf-users, linux-kernel, James Clark
Refactor and add some extra tests for all platforms which were useful
when developing and testing the BRBE (Branch Buffer Extension) driver
[1]. Then lastly extend the test for new features which are BRBE
specific.
Tested on the Arm FVP RevC model [2] and Intel Raptor Lake.
[1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=58074a0fce66
[2]: https://developer.arm.com/Tools%20and%20Software/Fixed%20Virtual%20Platforms
Signed-off-by: James Clark <james.clark@linaro.org>
---
James Clark (3):
perf test: Refactor brstack test
perf test: Add syscall and address tests to brstack test
perf test: Extend branch stack sampling test for Arm64 BRBE
tools/perf/tests/builtin-test.c | 1 +
tools/perf/tests/shell/test_brstack.sh | 106 ++++++++++++++++++++++++++++++---
tools/perf/tests/tests.h | 1 +
tools/perf/tests/workloads/Build | 2 +
tools/perf/tests/workloads/traploop.c | 31 ++++++++++
5 files changed, 132 insertions(+), 9 deletions(-)
---
base-commit: 6235ce77749f45cac27f630337e2fdf04e8a6c73
change-id: 20250811-james-brbe-test-f5a20dffd734
Best regards,
--
James Clark <james.clark@linaro.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/3] perf test: Refactor brstack test
2025-08-13 13:38 [PATCH 0/3] perf test: Extend branch stack sampling test for arm64 BRBE James Clark
@ 2025-08-13 13:38 ` James Clark
2025-08-13 13:38 ` [PATCH 2/3] perf test: Add syscall and address tests to " James Clark
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: James Clark @ 2025-08-13 13:38 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
Ian Rogers, Adrian Hunter, Anshuman Khandual, Mark Rutland,
Rob Herring (Arm), Adam Young, Will Deacon, German Gomez
Cc: linux-perf-users, linux-kernel, James Clark
check_branches() will be used by other tests in a later commit so make
it a function. And the any_call filters are duplicated and will also
be extended in a later commit, so move them to a variable.
No functional changes intended.
Signed-off-by: James Clark <james.clark@linaro.org>
---
tools/perf/tests/shell/test_brstack.sh | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/tools/perf/tests/shell/test_brstack.sh b/tools/perf/tests/shell/test_brstack.sh
index 9138fa83bf36..46e5aa9ce8ee 100755
--- a/tools/perf/tests/shell/test_brstack.sh
+++ b/tools/perf/tests/shell/test_brstack.sh
@@ -34,6 +34,13 @@ trap_cleanup() {
}
trap trap_cleanup EXIT TERM INT
+check_branches() {
+ if ! tr -s ' ' '\n' < "$TMPDIR/perf.script" | grep -E -m1 -q "$1"; then
+ echo "Branches missing $1"
+ err=1
+ fi
+}
+
test_user_branches() {
echo "Testing user branch stack sampling"
@@ -55,11 +62,7 @@ test_user_branches() {
)
for x in "${expected[@]}"
do
- if ! tr -s ' ' '\n' < "$TMPDIR/perf.script" | grep -E -m1 -q "$x"
- then
- echo "Branches missing $x"
- err=1
- fi
+ check_branches "$x"
done
# some branch types are still not being tested:
# IND COND_CALL COND_RET SYSCALL SYSRET IRQ SERROR NO_TX
@@ -101,14 +104,16 @@ set -e
test_user_branches
-test_filter "any_call" "CALL|IND_CALL|COND_CALL|SYSCALL|IRQ"
+any_call="CALL|IND_CALL|COND_CALL|SYSCALL|IRQ"
+
+test_filter "any_call" "$any_call"
test_filter "call" "CALL|SYSCALL"
test_filter "cond" "COND"
test_filter "any_ret" "RET|COND_RET|SYSRET|ERET"
test_filter "call,cond" "CALL|SYSCALL|COND"
-test_filter "any_call,cond" "CALL|IND_CALL|COND_CALL|IRQ|SYSCALL|COND"
-test_filter "cond,any_call,any_ret" "COND|CALL|IND_CALL|COND_CALL|SYSCALL|IRQ|RET|COND_RET|SYSRET|ERET"
+test_filter "any_call,cond" "$any_call|COND"
+test_filter "any_call,cond,any_ret" "$any_call|COND|RET|COND_RET"
cleanup
exit $err
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] perf test: Add syscall and address tests to brstack test
2025-08-13 13:38 [PATCH 0/3] perf test: Extend branch stack sampling test for arm64 BRBE James Clark
2025-08-13 13:38 ` [PATCH 1/3] perf test: Refactor brstack test James Clark
@ 2025-08-13 13:38 ` James Clark
2025-08-13 13:38 ` [PATCH 3/3] perf test: Extend branch stack sampling test for Arm64 BRBE James Clark
2025-08-18 21:38 ` [PATCH 0/3] perf test: Extend branch stack sampling test for arm64 BRBE Ian Rogers
3 siblings, 0 replies; 5+ messages in thread
From: James Clark @ 2025-08-13 13:38 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
Ian Rogers, Adrian Hunter, Anshuman Khandual, Mark Rutland,
Rob Herring (Arm), Adam Young, Will Deacon, German Gomez
Cc: linux-perf-users, linux-kernel, James Clark
Test that SYSCALL type branches are emitted from the expected 'getppid'
symbol. Test that when only 'k' is used, sources addresses are all in
the kernel. Test that no kernel addresses leak by checking for them in
the 'u' test.
Signed-off-by: James Clark <james.clark@linaro.org>
---
tools/perf/tests/shell/test_brstack.sh | 61 +++++++++++++++++++++++++++++++++-
1 file changed, 60 insertions(+), 1 deletion(-)
diff --git a/tools/perf/tests/shell/test_brstack.sh b/tools/perf/tests/shell/test_brstack.sh
index 46e5aa9ce8ee..252d22d39c7b 100755
--- a/tools/perf/tests/shell/test_brstack.sh
+++ b/tools/perf/tests/shell/test_brstack.sh
@@ -64,8 +64,50 @@ test_user_branches() {
do
check_branches "$x"
done
+
+ # Dump addresses only this time
+ perf script -i "$TMPDIR/perf.data" --fields brstack | \
+ tr ' ' '\n' > "$TMPDIR/perf.script"
+
+ # There should be no kernel addresses with the u option, in either
+ # source or target addresses.
+ if grep -E -m1 "0x[89a-f][0-9a-f]{15}" $TMPDIR/perf.script; then
+ echo "ERROR: Kernel address found in user mode"
+ err=1
+ fi
# some branch types are still not being tested:
- # IND COND_CALL COND_RET SYSCALL SYSRET IRQ SERROR NO_TX
+ # IND COND_CALL COND_RET SYSRET IRQ SERROR NO_TX
+}
+
+
+test_kernel_branches() {
+ echo "Testing that k option only includes kernel source addresses"
+
+ if ! perf record --branch-filter any,k -o- -- true > /dev/null; then
+ echo "skip: not enough privileges"
+ else
+ perf record -o $TMPDIR/perf.data --branch-filter any,k -- \
+ perf bench syscall basic --loop 1000
+ perf script -i $TMPDIR/perf.data --fields brstack | \
+ tr ' ' '\n' > $TMPDIR/perf.script
+
+ # Example of branch entries:
+ # "0xffffffff93bda241/0xffffffff93bda20f/M/-/-/..."
+ # Source addresses come first and target address can be either
+ # userspace or kernel even with k option, as long as the source
+ # is in kernel.
+
+ #Look for source addresses with top bit set
+ if ! grep -E -m1 "^0x[89a-f][0-9a-f]{15}" $TMPDIR/perf.script; then
+ echo "ERROR: Kernel branches missing"
+ err=1
+ fi
+ # Look for no source addresses without top bit set
+ if grep -E -m1 "^0x[0-7][0-9a-f]{0,15}" $TMPDIR/perf.script; then
+ echo "ERROR: User branches found with kernel filter"
+ err=1
+ fi
+ fi
}
# first argument <arg0> is the argument passed to "--branch-stack <arg0>,save_type,u"
@@ -100,9 +142,26 @@ test_filter() {
fi
}
+test_syscall() {
+ echo "Testing syscalls"
+ # skip if perf doesn't have enough privileges
+ if ! perf record --branch-filter any,k -o- -- true > /dev/null; then
+ echo "skip: not enough privileges"
+ else
+ perf record -o $TMPDIR/perf.data --branch-filter \
+ any_call,save_type,u,k -c 10000 -- \
+ perf bench syscall basic --loop 1000
+ perf script -i $TMPDIR/perf.data --fields brstacksym | \
+ tr ' ' '\n' > $TMPDIR/perf.script
+
+ check_branches "getppid[^ ]*/SYSCALL/"
+ fi
+}
set -e
test_user_branches
+test_syscall
+test_kernel_branches
any_call="CALL|IND_CALL|COND_CALL|SYSCALL|IRQ"
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] perf test: Extend branch stack sampling test for Arm64 BRBE
2025-08-13 13:38 [PATCH 0/3] perf test: Extend branch stack sampling test for arm64 BRBE James Clark
2025-08-13 13:38 ` [PATCH 1/3] perf test: Refactor brstack test James Clark
2025-08-13 13:38 ` [PATCH 2/3] perf test: Add syscall and address tests to " James Clark
@ 2025-08-13 13:38 ` James Clark
2025-08-18 21:38 ` [PATCH 0/3] perf test: Extend branch stack sampling test for arm64 BRBE Ian Rogers
3 siblings, 0 replies; 5+ messages in thread
From: James Clark @ 2025-08-13 13:38 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
Ian Rogers, Adrian Hunter, Anshuman Khandual, Mark Rutland,
Rob Herring (Arm), Adam Young, Will Deacon, German Gomez
Cc: linux-perf-users, linux-kernel, James Clark
BRBE emits IRQ and ERET branches for branching and returning from
trapped instructions. Add a test that loops on a trapped instruction
(MRS - Read special register) for this.
Extend the expected 'any_call' branches to include FAULT_DATA and
FAULT_INST as these are emitted by BRBE.
Co-developed-by: German Gomez <german.gomez@arm.com>
Signed-off-by: German Gomez <german.gomez@arm.com>
Signed-off-by: James Clark <james.clark@linaro.org>
---
tools/perf/tests/builtin-test.c | 1 +
tools/perf/tests/shell/test_brstack.sh | 26 +++++++++++++++++++++++++-
tools/perf/tests/tests.h | 1 +
tools/perf/tests/workloads/Build | 2 ++
tools/perf/tests/workloads/traploop.c | 31 +++++++++++++++++++++++++++++++
5 files changed, 60 insertions(+), 1 deletion(-)
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 85142dfb3e01..8921846b3f36 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -152,6 +152,7 @@ static struct test_workload *workloads[] = {
&workload__brstack,
&workload__datasym,
&workload__landlock,
+ &workload__traploop,
};
#define workloads__for_each(workload) \
diff --git a/tools/perf/tests/shell/test_brstack.sh b/tools/perf/tests/shell/test_brstack.sh
index 252d22d39c7b..85233d435be6 100755
--- a/tools/perf/tests/shell/test_brstack.sh
+++ b/tools/perf/tests/shell/test_brstack.sh
@@ -34,6 +34,10 @@ trap_cleanup() {
}
trap trap_cleanup EXIT TERM INT
+is_arm64() {
+ [ "$(uname -m)" = "aarch64" ];
+}
+
check_branches() {
if ! tr -s ' ' '\n' < "$TMPDIR/perf.script" | grep -E -m1 -q "$1"; then
echo "Branches missing $1"
@@ -76,9 +80,24 @@ test_user_branches() {
err=1
fi
# some branch types are still not being tested:
- # IND COND_CALL COND_RET SYSRET IRQ SERROR NO_TX
+ # IND COND_CALL COND_RET SYSRET SERROR NO_TX
}
+test_trap_eret_branches() {
+ echo "Testing trap & eret branches"
+ if ! is_arm64; then
+ echo "skip: not arm64"
+ else
+ perf record -o $TMPDIR/perf.data --branch-filter any,save_type,u,k -- \
+ perf test -w traploop 1000
+ perf script -i $TMPDIR/perf.data --fields brstacksym | \
+ tr ' ' '\n' > $TMPDIR/perf.script
+
+ # BRBINF<n>.TYPE == TRAP are mapped to PERF_BR_IRQ by the BRBE driver
+ check_branches "^trap_bench\+[^ ]+/[^ ]/IRQ/"
+ check_branches "^[^ ]+/trap_bench\+[^ ]+/ERET/"
+ fi
+}
test_kernel_branches() {
echo "Testing that k option only includes kernel source addresses"
@@ -162,9 +181,14 @@ set -e
test_user_branches
test_syscall
test_kernel_branches
+test_trap_eret_branches
any_call="CALL|IND_CALL|COND_CALL|SYSCALL|IRQ"
+if is_arm64; then
+ any_call="$any_call|FAULT_DATA|FAULT_INST"
+fi
+
test_filter "any_call" "$any_call"
test_filter "call" "CALL|SYSCALL"
test_filter "cond" "COND"
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 97e62db8764a..cf3a14a95b67 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -239,6 +239,7 @@ DECLARE_WORKLOAD(sqrtloop);
DECLARE_WORKLOAD(brstack);
DECLARE_WORKLOAD(datasym);
DECLARE_WORKLOAD(landlock);
+DECLARE_WORKLOAD(traploop);
extern const char *dso_to_test;
extern const char *test_objdump_path;
diff --git a/tools/perf/tests/workloads/Build b/tools/perf/tests/workloads/Build
index 5af17206f04d..fb1012cc4fc3 100644
--- a/tools/perf/tests/workloads/Build
+++ b/tools/perf/tests/workloads/Build
@@ -7,8 +7,10 @@ perf-test-y += sqrtloop.o
perf-test-y += brstack.o
perf-test-y += datasym.o
perf-test-y += landlock.o
+perf-test-y += traploop.o
CFLAGS_sqrtloop.o = -g -O0 -fno-inline -U_FORTIFY_SOURCE
CFLAGS_leafloop.o = -g -O0 -fno-inline -fno-omit-frame-pointer -U_FORTIFY_SOURCE
CFLAGS_brstack.o = -g -O0 -fno-inline -U_FORTIFY_SOURCE
CFLAGS_datasym.o = -g -O0 -fno-inline -U_FORTIFY_SOURCE
+CFLAGS_traploop.o = -g -O0 -fno-inline -U_FORTIFY_SOURCE
diff --git a/tools/perf/tests/workloads/traploop.c b/tools/perf/tests/workloads/traploop.c
new file mode 100644
index 000000000000..68dec399a735
--- /dev/null
+++ b/tools/perf/tests/workloads/traploop.c
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <stdlib.h>
+#include "../tests.h"
+
+#define BENCH_RUNS 999999
+
+#ifdef __aarch64__
+static void trap_bench(void)
+{
+ unsigned long val;
+
+ asm("mrs %0, ID_AA64ISAR0_EL1" : "=r" (val)); /* TRAP + ERET */
+}
+#else
+static void trap_bench(void) { }
+#endif
+
+static int traploop(int argc, const char **argv)
+{
+ int num_loops = BENCH_RUNS;
+
+ if (argc > 0)
+ num_loops = atoi(argv[0]);
+
+ for (int i = 0; i < num_loops; i++)
+ trap_bench();
+
+ return 0;
+}
+
+DEFINE_WORKLOAD(traploop);
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 0/3] perf test: Extend branch stack sampling test for arm64 BRBE
2025-08-13 13:38 [PATCH 0/3] perf test: Extend branch stack sampling test for arm64 BRBE James Clark
` (2 preceding siblings ...)
2025-08-13 13:38 ` [PATCH 3/3] perf test: Extend branch stack sampling test for Arm64 BRBE James Clark
@ 2025-08-18 21:38 ` Ian Rogers
3 siblings, 0 replies; 5+ messages in thread
From: Ian Rogers @ 2025-08-18 21:38 UTC (permalink / raw)
To: James Clark
Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
Adrian Hunter, Anshuman Khandual, Rob Herring (Arm), Adam Young,
Will Deacon, German Gomez, linux-perf-users, linux-kernel
On Wed, Aug 13, 2025 at 6:39 AM James Clark <james.clark@linaro.org> wrote:
>
> Refactor and add some extra tests for all platforms which were useful
> when developing and testing the BRBE (Branch Buffer Extension) driver
> [1]. Then lastly extend the test for new features which are BRBE
> specific.
>
> Tested on the Arm FVP RevC model [2] and Intel Raptor Lake.
>
> [1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=58074a0fce66
> [2]: https://developer.arm.com/Tools%20and%20Software/Fixed%20Virtual%20Platforms
>
> Signed-off-by: James Clark <james.clark@linaro.org>
Reviewed-by: Ian Rogers <irogers@google.com>
Thanks,
Ian
> ---
> James Clark (3):
> perf test: Refactor brstack test
> perf test: Add syscall and address tests to brstack test
> perf test: Extend branch stack sampling test for Arm64 BRBE
>
> tools/perf/tests/builtin-test.c | 1 +
> tools/perf/tests/shell/test_brstack.sh | 106 ++++++++++++++++++++++++++++++---
> tools/perf/tests/tests.h | 1 +
> tools/perf/tests/workloads/Build | 2 +
> tools/perf/tests/workloads/traploop.c | 31 ++++++++++
> 5 files changed, 132 insertions(+), 9 deletions(-)
> ---
> base-commit: 6235ce77749f45cac27f630337e2fdf04e8a6c73
> change-id: 20250811-james-brbe-test-f5a20dffd734
>
> Best regards,
> --
> James Clark <james.clark@linaro.org>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-08-18 21:38 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-13 13:38 [PATCH 0/3] perf test: Extend branch stack sampling test for arm64 BRBE James Clark
2025-08-13 13:38 ` [PATCH 1/3] perf test: Refactor brstack test James Clark
2025-08-13 13:38 ` [PATCH 2/3] perf test: Add syscall and address tests to " James Clark
2025-08-13 13:38 ` [PATCH 3/3] perf test: Extend branch stack sampling test for Arm64 BRBE James Clark
2025-08-18 21:38 ` [PATCH 0/3] perf test: Extend branch stack sampling test for arm64 BRBE Ian Rogers
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).