xref: /linux/tools/testing/selftests/bpf/progs/rcu_tasks_trace_gp.c (revision 8c994eff8fcfe8ecb1f1dbebed25b4d7bb75be12)
1 // SPDX-License-Identifier: GPL-2.0
2 #include <vmlinux.h>
3 #include <bpf/bpf_tracing.h>
4 #include <bpf/bpf_helpers.h>
5 
6 struct task_ls_map {
7 	__uint(type, BPF_MAP_TYPE_TASK_STORAGE);
8 	__uint(map_flags, BPF_F_NO_PREALLOC);
9 	__type(key, int);
10 	__type(value, int);
11 } task_ls_map SEC(".maps");
12 
13 long gp_seq;
14 
15 SEC("syscall")
16 int do_call_rcu_tasks_trace(void *ctx)
17 {
18     struct task_struct *current;
19     int *v;
20 
21     current = bpf_get_current_task_btf();
22     v = bpf_task_storage_get(&task_ls_map, current, NULL, BPF_LOCAL_STORAGE_GET_F_CREATE);
23     if (!v)
24         return 1;
25     /* Invoke call_rcu_tasks_trace */
26     return bpf_task_storage_delete(&task_ls_map, current);
27 }
28 
29 SEC("kprobe/rcu_tasks_trace_postgp")
30 int rcu_tasks_trace_postgp(void *ctx)
31 {
32     __sync_add_and_fetch(&gp_seq, 1);
33     return 0;
34 }
35 
36 char _license[] SEC("license") = "GPL";
37