Skip to content

Commit a85d888

Browse files
image-dragonAlexei Starovoitov
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]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent adf6b57 commit a85d888

File tree

5 files changed

+80
-2
lines changed

5 files changed

+80
-2
lines changed

tools/testing/selftests/bpf/bench.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,8 @@ extern const struct bench bench_trig_kretprobe;
512512
extern const struct bench bench_trig_kprobe_multi;
513513
extern const struct bench bench_trig_kretprobe_multi;
514514
extern const struct bench bench_trig_fentry;
515+
extern const struct bench bench_trig_kprobe_multi_all;
516+
extern const struct bench bench_trig_kretprobe_multi_all;
515517
extern const struct bench bench_trig_fexit;
516518
extern const struct bench bench_trig_fmodret;
517519
extern const struct bench bench_trig_tp;
@@ -587,6 +589,8 @@ static const struct bench *benchs[] = {
587589
&bench_trig_kprobe_multi,
588590
&bench_trig_kretprobe_multi,
589591
&bench_trig_fentry,
592+
&bench_trig_kprobe_multi_all,
593+
&bench_trig_kretprobe_multi_all,
590594
&bench_trig_fexit,
591595
&bench_trig_fmodret,
592596
&bench_trig_tp,

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,65 @@ 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+
/* Some recursive functions will be skipped in
236+
* bpf_get_ksyms -> skip_entry, as they can introduce sufficient
237+
* overhead. However, it's difficut to skip all the recursive
238+
* functions for a debug kernel.
239+
*
240+
* So, don't run the kprobe-multi-all and kretprobe-multi-all on
241+
* a debug kernel.
242+
*/
243+
if (bpf_get_ksyms(&syms, &cnt, true)) {
244+
fprintf(stderr, "failed to get ksyms\n");
245+
exit(1);
246+
}
247+
248+
opts.syms = (const char **) syms;
249+
opts.cnt = cnt;
250+
opts.retprobe = kretprobe;
251+
/* attach empty to all the kernel functions except bpf_get_numa_node_id. */
252+
if (!bpf_program__attach_kprobe_multi_opts(empty, NULL, &opts)) {
253+
fprintf(stderr, "failed to attach bpf_program__attach_kprobe_multi_opts to all\n");
254+
exit(1);
255+
}
256+
}
257+
258+
static void trigger_kprobe_multi_all_setup(void)
259+
{
260+
struct bpf_program *prog, *empty;
261+
262+
setup_ctx();
263+
empty = ctx.skel->progs.bench_kprobe_multi_empty;
264+
prog = ctx.skel->progs.bench_trigger_kprobe_multi;
265+
bpf_program__set_autoload(empty, true);
266+
bpf_program__set_autoload(prog, true);
267+
load_ctx();
268+
269+
attach_ksyms_all(empty, false);
270+
attach_bpf(prog);
271+
}
272+
273+
static void trigger_kretprobe_multi_all_setup(void)
274+
{
275+
struct bpf_program *prog, *empty;
276+
277+
setup_ctx();
278+
empty = ctx.skel->progs.bench_kretprobe_multi_empty;
279+
prog = ctx.skel->progs.bench_trigger_kretprobe_multi;
280+
bpf_program__set_autoload(empty, true);
281+
bpf_program__set_autoload(prog, true);
282+
load_ctx();
283+
284+
attach_ksyms_all(empty, true);
285+
attach_bpf(prog);
286+
}
287+
229288
static void trigger_fexit_setup(void)
230289
{
231290
setup_ctx();
@@ -512,6 +571,8 @@ BENCH_TRIG_KERNEL(kretprobe, "kretprobe");
512571
BENCH_TRIG_KERNEL(kprobe_multi, "kprobe-multi");
513572
BENCH_TRIG_KERNEL(kretprobe_multi, "kretprobe-multi");
514573
BENCH_TRIG_KERNEL(fentry, "fentry");
574+
BENCH_TRIG_KERNEL(kprobe_multi_all, "kprobe-multi-all");
575+
BENCH_TRIG_KERNEL(kretprobe_multi_all, "kretprobe-multi-all");
515576
BENCH_TRIG_KERNEL(fexit, "fexit");
516577
BENCH_TRIG_KERNEL(fmodret, "fmodret");
517578
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ static const char * const trace_blacklist[] = {
549549
"preempt_count_sub",
550550
"__rcu_read_lock",
551551
"__rcu_read_unlock",
552+
"bpf_get_numa_node_id",
552553
};
553554

554555
static bool skip_entry(char *name)

0 commit comments

Comments
 (0)