selftests/bpf: add uprobe triggering overhead benchmarks
Subsystems (3)
Andrii Nakryiko
maintainerPATCH v2 1/1 selftests/bpf: add uprobe triggering overhead benchmarks
Add benchmark to measure overhead of uprobes and uretprobes. Also have a baseline (no uprobe attached) benchmark.
On my dev machine, baseline benchmark can trigger 130M user_target() invocations. When uprobe is attached, this falls to just 700K. With uretprobe, we get down to 520K:
$ sudo ./bench trig-uprobe-base -a Summary: hits 131.289 ± 2.872M/s
# UPROBE
$ sudo ./bench -a trig-uprobe-without-nop Summary: hits 0.729 ± 0.007M/s
$ sudo ./bench -a trig-uprobe-with-nop Summary: hits 1.798 ± 0.017M/s
# URETPROBE
$ sudo ./bench -a trig-uretprobe-without-nop Summary: hits 0.508 ± 0.012M/s
$ sudo ./bench -a trig-uretprobe-with-nop Summary: hits 0.883 ± 0.008M/s
So there is almost 2.5x performance difference between probing nop vs non-nop instruction for entry uprobe. And 1.7x difference for uretprobe.
This means that non-nop uprobe overhead is around 1.4 microseconds for uprobe and 2 microseconds for non-nop uretprobe.
For nop variants, uprobe and uretprobe overhead is down to 0.556 and 1.13 microseconds, respectively.
For comparison, just doing a very low-overhead syscall (with no BPF programs attached anywhere) gives:
$ sudo ./bench trig-base -a Summary: hits 4.830 ± 0.036M/s
So uprobes are about 2.67x slower than pure context switch.
--- tools/testing/selftests/bpf/Makefile | 4 +- tools/testing/selftests/bpf/bench.c | 10 ++ .../selftests/bpf/benchs/bench_trigger.c | 146 ++++++++++++++++++ .../selftests/bpf/progs/trigger_bench.c | 7 + 4 files changed, 166 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/Makefile +3 -1
@@ -533,7 +533,9 @@ $(OUTPUT)/bench_ringbufs.o: $(OUTPUT)/ringbuf_bench.skel.h \ $(OUTPUT)/bench_bloom_filter_map.o: $(OUTPUT)/bloom_filter_bench.skel.h $(OUTPUT)/bench.o: bench.h testing_helpers.h $(BPFOBJ) $(OUTPUT)/bench: LDLIBS += -lm -$(OUTPUT)/bench: $(OUTPUT)/bench.o $(OUTPUT)/testing_helpers.o \ +$(OUTPUT)/bench: $(OUTPUT)/bench.o \ + $(OUTPUT)/testing_helpers.o \ + $(OUTPUT)/trace_helpers.o \ $(OUTPUT)/bench_count.o \ $(OUTPUT)/bench_rename.o \ $(OUTPUT)/bench_trigger.o \
tools/testing/selftests/bpf/bench.c +10 -0
@@ -359,6 +359,11 @@ extern const struct bench bench_trig_kprobe;extern const struct bench bench_trig_fentry;extern const struct bench bench_trig_fentry_sleep;extern const struct bench bench_trig_fmodret; +extern const struct bench bench_trig_uprobe_base; +extern const struct bench bench_trig_uprobe_with_nop; +extern const struct bench bench_trig_uretprobe_with_nop; +extern const struct bench bench_trig_uprobe_without_nop; +extern const struct bench bench_trig_uretprobe_without_nop;extern const struct bench bench_rb_libbpf;extern const struct bench bench_rb_custom;extern const struct bench bench_pb_libbpf;
@@ -385,6 +390,11 @@ static const struct bench *benchs[] = { &bench_trig_fentry, &bench_trig_fentry_sleep, &bench_trig_fmodret, + &bench_trig_uprobe_base, + &bench_trig_uprobe_with_nop, + &bench_trig_uretprobe_with_nop, + &bench_trig_uprobe_without_nop, + &bench_trig_uretprobe_without_nop, &bench_rb_libbpf, &bench_rb_custom, &bench_pb_libbpf,
tools/testing/selftests/bpf/benchs/bench_trigger.c +146 -0
161 lines not on this page · raw message
tools/testing/selftests/bpf/progs/trigger_bench.c +7 -0
@@ -52,3 +52,10 @@ int bench_trigger_fmodret(void *ctx)__sync_add_and_fetch (&hits,1 );return -22 ; } + +SEC("uprobe/self/uprobe_target") +int bench_trigger_uprobe (void *ctx) +{ +__sync_add_and_fetch (&hits,1 ); +return 0 ; +}
Signature · 1 line
2.30.2
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Quoted 8 lines · On Mon, 15 Nov 2021 17:30:41 -0800 you wrote:
Add benchmark to measure overhead of uprobes and uretprobes. Also have a baseline (no uprobe attached) benchmark.
On my dev machine, baseline benchmark can trigger 130M
user_target()invocations. When uprobe is attached, this falls to just 700K. With uretprobe, we get down to 520K:[...]
Here is the summary with links:
- [v2,bpf-next] selftests/bpf: add uprobe triggering overhead benchmarks
https://git.kernel.org/bpf/bpf-next/c/d41bc48bfab2
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html