tools/testing/selftests/bpf/benchs/bench_local_storage_create.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/benchs/bench_local_storage_create.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/bpf/benchs/bench_local_storage_create.c
Extension
.c
Size
5727 bytes
Lines
250
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 thread {
	int *fds;
	pthread_t *pthds;
	int *pthd_results;
};

static struct bench_local_storage_create *skel;
static struct thread *threads;
static long create_owner_errs;
static int storage_type = BPF_MAP_TYPE_SK_STORAGE;
static int batch_sz = 32;

enum {
	ARG_BATCH_SZ = 9000,
	ARG_STORAGE_TYPE = 9001,
};

static const struct argp_option opts[] = {
	{ "batch-size", ARG_BATCH_SZ, "BATCH_SIZE", 0,
	  "The number of storage creations in each batch" },
	{ "storage-type", ARG_STORAGE_TYPE, "STORAGE_TYPE", 0,
	  "The type of local storage to test (socket or task)" },
	{},
};

static error_t parse_arg(int key, char *arg, struct argp_state *state)
{
	int ret;

	switch (key) {
	case ARG_BATCH_SZ:
		ret = atoi(arg);
		if (ret < 1) {
			fprintf(stderr, "invalid batch-size\n");
			argp_usage(state);
		}
		batch_sz = ret;
		break;
	case ARG_STORAGE_TYPE:
		if (!strcmp(arg, "task")) {
			storage_type = BPF_MAP_TYPE_TASK_STORAGE;
		} else if (!strcmp(arg, "socket")) {
			storage_type = BPF_MAP_TYPE_SK_STORAGE;
		} else {
			fprintf(stderr, "invalid storage-type (socket or task)\n");
			argp_usage(state);
		}
		break;
	default:
		return ARGP_ERR_UNKNOWN;
	}

	return 0;
}

const struct argp bench_local_storage_create_argp = {
	.options = opts,
	.parser = parse_arg,
};

static void validate(void)
{
	if (env.consumer_cnt != 0) {
		fprintf(stderr,
			"local-storage-create benchmark does not need consumer\n");
		exit(1);
	}
}

static void setup(void)
{
	int i;

	skel = bench_local_storage_create__open_and_load();
	if (!skel) {
		fprintf(stderr, "error loading skel\n");
		exit(1);
	}

	skel->bss->bench_pid = getpid();
	if (storage_type == BPF_MAP_TYPE_SK_STORAGE) {
		if (!bpf_program__attach(skel->progs.socket_post_create)) {
			fprintf(stderr, "Error attaching bpf program\n");
			exit(1);
		}
	} else {
		if (!bpf_program__attach(skel->progs.sched_process_fork)) {
			fprintf(stderr, "Error attaching bpf program\n");
			exit(1);
		}

Annotation

Implementation Notes