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
7extern bool CONFIG_PREEMPT __kconfig __weak;
8extern const int bpf_task_storage_busy __ksym;
9
10char _license[] SEC("license") = "GPL";
11
12int pid = 0;
13int busy = 0;
14
15struct {
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
22SEC("raw_tp/sys_enter")
23int 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

source code of linux/tools/testing/selftests/bpf/progs/read_bpf_task_storage_busy.c