]> www.infradead.org Git - users/hch/misc.git/commitdiff
selftests/bpf: add benchmark testing for kprobe-multi-all
authorMenglong Dong <menglong8.dong@gmail.com>
Thu, 4 Sep 2025 02:10:11 +0000 (10:10 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 4 Sep 2025 16:00:25 +0000 (09:00 -0700)
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 <dongml2@chinatelecom.cn>
Link: https://lore.kernel.org/r/20250904021011.14069-4-dongml2@chinatelecom.cn
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/bench.c
tools/testing/selftests/bpf/benchs/bench_trigger.c
tools/testing/selftests/bpf/benchs/run_bench_trigger.sh
tools/testing/selftests/bpf/progs/trigger_bench.c
tools/testing/selftests/bpf/trace_helpers.c

index df4489ac14a0c993f372f82634ccca4c36fd2a63..bd29bb2e6cb5294033e7e033d33fffba58e0bede 100644 (file)
@@ -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,
index 82327657846e5f37b617830d14d13a73416c69f6..1e2aff007c2a40721cec02ee6401114b3a3e04c8 100644 (file)
@@ -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");
index a690f5a68b6b0275fa6669b75dae955b10fce6f2..f7573708a0c33f2f8a42604fbd04021731808372 100755 (executable)
@@ -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=("$@")
index 044a6d78923edf98b8329b2566d7d49363c5963c..3d5f30c29ae33987acfc057434bfa8b25acd3298 100644 (file)
@@ -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)
 {
index 9577979bd84da45902cd82b4c2fc81419dd87ec8..171987627f3a7b062514db96d7b355ef5bff89f6 100644 (file)
@@ -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)