The test bounds how many branch entries are spent reaching the snapshot
helper. The limit of 10 was calibrated on x86, which spends about 7.

arm64 spends up to 14: eight in the BPF trampoline, which makes
out-of-line calls and branches more than x86 does, and the rest in
masking exceptions before the branch buffer can be paused.

Raise the limit to 18 on arm64, leaving room for compiler and
configuration variation.

The skip threshold has to move with it. BRBE implements 8, 16, 32 or 64
records, so on a 16 record buffer the existing 'total_entries < 16'
check does not skip, but 14 wasted entries leave only 2 for the hit test
and it fails instead. Derive the minimum from the two limits it depends
on, so the arms cannot drift apart.

This leaves 8 and 16 record implementations skipped, since the required
hit count is absolute and does not scale with the buffer.

Signed-off-by: Puranjay Mohan <[email protected]>
---
 .../bpf/prog_tests/get_branch_snapshot.c      | 28 ++++++++++++-------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c 
b/tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c
index 0394a1156d99d..e06ae6798dbec 100644
--- a/tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c
+++ b/tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c
@@ -108,21 +108,29 @@ void serial_test_get_branch_snapshot(void)
 
        trigger_module_test_read(100);
 
-       if (skel->bss->total_entries < 16) {
+       /* Reaching the snapshot helper costs a few entries: about 7 on x86_64
+        * and about 14 on arm64, whose BPF trampoline branches more. Bound it
+        * so that a regression shows up here.
+        *
+        * Derive the buffer minimum from the two limits it depends on, so the
+        * arms cannot drift apart.
+        */
+#if defined(__aarch64__)
+#define WASTED_ENTRIES_MAX     18
+#else
+#define WASTED_ENTRIES_MAX     10
+#endif
+#define TEST1_HITS_MIN         7
+#define TOTAL_ENTRIES_MIN      (WASTED_ENTRIES_MAX - 1 + TEST1_HITS_MIN)
+
+       if (skel->bss->total_entries < TOTAL_ENTRIES_MIN) {
                /* too few entries for the hit/waste test */
                test__skip();
                goto cleanup;
        }
 
-       ASSERT_GT(skel->bss->test1_hits, 6, "find_looptest_in_lbr");
-
-       /* Given we stop LBR in software, we will waste a few entries.
-        * But we should try to waste as few as possible entries. We are at
-        * about 7 on x86_64 systems.
-        * Add a check for < 10 so that we get heads-up when something
-        * changes and wastes too many entries.
-        */
-       ASSERT_LT(skel->bss->wasted_entries, 10, "check_wasted_entries");
+       ASSERT_GT(skel->bss->test1_hits, TEST1_HITS_MIN - 1, 
"find_looptest_in_lbr");
+       ASSERT_LT(skel->bss->wasted_entries, WASTED_ENTRIES_MAX, 
"check_wasted_entries");
 
 cleanup:
        get_branch_snapshot__destroy(skel);
-- 
2.53.0-Meta


Reply via email to