1 // SPDX-License-Identifier: GPL-2.0
5 #include <test_progs.h>
7 #include <network_helpers.h>
8 #include <sys/sysinfo.h>
10 #include "timer_lockup.skel.h"
13 static int *timer1_err;
14 static int *timer2_err;
19 static void *timer_lockup_thread(void *arg)
21 LIBBPF_OPTS(bpf_test_run_opts, opts,
23 .data_size_in = sizeof(pkt_v4),
26 int i, prog_fd = *(int *)arg;
30 CPU_SET(__sync_fetch_and_add(&cpu, 1), &cpuset);
31 ASSERT_OK(pthread_setaffinity_np(pthread_self(), sizeof(cpuset),
35 for (i = 0; !READ_ONCE(*timer1_err) && !READ_ONCE(*timer2_err); i++) {
36 bpf_prog_test_run_opts(prog_fd, &opts);
37 /* Skip the test if we can't reproduce the race in a reasonable
41 WRITE_ONCE(skip, true);
49 void test_timer_lockup(void)
51 int timer1_prog, timer2_prog;
52 struct timer_lockup *skel;
56 if (get_nprocs() < 2) {
61 skel = timer_lockup__open_and_load();
62 if (!ASSERT_OK_PTR(skel, "timer_lockup__open_and_load"))
65 timer1_prog = bpf_program__fd(skel->progs.timer1_prog);
66 timer2_prog = bpf_program__fd(skel->progs.timer2_prog);
68 timer1_err = &skel->bss->timer1_err;
69 timer2_err = &skel->bss->timer2_err;
71 if (!ASSERT_OK(pthread_create(&thrds[0], NULL, timer_lockup_thread,
73 "pthread_create thread1"))
75 if (!ASSERT_OK(pthread_create(&thrds[1], NULL, timer_lockup_thread,
77 "pthread_create thread2")) {
78 pthread_exit(&thrds[0]);
82 pthread_join(thrds[1], &ret);
83 pthread_join(thrds[0], &ret);
90 if (*timer1_err != -EDEADLK && *timer1_err != 0)
91 ASSERT_FAIL("timer1_err bad value");
92 if (*timer2_err != -EDEADLK && *timer2_err != 0)
93 ASSERT_FAIL("timer2_err bad value");
95 timer_lockup__destroy(skel);