Skip to content

Commit 46eb012

Browse files
author
Alexei Starovoitov
committed
Merge branch 'selftests-bpf-fix-a-few-issues-in-arena_spin_lock'
Ilya Leoshkevich says: ==================== I tried running the arena_spin_lock test on s390x and ran into the following issues: * Changing the header file does not lead to rebuilding the test. * The checked for number of CPUs and the actually required number of CPUs are different. * Endianness issue in spinlock definition. This series fixes all three. ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
2 parents 4cc2048 + be55219 commit 46eb012

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-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);

tools/testing/selftests/bpf/bpf_arena_spin_lock.h renamed to tools/testing/selftests/bpf/progs/bpf_arena_spin_lock.h

+12
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ extern unsigned long CONFIG_NR_CPUS __kconfig;
3232
struct __qspinlock {
3333
union {
3434
atomic_t val;
35+
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
3536
struct {
3637
u8 locked;
3738
u8 pending;
@@ -40,6 +41,17 @@ struct __qspinlock {
4041
u16 locked_pending;
4142
u16 tail;
4243
};
44+
#else
45+
struct {
46+
u16 tail;
47+
u16 locked_pending;
48+
};
49+
struct {
50+
u8 reserved[2];
51+
u8 pending;
52+
u8 locked;
53+
};
54+
#endif
4355
};
4456
};
4557

0 commit comments

Comments
 (0)