Skip to content

Commit 46c0e2f

Browse files
image-dragonKernel Patches Daemon
authored andcommitted
selftests/bpf: add benchmark testing for kprobe-multi-all
For now, the benchmark for kprobe-multi is single, which means there is only 1 function is hooked during testing. Add the testing "kprobe-multi-all", which will hook all the kernel functions during the benchmark. Signed-off-by: Menglong Dong <[email protected]>
1 parent fcfe740 commit 46c0e2f

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

tools/testing/selftests/bpf/bench.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ extern const struct bench bench_trig_kretprobe;
510510
extern const struct bench bench_trig_kprobe_multi;
511511
extern const struct bench bench_trig_kretprobe_multi;
512512
extern const struct bench bench_trig_fentry;
513+
extern const struct bench bench_trig_kprobe_multi_all;
513514
extern const struct bench bench_trig_fexit;
514515
extern const struct bench bench_trig_fmodret;
515516
extern const struct bench bench_trig_tp;
@@ -578,6 +579,7 @@ static const struct bench *benchs[] = {
578579
&bench_trig_kprobe_multi,
579580
&bench_trig_kretprobe_multi,
580581
&bench_trig_fentry,
582+
&bench_trig_kprobe_multi_all,
581583
&bench_trig_fexit,
582584
&bench_trig_fmodret,
583585
&bench_trig_tp,

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,35 @@ static void trigger_fentry_setup(void)
226226
attach_bpf(ctx.skel->progs.bench_trigger_fentry);
227227
}
228228

229+
static void trigger_kprobe_multi_all_setup(void)
230+
{
231+
LIBBPF_OPTS(bpf_kprobe_multi_opts, opts);
232+
struct bpf_program *prog;
233+
struct bpf_link *link;
234+
char **syms = NULL;
235+
size_t cnt = 0;
236+
237+
setup_ctx();
238+
prog = ctx.skel->progs.bench_trigger_kprobe_multi;
239+
bpf_program__set_autoload(prog, true);
240+
load_ctx();
241+
242+
if (bpf_get_ksyms(&syms, &cnt, true)) {
243+
printf("failed to get ksyms\n");
244+
exit(1);
245+
}
246+
247+
printf("found %zu ksyms\n", cnt);
248+
opts.syms = (const char **) syms;
249+
opts.cnt = cnt;
250+
link = bpf_program__attach_kprobe_multi_opts(prog, NULL, &opts);
251+
if (!link) {
252+
printf("failed to attach bpf_program__attach_kprobe_multi_opts to all\n");
253+
exit(1);
254+
}
255+
ctx.skel->links.bench_trigger_kprobe_multi = link;
256+
}
257+
229258
static void trigger_fexit_setup(void)
230259
{
231260
setup_ctx();
@@ -512,6 +541,7 @@ BENCH_TRIG_KERNEL(kretprobe, "kretprobe");
512541
BENCH_TRIG_KERNEL(kprobe_multi, "kprobe-multi");
513542
BENCH_TRIG_KERNEL(kretprobe_multi, "kretprobe-multi");
514543
BENCH_TRIG_KERNEL(fentry, "fentry");
544+
BENCH_TRIG_KERNEL(kprobe_multi_all, "kprobe-multi-all");
515545
BENCH_TRIG_KERNEL(fexit, "fexit");
516546
BENCH_TRIG_KERNEL(fmodret, "fmodret");
517547
BENCH_TRIG_KERNEL(tp, "tp");

tools/testing/selftests/bpf/benchs/run_bench_trigger.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def_tests=( \
66
usermode-count kernel-count syscall-count \
77
fentry fexit fmodret \
88
rawtp tp \
9-
kprobe kprobe-multi \
9+
kprobe kprobe-multi kprobe-multi-all \
1010
kretprobe kretprobe-multi \
1111
)
1212

0 commit comments

Comments
 (0)