tools/testing/selftests/bpf/progs/htab_mem_bench.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/htab_mem_bench.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/htab_mem_bench.c- Extension
.c- Size
- 2256 bytes
- Lines
- 106
- 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
stdbool.herrno.hlinux/types.hlinux/bpf.hbpf/bpf_helpers.hbpf/bpf_tracing.h
Detected Declarations
struct update_ctxfunction write_htabfunction overwrite_htabfunction newwrite_htabfunction del_htabfunction overwritefunction batch_add_batch_delfunction add_onlyfunction del_only
Annotated Snippet
struct update_ctx {
unsigned int from;
unsigned int step;
};
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__uint(key_size, 4);
__uint(map_flags, BPF_F_NO_PREALLOC);
} htab SEC(".maps");
char _license[] SEC("license") = "GPL";
unsigned char zeroed_value[4096];
unsigned int nr_thread = 0;
long op_cnt = 0;
static int write_htab(unsigned int i, struct update_ctx *ctx, unsigned int flags)
{
bpf_map_update_elem(&htab, &ctx->from, zeroed_value, flags);
ctx->from += ctx->step;
return 0;
}
static int overwrite_htab(unsigned int i, struct update_ctx *ctx)
{
return write_htab(i, ctx, 0);
}
static int newwrite_htab(unsigned int i, struct update_ctx *ctx)
{
return write_htab(i, ctx, BPF_NOEXIST);
}
static int del_htab(unsigned int i, struct update_ctx *ctx)
{
bpf_map_delete_elem(&htab, &ctx->from);
ctx->from += ctx->step;
return 0;
}
SEC("?tp/syscalls/sys_enter_getpgid")
int overwrite(void *ctx)
{
struct update_ctx update;
update.from = bpf_get_smp_processor_id();
update.step = nr_thread;
bpf_loop(OP_BATCH, overwrite_htab, &update, 0);
__sync_fetch_and_add(&op_cnt, 1);
return 0;
}
SEC("?tp/syscalls/sys_enter_getpgid")
int batch_add_batch_del(void *ctx)
{
struct update_ctx update;
update.from = bpf_get_smp_processor_id();
update.step = nr_thread;
bpf_loop(OP_BATCH, overwrite_htab, &update, 0);
update.from = bpf_get_smp_processor_id();
bpf_loop(OP_BATCH, del_htab, &update, 0);
__sync_fetch_and_add(&op_cnt, 2);
return 0;
}
SEC("?tp/syscalls/sys_enter_getpgid")
int add_only(void *ctx)
{
struct update_ctx update;
update.from = bpf_get_smp_processor_id() / 2;
update.step = nr_thread / 2;
bpf_loop(OP_BATCH, newwrite_htab, &update, 0);
__sync_fetch_and_add(&op_cnt, 1);
return 0;
}
SEC("?tp/syscalls/sys_enter_getppid")
int del_only(void *ctx)
{
struct update_ctx update;
update.from = bpf_get_smp_processor_id() / 2;
update.step = nr_thread / 2;
Annotation
- Immediate include surface: `stdbool.h`, `errno.h`, `linux/types.h`, `linux/bpf.h`, `bpf/bpf_helpers.h`, `bpf/bpf_tracing.h`.
- Detected declarations: `struct update_ctx`, `function write_htab`, `function overwrite_htab`, `function newwrite_htab`, `function del_htab`, `function overwrite`, `function batch_add_batch_del`, `function add_only`, `function del_only`.
- 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.