File tree Expand file tree Collapse file tree 2 files changed +78
-0
lines changed
tools/testing/selftests/bpf Expand file tree Collapse file tree 2 files changed +78
-0
lines changed Original file line number Diff line number Diff line change 33#include <test_progs.h>
44#include "timer.skel.h"
55#include "timer_failure.skel.h"
6+ #include "timer_interrupt.skel.h"
67
78#define NUM_THR 8
89
@@ -95,3 +96,32 @@ void serial_test_timer(void)
9596
9697 RUN_TESTS (timer_failure );
9798}
99+
100+ void test_timer_interrupt (void )
101+ {
102+ struct timer_interrupt * skel = NULL ;
103+ int err , prog_fd ;
104+ LIBBPF_OPTS (bpf_test_run_opts , opts );
105+
106+ skel = timer_interrupt__open_and_load ();
107+ if (!ASSERT_OK_PTR (skel , "timer_interrupt__open_and_load" ))
108+ return ;
109+
110+ err = timer_interrupt__attach (skel );
111+ if (!ASSERT_OK (err , "timer_interrupt__attach" ))
112+ goto out ;
113+
114+ prog_fd = bpf_program__fd (skel -> progs .test_timer_interrupt );
115+ err = bpf_prog_test_run_opts (prog_fd , & opts );
116+ if (!ASSERT_OK (err , "bpf_prog_test_run_opts" ))
117+ goto out ;
118+
119+ usleep (50 );
120+
121+ ASSERT_EQ (skel -> bss -> in_interrupt , 0 , "in_interrupt" );
122+ if (skel -> bss -> preempt_count )
123+ ASSERT_NEQ (skel -> bss -> in_interrupt_cb , 0 , "in_interrupt_cb" );
124+
125+ out :
126+ timer_interrupt__destroy (skel );
127+ }
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: GPL-2.0
2+ #include <vmlinux.h>
3+ #include <bpf/bpf_helpers.h>
4+ #include <bpf/bpf_tracing.h>
5+ #include "bpf_experimental.h"
6+
7+ char _license [] SEC ("license" ) = "GPL" ;
8+
9+ #define CLOCK_MONOTONIC 1
10+
11+ int preempt_count ;
12+ int in_interrupt ;
13+ int in_interrupt_cb ;
14+
15+ struct elem {
16+ struct bpf_timer t ;
17+ };
18+
19+ struct {
20+ __uint (type , BPF_MAP_TYPE_ARRAY );
21+ __uint (max_entries , 1 );
22+ __type (key , int );
23+ __type (value , struct elem );
24+ } array SEC (".maps" );
25+
26+ static int timer_in_interrupt (void * map , int * key , struct bpf_timer * timer )
27+ {
28+ preempt_count = get_preempt_count ();
29+ in_interrupt_cb = bpf_in_interrupt ();
30+ return 0 ;
31+ }
32+
33+ SEC ("fentry/bpf_fentry_test1" )
34+ int BPF_PROG (test_timer_interrupt )
35+ {
36+ struct bpf_timer * timer ;
37+ int key = 0 ;
38+
39+ timer = bpf_map_lookup_elem (& array , & key );
40+ if (!timer )
41+ return 0 ;
42+
43+ in_interrupt = bpf_in_interrupt ();
44+ bpf_timer_init (timer , & array , CLOCK_MONOTONIC );
45+ bpf_timer_set_callback (timer , timer_in_interrupt );
46+ bpf_timer_start (timer , 0 , 0 );
47+ return 0 ;
48+ }
You can’t perform that action at this time.
0 commit comments