]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
selftests/bpf: rename and clean up userspace-triggered benchmarks
authorAndrii Nakryiko <andrii@kernel.org>
Tue, 26 Mar 2024 16:21:46 +0000 (09:21 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 29 Mar 2024 01:31:39 +0000 (18:31 -0700)
Rename uprobe-base to more precise usermode-count (it will match other
baseline-like benchmarks, kernel-count and syscall-count). Also use
BENCH_TRIG_USERMODE() macro to define all usermode-based triggering
benchmarks, which include usermode-count and uprobe/uretprobe benchmarks.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20240326162151.3981687-2-andrii@kernel.org
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_uprobes.sh

index b2b4c391eb0ac295282c306db7a346f75b2b9ddd..7ca1e1eb5c30ff89ee3eabcf4dbd4a5586ee2134 100644 (file)
@@ -491,7 +491,12 @@ extern const struct bench bench_rename_kretprobe;
 extern const struct bench bench_rename_rawtp;
 extern const struct bench bench_rename_fentry;
 extern const struct bench bench_rename_fexit;
+
+/* pure counting benchmarks to establish theoretical lmits */
+extern const struct bench bench_trig_usermode_count;
 extern const struct bench bench_trig_base;
+
+/* kernel-side syscall-triggered benchmarks */
 extern const struct bench bench_trig_tp;
 extern const struct bench bench_trig_rawtp;
 extern const struct bench bench_trig_kprobe;
@@ -502,13 +507,15 @@ extern const struct bench bench_trig_fentry;
 extern const struct bench bench_trig_fexit;
 extern const struct bench bench_trig_fentry_sleep;
 extern const struct bench bench_trig_fmodret;
-extern const struct bench bench_trig_uprobe_base;
+
+/* uprobe/uretprobe benchmarks */
 extern const struct bench bench_trig_uprobe_nop;
 extern const struct bench bench_trig_uretprobe_nop;
 extern const struct bench bench_trig_uprobe_push;
 extern const struct bench bench_trig_uretprobe_push;
 extern const struct bench bench_trig_uprobe_ret;
 extern const struct bench bench_trig_uretprobe_ret;
+
 extern const struct bench bench_rb_libbpf;
 extern const struct bench bench_rb_custom;
 extern const struct bench bench_pb_libbpf;
@@ -539,7 +546,10 @@ static const struct bench *benchs[] = {
        &bench_rename_rawtp,
        &bench_rename_fentry,
        &bench_rename_fexit,
+       /* pure counting benchmarks for establishing theoretical limits */
+       &bench_trig_usermode_count,
        &bench_trig_base,
+       /* syscall-driven triggering benchmarks */
        &bench_trig_tp,
        &bench_trig_rawtp,
        &bench_trig_kprobe,
@@ -550,7 +560,7 @@ static const struct bench *benchs[] = {
        &bench_trig_fexit,
        &bench_trig_fentry_sleep,
        &bench_trig_fmodret,
-       &bench_trig_uprobe_base,
+       /* uprobes */
        &bench_trig_uprobe_nop,
        &bench_trig_uretprobe_nop,
        &bench_trig_uprobe_push,
index d66eddacd64266ef4f3e04b46bcc2fb07ce89aab..97aba7e6458d18e1bbe17b63ec8f31d9a1abcd6a 100644 (file)
@@ -14,6 +14,7 @@
 /* BPF triggering benchmarks */
 static struct trigger_ctx {
        struct trigger_bench *skel;
+       bool usermode_counters;
 } ctx;
 
 static struct counter base_hits[MAX_BUCKETS];
@@ -74,7 +75,10 @@ static void *trigger_producer(void *input)
 
 static void trigger_measure(struct bench_res *res)
 {
-       res->hits = sum_and_reset_counters(ctx.skel->bss->hits);
+       if (ctx.usermode_counters)
+               res->hits = sum_and_reset_counters(base_hits);
+       else
+               res->hits = sum_and_reset_counters(ctx.skel->bss->hits);
 }
 
 static void setup_ctx(void)
@@ -192,7 +196,7 @@ __nocf_check __weak void uprobe_target_ret(void)
        asm volatile ("");
 }
 
-static void *uprobe_base_producer(void *input)
+static void *uprobe_producer_count(void *input)
 {
        while (true) {
                uprobe_target_nop();
@@ -248,32 +252,37 @@ static void usetup(bool use_retprobe, void *target_addr)
        ctx.skel->links.bench_trigger_uprobe = link;
 }
 
-static void uprobe_setup_nop(void)
+static void usermode_count_setup(void)
+{
+       ctx.usermode_counters = true;
+}
+
+static void uprobe_nop_setup(void)
 {
        usetup(false, &uprobe_target_nop);
 }
 
-static void uretprobe_setup_nop(void)
+static void uretprobe_nop_setup(void)
 {
        usetup(true, &uprobe_target_nop);
 }
 
-static void uprobe_setup_push(void)
+static void uprobe_push_setup(void)
 {
        usetup(false, &uprobe_target_push);
 }
 
-static void uretprobe_setup_push(void)
+static void uretprobe_push_setup(void)
 {
        usetup(true, &uprobe_target_push);
 }
 
-static void uprobe_setup_ret(void)
+static void uprobe_ret_setup(void)
 {
        usetup(false, &uprobe_target_ret);
 }
 
-static void uretprobe_setup_ret(void)
+static void uretprobe_ret_setup(void)
 {
        usetup(true, &uprobe_target_ret);
 }
@@ -387,65 +396,22 @@ const struct bench bench_trig_fmodret = {
        .report_final = hits_drops_report_final,
 };
 
-const struct bench bench_trig_uprobe_base = {
-       .name = "trig-uprobe-base",
-       .setup = NULL, /* no uprobe/uretprobe is attached */
-       .producer_thread = uprobe_base_producer,
-       .measure = trigger_base_measure,
-       .report_progress = hits_drops_report_progress,
-       .report_final = hits_drops_report_final,
-};
-
-const struct bench bench_trig_uprobe_nop = {
-       .name = "trig-uprobe-nop",
-       .setup = uprobe_setup_nop,
-       .producer_thread = uprobe_producer_nop,
-       .measure = trigger_measure,
-       .report_progress = hits_drops_report_progress,
-       .report_final = hits_drops_report_final,
-};
-
-const struct bench bench_trig_uretprobe_nop = {
-       .name = "trig-uretprobe-nop",
-       .setup = uretprobe_setup_nop,
-       .producer_thread = uprobe_producer_nop,
-       .measure = trigger_measure,
-       .report_progress = hits_drops_report_progress,
-       .report_final = hits_drops_report_final,
-};
-
-const struct bench bench_trig_uprobe_push = {
-       .name = "trig-uprobe-push",
-       .setup = uprobe_setup_push,
-       .producer_thread = uprobe_producer_push,
-       .measure = trigger_measure,
-       .report_progress = hits_drops_report_progress,
-       .report_final = hits_drops_report_final,
-};
-
-const struct bench bench_trig_uretprobe_push = {
-       .name = "trig-uretprobe-push",
-       .setup = uretprobe_setup_push,
-       .producer_thread = uprobe_producer_push,
-       .measure = trigger_measure,
-       .report_progress = hits_drops_report_progress,
-       .report_final = hits_drops_report_final,
-};
-
-const struct bench bench_trig_uprobe_ret = {
-       .name = "trig-uprobe-ret",
-       .setup = uprobe_setup_ret,
-       .producer_thread = uprobe_producer_ret,
-       .measure = trigger_measure,
-       .report_progress = hits_drops_report_progress,
-       .report_final = hits_drops_report_final,
-};
-
-const struct bench bench_trig_uretprobe_ret = {
-       .name = "trig-uretprobe-ret",
-       .setup = uretprobe_setup_ret,
-       .producer_thread = uprobe_producer_ret,
-       .measure = trigger_measure,
-       .report_progress = hits_drops_report_progress,
-       .report_final = hits_drops_report_final,
-};
+/* uprobe benchmarks */
+#define BENCH_TRIG_USERMODE(KIND, PRODUCER, NAME)                      \
+const struct bench bench_trig_##KIND = {                               \
+       .name = "trig-" NAME,                                           \
+       .validate = trigger_validate,                                   \
+       .setup = KIND##_setup,                                          \
+       .producer_thread = uprobe_producer_##PRODUCER,                  \
+       .measure = trigger_measure,                                     \
+       .report_progress = hits_drops_report_progress,                  \
+       .report_final = hits_drops_report_final,                        \
+}
+
+BENCH_TRIG_USERMODE(usermode_count, count, "usermode-count");
+BENCH_TRIG_USERMODE(uprobe_nop, nop, "uprobe-nop");
+BENCH_TRIG_USERMODE(uprobe_push, push, "uprobe-push");
+BENCH_TRIG_USERMODE(uprobe_ret, ret, "uprobe-ret");
+BENCH_TRIG_USERMODE(uretprobe_nop, nop, "uretprobe-nop");
+BENCH_TRIG_USERMODE(uretprobe_push, push, "uretprobe-push");
+BENCH_TRIG_USERMODE(uretprobe_ret, ret, "uretprobe-ret");
index 9bdcc74e03a41f9d0350b6e6727fd610b47e3c74..36021d243397dee0754c87a54968a90e74d9eb7b 100755 (executable)
@@ -2,7 +2,7 @@
 
 set -eufo pipefail
 
-for i in base {uprobe,uretprobe}-{nop,push,ret}
+for i in usermode-count base {uprobe,uretprobe}-{nop,push,ret}
 do
        summary=$(sudo ./bench -w2 -d5 -a trig-$i | tail -n1 | cut -d'(' -f1 | cut -d' ' -f3-)
        printf "%-15s: %s\n" $i "$summary"