Skip to content

Commit 4d0a177

Browse files
olsajiriKernel Patches Daemon
authored andcommitted
selftests/bpf: Add usdt trigger bench
Adding usdt trigger bench for usdt: trig-usdt_nop - usdt on top of nop1 instruction trig-usdt_nop_combo - usdt on top of nop1/nop5 combo Adding it to benchs/run_bench_uprobes.sh script. Example run on x86_64 kernel with uprobe syscall: # ./benchs/run_bench_uprobes.sh usermode-count : 152.507 ± 0.098M/s syscall-count : 14.309 ± 0.093M/s uprobe-nop : 3.190 ± 0.012M/s uprobe-push : 3.057 ± 0.004M/s uprobe-ret : 1.095 ± 0.009M/s uprobe-nop5 : 7.305 ± 0.034M/s uretprobe-nop : 2.175 ± 0.005M/s uretprobe-push : 2.109 ± 0.003M/s uretprobe-ret : 0.945 ± 0.002M/s uretprobe-nop5 : 3.530 ± 0.006M/s usdt_nop : 3.235 ± 0.008M/s <-- added usdt_nop_combo : 7.511 ± 0.045M/s <-- added Signed-off-by: Jiri Olsa <jolsa@kernel.org>
1 parent 9fe229b commit 4d0a177

File tree

5 files changed

+76
-2
lines changed

5 files changed

+76
-2
lines changed

tools/testing/selftests/bpf/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,8 @@ $(OUTPUT)/bench: $(OUTPUT)/bench.o \
874874
$(OUTPUT)/bench_bpf_crypto.o \
875875
$(OUTPUT)/bench_sockmap.o \
876876
$(OUTPUT)/bench_lpm_trie_map.o \
877+
$(OUTPUT)/usdt_1.o \
878+
$(OUTPUT)/usdt_2.o \
877879
#
878880
$(call msg,BINARY,,$@)
879881
$(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(filter %.a %.o,$^) $(LDLIBS) -o $@

tools/testing/selftests/bpf/bench.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,8 @@ extern const struct bench bench_trig_uprobe_nop5;
541541
extern const struct bench bench_trig_uretprobe_nop5;
542542
extern const struct bench bench_trig_uprobe_multi_nop5;
543543
extern const struct bench bench_trig_uretprobe_multi_nop5;
544+
extern const struct bench bench_trig_usdt_nop;
545+
extern const struct bench bench_trig_usdt_nop_combo;
544546
#endif
545547

546548
extern const struct bench bench_rb_libbpf;
@@ -617,6 +619,8 @@ static const struct bench *benchs[] = {
617619
&bench_trig_uretprobe_nop5,
618620
&bench_trig_uprobe_multi_nop5,
619621
&bench_trig_uretprobe_multi_nop5,
622+
&bench_trig_usdt_nop,
623+
&bench_trig_usdt_nop_combo,
620624
#endif
621625
/* ringbuf/perfbuf benchmarks */
622626
&bench_rb_libbpf,

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,23 @@ static void *uprobe_producer_nop5(void *input)
405405
uprobe_target_nop5();
406406
return NULL;
407407
}
408+
409+
void usdt_1(void);
410+
void usdt_2(void);
411+
412+
static void *uprobe_producer_usdt_nop(void *input)
413+
{
414+
while (true)
415+
usdt_1();
416+
return NULL;
417+
}
418+
419+
static void *uprobe_producer_usdt_nop_combo(void *input)
420+
{
421+
while (true)
422+
usdt_2();
423+
return NULL;
424+
}
408425
#endif
409426

410427
static void usetup(bool use_retprobe, bool use_multi, void *target_addr)
@@ -542,6 +559,47 @@ static void uretprobe_multi_nop5_setup(void)
542559
{
543560
usetup(true, true /* use_multi */, &uprobe_target_nop5);
544561
}
562+
563+
static void usdt_setup(const char *name)
564+
{
565+
struct bpf_link *link;
566+
int err;
567+
568+
setup_libbpf();
569+
570+
ctx.skel = trigger_bench__open();
571+
if (!ctx.skel) {
572+
fprintf(stderr, "failed to open skeleton\n");
573+
exit(1);
574+
}
575+
576+
bpf_program__set_autoload(ctx.skel->progs.bench_trigger_usdt, true);
577+
578+
err = trigger_bench__load(ctx.skel);
579+
if (err) {
580+
fprintf(stderr, "failed to load skeleton\n");
581+
exit(1);
582+
}
583+
584+
link = bpf_program__attach_usdt(ctx.skel->progs.bench_trigger_usdt,
585+
0 /*self*/, "/proc/self/exe",
586+
"optimized_attach", name, NULL);
587+
if (libbpf_get_error(link)) {
588+
fprintf(stderr, "failed to attach optimized_attach:%s usdt probe\n", name);
589+
exit(1);
590+
}
591+
ctx.skel->links.bench_trigger_usdt = link;
592+
}
593+
594+
static void usdt_nop_setup(void)
595+
{
596+
usdt_setup("usdt_1");
597+
}
598+
599+
static void usdt_nop_combo_setup(void)
600+
{
601+
usdt_setup("usdt_2");
602+
}
545603
#endif
546604

547605
const struct bench bench_trig_syscall_count = {
@@ -609,4 +667,6 @@ BENCH_TRIG_USERMODE(uprobe_nop5, nop5, "uprobe-nop5");
609667
BENCH_TRIG_USERMODE(uretprobe_nop5, nop5, "uretprobe-nop5");
610668
BENCH_TRIG_USERMODE(uprobe_multi_nop5, nop5, "uprobe-multi-nop5");
611669
BENCH_TRIG_USERMODE(uretprobe_multi_nop5, nop5, "uretprobe-multi-nop5");
670+
BENCH_TRIG_USERMODE(usdt_nop, usdt_nop, "usdt_nop");
671+
BENCH_TRIG_USERMODE(usdt_nop_combo, usdt_nop_combo, "usdt_nop_combo");
612672
#endif

tools/testing/selftests/bpf/benchs/run_bench_uprobes.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -eufo pipefail
44

5-
for i in usermode-count syscall-count {uprobe,uretprobe}-{nop,push,ret,nop5}
5+
for i in usermode-count syscall-count {uprobe,uretprobe}-{nop,push,ret,nop5} usdt_nop usdt_nop_combo
66
do
77
summary=$(sudo ./bench -w2 -d5 -a trig-$i | tail -n1 | cut -d'(' -f1 | cut -d' ' -f3-)
88
printf "%-15s: %s\n" $i "$summary"

tools/testing/selftests/bpf/progs/trigger_bench.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// SPDX-License-Identifier: GPL-2.0
22
// Copyright (c) 2020 Facebook
3-
#include <linux/bpf.h>
3+
#include "vmlinux.h"
44
#include <asm/unistd.h>
55
#include <bpf/bpf_helpers.h>
66
#include <bpf/bpf_tracing.h>
77
#include "bpf_misc.h"
8+
#include "bpf/usdt.bpf.h"
89

910
char _license[] SEC("license") = "GPL";
1011

@@ -180,3 +181,10 @@ int bench_trigger_rawtp(void *ctx)
180181
handle(ctx);
181182
return 0;
182183
}
184+
185+
SEC("usdt")
186+
int bench_trigger_usdt(void *ctx)
187+
{
188+
inc_counter();
189+
return 0;
190+
}

0 commit comments

Comments
 (0)