tools/testing/selftests/bpf/benchs/bench_htab_mem.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/benchs/bench_htab_mem.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/benchs/bench_htab_mem.c- Extension
.c- Size
- 9058 bytes
- Lines
- 382
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
argp.hstdbool.hpthread.hsys/types.hsys/stat.hsys/param.hfcntl.hbench.hbpf_util.hcgroup_helpers.hhtab_mem_bench.skel.h
Detected Declarations
struct htab_mem_use_casefunction htab_mem_parse_argfunction htab_mem_validatefunction htab_mem_bench_init_barriersfunction htab_mem_bench_exit_barriersfunction htab_mem_setup_implfunction htab_mem_setupfunction rhtab_mem_setupfunction htab_mem_add_fnfunction htab_mem_delete_fnfunction htab_mem_read_mem_cgrp_filefunction htab_mem_measurefunction htab_mem_report_progressfunction htab_mem_report_finalfunction rhtab_mem_validate
Annotated Snippet
struct htab_mem_use_case {
const char *name;
const char **progs;
/* Do synchronization between addition thread and deletion thread */
bool need_sync;
};
static struct htab_mem_ctx {
const struct htab_mem_use_case *uc;
struct htab_mem_bench *skel;
pthread_barrier_t *notify;
int fd;
} ctx;
const char *ow_progs[] = {"overwrite", NULL};
const char *batch_progs[] = {"batch_add_batch_del", NULL};
const char *add_del_progs[] = {"add_only", "del_only", NULL};
const static struct htab_mem_use_case use_cases[] = {
{ .name = "overwrite", .progs = ow_progs },
{ .name = "batch_add_batch_del", .progs = batch_progs },
{ .name = "add_del_on_diff_cpu", .progs = add_del_progs, .need_sync = true },
};
static struct htab_mem_args {
u32 value_size;
const char *use_case;
bool preallocated;
} args = {
.value_size = 8,
.use_case = "overwrite",
.preallocated = false,
};
enum {
ARG_VALUE_SIZE = 10000,
ARG_USE_CASE = 10001,
ARG_PREALLOCATED = 10002,
};
static const struct argp_option opts[] = {
{ "value-size", ARG_VALUE_SIZE, "VALUE_SIZE", 0,
"Set the value size of hash map (default 8)" },
{ "use-case", ARG_USE_CASE, "USE_CASE", 0,
"Set the use case of hash map: overwrite|batch_add_batch_del|add_del_on_diff_cpu" },
{ "preallocated", ARG_PREALLOCATED, NULL, 0, "use preallocated hash map" },
{},
};
static error_t htab_mem_parse_arg(int key, char *arg, struct argp_state *state)
{
switch (key) {
case ARG_VALUE_SIZE:
args.value_size = strtoul(arg, NULL, 10);
if (args.value_size > 4096) {
fprintf(stderr, "too big value size %u\n", args.value_size);
argp_usage(state);
}
break;
case ARG_USE_CASE:
args.use_case = strdup(arg);
if (!args.use_case) {
fprintf(stderr, "no mem for use-case\n");
argp_usage(state);
}
break;
case ARG_PREALLOCATED:
args.preallocated = true;
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
const struct argp bench_htab_mem_argp = {
.options = opts,
.parser = htab_mem_parse_arg,
};
static void htab_mem_validate(void)
{
if (!strcmp(use_cases[2].name, args.use_case) && env.producer_cnt % 2) {
fprintf(stderr, "%s needs an even number of producers\n", args.use_case);
exit(1);
}
}
static int htab_mem_bench_init_barriers(void)
{
Annotation
- Immediate include surface: `argp.h`, `stdbool.h`, `pthread.h`, `sys/types.h`, `sys/stat.h`, `sys/param.h`, `fcntl.h`, `bench.h`.
- Detected declarations: `struct htab_mem_use_case`, `function htab_mem_parse_arg`, `function htab_mem_validate`, `function htab_mem_bench_init_barriers`, `function htab_mem_bench_exit_barriers`, `function htab_mem_setup_impl`, `function htab_mem_setup`, `function rhtab_mem_setup`, `function htab_mem_add_fn`, `function htab_mem_delete_fn`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.