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.

Dependency Surface

Detected Declarations

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

Implementation Notes