Skip to content

Commit 0240e5a

Browse files
iii-iAlexei Starovoitov
authored and
Alexei Starovoitov
committed
selftests/bpf: Fix arena_spin_lock on systems with less than 16 CPUs
test_arena_spin_lock_size() explicitly requires having at least 2 CPUs, but if the machine has less than 16, then pthread_setaffinity_np() call in spin_lock_thread() fails. Cap threads to the number of CPUs. Alternative solutions are raising the number of required CPUs to 16, or pinning multiple threads to the same CPU, but they are not that useful. Signed-off-by: Ilya Leoshkevich <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent ddfd1f3 commit 0240e5a

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

tools/testing/selftests/bpf/prog_tests/arena_spin_lock.c

+8-6
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ static void test_arena_spin_lock_size(int size)
5151
struct arena_spin_lock *skel;
5252
pthread_t thread_id[16];
5353
int prog_fd, i, err;
54+
int nthreads;
5455
void *ret;
5556

56-
if (get_nprocs() < 2) {
57+
nthreads = MIN(get_nprocs(), ARRAY_SIZE(thread_id));
58+
if (nthreads < 2) {
5759
test__skip();
5860
return;
5961
}
@@ -66,25 +68,25 @@ static void test_arena_spin_lock_size(int size)
6668
goto end;
6769
}
6870
skel->bss->cs_count = size;
69-
skel->bss->limit = repeat * 16;
71+
skel->bss->limit = repeat * nthreads;
7072

71-
ASSERT_OK(pthread_barrier_init(&barrier, NULL, 16), "barrier init");
73+
ASSERT_OK(pthread_barrier_init(&barrier, NULL, nthreads), "barrier init");
7274

7375
prog_fd = bpf_program__fd(skel->progs.prog);
74-
for (i = 0; i < 16; i++) {
76+
for (i = 0; i < nthreads; i++) {
7577
err = pthread_create(&thread_id[i], NULL, &spin_lock_thread, &prog_fd);
7678
if (!ASSERT_OK(err, "pthread_create"))
7779
goto end_barrier;
7880
}
7981

80-
for (i = 0; i < 16; i++) {
82+
for (i = 0; i < nthreads; i++) {
8183
if (!ASSERT_OK(pthread_join(thread_id[i], &ret), "pthread_join"))
8284
goto end_barrier;
8385
if (!ASSERT_EQ(ret, &prog_fd, "ret == prog_fd"))
8486
goto end_barrier;
8587
}
8688

87-
ASSERT_EQ(skel->bss->counter, repeat * 16, "check counter value");
89+
ASSERT_EQ(skel->bss->counter, repeat * nthreads, "check counter value");
8890

8991
end_barrier:
9092
pthread_barrier_destroy(&barrier);

0 commit comments

Comments
 (0)