xref: /linux/tools/testing/selftests/bpf/progs/htab_reuse.c (revision c4dde411bc366f568dbe33366253bbfea049e8ea)
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2023. Huawei Technologies Co., Ltd */
3 #include <linux/bpf.h>
4 #include <bpf/bpf_helpers.h>
5 
6 char _license[] SEC("license") = "GPL";
7 
8 struct htab_val {
9 	struct bpf_spin_lock lock;
10 	unsigned int data;
11 };
12 
13 struct {
14 	__uint(type, BPF_MAP_TYPE_HASH);
15 	__uint(max_entries, 64);
16 	__type(key, unsigned int);
17 	__type(value, struct htab_val);
18 	__uint(map_flags, BPF_F_NO_PREALLOC);
19 } htab SEC(".maps");
20 
21 #define HTAB_NDATA 256
22 
23 struct htab_val_large {
24 	struct bpf_spin_lock lock;
25 	__u32 seq;
26 	__u64 data[HTAB_NDATA];
27 };
28 
29 struct {
30 	__uint(type, BPF_MAP_TYPE_HASH);
31 	__uint(max_entries, 8);
32 	__type(key, unsigned int);
33 	__type(value, struct htab_val_large);
34 	__uint(map_flags, BPF_F_NO_PREALLOC);
35 } htab_lock_consistency SEC(".maps");
36