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

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

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/bpf/benchs/bench_rename.c
Extension
.c
Size
3407 bytes
Lines
168
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

if (err < 0) {
			fprintf(stderr, "write failed\n");
			exit(1);
		}
		atomic_inc(&ctx.hits.value);
	}
}

static void measure(struct bench_res *res)
{
	res->hits = atomic_swap(&ctx.hits.value, 0);
}

static void setup_ctx(void)
{
	setup_libbpf();

	ctx.skel = test_overhead__open_and_load();
	if (!ctx.skel) {
		fprintf(stderr, "failed to open skeleton\n");
		exit(1);
	}

	ctx.fd = open("/proc/self/comm", O_WRONLY|O_TRUNC);
	if (ctx.fd < 0) {
		fprintf(stderr, "failed to open /proc/self/comm: %d\n", -errno);
		exit(1);
	}
}

static void attach_bpf(struct bpf_program *prog)
{
	struct bpf_link *link;

	link = bpf_program__attach(prog);
	if (!link) {
		fprintf(stderr, "failed to attach program!\n");
		exit(1);
	}
}

static void setup_base(void)
{
	setup_ctx();
}

static void setup_kprobe(void)
{
	setup_ctx();
	attach_bpf(ctx.skel->progs.prog1);
}

static void setup_kretprobe(void)
{
	setup_ctx();
	attach_bpf(ctx.skel->progs.prog2);
}

static void setup_rawtp(void)
{
	setup_ctx();
	attach_bpf(ctx.skel->progs.prog3);
}

static void setup_fentry(void)
{
	setup_ctx();
	attach_bpf(ctx.skel->progs.prog4);
}

static void setup_fexit(void)
{
	setup_ctx();
	attach_bpf(ctx.skel->progs.prog5);
}

const struct bench bench_rename_base = {
	.name = "rename-base",
	.validate = validate,
	.setup = setup_base,
	.producer_thread = producer,
	.measure = measure,
	.report_progress = hits_drops_report_progress,
	.report_final = hits_drops_report_final,
};

const struct bench bench_rename_kprobe = {
	.name = "rename-kprobe",
	.validate = validate,
	.setup = setup_kprobe,

Annotation

Implementation Notes