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 <dong...@chinatelecom.cn>
---
v2:
- use fprintf() instead of printf()
---
 tools/testing/selftests/bpf/bench.c           |  4 ++
 .../selftests/bpf/benchs/bench_trigger.c      | 53 +++++++++++++++++++
 .../selftests/bpf/benchs/run_bench_trigger.sh |  4 +-
 .../selftests/bpf/progs/trigger_bench.c       | 12 +++++
 tools/testing/selftests/bpf/trace_helpers.c   |  1 +
 5 files changed, 72 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/bpf/bench.c 
b/tools/testing/selftests/bpf/bench.c
index ddd73d06a1eb..29dbf937818a 100644
--- a/tools/testing/selftests/bpf/bench.c
+++ b/tools/testing/selftests/bpf/bench.c
@@ -510,6 +510,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;
@@ -578,6 +580,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,
diff --git a/tools/testing/selftests/bpf/benchs/bench_trigger.c 
b/tools/testing/selftests/bpf/benchs/bench_trigger.c
index 82327657846e..b483c6f64444 100644
--- a/tools/testing/selftests/bpf/benchs/bench_trigger.c
+++ b/tools/testing/selftests/bpf/benchs/bench_trigger.c
@@ -226,6 +226,57 @@ 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;
+
+       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 +563,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");
diff --git a/tools/testing/selftests/bpf/benchs/run_bench_trigger.sh 
b/tools/testing/selftests/bpf/benchs/run_bench_trigger.sh
index a690f5a68b6b..f7573708a0c3 100755
--- a/tools/testing/selftests/bpf/benchs/run_bench_trigger.sh
+++ b/tools/testing/selftests/bpf/benchs/run_bench_trigger.sh
@@ -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=("$@")
diff --git a/tools/testing/selftests/bpf/progs/trigger_bench.c 
b/tools/testing/selftests/bpf/progs/trigger_bench.c
index 044a6d78923e..3d5f30c29ae3 100644
--- a/tools/testing/selftests/bpf/progs/trigger_bench.c
+++ b/tools/testing/selftests/bpf/progs/trigger_bench.c
@@ -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)
 {
diff --git a/tools/testing/selftests/bpf/trace_helpers.c 
b/tools/testing/selftests/bpf/trace_helpers.c
index 9577979bd84d..171987627f3a 100644
--- a/tools/testing/selftests/bpf/trace_helpers.c
+++ b/tools/testing/selftests/bpf/trace_helpers.c
@@ -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)
-- 
2.51.0


Reply via email to