1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2019 Facebook
4 #include <linux/version.h>
5 #include <bpf/bpf_helpers.h>
10 struct bpf_spin_lock lock
;
15 __uint(type
, BPF_MAP_TYPE_HASH
);
16 __uint(max_entries
, 1);
18 __type(value
, struct hmap_elem
);
19 } hash_map
SEC(".maps");
22 struct bpf_spin_lock lock
;
27 __uint(type
, BPF_MAP_TYPE_ARRAY
);
28 __uint(max_entries
, 1);
30 __type(value
, struct array_elem
);
31 } array_map
SEC(".maps");
34 int bpf_map_lock_test(struct __sk_buff
*skb
)
36 struct hmap_elem zero
= {}, *val
;
37 int rnd
= bpf_get_prandom_u32();
38 int key
= 0, err
= 1, i
;
41 val
= bpf_map_lookup_elem(&hash_map
, &key
);
44 /* spin_lock in hash map */
45 bpf_spin_lock(&val
->lock
);
46 for (i
= 0; i
< VAR_NUM
; i
++)
48 bpf_spin_unlock(&val
->lock
);
50 /* spin_lock in array */
51 q
= bpf_map_lookup_elem(&array_map
, &key
);
54 bpf_spin_lock(&q
->lock
);
55 for (i
= 0; i
< VAR_NUM
; i
++)
57 bpf_spin_unlock(&q
->lock
);
62 char _license
[] SEC("license") = "GPL";