1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2023. Huawei Technologies Co., Ltd */
4 #include <bpf/bpf_tracing.h>
5 #include <bpf/bpf_helpers.h>
8 #include "bpf_experimental.h"
12 struct bpf_list_node node;
16 struct bpf_list_head head __contains(node_data, node);
17 struct bpf_spin_lock lock;
20 struct inner_array_type {
21 __uint(type, BPF_MAP_TYPE_ARRAY);
23 __type(value, struct map_value);
24 __uint(max_entries, 1);
25 } inner_array SEC(".maps");
28 __uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
30 __uint(value_size, 4);
31 __uint(max_entries, 1);
32 __array(values, struct inner_array_type);
33 } outer_array SEC(".maps") = {
39 char _license[] SEC("license") = "GPL";
44 SEC("fentry/" SYS_PREFIX "sys_nanosleep")
45 int add_to_list_in_inner_array(void *ctx)
47 struct map_value *value;
48 struct node_data *new;
52 if (done || (u32)bpf_get_current_pid_tgid() != pid)
55 map = bpf_map_lookup_elem(&outer_array, &zero);
59 value = bpf_map_lookup_elem(map, &zero);
63 new = bpf_obj_new(typeof(*new));
67 bpf_spin_lock(&value->lock);
68 bpf_list_push_back(&value->head, &new->node);
69 bpf_spin_unlock(&value->lock);