samples/bpf/map_perf_test.bpf.c

Source file repositories/reference/linux-study-clean/samples/bpf/map_perf_test.bpf.c

File Facts

System
Linux kernel
Corpus path
samples/bpf/map_perf_test.bpf.c
Extension
.c
Size
6526 bytes
Lines
298
Domain
Support Tooling And Documentation
Bucket
samples
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

struct inner_lru {
	__uint(type, BPF_MAP_TYPE_LRU_HASH);
	__type(key, u32);
	__type(value, long);
	__uint(max_entries, MAX_ENTRIES);
	__uint(map_flags, BPF_F_NUMA_NODE);
	__uint(numa_node, 0);
} inner_lru_hash_map SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
	__uint(max_entries, MAX_NR_CPUS);
	__uint(key_size, sizeof(u32));
	__array(values, struct inner_lru); /* use inner_lru as inner map */
} array_of_lru_hashs SEC(".maps") = {
	/* statically initialize the first element */
	.values = { &inner_lru_hash_map },
};

struct {
	__uint(type, BPF_MAP_TYPE_PERCPU_HASH);
	__uint(key_size, sizeof(u32));
	__uint(value_size, sizeof(long));
	__uint(max_entries, MAX_ENTRIES);
} percpu_hash_map SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_HASH);
	__type(key, u32);
	__type(value, long);
	__uint(max_entries, MAX_ENTRIES);
	__uint(map_flags, BPF_F_NO_PREALLOC);
} hash_map_alloc SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_PERCPU_HASH);
	__uint(key_size, sizeof(u32));
	__uint(value_size, sizeof(long));
	__uint(max_entries, MAX_ENTRIES);
	__uint(map_flags, BPF_F_NO_PREALLOC);
} percpu_hash_map_alloc SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_LPM_TRIE);
	__uint(key_size, 8);
	__uint(value_size, sizeof(long));
	__uint(max_entries, 10000);
	__uint(map_flags, BPF_F_NO_PREALLOC);
} lpm_trie_map_alloc SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_ARRAY);
	__type(key, u32);
	__type(value, long);
	__uint(max_entries, MAX_ENTRIES);
} array_map SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_LRU_HASH);
	__type(key, u32);
	__type(value, long);
	__uint(max_entries, MAX_ENTRIES);
} lru_hash_lookup_map SEC(".maps");

SEC("ksyscall/getuid")
int BPF_KSYSCALL(stress_hmap)
{
	u32 key = bpf_get_current_pid_tgid();
	long init_val = 1;
	long *value;
	int i;

	for (i = 0; i < 10; i++) {
		bpf_map_update_elem(&hash_map, &key, &init_val, BPF_ANY);
		value = bpf_map_lookup_elem(&hash_map, &key);
		if (value)
			bpf_map_delete_elem(&hash_map, &key);
	}

	return 0;
}

SEC("ksyscall/geteuid")
int BPF_KSYSCALL(stress_percpu_hmap)
{
	u32 key = bpf_get_current_pid_tgid();
	long init_val = 1;
	long *value;
	int i;

Annotation

Implementation Notes