Commit a85d8887 authored by Menglong Dong's avatar Menglong Dong Committed by Alexei Starovoitov
Browse files

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: default avatarMenglong Dong <dongml2@chinatelecom.cn>
Link: https://lore.kernel.org/r/20250904021011.14069-4-dongml2@chinatelecom.cn


Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent adf6b57c
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -512,6 +512,8 @@ extern const struct bench bench_trig_kretprobe;
extern const struct bench bench_trig_kprobe_multi;
extern const struct bench bench_trig_kretprobe_multi;
extern const struct bench bench_trig_fentry;
extern const struct bench bench_trig_kprobe_multi_all;
extern const struct bench bench_trig_kretprobe_multi_all;
extern const struct bench bench_trig_fexit;
extern const struct bench bench_trig_fmodret;
extern const struct bench bench_trig_tp;
@@ -587,6 +589,8 @@ static const struct bench *benchs[] = {
	&bench_trig_kprobe_multi,
	&bench_trig_kretprobe_multi,
	&bench_trig_fentry,
	&bench_trig_kprobe_multi_all,
	&bench_trig_kretprobe_multi_all,
	&bench_trig_fexit,
	&bench_trig_fmodret,
	&bench_trig_tp,
+61 −0
Original line number Diff line number Diff line
@@ -226,6 +226,65 @@ static void trigger_fentry_setup(void)
	attach_bpf(ctx.skel->progs.bench_trigger_fentry);
}

static void attach_ksyms_all(struct bpf_program *empty, bool kretprobe)
{
	LIBBPF_OPTS(bpf_kprobe_multi_opts, opts);
	char **syms = NULL;
	size_t cnt = 0;

	/* Some recursive functions will be skipped in
	 * bpf_get_ksyms -> skip_entry, as they can introduce sufficient
	 * overhead. However, it's difficut to skip all the recursive
	 * functions for a debug kernel.
	 *
	 * So, don't run the kprobe-multi-all and kretprobe-multi-all on
	 * a debug kernel.
	 */
	if (bpf_get_ksyms(&syms, &cnt, true)) {
		fprintf(stderr, "failed to get ksyms\n");
		exit(1);
	}

	opts.syms = (const char **) syms;
	opts.cnt = cnt;
	opts.retprobe = kretprobe;
	/* attach empty to all the kernel functions except bpf_get_numa_node_id. */
	if (!bpf_program__attach_kprobe_multi_opts(empty, NULL, &opts)) {
		fprintf(stderr, "failed to attach bpf_program__attach_kprobe_multi_opts to all\n");
		exit(1);
	}
}

static void trigger_kprobe_multi_all_setup(void)
{
	struct bpf_program *prog, *empty;

	setup_ctx();
	empty = ctx.skel->progs.bench_kprobe_multi_empty;
	prog = ctx.skel->progs.bench_trigger_kprobe_multi;
	bpf_program__set_autoload(empty, true);
	bpf_program__set_autoload(prog, true);
	load_ctx();

	attach_ksyms_all(empty, false);
	attach_bpf(prog);
}

static void trigger_kretprobe_multi_all_setup(void)
{
	struct bpf_program *prog, *empty;

	setup_ctx();
	empty = ctx.skel->progs.bench_kretprobe_multi_empty;
	prog = ctx.skel->progs.bench_trigger_kretprobe_multi;
	bpf_program__set_autoload(empty, true);
	bpf_program__set_autoload(prog, true);
	load_ctx();

	attach_ksyms_all(empty, true);
	attach_bpf(prog);
}

static void trigger_fexit_setup(void)
{
	setup_ctx();
@@ -512,6 +571,8 @@ BENCH_TRIG_KERNEL(kretprobe, "kretprobe");
BENCH_TRIG_KERNEL(kprobe_multi, "kprobe-multi");
BENCH_TRIG_KERNEL(kretprobe_multi, "kretprobe-multi");
BENCH_TRIG_KERNEL(fentry, "fentry");
BENCH_TRIG_KERNEL(kprobe_multi_all, "kprobe-multi-all");
BENCH_TRIG_KERNEL(kretprobe_multi_all, "kretprobe-multi-all");
BENCH_TRIG_KERNEL(fexit, "fexit");
BENCH_TRIG_KERNEL(fmodret, "fmodret");
BENCH_TRIG_KERNEL(tp, "tp");
+2 −2
Original line number Diff line number Diff line
@@ -6,8 +6,8 @@ def_tests=( \
	usermode-count kernel-count syscall-count \
	fentry fexit fmodret \
	rawtp tp \
	kprobe kprobe-multi \
	kretprobe kretprobe-multi \
	kprobe kprobe-multi kprobe-multi-all \
	kretprobe kretprobe-multi kretprobe-multi-all \
)

tests=("$@")
+12 −0
Original line number Diff line number Diff line
@@ -97,6 +97,12 @@ int bench_trigger_kprobe_multi(void *ctx)
	return 0;
}

SEC("?kprobe.multi/bpf_get_numa_node_id")
int bench_kprobe_multi_empty(void *ctx)
{
	return 0;
}

SEC("?kretprobe.multi/bpf_get_numa_node_id")
int bench_trigger_kretprobe_multi(void *ctx)
{
@@ -104,6 +110,12 @@ int bench_trigger_kretprobe_multi(void *ctx)
	return 0;
}

SEC("?kretprobe.multi/bpf_get_numa_node_id")
int bench_kretprobe_multi_empty(void *ctx)
{
	return 0;
}

SEC("?fentry/bpf_get_numa_node_id")
int bench_trigger_fentry(void *ctx)
{
+1 −0
Original line number Diff line number Diff line
@@ -549,6 +549,7 @@ static const char * const trace_blacklist[] = {
	"preempt_count_sub",
	"__rcu_read_lock",
	"__rcu_read_unlock",
	"bpf_get_numa_node_id",
};

static bool skip_entry(char *name)