selftests/bpf: extend uprobe/uretprobe triggering benchmarks
Subsystems (3)
Andrii Nakryiko
maintainerPATCH 1/1 selftests/bpf: extend uprobe/uretprobe triggering benchmarks
Settle on three "flavors" of uprobe/uretprobe, installed on different kinds of instruction: nop, push, and ret. All three are testing different internal code paths emulating or single-stepping instructions, so are interesting to compare and benchmark separately.
To ensure push rbp instruction we ensure that uprobe_target_push() is not a leaf function by calling (global __weak) noop function and returning something afterwards (if we don't do that, compiler will just do a tail call optimization).
Also, we need to make sure that compiler isn't skipping frame pointer generation, so let's add -fno-omit-frame-pointers to Makefile.
Just to give an idea of where we currently stand in terms of relative performance of different uprobe/uretprobe cases vs a cheap syscall (getpgid()) baseline, here are results from my local machine:
$ benchs/run_bench_uprobes.sh base : 1.561 ± 0.020M/s uprobe-nop : 0.947 ± 0.007M/s uprobe-push : 0.951 ± 0.004M/s uprobe-ret : 0.443 ± 0.007M/s uretprobe-nop : 0.471 ± 0.013M/s uretprobe-push : 0.483 ± 0.004M/s uretprobe-ret : 0.306 ± 0.007M/s
--- tools/testing/selftests/bpf/Makefile | 2 +- tools/testing/selftests/bpf/bench.c | 20 +-- .../selftests/bpf/benchs/bench_trigger.c | 118 ++++++++++++------ .../selftests/bpf/benchs/run_bench_uprobes.sh | 9 ++ 4 files changed, 103 insertions(+), 46 deletions(-) create mode 100755 tools/testing/selftests/bpf/benchs/run_bench_uprobes.sh
tools/testing/selftests/bpf/Makefile +1 -1
@@ -34,7 +34,7 @@ LIBELF_CFLAGS := $(shell $(PKG_CONFIG) libelf --cflags 2>/dev/null) LIBELF_LIBS := $(shell $(PKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf) CFLAGS += -g $(OPT_FLAGS) -rdynamic \ - -Wall -Werror \ + -Wall -Werror -fno-omit-frame-pointer \ $(GENFLAGS) $(SAN_CFLAGS) $(LIBELF_CFLAGS) \ -I$(CURDIR) -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR) \ -I$(TOOLSINCDIR) -I$(APIDIR) -I$(OUTPUT)
tools/testing/selftests/bpf/bench.c +12 -8
@@ -499,10 +499,12 @@ 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_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;
@@ -541,10 +543,12 @@ static const struct bench *benchs[] = { &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_trig_uprobe_nop, + &bench_trig_uretprobe_nop, + &bench_trig_uprobe_push, + &bench_trig_uretprobe_push, + &bench_trig_uprobe_ret, + &bench_trig_uretprobe_ret, &bench_rb_libbpf, &bench_rb_custom, &bench_pb_libbpf,
tools/testing/selftests/bpf/benchs/bench_trigger.c +81 -37
192 lines not on this page · raw message
tools/testing/selftests/bpf/benchs/run_bench_uprobes.sh new file +9 -0
@@ -0,0 +1,9 @@ +#!/bin/bash + +set -eufo pipefail + +for i in 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" +done
Signature · 1 line
2.43.0
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 11 lines · On Fri, 1 Mar 2024 13:45:51 -0800 you wrote:
Settle on three "flavors" of uprobe/uretprobe, installed on different kinds of instruction: nop, push, and ret. All three are testing different internal code paths emulating or single-stepping instructions, so are interesting to compare and benchmark separately.
To ensure
push rbpinstruction we ensure thatuprobe_target_push()is not a leaf function by calling (global__weak) noop function and returning something afterwards (if we don't do that, compiler will just do a tail call optimization).[...]
Here is the summary with links:
- [bpf-next] selftests/bpf: extend uprobe/uretprobe triggering benchmarks
https://git.kernel.org/bpf/bpf-next/c/8f79870ec8a9
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Daniel Borkmann
maintainerOn 3/1/24 10:45 PM, Andrii Nakryiko wrote:
[...]
Quoted 8 lines
tools/testing/selftests/bpf/benchs/bench_trigger.c +0
-0@@ -113,12 +113,25 @@ static void trigger_fmodret_setup(void)* GCC doesn't generate stack setup preample for these functions due to them * having no input arguments and doing nothing in the body. */
tools/testing/selftests/bpf/benchs/bench_trigger.c static void trigger_fmodret_setup(void) · line 123
Quoted 10 lines
tools/testing/selftests/bpf/benchs/bench_trigger.c +4
-2-__weak void uprobe_target_with_nop (void ) +__weak void uprobe_target_nop (void ) { asmvolatile ("nop" ); } -__weak void uprobe_target_without_nop (void ) +__weak void opaque_noop_func () +{ +}
Nice work and super useful to have! I fixed up the void while applying.
Thanks,
Daniel