Skip to content

Commit 90e410f

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. And the "kretprobe-multi-all" is added too. Signed-off-by: Menglong Dong <[email protected]>
1 parent cc5f327 commit 90e410f

File tree

5 files changed

+75
-2
lines changed

5 files changed

+75
-2
lines changed

tools/testing/selftests/bpf/bench.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,8 @@ 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;
514+
extern const struct bench bench_trig_kretprobe_multi_all;
513515
extern const struct bench bench_trig_fexit;
514516
extern const struct bench bench_trig_fmodret;
515517
extern const struct bench bench_trig_tp;
@@ -578,6 +580,8 @@ static const struct bench *benchs[] = {
578580
&bench_trig_kprobe_multi,
579581
&bench_trig_kretprobe_multi,
580582
&bench_trig_fentry,
583+
&bench_trig_kprobe_multi_all,
584+
&bench_trig_kretprobe_multi_all,
581585
&bench_trig_fexit,
582586
&bench_trig_fmodret,
583587
&bench_trig_tp,

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

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

229+
static void attach_ksyms_all(struct bpf_program *empty, bool kretprobe)
230+
{
231+
LIBBPF_OPTS(bpf_kprobe_multi_opts, opts);
232+
char **syms = NULL;
233+
size_t cnt = 0;
234+
235+
if (bpf_get_ksyms(&syms, &cnt, true)) {
236+
printf("failed to get ksyms\n");
237+
exit(1);
238+
}
239+
240+
printf("found %zu ksyms\n", cnt);
241+
opts.syms = (const char **) syms;
242+
opts.cnt = cnt;
243+
opts.retprobe = kretprobe;
244+
/* attach empty to all the kernel functions except bpf_get_numa_node_id. */
245+
if (!bpf_program__attach_kprobe_multi_opts(empty, NULL, &opts)) {
246+
printf("failed to attach bpf_program__attach_kprobe_multi_opts to all\n");
247+
exit(1);
248+
}
249+
}
250+
251+
static void trigger_kprobe_multi_all_setup(void)
252+
{
253+
struct bpf_program *prog, *empty;
254+
255+
setup_ctx();
256+
empty = ctx.skel->progs.bench_kprobe_multi_empty;
257+
prog = ctx.skel->progs.bench_trigger_kprobe_multi;
258+
bpf_program__set_autoload(empty, true);
259+
bpf_program__set_autoload(prog, true);
260+
load_ctx();
261+
262+
attach_ksyms_all(empty, false);
263+
attach_bpf(prog);
264+
}
265+
266+
static void trigger_kretprobe_multi_all_setup(void)
267+
{
268+
struct bpf_program *prog, *empty;
269+
270+
setup_ctx();
271+
empty = ctx.skel->progs.bench_kretprobe_multi_empty;
272+
prog = ctx.skel->progs.bench_trigger_kretprobe_multi;
273+
bpf_program__set_autoload(empty, true);
274+
bpf_program__set_autoload(prog, true);
275+
load_ctx();
276+
277+
attach_ksyms_all(empty, true);
278+
attach_bpf(prog);
279+
}
280+
229281
static void trigger_fexit_setup(void)
230282
{
231283
setup_ctx();
@@ -512,6 +564,8 @@ BENCH_TRIG_KERNEL(kretprobe, "kretprobe");
512564
BENCH_TRIG_KERNEL(kprobe_multi, "kprobe-multi");
513565
BENCH_TRIG_KERNEL(kretprobe_multi, "kretprobe-multi");
514566
BENCH_TRIG_KERNEL(fentry, "fentry");
567+
BENCH_TRIG_KERNEL(kprobe_multi_all, "kprobe-multi-all");
568+
BENCH_TRIG_KERNEL(kretprobe_multi_all, "kretprobe-multi-all");
515569
BENCH_TRIG_KERNEL(fexit, "fexit");
516570
BENCH_TRIG_KERNEL(fmodret, "fmodret");
517571
BENCH_TRIG_KERNEL(tp, "tp");

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ def_tests=( \
66
usermode-count kernel-count syscall-count \
77
fentry fexit fmodret \
88
rawtp tp \
9-
kprobe kprobe-multi \
10-
kretprobe kretprobe-multi \
9+
kprobe kprobe-multi kprobe-multi-all \
10+
kretprobe kretprobe-multi kretprobe-multi-all \
1111
)
1212

1313
tests=("$@")

tools/testing/selftests/bpf/progs/trigger_bench.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,25 @@ int bench_trigger_kprobe_multi(void *ctx)
9797
return 0;
9898
}
9999

100+
SEC("?kprobe.multi/bpf_get_numa_node_id")
101+
int bench_kprobe_multi_empty(void *ctx)
102+
{
103+
return 0;
104+
}
105+
100106
SEC("?kretprobe.multi/bpf_get_numa_node_id")
101107
int bench_trigger_kretprobe_multi(void *ctx)
102108
{
103109
inc_counter();
104110
return 0;
105111
}
106112

113+
SEC("?kretprobe.multi/bpf_get_numa_node_id")
114+
int bench_kretprobe_multi_empty(void *ctx)
115+
{
116+
return 0;
117+
}
118+
107119
SEC("?fentry/bpf_get_numa_node_id")
108120
int bench_trigger_fentry(void *ctx)
109121
{

tools/testing/selftests/bpf/trace_helpers.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,9 @@ static bool skip_entry(char *name)
575575
if (!strcmp(name, "__rcu_read_unlock"))
576576
return true;
577577

578+
if (!strcmp(name, "bpf_get_numa_node_id"))
579+
return true;
580+
578581
return false;
579582
}
580583

0 commit comments

Comments
 (0)