samples/bpf/map_perf_test_user.c
Source file repositories/reference/linux-study-clean/samples/bpf/map_perf_test_user.c
File Facts
- System
- Linux kernel
- Corpus path
samples/bpf/map_perf_test_user.c- Extension
.c- Size
- 11828 bytes
- Lines
- 504
- 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.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
sched.hstdio.hsys/types.hasm/unistd.hunistd.hassert.hsys/wait.hstdlib.hsignal.hstring.htime.harpa/inet.herrno.hbpf/bpf.hbpf/libbpf.h
Detected Declarations
enum test_typeenum map_idxfunction time_get_nsfunction check_test_flagsfunction test_hash_preallocfunction pre_test_lru_hash_lookupfunction do_test_lrufunction test_lru_hash_preallocfunction test_nocommon_lru_hash_preallocfunction test_inner_lru_hash_preallocfunction test_lru_hash_lookupfunction test_percpu_hash_preallocfunction test_hash_kmallocfunction test_percpu_hash_kmallocfunction test_lpm_kmallocfunction test_hash_lookupfunction test_array_lookupfunction pre_testfunction loopfunction run_perf_testfunction fill_lpm_triefunction fixup_mapfunction bpf_object__for_each_mapfunction mainfunction bpf_object__for_each_program
Annotated Snippet
if (inner_lru_map_fds[cpu] == -1) {
printf("cannot create BPF_MAP_TYPE_LRU_HASH %s(%d)\n",
strerror(errno), errno);
exit(1);
}
ret = bpf_map_update_elem(outer_fd, &cpu,
&inner_lru_map_fds[cpu],
BPF_ANY);
if (ret) {
printf("cannot update ARRAY_OF_LRU_HASHS with key:%u. %s(%d)\n",
cpu, strerror(errno), errno);
exit(1);
}
}
in6.sin6_addr.s6_addr16[0] = 0xdead;
in6.sin6_addr.s6_addr16[1] = 0xbeef;
if (test == LRU_HASH_PREALLOC) {
test_name = "lru_hash_map_perf";
in6.sin6_addr.s6_addr16[2] = 0;
} else if (test == NOCOMMON_LRU_HASH_PREALLOC) {
test_name = "nocommon_lru_hash_map_perf";
in6.sin6_addr.s6_addr16[2] = 1;
} else if (test == INNER_LRU_HASH_PREALLOC) {
test_name = "inner_lru_hash_map_perf";
in6.sin6_addr.s6_addr16[2] = 2;
} else if (test == LRU_HASH_LOOKUP) {
test_name = "lru_hash_lookup_perf";
in6.sin6_addr.s6_addr16[2] = 3;
in6.sin6_addr.s6_addr32[3] = 0;
} else {
assert(0);
}
start_time = time_get_ns();
for (i = 0; i < max_cnt; i++) {
ret = connect(-1, (const struct sockaddr *)&in6, sizeof(in6));
assert(ret == -1 && errno == EBADF);
if (in6.sin6_addr.s6_addr32[3] <
lru_hash_lookup_test_entries - 32)
in6.sin6_addr.s6_addr32[3] += 32;
else
in6.sin6_addr.s6_addr32[3] = 0;
}
printf("%d:%s pre-alloc %lld events per sec\n",
cpu, test_name,
max_cnt * 1000000000ll / (time_get_ns() - start_time));
}
static void test_lru_hash_prealloc(int cpu)
{
do_test_lru(LRU_HASH_PREALLOC, cpu);
}
static void test_nocommon_lru_hash_prealloc(int cpu)
{
do_test_lru(NOCOMMON_LRU_HASH_PREALLOC, cpu);
}
static void test_inner_lru_hash_prealloc(int cpu)
{
do_test_lru(INNER_LRU_HASH_PREALLOC, cpu);
}
static void test_lru_hash_lookup(int cpu)
{
do_test_lru(LRU_HASH_LOOKUP, cpu);
}
static void test_percpu_hash_prealloc(int cpu)
{
__u64 start_time;
int i;
start_time = time_get_ns();
for (i = 0; i < max_cnt; i++)
syscall(__NR_geteuid);
printf("%d:percpu_hash_map_perf pre-alloc %lld events per sec\n",
cpu, max_cnt * 1000000000ll / (time_get_ns() - start_time));
}
static void test_hash_kmalloc(int cpu)
{
__u64 start_time;
int i;
start_time = time_get_ns();
for (i = 0; i < max_cnt; i++)
Annotation
- Immediate include surface: `sched.h`, `stdio.h`, `sys/types.h`, `asm/unistd.h`, `unistd.h`, `assert.h`, `sys/wait.h`, `stdlib.h`.
- Detected declarations: `enum test_type`, `enum map_idx`, `function time_get_ns`, `function check_test_flags`, `function test_hash_prealloc`, `function pre_test_lru_hash_lookup`, `function do_test_lru`, `function test_lru_hash_prealloc`, `function test_nocommon_lru_hash_prealloc`, `function test_inner_lru_hash_prealloc`.
- Atlas domain: Support Tooling And Documentation / samples.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.