selftests: replace iperf with kperf and add RR
Subsystems (3)
v2 cover selftests: replace iperf with kperf and add RR
From: Stanislav Fomichev <[email protected]>
Recently added iperf throughput runs (918696-924166) have not been stable:
ktap-metric-json: {"goal":"higher","name":"throughput","value":99.60508305201279}
ktap-metric-json: {"goal":"higher","name":"throughput","value":90.65816851430006}
ktap-metric-json: {"goal":"higher","name":"throughput","value":92.02795621872379}
ktap-metric-json: {"goal":"higher","name":"throughput","value":98.78863365714747}
ktap-metric-json: {"goal":"higher","name":"throughput","value":103.38157195808748}
ktap-metric-json: {"goal":"higher","name":"throughput","value":93.64137239021106}
ktap-metric-json: {"goal":"higher","name":"throughput","value":101.73578035463773}
ktap-metric-json: {"goal":"higher","name":"throughput","value":78.15304223077422}
ktap-metric-json: {"goal":"higher","name":"throughput","value":103.79536587818043}
ktap-metric-json: {"goal":"higher","name":"throughput","value":91.48843017237692}
ktap-metric-json: {"goal":"higher","name":"throughput","value":75.27885187718259}
ktap-metric-json: {"goal":"higher","name":"throughput","value":103.5323033205535}
ktap-metric-json: {"goal":"higher","name":"throughput","value":92.04284599832805}
Compared to kperf devmem:
ktap-metric-json: {"goal":"higher","name":"throughput","value":185.588}
ktap-metric-json: {"goal":"higher","name":"throughput","value":185.63}
ktap-metric-json: {"goal":"higher","name":"throughput","value":185.606}
ktap-metric-json: {"goal":"higher","name":"throughput","value":185.594}
ktap-metric-json: {"goal":"higher","name":"throughput","value":185.54}
ktap-metric-json: {"goal":"higher","name":"throughput","value":185.594}
ktap-metric-json: {"goal":"higher","name":"throughput","value":185.552}
ktap-metric-json: {"goal":"higher","name":"throughput","value":185.561}
ktap-metric-json: {"goal":"higher","name":"throughput","value":185.616}
ktap-metric-json: {"goal":"higher","name":"throughput","value":185.63}
ktap-metric-json: {"goal":"higher","name":"throughput","value":185.532}
ktap-metric-json: {"goal":"higher","name":"throughput","value":185.62}
This is most likely due to --pin-off we are doing with kperf. So replace iperf with kperf (add regular and zerocopy variants).
At the same time, add closed loop RR stats to estimate the amount PPS we can take (so I can follow up with open loop RR).
v2:
- fix the ruff UP045 warnings (Willem)
- (trying to) send with matching From and Signed-off-by addresses (Willem)
- say that the first value kperf reports for each metric is kept, rather than the values of the first flow (Sashiko)
Stanislav Fomichev (4):
selftests: drv-net: kperf: support request-response tests
selftests: drv-net: add a closed-loop request-response test
selftests: drv-net: add a kperf stream test
selftests: drv-net: remove the iperf performance test
.../selftests/drivers/net/lib/py/kperf.py | 33 ++++++++++++- .../selftests/drivers/net/perf/Makefile | 3 +- .../selftests/drivers/net/perf/iperf.py | 23 --------- .../testing/selftests/drivers/net/perf/rr.py | 47 +++++++++++++++++++ .../selftests/drivers/net/perf/stream.py | 40 ++++++++++++++++ 5 files changed, 120 insertions(+), 26 deletions(-) delete mode 100755 tools/testing/selftests/drivers/net/perf/iperf.py create mode 100755 tools/testing/selftests/drivers/net/perf/rr.py create mode 100755 tools/testing/selftests/drivers/net/perf/stream.py
Signature · 1 line
2.53.1-Meta
PATCH v2 1/4 selftests: drv-net: kperf: support request-response tests
From: Stanislav Fomichev <[email protected]>
Let KperfResult tell the rate of the transactions of request-response tests and, when the client is asked for them with --time-stats 2, their latency percentiles and maximum, as seen by the source, which sends the requests. Request-response tests should run one connection; of more, the first value kperf reports for each metric is kept.
---
v1: https://lore.kernel.org/netdev/[email protected]/
--- .../selftests/drivers/net/lib/py/kperf.py | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-)
tools/testing/selftests/drivers/net/lib/py/kperf.py +31 -2
@@ -2,6 +2,8 @@ """Run and parse kperf network performance measurements.""" +from __future__ import annotations + import re import shlex import subprocess
@@ -13,14 +15,29 @@ from lib.py import cmd, ksft_pr, rand_port, wait_port_listen _SECTION_RE = re.compile(r"==\s+(Source|Target)\b") _RATE_RE = re.compile(r"\b(Tx|Rx)\s*([0-9]+(?:\.[0-9]+)?)\s+Gbps\b") +_RPS_RE = re.compile(r"\b([0-9]+(?:\.[0-9]+)?) RPS\b") +_LAT_RE = re.compile( + r"\b(p25|p50|p90|p99|p999|p9999|max):([0-9]+(?:\.[0-9]+)?)us\b") @dataclass class KperfResult: - """Aggregate throughput (Gbps) of both endpoints.""" + """Aggregate throughput (Gbps) of both endpoints. Request-response tests + also tell the rate (per second) of the source, which sends the requests, + and with --time-stats 2 its latencies (usec). They should run one + connection: of more, the first value kperf reports for each is kept. + """ source_throughput: float target_throughput: float + rate: float | None = None + p25: float | None = None + p50: float | None = None + p90: float | None = None + p99: float | None = None + p999: float | None = None + p9999: float | None = None + lat_max: float | None = None class KperfRunner:
@@ -133,6 +150,7 @@ _RATE_RE = re.compile(r"\b(Tx|Rx)\s*([0-9]+(?:\.[0-9]+)?)\s+Gbps\b") def parse(output): """Parse human-readable kperf client output.""" throughput = {"Source": [], "Target": []} + rr = {} section = None for line in output.splitlines():
@@ -149,9 +167,20 @@ _RATE_RE = re.compile(r"\b(Tx|Rx)\s*([0-9]+(?:\.[0-9]+)?)\s+Gbps\b") if (section, direction) in (("Source", "Tx"), ("Target", "Rx")): throughput[section].append(float(value)) + if section != "Source": + continue + + # Request-response tests run one connection, keep the first + # value kperf reports for each metric + match = _RPS_RE.search(line) + if match: + rr.setdefault("rate", float(match.group(1))) + for name, value in _LAT_RE.findall(line): + key = "lat_max" if name == "max" else name + rr.setdefault(key, float(value)) if not all(throughput.values()): raise ValueError("incomplete kperf result") return KperfResult(sum(throughput["Source"]), - sum(throughput["Target"])) + sum(throughput["Target"]), **rr)
Signature · 1 line
2.53.1-Meta
PATCH v2 2/4 selftests: drv-net: add a closed-loop request-response test
In reply to Stanislav FomichevFrom: Stanislav Fomichev <[email protected]>
Add rr.py, which measures back-to-back transactions of a kilobyte each way, which fits in a 1500 byte MTU, over one connection with kperf, and reports their rate and the latency percentiles and maximum which kperf reports.
--- .../selftests/drivers/net/perf/Makefile | 1 + .../testing/selftests/drivers/net/perf/rr.py | 47 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100755 tools/testing/selftests/drivers/net/perf/rr.py
tools/testing/selftests/drivers/net/perf/Makefile +1 -0
@@ -3,6 +3,7 @@ TEST_PROGS := \ devmem.py \ iperf.py \ + rr.py \ # end of TEST_PROGS TEST_INCLUDES := \
tools/testing/selftests/drivers/net/perf/rr.py new file +47 -0
47 lines not on this page · raw message
Signature · 1 line
2.53.1-Meta
PATCH v2 3/4 selftests: drv-net: add a kperf stream test
In reply to Stanislav FomichevFrom: Stanislav Fomichev <[email protected]>
Add stream.py, which measures the throughput of one TCP connection with kperf, with the same settings as devmem.py otherwise: once over copying sockets, and once with MSG_ZEROCOPY on the sender and TCP_ZEROCOPY_RECEIVE on the receiver. kperf pins the application a few CPUs away from the interrupts of the flow, so that the CPUs of a run do not depend on the scheduler. One connection is bound by the CPU rather than the line rate, so that the throughput follows changes to the cost of the stack and the driver.
--- .../selftests/drivers/net/perf/Makefile | 1 + .../selftests/drivers/net/perf/stream.py | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100755 tools/testing/selftests/drivers/net/perf/stream.py
tools/testing/selftests/drivers/net/perf/Makefile +1 -0
@@ -4,6 +4,7 @@ TEST_PROGS := \ devmem.py \ iperf.py \ rr.py \ + stream.py \ # end of TEST_PROGS TEST_INCLUDES := \
tools/testing/selftests/drivers/net/perf/stream.py new file +40 -0
@@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +"""Measure TCP stream throughput with kperf.""" + +from lib.py import KperfRunner, KsftNamedVariant, NetDrvEpEnv, ksft_exit +from lib.py import ksft_metric, ksft_run, ksft_variants + + +@ksft_variants([ + KsftNamedVariant("copy", []), + KsftNamedVariant("zerocopy", ["--msg-zerocopy", "--zerocopy-rx"]), +]) +def tcp(cfg, mode_args) -> None: + """Measure the throughput of one TCP connection.""" + stream_args = [ + "--time", "15", + "--num-connections", "1", + "--read-size", str(64 << 20), + "--write-size", str(64 << 20), + "--pin-off", "4", + "--validate", "no", + *mode_args, + ] + + with KperfRunner(cfg) as runner: + result = runner.run(stream_args) + + ksft_metric("throughput", result.target_throughput, goal="higher") + + +def main() -> None: + """Run the stream performance test.""" + with NetDrvEpEnv(__file__, nsim_test=False) as cfg: + ksft_run([tcp], args=(cfg,)) + ksft_exit() + + +if __name__ == "__main__": + main()
Signature · 1 line
2.53.1-Meta
PATCH v2 4/4 selftests: drv-net: remove the iperf performance test
In reply to Stanislav FomichevFrom: Stanislav Fomichev <[email protected]>
The throughput of one iperf3 stream changes by about 10% between back-to-back runs on the same hosts, e.g. from 90.7 to 99.6 Gbps over four runs, as much as a regression would. stream.py measures one TCP connection with kperf instead, remove iperf.py.
--- .../selftests/drivers/net/perf/Makefile | 1 - .../selftests/drivers/net/perf/iperf.py | 23 ------------------- 2 files changed, 24 deletions(-) delete mode 100755 tools/testing/selftests/drivers/net/perf/iperf.py
tools/testing/selftests/drivers/net/perf/Makefile +0 -1
@@ -2,7 +2,6 @@ TEST_PROGS := \ devmem.py \ - iperf.py \ rr.py \ stream.py \ # end of TEST_PROGS
tools/testing/selftests/drivers/net/perf/iperf.py deleted +0 -23
@@ -1,23 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: GPL-2.0 - -"""Measure TCP throughput with iperf3.""" - -from lib.py import Iperf3Runner, NetDrvEpEnv, ksft_exit, ksft_metric, ksft_run - - -def tcp(cfg): - """Measure TCP throughput.""" - result = Iperf3Runner(cfg).measure() - ksft_metric("throughput", result.throughput, goal="higher") - - -def main(): - """Run the iperf performance test.""" - with NetDrvEpEnv(__file__, nsim_test=False) as cfg: - ksft_run([tcp], args=(cfg,)) - ksft_exit() - - -if __name__ == "__main__": - main()
Signature · 1 line
2.53.1-Meta
Quoted 4 lines · Stanislav Fomichev
From: Stanislav Fomichev <[email protected]>
Recently added iperf throughput runs (918696-924166) have not been stable:
Quoted 13 lines
ktap-metric-json: {"goal":"higher","name":"throughput","value":99.60508305201279}
ktap-metric-json: {"goal":"higher","name":"throughput","value":90.65816851430006}
ktap-metric-json: {"goal":"higher","name":"throughput","value":92.02795621872379}
ktap-metric-json: {"goal":"higher","name":"throughput","value":98.78863365714747}
ktap-metric-json: {"goal":"higher","name":"throughput","value":103.38157195808748}
ktap-metric-json: {"goal":"higher","name":"throughput","value":93.64137239021106}
ktap-metric-json: {"goal":"higher","name":"throughput","value":101.73578035463773}
ktap-metric-json: {"goal":"higher","name":"throughput","value":78.15304223077422}
ktap-metric-json: {"goal":"higher","name":"throughput","value":103.79536587818043}
ktap-metric-json: {"goal":"higher","name":"throughput","value":91.48843017237692}
ktap-metric-json: {"goal":"higher","name":"throughput","value":75.27885187718259}
ktap-metric-json: {"goal":"higher","name":"throughput","value":103.5323033205535}
ktap-metric-json: {"goal":"higher","name":"throughput","value":92.04284599832805}
Nice getting RR stats in! Curious; the kperf copy runs, are they as stable as the devmem runs now?
For the series:
[email protected]
AI reviewRe: [PATCH net-next v2 1/4] selftests: drv-net: kperf: support request-response tests
In reply to Stanislav FomichevThank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The docstring of KperfResult in tools/testing/selftests/drivers/net/lib/py/kperf.py reads "They should…
--
selftests: drv-net: kperf: support request-response tests
This commit extends KperfResult with the transaction rate of request-response tests. With --time-stats 2 it also records the latency percentiles and maximum, as seen by the source. parse() keeps the first value kperf reports for each of these metrics.
Quoted 2 lines
Request-response tests should run one connection; of more, the first value kperf reports for each metric is kept.
This isn't a bug, but "of more" in the commit message doesn't read correctly. Was "if more are run" intended?
Quoted 4 lines
tools/testing/selftests/drivers/net/lib/py/kperf.py +0
-0
[ ... ]
Quoted 6 lines
tools/testing/selftests/drivers/net/lib/py/kperf.py +2
-0@@ -13,14 +15,29 @@ from lib.py import cmd, ksft_pr, rand_port, wait_port_listen _SECTION_RE = re.compile(r"==\s+(Source|Target)\b") _RATE_RE = re.compile(r"\b(Tx|Rx)\s*([0-9]+(?:\.[0-9]+)?)\s+Gbps\b") +_RPS_RE = re.compile(r"\b([0-9]+(?:\.[0-9]+)?) RPS\b") +_LAT_RE = re.compile(
tools/testing/selftests/drivers/net/lib/py/kperf.py from lib.py import cmd, ksft_pr, rand_port, wait_port_listen · line 28
Quoted 10 lines
tools/testing/selftests/drivers/net/lib/py/kperf.py +5
-1+ r"\b(p25|p50|p90|p99|p999|p9999|max):([0-9]+(?:\.[0-9]+)?)us\b") @dataclass class KperfResult: - """Aggregate throughput (Gbps) of both endpoints.""" + """Aggregate throughput (Gbps) of both endpoints. Request-response tests + also tell the rate (per second) of the source, which sends the requests, + and with --time-stats 2 its latencies (usec). They should run one + connection: of more, the first value kperf reports for each is kept.
[Severity: Low]
This isn't a bug, but the docstring has the same "of more" wording. This sentence is the only place in the code that documents the multi-connection behavior.
In parse(), rr.setdefault() keeps only the first connection's rate and latency values, while throughput is summed across all connections.
Would something like this be clearer?
If more connections are run, only the first value kperf reports for each metric is kept.
Quoted 4 lines
tools/testing/selftests/drivers/net/lib/py/kperf.py +1
-0+ """ source_throughput: float target_throughput: float
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130174609.314114-1-sdf.kernel%40gmail.com
[email protected]
AI reviewRe: [PATCH net-next v2 2/4] selftests: drv-net: add a closed-loop request-response test
In reply to Stanislav FomichevThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] closed_loop() and _report() in tools/testing/selftests/drivers/net/perf/rr.py pass the request-…
--
selftests: drv-net: add a closed-loop request-response test
This adds rr.py. It uses kperf to run back-to-back 1 KiB request-response transactions over a single connection. It then reports the transaction rate, the latency percentiles and the maximum latency as ksft metrics.
Quoted 5 lines
tools/testing/selftests/drivers/net/perf/rr.py new file +0
-0
[ ... ]
Quoted 5 lines
tools/testing/selftests/drivers/net/perf/rr.py new file +5
-0+def _report(result) -> None: + ksft_metric("rate", result.rate, goal="higher") + ksft_metric("latency_p25", result.p25, goal="lower") + ksft_metric("latency_p50", result.p50, goal="lower") + ksft_metric("latency_p90", result.p90, goal="lower")
tools/testing/selftests/drivers/net/perf/rr.py line 36
Quoted 10 lines
tools/testing/selftests/drivers/net/perf/rr.py new file +10
-0+ ksft_metric("latency_p99", result.p99, goal="lower") + ksft_metric("latency_p999", result.p999, goal="lower") + ksft_metric("latency_p9999", result.p9999, goal="lower") + ksft_metric("latency_max", result.lat_max, goal="lower") + + +def closed_loop(cfg) -> None: + """Measure back-to-back transactions.""" + with KperfRunner(cfg) as runner: + _report(runner.run(RR_ARGS))
[Severity: Medium]
If kperf produces no request-response data, can closed_loop() still report PASS?
In tools/testing/selftests/drivers/net/lib/py/kperf.py, every request-response field of KperfResult defaults to None:
rate: float | None = None
p25: float | None = None
...
lat_max: float | None = None
KperfRunner.parse() fills these fields only when _RPS_RE or _LAT_RE matches a line in the Source section. Its only completeness check covers throughput:
rr.setdefault("rate", float(match.group(1)))
...
rr.setdefault(key, float(value))
...
if not all(throughput.values()):
raise ValueError("incomplete kperf result")ksft_metric() does not validate value either. json.dumps() turns None into null, and metrics do not affect the test result.
So the test would pass if kperf printed no RPS line or no latency lines in the Source section. That could happen if a kperf build ignores --time-stats 2, uses a different output format or unit, or prints the stats under Target. The output would then be eight ktap-metric-json records with "value":null.
Would it make sense to check these fields in closed_loop() or _report()? lib.py already exports ksft_not_none(), or rr.py could raise KsftFailEx when a field is missing.
Nothing later in the series changes rr.py, kperf.py or ksft.py.
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130174609.314114-1-sdf.kernel%40gmail.com
[email protected]
AI reviewRe: [PATCH net-next v2 3/4] selftests: drv-net: add a kperf stream test
In reply to Stanislav FomichevThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] The "zerocopy" variant of tcp() in stream.py adds "--msg- zerocopy" and "--zerocopy-rx".
- [Low] The commit message for stream.py says it measures one TCP connection "with the same settings as devmem.py otherwise".
--
selftests: drv-net: add a kperf stream test
This adds stream.py, a drv-net perf selftest that uses kperf to measure the throughput of a single TCP connection. It has two variants: plain copy, and MSG_ZEROCOPY on the sender with TCP_ZEROCOPY_RECEIVE on the receiver.
Quoted 4 lines
Add
stream.py, which measures the throughput of one TCP connection with kperf, with the same settings asdevmem.pyotherwise: once over copying sockets, and once withMSG_ZEROCOPYon the sender andTCP_ZEROCOPY_RECEIVEon the receiver.
[Severity: Low]
Is "with the same settings as devmem.py otherwise" accurate?
The two tests share the kperf client options: --time 15, the 64 MiB read and write sizes, --pin-off 4 and --validate no.
devmem.py's kperf() also sets up the device before it measures:
tools/testing/selftests/drivers/net/perf/devmem.py:kperf() {
...
_enable_hw_gro(cfg)
...
"tcp-data-split": "enabled",
...
config["hds-thresh"] = 0
defer(ethnl.rings_set, restore)
ethnl.rings_set(config)
...
"--num-rx-queues", "4",
...
}stream.py's tcp() does none of this, so it runs with the driver's default GRO, HDS and RSS settings. The message only mentions the change from 4 connections to 1.
Could the message say that the device-level setup also differs? Then the stream.py and devmem.py numbers wouldn't be read as directly comparable.
Quoted 6 lines
tools/testing/selftests/drivers/net/perf/stream.py new file +0
-0@@ -0,0 +1,40 @@
[ ... ]
Quoted 7 lines
+@ksft_variants([
tools/testing/selftests/drivers/net/perf/stream.py new file +6
-0+ KsftNamedVariant("copy", []), + KsftNamedVariant("zerocopy", ["--msg-zerocopy", "--zerocopy-rx"]), +]) +def tcp(cfg, mode_args) -> None: + """Measure the throughput of one TCP connection.""" + stream_args = [
[ ... ]
tools/testing/selftests/drivers/net/perf/stream.py line 29
Quoted 4 lines
tools/testing/selftests/drivers/net/perf/stream.py new file +4
-0+ with KperfRunner(cfg) as runner: + result = runner.run(stream_args) + + ksft_metric("throughput", result.target_throughput, goal="higher")
[Severity: Medium]
Does the zerocopy variant actually exercise TCP_ZEROCOPY_RECEIVE on a device with default settings?
The variant only adds kperf flags. On the kernel side, can_map_frag() only maps full-page frags at offset 0:
net/ipv4/tcp.c:can_map_frag() {
...
if (skb_frag_size(frag) != PAGE_SIZE || skb_frag_off(frag))
return false;
...
}NICs normally produce frags like that only with header-data split and an MTU large enough for page-sized payloads. stream.py sets neither. devmem.py at least enables tcp-data-split.
With no HDS and a 1500 MTU, every payload frag fails can_map_frag(). tcp_zerocopy_receive() then maps nothing, and the receiver copies the data instead.
Nothing here checks whether zerocopy happened. KperfRunner.parse() in drivers/net/lib/py/kperf.py only extracts throughput, rate and latency:
return KperfResult(sum(throughput["Source"]),
sum(throughput["Target"]), **rr)tcp() then reports only the throughput metric.
Can the "zerocopy" result come from the copy receive path and still be labelled zerocopy? If so, a loss of TCP_ZEROCOPY_RECEIVE, or a regression in it, would not show up in this sub-case.
If kperf fails instead of falling back when nothing can be mapped, wouldn't this variant fail on most default setups?
Would it make sense to enable HDS (and possibly raise the MTU) for this variant? Another option is to check that pages were actually mapped, or that SO_EE_CODE_ZEROCOPY_COPIED was not reported.
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130174609.314114-1-sdf.kernel%40gmail.com