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
timer_in_interrupt(void * map,int * key,struct bpf_timer * timer)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")
BPF_PROG(test_timer_interrupt)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 }
49