From 5eced83779fd60cfa2a1a86fd89d282d02d40d05 Mon Sep 17 00:00:00 2001 From: Alexei Starovoitov Date: Sat, 31 Oct 2026 21:55:38 +0000 Subject: [PATCH] selftests/bpf: End the loop of parallel_test_bitmap after 50 ms The two progs of parallel_test_bitmap change bits of the same words in a loop of 10000000 iterations with can_loop. The loop goes on until may_goto stops it. The functions that it calls retry a cmpxchg that fails: do { ... actual = cmpxchg(&bmp->bits[idx], old, new); if (actual == old) return true; } while (can_loop); return false; The retry is always possible only while each stack frame has a time slice of its own. With one time slice for all may_goto of a prog, a function that is called after the time is up makes no iteration. The bit does not change, and the test fails with -EINVAL, in 53 of 900 runs. Leave the loop after 50 ms. Signed-off-by: Alexei Starovoitov Link: https://patch.msgid.link/20261031215543.682284-5-alexei.starovoitov@gmail.com --- .../bpf/libarena/selftests/test_parallel_bitmap.bpf.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/testing/selftests/bpf/libarena/selftests/test_parallel_bitmap.bpf.c b/tools/testing/selftests/bpf/libarena/selftests/test_parallel_bitmap.bpf.c index ea1fac95b461..017add229bef 100644 --- a/tools/testing/selftests/bpf/libarena/selftests/test_parallel_bitmap.bpf.c +++ b/tools/testing/selftests/bpf/libarena/selftests/test_parallel_bitmap.bpf.c @@ -11,6 +11,7 @@ #define TEST_BITMAP_BITS (2 * BITS_PER_LONG_LONG) #define TEST_BITMAP_SYNC_SPINS BPF_MAX_LOOPS #define TEST_BITMAP_ITERS 10 * 1000 * 1000 +#define TEST_BITMAP_NSEC (50 * 1000 * 1000) static struct arena_bitmap __arena *bitmap; static volatile u64 started; @@ -129,6 +130,7 @@ static int bitmap_test_common_single(int parity) static int bitmap_test_common(int parity) { + u64 start; int ret; u32 i; @@ -138,6 +140,7 @@ static int bitmap_test_common(int parity) if (ret) return ret; + start = bpf_ktime_get_ns(); for (i = zero; i < TEST_BITMAP_ITERS && can_loop; i++) { ret = bitmap_test_common_single(parity); if (ret) @@ -147,6 +150,13 @@ static int bitmap_test_common(int parity) break; bitmap_test_reset_single(parity); + + /* + * Stop before the time slice of may_goto is used up. After that the + * bmp_*() functions can't retry a cmpxchg that fails. + */ + if (bpf_ktime_get_ns() - start > TEST_BITMAP_NSEC) + break; } return 0;