tools/testing/selftests/bpf/progs/test_map_lookup_percpu_elem.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/test_map_lookup_percpu_elem.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/test_map_lookup_percpu_elem.c- Extension
.c- Size
- 1719 bytes
- Lines
- 77
- 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.h
Detected Declarations
struct read_percpu_elem_ctxfunction read_percpu_elem_callbackfunction sysenter_getuid
Annotated Snippet
struct read_percpu_elem_ctx {
void *map;
__u64 sum;
};
static int read_percpu_elem_callback(__u32 index, struct read_percpu_elem_ctx *ctx)
{
__u64 key = 0;
__u64 *value;
value = bpf_map_lookup_percpu_elem(ctx->map, &key, index);
if (value)
ctx->sum += *value;
return 0;
}
SEC("tp/syscalls/sys_enter_getuid")
int sysenter_getuid(const void *ctx)
{
struct read_percpu_elem_ctx map_ctx;
if (my_pid != (bpf_get_current_pid_tgid() >> 32))
return 0;
map_ctx.map = &percpu_array_map;
map_ctx.sum = 0;
bpf_loop(nr_cpus, read_percpu_elem_callback, &map_ctx, 0);
percpu_array_elem_sum = map_ctx.sum;
map_ctx.map = &percpu_hash_map;
map_ctx.sum = 0;
bpf_loop(nr_cpus, read_percpu_elem_callback, &map_ctx, 0);
percpu_hash_elem_sum = map_ctx.sum;
map_ctx.map = &percpu_lru_hash_map;
map_ctx.sum = 0;
bpf_loop(nr_cpus, read_percpu_elem_callback, &map_ctx, 0);
percpu_lru_hash_elem_sum = map_ctx.sum;
return 0;
}
char _license[] SEC("license") = "GPL";
Annotation
- Immediate include surface: `vmlinux.h`, `bpf/bpf_helpers.h`.
- Detected declarations: `struct read_percpu_elem_ctx`, `function read_percpu_elem_callback`, `function sysenter_getuid`.
- 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.