1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2021 Facebook */
6 #include "bpf_loop_bench.skel.h"
8 /* BPF triggering benchmarks */
10 struct bpf_loop_bench *skel;
23 static const struct argp_option opts[] = {
24 { "nr_loops", ARG_NR_LOOPS, "nr_loops", 0,
25 "Set number of loops for the bpf_loop helper"},
29 static error_t parse_arg(int key, char *arg, struct argp_state *state)
33 args.nr_loops = strtol(arg, NULL, 10);
36 return ARGP_ERR_UNKNOWN;
42 /* exported into benchmark runner */
43 const struct argp bench_bpf_loop_argp = {
48 static void validate(void)
50 if (env.consumer_cnt != 0) {
51 fprintf(stderr, "benchmark doesn't support consumer!\n");
56 static void *producer(void *input)
59 /* trigger the bpf program */
60 syscall(__NR_getpgid);
65 static void measure(struct bench_res *res)
67 res->hits = atomic_swap(&ctx.skel->bss->hits, 0);
70 static void setup(void)
72 struct bpf_link *link;
76 ctx.skel = bpf_loop_bench__open_and_load();
78 fprintf(stderr, "failed to open skeleton\n");
82 link = bpf_program__attach(ctx.skel->progs.benchmark);
84 fprintf(stderr, "failed to attach program!\n");
88 ctx.skel->bss->nr_loops = args.nr_loops;
91 const struct bench bench_bpf_loop = {
93 .argp = &bench_bpf_loop_argp,
96 .producer_thread = producer,
98 .report_progress = ops_report_progress,
99 .report_final = ops_report_final,