1 | // SPDX-License-Identifier: GPL-2.0 |
2 | /* Copyright (C) 2022. Huawei Technologies Co., Ltd */ |
3 | #include "vmlinux.h" |
4 | #include <bpf/bpf_helpers.h> |
5 | #include <bpf/bpf_tracing.h> |
6 | |
7 | extern bool CONFIG_PREEMPT __kconfig __weak; |
8 | extern const int bpf_task_storage_busy __ksym; |
9 | |
10 | char _license[] SEC("license" ) = "GPL" ; |
11 | |
12 | int pid = 0; |
13 | int busy = 0; |
14 | |
15 | struct { |
16 | __uint(type, BPF_MAP_TYPE_TASK_STORAGE); |
17 | __uint(map_flags, BPF_F_NO_PREALLOC); |
18 | __type(key, int); |
19 | __type(value, long); |
20 | } task SEC(".maps" ); |
21 | |
22 | SEC("raw_tp/sys_enter" ) |
23 | int BPF_PROG(read_bpf_task_storage_busy) |
24 | { |
25 | int *value; |
26 | |
27 | if (!CONFIG_PREEMPT) |
28 | return 0; |
29 | |
30 | if (bpf_get_current_pid_tgid() >> 32 != pid) |
31 | return 0; |
32 | |
33 | value = bpf_this_cpu_ptr(&bpf_task_storage_busy); |
34 | if (value) |
35 | busy = *value; |
36 | |
37 | return 0; |
38 | } |
39 | |