tools/testing/selftests/bpf/progs/lpm_trie_bench.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/lpm_trie_bench.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/lpm_trie_bench.c- Extension
.c- Size
- 4565 bytes
- Lines
- 231
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
vmlinux.herrno.hbpf/bpf_tracing.hbpf/bpf_helpers.hbpf/bpf_core_read.hbpf_misc.hbpf_atomic.hprogs/lpm_trie.h
Detected Declarations
function BPF_PROGfunction BPF_PROGfunction generate_keyfunction noopfunction baselinefunction lookupfunction insertfunction updatefunction deletefunction BPF_PROG
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2025 Cloudflare */
#include <vmlinux.h>
#include <errno.h>
#include <bpf/bpf_tracing.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_core_read.h>
#include "bpf_misc.h"
#include <bpf_atomic.h>
#include "progs/lpm_trie.h"
#define BPF_OBJ_NAME_LEN 16U
#define MAX_ENTRIES 100000000
#define NR_LOOPS 10000
char _license[] SEC("license") = "GPL";
/* Filled by userspace. See fill_map() in bench_lpm_trie_map.c */
struct {
__uint(type, BPF_MAP_TYPE_LPM_TRIE);
__type(key, struct trie_key);
__type(value, __u32);
__uint(map_flags, BPF_F_NO_PREALLOC);
__uint(max_entries, MAX_ENTRIES);
} trie_map SEC(".maps");
long hits;
long duration_ns;
/* Configured from userspace */
__u32 nr_entries;
__u32 prefixlen;
bool random;
__u8 op;
static __u64 latency_free_start;
SEC("fentry/bpf_map_free_deferred")
int BPF_PROG(trie_free_entry, struct work_struct *work)
{
struct bpf_map *map = container_of(work, struct bpf_map, work);
char name[BPF_OBJ_NAME_LEN];
u32 map_type;
map_type = BPF_CORE_READ(map, map_type);
if (map_type != BPF_MAP_TYPE_LPM_TRIE)
return 0;
/*
* Ideally we'd have access to the map ID but that's already
* freed before we enter trie_free().
*/
BPF_CORE_READ_STR_INTO(&name, map, name);
if (bpf_strncmp(name, BPF_OBJ_NAME_LEN, "trie_free_map"))
return 0;
latency_free_start = bpf_ktime_get_ns();
return 0;
}
SEC("fexit/bpf_map_free_deferred")
int BPF_PROG(trie_free_exit, struct work_struct *work)
{
__u64 val;
if (!latency_free_start)
return 0;
val = bpf_ktime_get_ns() - latency_free_start;
latency_free_start = 0;
__sync_add_and_fetch(&duration_ns, val);
__sync_add_and_fetch(&hits, 1);
return 0;
}
static __u32 cur_key;
static __always_inline void generate_key(struct trie_key *key)
{
key->prefixlen = prefixlen;
if (random)
key->data = bpf_get_prandom_u32() % nr_entries;
else
key->data = cur_key++ % nr_entries;
}
Annotation
- Immediate include surface: `vmlinux.h`, `errno.h`, `bpf/bpf_tracing.h`, `bpf/bpf_helpers.h`, `bpf/bpf_core_read.h`, `bpf_misc.h`, `bpf_atomic.h`, `progs/lpm_trie.h`.
- Detected declarations: `function BPF_PROG`, `function BPF_PROG`, `function generate_key`, `function noop`, `function baseline`, `function lookup`, `function insert`, `function update`, `function delete`, `function BPF_PROG`.
- Atlas domain: Support Tooling And Documentation / tools.
- 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.