page_pool: import Jesper's page_pool benchmark
Subsystems (3)
RFC PATCH v2 1/1 page_pool: import Jesper's page_pool benchmark
From: Jesper Dangaard Brouer <[email protected]>
We frequently consult with Jesper's out-of-tree page_pool benchmark to evaluate page_pool changes.
Import the benchmark into the upstream linux kernel tree so that (a) we're all running the same version, (b) pave the way for shared improvements, and (c) maybe one day integrate it with nipa, if possible.
Import bench_page_pool_simple from commit 35b1716d0c30 ("Add page_bench06_walk_all"), from this repository:
https://github.com/netoptimizer/prototype-kernel.git
Changes done during upstreaming:
- Fix checkpatch issues.
- Remove the tasklet logic not needed.
- Move under tools/testing
- Create ksft for the benchmark.
- Changed slightly how the benchmark gets build. Out of tree, time_bench is built as an independent .ko. Here it is included in bench_page_pool.ko
Steps to run:
``` mkdir -p /tmp/run-pp-bench make -C ./tools/testing/selftests/net/bench make -C ./tools/testing/selftests/net/bench install INSTALL_PATH=/tmp/run-pp-bench rsync --delete -avz --progress /tmp/run-pp-bench mina@$SERVER:~/ ssh mina@$SERVER << EOF cd ~/run-pp-bench && sudo ./test_bench_page_pool.sh EOF ```
Output:
``` (benchmrk dmesg logs) Fast path results: no-softirq-page_pool01 Per elem: 11 cycles(tsc) 4.368 ns ptr_ring results: no-softirq-page_pool02 Per elem: 527 cycles(tsc) 195.187 ns slow path results: no-softirq-page_pool03 Per elem: 549 cycles(tsc) 203.466 ns ```
---
v2:
- Move under tools/selftests (Jakub)
- Create ksft for it.
- Remove the tasklet logic no longer needed (Jesper + Toke)
RFC discussion points:
- Desirable to import it?
- Can the benchmark be imported as-is for an initial version? Or needs lots of modifications?
- Code location. I retained the location in Jesper's tree, but a path like net/core/bench/ may make more sense.
--- tools/testing/selftests/net/bench/Makefile | 7 + .../selftests/net/bench/page_pool/Makefile | 17 + .../bench/page_pool/bench_page_pool_simple.c | 275 ++++++++++++ .../bench/page_pool/test_bench_page_pool.sh | 32 ++ .../net/bench/page_pool/time_bench.c | 406 ++++++++++++++++++ .../net/bench/page_pool/time_bench.h | 259 +++++++++++ 6 files changed, 996 insertions(+) create mode 100644 tools/testing/selftests/net/bench/Makefile create mode 100644 tools/testing/selftests/net/bench/page_pool/Makefile create mode 100644 tools/testing/selftests/net/bench/page_pool/bench_page_pool_simple.c create mode 100755 tools/testing/selftests/net/bench/page_pool/test_bench_page_pool.sh create mode 100644 tools/testing/selftests/net/bench/page_pool/time_bench.c create mode 100644 tools/testing/selftests/net/bench/page_pool/time_bench.h
tools/testing/selftests/net/bench/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0 + +TEST_GEN_MODS_DIR := page_pool + +TEST_PROGS += page_pool/test_bench_page_pool.sh + +include ../../lib.mk
tools/testing/selftests/net/bench/page_pool/Makefile new file +17 -0
@@ -0,0 +1,17 @@ +BENCH_PAGE_POOL_SIMPLE_TEST_DIR := $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))) +KDIR ?= /lib/modules/$(shell uname -r)/build + +ifeq ($(V),1) +Q = +else +Q = @ +endif + +obj-m += bench_page_pool.o +bench_page_pool-y += bench_page_pool_simple.o time_bench.o + +all: + +$(Q)make -C $(KDIR) M=$(BENCH_PAGE_POOL_SIMPLE_TEST_DIR) modules + +clean: + +$(Q)make -C $(KDIR) M=$(BENCH_PAGE_POOL_SIMPLE_TEST_DIR) clean
tools/testing/selftests/net/bench/page_pool/bench_page_pool_simple.c new file +275 -0
275 lines not on this page · raw message
tools/testing/selftests/net/bench/page_pool/test_bench_page_pool.sh new file +32 -0
@@ -0,0 +1,32 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# + +set -e + +DRIVER="./page_pool/bench_page_pool.ko" +result="" + +function run_test() +{ + rmmod "bench_page_pool.ko" || true + insmod $DRIVER > /dev/null 2>&1 + result=$(dmesg | tail -10) + echo "$result" + + echo + echo "Fast path results:" + echo ${result} | grep -o -E "no-softirq-page_pool01 Per elem: ([0-9]+) cycles\(tsc\) ([0-9]+\.[0-9]+) ns" + + echo + echo "ptr_ring results:" + echo ${result} | grep -o -E "no-softirq-page_pool02 Per elem: ([0-9]+) cycles\(tsc\) ([0-9]+\.[0-9]+) ns" + + echo + echo "slow path results:" + echo ${result} | grep -o -E "no-softirq-page_pool03 Per elem: ([0-9]+) cycles\(tsc\) ([0-9]+\.[0-9]+) ns" +} + +run_test + +exit 0
tools/testing/selftests/net/bench/page_pool/time_bench.c new file +406 -0
406 lines not on this page · raw message
tools/testing/selftests/net/bench/page_pool/time_bench.h new file +259 -0
259 lines not on this page · raw message
base-commit: ea15e046263b19e91ffd827645ae5dfa44ebd044
Signature · 1 line
2.49.0.1151.ga128411c76-goog
Quoted 49 lines · Mina Almasry
From: Jesper Dangaard Brouer <[email protected]>
We frequently consult with Jesper's out-of-tree
page_poolbenchmark to evaluatepage_poolchanges.Import the benchmark into the upstream linux kernel tree so that (a) we're all running the same version, (b) pave the way for shared improvements, and (c) maybe one day integrate it with nipa, if possible.
Import
bench_page_pool_simplefrom commit35b1716d0c30("Addpage_bench06_walk_all"), from this repository:
https://github.com/netoptimizer/prototype-kernel.gitChanges done during upstreaming:
- Fix checkpatch issues.
- Remove the tasklet logic not needed.
- Move undertools/testing
- Create ksft for the benchmark.
- Changed slightly how the benchmark gets build. Out of tree,time_benchis built as an independent .ko. Here it is included in bench_page_pool.koSteps to run:
``` mkdir -p /tmp/run-pp-bench make -C ./tools/testing/selftests/net/bench make -C ./tools/testing/selftests/net/bench install INSTALL_PATH=/tmp/run-pp-bench rsync --delete -avz --progress /tmp/run-pp-bench mina@$SERVER:~/ ssh mina@$SERVER << EOF cd ~/run-pp-bench && sudo ./test_bench_page_pool.sh EOF ```Output:
``` (benchmrk dmesg logs) Fast path results: no-softirq-page_pool01 Per elem: 11 cycles(tsc) 4.368 ns ptr_ring results: no-softirq-page_pool02 Per elem: 527 cycles(tsc) 195.187 ns slow path results: no-softirq-page_pool03 Per elem: 549 cycles(tsc) 203.466 ns ```
Quoted 6 lines
Cc Jesper Dangaard Brouer <[email protected]>Cc Ilias Apalodimas <[email protected]>Cc Jakub Kicinski <[email protected]>Cc Toke Høiland-Jørgensen <[email protected]>Signed-off-by Mina Almasry <[email protected]>
Back when you posted the first RFC, Jesper and I chatted about ways to avoid the ugly "load module and read the output from dmesg" interface to the test.
One idea we came up with was to make the module include only the "inner" functions for the benchmark, and expose those to BPF as kfuncs. Then the test runner can be a BPF program that runs the tests, collects the data and passes it to userspace via maps or a ringbuffer or something. That's a nicer and more customisable interface than the printk output. And if they're small enough, maybe we could even include the functions into the page_pool code itself, instead of in a separate benchmark module?
WDYT of that idea? :)
-Toke
Quoted 15 lines · Toke Høiland-Jørgensen
Quoted 15 lines
Fast path results:
no-softirq-page_pool01 Per elem: 11 cycles(tsc) 4.368 ns
ptr_ringresults:
no-softirq-page_pool02 Per elem: 527 cycles(tsc) 195.187 nsslow path results:
no-softirq-page_pool03 Per elem: 549 cycles(tsc) 203.466 ns ```Cc Jesper Dangaard Brouer <[email protected]>Cc Ilias Apalodimas <[email protected]>Cc Jakub Kicinski <[email protected]>Cc Toke Høiland-Jørgensen <[email protected]>
Quoted 6 lines
Quoted 1 line
Signed-off-by Mina Almasry <[email protected]>Back when you posted the first RFC, Jesper and I chatted about ways to avoid the ugly "load module and read the output from dmesg" interface to the test.
I agree the existing interface is ugly.
Quoted 9 lines
One idea we came up with was to make the module include only the "inner" functions for the benchmark, and expose those to BPF as kfuncs. Then the test runner can be a BPF program that runs the tests, collects the data and passes it to userspace via maps or a ringbuffer or something. That's a nicer and more customisable interface than the printk output. And if they're small enough, maybe we could even include the functions into the
page_poolcode itself, instead of in a separate benchmark module?WDYT of that idea? :)
...but this sounds like an enormous amount of effort, for something that is a bit ugly but isn't THAT bad. Especially for me, I'm not that much of an expert that I know how to implement what you're referring to off the top of my head. I normally am open to spending time but this is not that high on my todolist and I have limited bandwidth to resolve this :(
I also feel that this is something that could be improved post merge. I think it's very beneficial to have this merged in some form that can be improved later. Byungchul is making a lot of changes to these mm things and it would be nice to have an easy way to run the benchmark in tree and maybe even get automated results from nipa. If we could agree on mvp that is appropriate to merge without too much scope creep that would be ideal from my side at least.
Signature · 2 lines
Thanks, Mina
Quoted 42 lines · Mina Almasry
Quoted 15 lines · Toke Høiland-Jørgensen
Quoted 15 lines
Fast path results:
no-softirq-page_pool01 Per elem: 11 cycles(tsc) 4.368 ns
ptr_ringresults:
no-softirq-page_pool02 Per elem: 527 cycles(tsc) 195.187 nsslow path results:
no-softirq-page_pool03 Per elem: 549 cycles(tsc) 203.466 ns ```Cc Jesper Dangaard Brouer <[email protected]>Cc Ilias Apalodimas <[email protected]>Cc Jakub Kicinski <[email protected]>Cc Toke Høiland-Jørgensen <[email protected]>Quoted 6 lines
Quoted 1 line
Signed-off-by Mina Almasry <[email protected]>Back when you posted the first RFC, Jesper and I chatted about ways to avoid the ugly "load module and read the output from dmesg" interface to the test.
I agree the existing interface is ugly.
Quoted 9 lines
One idea we came up with was to make the module include only the "inner" functions for the benchmark, and expose those to BPF as kfuncs. Then the test runner can be a BPF program that runs the tests, collects the data and passes it to userspace via maps or a ringbuffer or something. That's a nicer and more customisable interface than the printk output. And if they're small enough, maybe we could even include the functions into the
page_poolcode itself, instead of in a separate benchmark module?WDYT of that idea? :)
...but this sounds like an enormous amount of effort, for something that is a bit ugly but isn't THAT bad. Especially for me, I'm not that much of an expert that I know how to implement what you're referring to off the top of my head. I normally am open to spending time but this is not that high on my todolist and I have limited bandwidth to resolve this :(
Quoted 7 lines
I also feel that this is something that could be improved post merge. I think it's very beneficial to have this merged in some form that can be improved later. Byungchul is making a lot of changes to these mm things and it would be nice to have an easy way to run the benchmark in tree and maybe even get automated results from nipa. If we could agree on mvp that is appropriate to merge without too much scope creep that would be ideal from my side at least.
Right, fair. I guess we can merge it as-is, and then investigate whether we can move it to BPF-based (or maybe 'perf bench' - Cc acme) later :)
-Toke
Quoted 18 lines · Toke Høiland-Jørgensen
Quoted 16 lines · Mina Almasry
Quoted 3 lines · Toke Høiland-Jørgensen
Back when you posted the first RFC, Jesper and I chatted about ways to avoid the ugly "load module and read the output from dmesg" interface to the test.
I agree the existing interface is ugly.
Quoted 9 lines
One idea we came up with was to make the module include only the "inner" functions for the benchmark, and expose those to BPF as kfuncs. Then the test runner can be a BPF program that runs the tests, collects the data and passes it to userspace via maps or a ringbuffer or something. That's a nicer and more customisable interface than the printk output. And if they're small enough, maybe we could even include the functions into the
page_poolcode itself, instead of in a separate benchmark module?WDYT of that idea? :)
Quoted 8 lines
Quoted 8 lines
...but this sounds like an enormous amount of effort, for something that is a bit ugly but isn't THAT bad. Especially for me, I'm not that much of an expert that I know how to implement what you're referring to off the top of my head. I normally am open to spending time but this is not that high on my todolist and I have limited bandwidth to resolve this :(
I also feel that this is something that could be improved post merge.
agreed
Quoted 9 lines
Quoted 6 lines
I think it's very beneficial to have this merged in some form that can be improved later. Byungchul is making a lot of changes to these mm things and it would be nice to have an easy way to run the benchmark in tree and maybe even get automated results from nipa. If we could agree on mvp that is appropriate to merge without too much scope creep that would be ideal from my side at least.
Right, fair. I guess we can merge it as-is, and then investigate whether we can move it to BPF-based (or maybe 'perf bench' - Cc acme) later :)
tldr; I'd advise to merge it as-is, then kfunc'ify parts of it and use it from a 'perf bench' suite.
Yeah, the model would be what I did for uprobes, but even then there is a selftests based uprobes benchmark ;-)
The 'perf bench' part, that calls into the skel:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/perf/bench/uprobe.c
The skel:
While this one is just to generate BPF load to measure the impact on uprobes, for your case it would involve using a ring buffer to communicate from the skel (BPF/kernel side) to the userspace part, similar to what is done in various other BPF based perf tooling available in:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/perf/util/bpf_skel
Like at this line (BPF skel part):
The simplest part is in the canonical, standalone runqslower tool, also hosted in the kernel sources:
BPF skel sending stuff to userspace:
The userspace part that reads it:
This is a callback that gets called for every event that the BPF skel produces, called from this loop:
That handle_event callback was associated via:
There is a dissection I did about this process a long time ago, but still relevant, I think:
http://oldvger.kernel.org/~acme/bpf/devconf.cz-2020-BPF-The-Status-of-BTF-producers-consumers/#/33
The part explaining the interaction userspace/kernel starts here:
http://oldvger.kernel.org/~acme/bpf/devconf.cz-2020-BPF-The-Status-of-BTF-producers-consumers/#/40
(yeah, its http, but then, its _old_vger ;-)
Doing it in perf is interesting because it gets widely packaged, so whatever you add to it gets visibility for people using 'perf bench' and also gets available in most places, it would add to this collection:
root@number:~# perf bench Usage: perf bench [<common options>] <collection> <benchmark> [<options>]
# List of all available benchmark collections:
sched: Scheduler and IPC benchmarks
syscall: System call benchmarks
mem: Memory access benchmarks
numa: NUMA scheduling and MM benchmarks
futex: Futex stressing benchmarks
epoll: Epoll stressing benchmarks
internals: Perf-internals benchmarks
breakpoint: Breakpoint benchmarks
uprobe: uprobe benchmarks
all: All benchmarks
root@number:~#
the 'perf bench' that uses BPF skel:
root@number:~# perf bench uprobe baseline
# Running 'uprobe/baseline' benchmark:
# Executed 1,000 usleep(1000) calls
Total time: 1,050,383 usecs1,050.383 usecs/op
root@number:~# perf trace --summary perf bench uprobe trace_printk
# Running 'uprobe/trace_printk' benchmark:
# Executed 1,000 usleep(1000) calls
Total time: 1,053,082 usecs1,053.082 usecs/op
Summary of events:
uprobe-trace_pr (1247691), 3316 events, 96.9%
syscall calls errors total min avg max stddev
(msec) (msec) (msec) (msec) (%)
--------------- -------- ------ -------- --------- --------- --------- ------
clock_nanosleep 1000 0 1101.236 1.007 1.101 50.939 4.53% close 98 0 32.979 0.001 0.337 32.821 99.52% perf_event_open 1 0 18.691 18.691 18.691 18.691 0.00% mmap 209 0 0.567 0.001 0.003 0.007 2.59% bpf 38 2 0.380 0.000 0.010 0.092 28.38% openat 65 0 0.171 0.001 0.003 0.012 7.14% mprotect 56 0 0.141 0.001 0.003 0.008 6.86% read 68 0 0.082 0.001 0.001 0.010 11.60% fstat 65 0 0.056 0.001 0.001 0.003 5.40% brk 10 0 0.050 0.001 0.005 0.012 24.29% pread64 8 0 0.042 0.001 0.005 0.021 49.29%
<SNIP other syscalls>
root@number:~#
- Arnaldo
Quoted 153 lines · Arnaldo Carvalho de Melo
Quoted 18 lines · Toke Høiland-Jørgensen
Quoted 16 lines · Mina Almasry
Quoted 3 lines · Toke Høiland-Jørgensen
Back when you posted the first RFC, Jesper and I chatted about ways to avoid the ugly "load module and read the output from dmesg" interface to the test.
I agree the existing interface is ugly.
Quoted 9 lines
One idea we came up with was to make the module include only the "inner" functions for the benchmark, and expose those to BPF as kfuncs. Then the test runner can be a BPF program that runs the tests, collects the data and passes it to userspace via maps or a ringbuffer or something. That's a nicer and more customisable interface than the printk output. And if they're small enough, maybe we could even include the functions into the
page_poolcode itself, instead of in a separate benchmark module?WDYT of that idea? :)
Quoted 8 lines
Quoted 8 lines
...but this sounds like an enormous amount of effort, for something that is a bit ugly but isn't THAT bad. Especially for me, I'm not that much of an expert that I know how to implement what you're referring to off the top of my head. I normally am open to spending time but this is not that high on my todolist and I have limited bandwidth to resolve this :(
I also feel that this is something that could be improved post merge.
agreed
Quoted 9 lines
Quoted 6 lines
I think it's very beneficial to have this merged in some form that can be improved later. Byungchul is making a lot of changes to these mm things and it would be nice to have an easy way to run the benchmark in tree and maybe even get automated results from nipa. If we could agree on mvp that is appropriate to merge without too much scope creep that would be ideal from my side at least.
Right, fair. I guess we can merge it as-is, and then investigate whether we can move it to BPF-based (or maybe 'perf bench' - Cc acme) later :)
tldr; I'd advise to merge it as-is, then kfunc'ify parts of it and use it from a 'perf bench' suite.
Yeah, the model would be what I did for uprobes, but even then there is a selftests based uprobes benchmark ;-)
The 'perf bench' part, that calls into the skel:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/perf/bench/uprobe.c
The skel:
While this one is just to generate BPF load to measure the impact on uprobes, for your case it would involve using a ring buffer to communicate from the skel (BPF/kernel side) to the userspace part, similar to what is done in various other BPF based perf tooling available in:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/perf/util/bpf_skel
Like at this line (BPF skel part):
The simplest part is in the canonical, standalone runqslower tool, also hosted in the kernel sources:
BPF skel sending stuff to userspace:
The userspace part that reads it:
This is a callback that gets called for every event that the BPF skel produces, called from this loop:
That
handle_eventcallback was associated via:There is a dissection I did about this process a long time ago, but still relevant, I think:
http://oldvger.kernel.org/~acme/bpf/devconf.cz-2020-BPF-The-Status-of-BTF-producers-consumers/#/33
The part explaining the interaction userspace/kernel starts here:
http://oldvger.kernel.org/~acme/bpf/devconf.cz-2020-BPF-The-Status-of-BTF-producers-consumers/#/40
(yeah, its http, but then, its
_old_vger;-)Doing it in perf is interesting because it gets widely packaged, so whatever you add to it gets visibility for people using 'perf bench' and also gets available in most places, it would add to this collection:
root@number:~# perf bench Usage: perf bench [<common options>] <collection> <benchmark> [<options>]# List of all available benchmark collections:
sched: Scheduler and IPC benchmarks
syscall: System call benchmarks
mem: Memory access benchmarks
numa: NUMA scheduling and MM benchmarks
futex: Futex stressing benchmarks
epoll: Epoll stressing benchmarks
internals: Perf-internals benchmarks
breakpoint: Breakpoint benchmarks
uprobe: uprobe benchmarks
all: All benchmarksroot@number:~#
the 'perf bench' that uses BPF skel:
root@number:~# perf bench uprobe baseline # Running 'uprobe/baseline' benchmark: # Executed 1,000 usleep(1000) calls Total time: 1,050,383 usecs1,050.383 usecs/op
root@number:~# perf trace --summary perf bench uprobe trace_printk # Running 'uprobe/trace_printk' benchmark: # Executed 1,000 usleep(1000) calls Total time: 1,053,082 usecs1,053.082 usecs/op
Summary of events:
uprobe-trace_pr (1247691), 3316 events, 96.9%
syscall calls errors total min avg max stddev (msec) (msec) (msec) (msec) (%) --------------- -------- ------ -------- --------- --------- --------- ------ clock_nanosleep 1000 0 1101.236 1.007 1.101 50.939 4.53% close 98 0 32.979 0.001 0.337 32.821 99.52% perf_event_open 1 0 18.691 18.691 18.691 18.691 0.00% mmap 209 0 0.567 0.001 0.003 0.007 2.59% bpf 38 2 0.380 0.000 0.010 0.092 28.38% openat 65 0 0.171 0.001 0.003 0.012 7.14% mprotect 56 0 0.141 0.001 0.003 0.008 6.86% read 68 0 0.082 0.001 0.001 0.010 11.60% fstat 65 0 0.056 0.001 0.001 0.003 5.40% brk 10 0 0.050 0.001 0.005 0.012 24.29% pread64 8 0 0.042 0.001 0.005 0.021 49.29%
Quoted 3 lines
<SNIP other syscalls>
root@number:~#
Cool, thanks for the pointers! Guess we'd need to restructure the functions to be benchmarked a bit, but that should be doable I guess.
-Toke
Ilias Apalodimas
Acked-byHi all,
This is very useful.
Quoted 154 lines · Arnaldo Carvalho de Melo
Quoted 18 lines · Toke Høiland-Jørgensen
Quoted 16 lines · Mina Almasry
Quoted 3 lines · Toke Høiland-Jørgensen
Back when you posted the first RFC, Jesper and I chatted about ways to avoid the ugly "load module and read the output from dmesg" interface to the test.
I agree the existing interface is ugly.
Quoted 9 lines
One idea we came up with was to make the module include only the "inner" functions for the benchmark, and expose those to BPF as kfuncs. Then the test runner can be a BPF program that runs the tests, collects the data and passes it to userspace via maps or a ringbuffer or something. That's a nicer and more customisable interface than the printk output. And if they're small enough, maybe we could even include the functions into the
page_poolcode itself, instead of in a separate benchmark module?WDYT of that idea? :)
Quoted 8 lines
Quoted 8 lines
...but this sounds like an enormous amount of effort, for something that is a bit ugly but isn't THAT bad. Especially for me, I'm not that much of an expert that I know how to implement what you're referring to off the top of my head. I normally am open to spending time but this is not that high on my todolist and I have limited bandwidth to resolve this :(
I also feel that this is something that could be improved post merge.
agreed
Quoted 9 lines
Quoted 6 lines
I think it's very beneficial to have this merged in some form that can be improved later. Byungchul is making a lot of changes to these mm things and it would be nice to have an easy way to run the benchmark in tree and maybe even get automated results from nipa. If we could agree on mvp that is appropriate to merge without too much scope creep that would be ideal from my side at least.
Right, fair. I guess we can merge it as-is, and then investigate whether we can move it to BPF-based (or maybe 'perf bench' - Cc acme) later :)
tldr; I'd advise to merge it as-is, then kfunc'ify parts of it and use it from a 'perf bench' suite.
Yeah, the model would be what I did for uprobes, but even then there is a selftests based uprobes benchmark ;-)
The 'perf bench' part, that calls into the skel:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/perf/bench/uprobe.c
The skel:
While this one is just to generate BPF load to measure the impact on uprobes, for your case it would involve using a ring buffer to communicate from the skel (BPF/kernel side) to the userspace part, similar to what is done in various other BPF based perf tooling available in:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/perf/util/bpf_skel
Like at this line (BPF skel part):
The simplest part is in the canonical, standalone runqslower tool, also hosted in the kernel sources:
BPF skel sending stuff to userspace:
The userspace part that reads it:
This is a callback that gets called for every event that the BPF skel produces, called from this loop:
That
handle_eventcallback was associated via:There is a dissection I did about this process a long time ago, but still relevant, I think:
http://oldvger.kernel.org/~acme/bpf/devconf.cz-2020-BPF-The-Status-of-BTF-producers-consumers/#/33
The part explaining the interaction userspace/kernel starts here:
http://oldvger.kernel.org/~acme/bpf/devconf.cz-2020-BPF-The-Status-of-BTF-producers-consumers/#/40
(yeah, its http, but then, its
_old_vger;-)Doing it in perf is interesting because it gets widely packaged, so whatever you add to it gets visibility for people using 'perf bench' and also gets available in most places, it would add to this collection:
root@number:~# perf bench Usage: perf bench [<common options>] <collection> <benchmark> [<options>]# List of all available benchmark collections:
sched: Scheduler and IPC benchmarks
syscall: System call benchmarks
mem: Memory access benchmarks
numa: NUMA scheduling and MM benchmarks
futex: Futex stressing benchmarks
epoll: Epoll stressing benchmarks
internals: Perf-internals benchmarks
breakpoint: Breakpoint benchmarks
uprobe: uprobe benchmarks
all: All benchmarksroot@number:~#
the 'perf bench' that uses BPF skel:
root@number:~# perf bench uprobe baseline # Running 'uprobe/baseline' benchmark: # Executed 1,000 usleep(1000) calls Total time: 1,050,383 usecs1,050.383 usecs/op
root@number:~# perf trace --summary perf bench uprobe trace_printk # Running 'uprobe/trace_printk' benchmark: # Executed 1,000 usleep(1000) calls Total time: 1,053,082 usecs1,053.082 usecs/op
Summary of events:
uprobe-trace_pr (1247691), 3316 events, 96.9%
syscall calls errors total min avg max stddev (msec) (msec) (msec) (msec) (%) --------------- -------- ------ -------- --------- --------- --------- ------ clock_nanosleep 1000 0 1101.236 1.007 1.101 50.939 4.53% close 98 0 32.979 0.001 0.337 32.821 99.52% perf_event_open 1 0 18.691 18.691 18.691 18.691 0.00% mmap 209 0 0.567 0.001 0.003 0.007 2.59% bpf 38 2 0.380 0.000 0.010 0.092 28.38% openat 65 0 0.171 0.001 0.003 0.012 7.14% mprotect 56 0 0.141 0.001 0.003 0.008 6.86% read 68 0 0.082 0.001 0.001 0.010 11.60% fstat 65 0 0.056 0.001 0.001 0.003 5.40% brk 10 0 0.050 0.001 0.005 0.012 24.29% pread64 8 0 0.042 0.001 0.005 0.021 49.29%
Quoted 3 lines
<SNIP other syscalls>
root@number:~#
Thanks for all the pointers here.
Overall I agree we should merge this. Yes it's not ideal, but we've been pointing people to run it over several years before accepting patches. Having it out of tree doesn't help much. It's a test, it's a bit ugly now, but it serves our purpose and the maintenance burden is minimal.
Quoted 2 lines
- Arnaldo
Quoted 53 lines · Toke Høiland-Jørgensen
Quoted 42 lines · Mina Almasry
Quoted 15 lines · Toke Høiland-Jørgensen
Quoted 15 lines
Fast path results:
no-softirq-page_pool01 Per elem: 11 cycles(tsc) 4.368 ns
ptr_ringresults:
no-softirq-page_pool02 Per elem: 527 cycles(tsc) 195.187 nsslow path results:
no-softirq-page_pool03 Per elem: 549 cycles(tsc) 203.466 ns ```Cc Jesper Dangaard Brouer <[email protected]>Cc Ilias Apalodimas <[email protected]>Cc Jakub Kicinski <[email protected]>Cc Toke Høiland-Jørgensen <[email protected]>Quoted 6 lines
Quoted 1 line
Signed-off-by Mina Almasry <[email protected]>Back when you posted the first RFC, Jesper and I chatted about ways to avoid the ugly "load module and read the output from dmesg" interface to the test.
I agree the existing interface is ugly.
Quoted 9 lines
One idea we came up with was to make the module include only the "inner" functions for the benchmark, and expose those to BPF as kfuncs. Then the test runner can be a BPF program that runs the tests, collects the data and passes it to userspace via maps or a ringbuffer or something. That's a nicer and more customisable interface than the printk output. And if they're small enough, maybe we could even include the functions into the
page_poolcode itself, instead of in a separate benchmark module?WDYT of that idea? :)
...but this sounds like an enormous amount of effort, for something that is a bit ugly but isn't THAT bad. Especially for me, I'm not that much of an expert that I know how to implement what you're referring to off the top of my head. I normally am open to spending time but this is not that high on my todolist and I have limited bandwidth to resolve this :(
Quoted 7 lines
I also feel that this is something that could be improved post merge. I think it's very beneficial to have this merged in some form that can be improved later. Byungchul is making a lot of changes to these mm things and it would be nice to have an easy way to run the benchmark in tree and maybe even get automated results from nipa. If we could agree on mvp that is appropriate to merge without too much scope creep that would be ideal from my side at least.
Quoted 2 lines
Right, fair. I guess we can merge it as-is, and then investigate whether we can move it to BPF-based (or maybe 'perf bench' - Cc acme) later :)
Thanks for the pliability. Reviewed-bys and comments welcome.
Additionally Signed-off-by from Jesper is needed I think. Since most of this code is his, I retained his authorship. Jesper, whenever this looks good to me, a signed-off-by would be good and I would carry it to future versions. Changing authorship to me is also fine by me but I would think you want to retain the credit.
Signature · 2 lines
Thanks, Mina
Quoted 57 lines · Mina Almasry
Quoted 53 lines · Toke Høiland-Jørgensen
Quoted 42 lines · Mina Almasry
Quoted 15 lines · Toke Høiland-Jørgensen
Quoted 15 lines
Fast path results:
no-softirq-page_pool01 Per elem: 11 cycles(tsc) 4.368 ns
ptr_ringresults:
no-softirq-page_pool02 Per elem: 527 cycles(tsc) 195.187 nsslow path results:
no-softirq-page_pool03 Per elem: 549 cycles(tsc) 203.466 ns ```Cc Jesper Dangaard Brouer <[email protected]>Cc Ilias Apalodimas <[email protected]>Cc Jakub Kicinski <[email protected]>Cc Toke Høiland-Jørgensen <[email protected]>Quoted 6 lines
Quoted 1 line
Signed-off-by Mina Almasry <[email protected]>Back when you posted the first RFC, Jesper and I chatted about ways to avoid the ugly "load module and read the output from dmesg" interface to the test.
I agree the existing interface is ugly.
Quoted 9 lines
One idea we came up with was to make the module include only the "inner" functions for the benchmark, and expose those to BPF as kfuncs. Then the test runner can be a BPF program that runs the tests, collects the data and passes it to userspace via maps or a ringbuffer or something. That's a nicer and more customisable interface than the printk output. And if they're small enough, maybe we could even include the functions into the
page_poolcode itself, instead of in a separate benchmark module?WDYT of that idea? :)
...but this sounds like an enormous amount of effort, for something that is a bit ugly but isn't THAT bad. Especially for me, I'm not that much of an expert that I know how to implement what you're referring to off the top of my head. I normally am open to spending time but this is not that high on my todolist and I have limited bandwidth to resolve this :(
Quoted 7 lines
I also feel that this is something that could be improved post merge. I think it's very beneficial to have this merged in some form that can be improved later. Byungchul is making a lot of changes to these mm things and it would be nice to have an easy way to run the benchmark in tree and maybe even get automated results from nipa. If we could agree on mvp that is appropriate to merge without too much scope creep that would be ideal from my side at least.
Quoted 2 lines
Right, fair. I guess we can merge it as-is, and then investigate whether we can move it to BPF-based (or maybe 'perf bench' - Cc acme) later :)
Quoted 7 lines
Thanks for the pliability. Reviewed-bys and comments welcome.
Additionally Signed-off-by from Jesper is needed I think. Since most of this code is his, I retained his authorship. Jesper, whenever this looks good to me, a signed-off-by would be good and I would carry it to future versions. Changing authorship to me is also fine by me but I would think you want to retain the credit.
Okay, I think Ilias'es comment[1] and ACK convinced me, let us merge this as-is. We have been asking people to run it over several years before accepting patches. We shouldn't be pointing people to use out-of-tree tests for accepting patches.
It is not perfect, but it have served us well for benchmarking in the last approx 10 years (5 years for page_pool test). It is isolated as a selftest under (tools/testing/selftests/net/bench/page_pool/).
Realistically we are all too busy inventing a new "perfect" benchmark for page_pool. That said, I do encourage others with free cycles to integrated a better benchmark test into perf bench. Then we can just remove this module again.
[1]
https://lore.kernel.org/all/CAC_iWjLmO4XZ_+PBaCNxpVCTmGKNBsLGyeeKS2ptRrepn1u0SQ@mail.gmail.com/
Thanks Mina for pushing this forward,
--Jesper
Thanks Jesper,
Quoted 74 lines · Jesper Dangaard Brouer
Quoted 57 lines · Mina Almasry
Quoted 53 lines · Toke Høiland-Jørgensen
Quoted 42 lines · Mina Almasry
Quoted 15 lines · Toke Høiland-Jørgensen
Quoted 15 lines
Fast path results:
no-softirq-page_pool01 Per elem: 11 cycles(tsc) 4.368 ns
ptr_ringresults:
no-softirq-page_pool02 Per elem: 527 cycles(tsc) 195.187 nsslow path results:
no-softirq-page_pool03 Per elem: 549 cycles(tsc) 203.466 ns ```Cc Jesper Dangaard Brouer <[email protected]>Cc Ilias Apalodimas <[email protected]>Cc Jakub Kicinski <[email protected]>Cc Toke Høiland-Jørgensen <[email protected]>Quoted 6 lines
Quoted 1 line
Signed-off-by Mina Almasry <[email protected]>Back when you posted the first RFC, Jesper and I chatted about ways to avoid the ugly "load module and read the output from dmesg" interface to the test.
I agree the existing interface is ugly.
Quoted 9 lines
One idea we came up with was to make the module include only the "inner" functions for the benchmark, and expose those to BPF as kfuncs. Then the test runner can be a BPF program that runs the tests, collects the data and passes it to userspace via maps or a ringbuffer or something. That's a nicer and more customisable interface than the printk output. And if they're small enough, maybe we could even include the functions into the
page_poolcode itself, instead of in a separate benchmark module?WDYT of that idea? :)
...but this sounds like an enormous amount of effort, for something that is a bit ugly but isn't THAT bad. Especially for me, I'm not that much of an expert that I know how to implement what you're referring to off the top of my head. I normally am open to spending time but this is not that high on my todolist and I have limited bandwidth to resolve this :(
Quoted 7 lines
I also feel that this is something that could be improved post merge. I think it's very beneficial to have this merged in some form that can be improved later. Byungchul is making a lot of changes to these mm things and it would be nice to have an easy way to run the benchmark in tree and maybe even get automated results from nipa. If we could agree on mvp that is appropriate to merge without too much scope creep that would be ideal from my side at least.
Quoted 2 lines
Right, fair. I guess we can merge it as-is, and then investigate whether we can move it to BPF-based (or maybe 'perf bench' - Cc acme) later :)
Quoted 7 lines
Thanks for the pliability. Reviewed-bys and comments welcome.
Additionally Signed-off-by from Jesper is needed I think. Since most of this code is his, I retained his authorship. Jesper, whenever this looks good to me, a signed-off-by would be good and I would carry it to future versions. Changing authorship to me is also fine by me but I would think you want to retain the credit.
Okay, I think Ilias'es comment[1] and ACK convinced me, let us merge this as-is. We have been asking people to run it over several years before accepting patches. We shouldn't be pointing people to use out-of-tree tests for accepting patches.
Quoted 8 lines
It is not perfect, but it have served us well for benchmarking in the last approx 10 years (5 years for
page_pooltest). It is isolated as a selftest under (tools/testing/selftests/net/bench/page_pool/).Realistically we are all too busy inventing a new "perfect" benchmark for
page_pool. That said, I do encourage others with free cycles to integrated a better benchmark test intoperf bench. Then we can just remove this module again.
I'll spend some time looking at acme comments. They seem to be moving towards the right direction
Thanks
/Ilias
Quoted 8 lines
Signed-off-by Jesper Dangaard Brouer <[email protected]>[1]
https://lore.kernel.org/all/CAC_iWjLmO4XZ_+PBaCNxpVCTmGKNBsLGyeeKS2ptRrepn1u0SQ@mail.gmail.com/Thanks Mina for pushing this forward,
--Jesper
Quoted 10 lines · Ilias Apalodimas
Quoted 8 lines · Jesper Dangaard Brouer
Okay, I think Ilias'es comment[1] and ACK convinced me, let us merge this as-is. We have been asking people to run it over several years before accepting patches. We shouldn't be pointing people to use out-of-tree tests for accepting patches.
It is not perfect, but it have served us well for benchmarking in the last approx 10 years (5 years for
page_pooltest). It is isolated as a selftest under (tools/testing/selftests/net/bench/page_pool/).
Quoted 7 lines
Quoted 4 lines
Realistically we are all too busy inventing a new "perfect" benchmark for
page_pool. That said, I do encourage others with free cycles to integrated a better benchmark test intoperf bench. Then we can just remove this module again.I'll spend some time looking at acme comments. They seem to be moving towards the right direction
Glad that you think that way, and to add another perspective, 'perf test' and 'perf bench' goals are to run in any kernel, not just some specific one where a regression was fixed, so people running plain 'perf bench' will run whatever tests we add and thus widen the tester base for the benchmarks in there.
Being able to combine 'perf trace perf bench', 'perf stat perf bench', etc is something common and powerful.
But then the most important thing is to have actionable and expertly written benchmarks in place, that have been in use for a long time, in whatever form :-)
- Arnaldo