tools/testing/selftests/bpf/progs/local_storage_bench.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/local_storage_bench.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/local_storage_bench.c- Extension
.c- Size
- 2324 bytes
- Lines
- 105
- 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.hbpf/bpf_helpers.hbpf_misc.h
Detected Declarations
struct loop_ctxfunction do_lookupfunction loopfunction get_local
Annotated Snippet
struct loop_ctx {
struct task_struct *task;
long loop_hits;
long loop_important_hits;
};
static int do_lookup(unsigned int elem, struct loop_ctx *lctx)
{
void *map, *inner_map;
int idx = 0;
if (use_hashmap)
map = &array_of_hash_maps;
else
map = &array_of_local_storage_maps;
inner_map = bpf_map_lookup_elem(map, &elem);
if (!inner_map)
return -1;
if (use_hashmap) {
idx = bpf_get_prandom_u32() % hashmap_num_keys;
bpf_map_lookup_elem(inner_map, &idx);
} else {
bpf_task_storage_get(inner_map, lctx->task, &idx,
BPF_LOCAL_STORAGE_GET_F_CREATE);
}
lctx->loop_hits++;
if (!elem)
lctx->loop_important_hits++;
return 0;
}
static long loop(u32 index, void *ctx)
{
struct loop_ctx *lctx = (struct loop_ctx *)ctx;
unsigned int map_idx = index % num_maps;
do_lookup(map_idx, lctx);
if (interleave && map_idx % 3 == 0)
do_lookup(0, lctx);
return 0;
}
SEC("fentry/" SYS_PREFIX "sys_getpgid")
int get_local(void *ctx)
{
struct loop_ctx lctx;
lctx.task = bpf_get_current_task_btf();
lctx.loop_hits = 0;
lctx.loop_important_hits = 0;
bpf_loop(10000, &loop, &lctx, 0);
__sync_add_and_fetch(&hits, lctx.loop_hits);
__sync_add_and_fetch(&important_hits, lctx.loop_important_hits);
return 0;
}
char _license[] SEC("license") = "GPL";
Annotation
- Immediate include surface: `vmlinux.h`, `bpf/bpf_helpers.h`, `bpf_misc.h`.
- Detected declarations: `struct loop_ctx`, `function do_lookup`, `function loop`, `function get_local`.
- 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.