~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/prog_tests/timer_lockup.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 
  3 #define _GNU_SOURCE
  4 #include <sched.h>
  5 #include <test_progs.h>
  6 #include <pthread.h>
  7 #include <network_helpers.h>
  8 
  9 #include "timer_lockup.skel.h"
 10 
 11 static long cpu;
 12 static int *timer1_err;
 13 static int *timer2_err;
 14 static bool skip;
 15 
 16 volatile int k = 0;
 17 
 18 static void *timer_lockup_thread(void *arg)
 19 {
 20         LIBBPF_OPTS(bpf_test_run_opts, opts,
 21                 .data_in        = &pkt_v4,
 22                 .data_size_in   = sizeof(pkt_v4),
 23                 .repeat         = 1000,
 24         );
 25         int i, prog_fd = *(int *)arg;
 26         cpu_set_t cpuset;
 27 
 28         CPU_ZERO(&cpuset);
 29         CPU_SET(__sync_fetch_and_add(&cpu, 1), &cpuset);
 30         ASSERT_OK(pthread_setaffinity_np(pthread_self(), sizeof(cpuset),
 31                                          &cpuset),
 32                   "cpu affinity");
 33 
 34         for (i = 0; !READ_ONCE(*timer1_err) && !READ_ONCE(*timer2_err); i++) {
 35                 bpf_prog_test_run_opts(prog_fd, &opts);
 36                 /* Skip the test if we can't reproduce the race in a reasonable
 37                  * amount of time.
 38                  */
 39                 if (i > 50) {
 40                         WRITE_ONCE(skip, true);
 41                         break;
 42                 }
 43         }
 44 
 45         return NULL;
 46 }
 47 
 48 void test_timer_lockup(void)
 49 {
 50         int timer1_prog, timer2_prog;
 51         struct timer_lockup *skel;
 52         pthread_t thrds[2];
 53         void *ret;
 54 
 55         skel = timer_lockup__open_and_load();
 56         if (!ASSERT_OK_PTR(skel, "timer_lockup__open_and_load"))
 57                 return;
 58 
 59         timer1_prog = bpf_program__fd(skel->progs.timer1_prog);
 60         timer2_prog = bpf_program__fd(skel->progs.timer2_prog);
 61 
 62         timer1_err = &skel->bss->timer1_err;
 63         timer2_err = &skel->bss->timer2_err;
 64 
 65         if (!ASSERT_OK(pthread_create(&thrds[0], NULL, timer_lockup_thread,
 66                                       &timer1_prog),
 67                        "pthread_create thread1"))
 68                 goto out;
 69         if (!ASSERT_OK(pthread_create(&thrds[1], NULL, timer_lockup_thread,
 70                                       &timer2_prog),
 71                        "pthread_create thread2")) {
 72                 pthread_exit(&thrds[0]);
 73                 goto out;
 74         }
 75 
 76         pthread_join(thrds[1], &ret);
 77         pthread_join(thrds[0], &ret);
 78 
 79         if (skip) {
 80                 test__skip();
 81                 goto out;
 82         }
 83 
 84         if (*timer1_err != -EDEADLK && *timer1_err != 0)
 85                 ASSERT_FAIL("timer1_err bad value");
 86         if (*timer2_err != -EDEADLK && *timer2_err != 0)
 87                 ASSERT_FAIL("timer2_err bad value");
 88 out:
 89         timer_lockup__destroy(skel);
 90         return;
 91 }
 92 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php