Skip to contentSkip to conversation

selftests: net: add performance metric reporting

PATCH Superseded Stanislav Fomichev 3 participants 12 messages Nov 2 – Nov 9

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover selftests: net: add performance metric reporting

Let Python selftests report numeric measurements, so that CI can track the performance of drivers over time, and add two performance tests.

ksft_metric() reports a measurement of the current test case, which is printed as JSON right before the test result:

# ktap-metric-json: {"goal":"higher","name":"throughput","value":389.127}

The goal tells a performance metric, which is better higher or lower, from an error metric, which must be zero. Everything else, such as units, history and regression thresholds, is up to the consumer.

The tests are in a new drivers/net/perf target, apart from the functional tests: they need real hardware, take a while, and make no sense on debug kernels. iperf.py measures single-stream TCP throughput with iperf3, devmem.py the throughput of udmabuf-backed devmem TCP with kperf [1].

System monitoring stays in NIPA, which runs each case of the perf tests in a process of its own and attaches CPU and NIC metrics to its results. The NIPA changes are at [2]; git clone & ./nipa local view starts an http server on :44109 with two sample runs.

[1] https://github.com/facebookexperimental/kperf
[2] https://github.com/fomichev/nipa/tree/nipa-local-hw-metrics

v3:
- drop the timestamp of metrics (Jakub)
- drop the note on nested output from the docs (Jakub)
- report plain numbers, drop kind/type (Jakub)
- replace ksft_metric_policy() with a goal per metric: higher, lower or zero (Jakub)
- move the tests to drivers/net/perf, with a lib/py of their own (Jakub)
- fix the format of the Makefile lists (Jakub)
- report metrics from the tests rather than the runners (Jakub)
- drop the kperf section of the README (Jakub)
- stop reporting TCP retransmits
- drop the metric labels, report the throughput of the receiver only

v2:
- move system monitoring to NIPA (Jakub)
- move performance tests to drivers/net/hw/performance (Jakub)
- rename metric shape to type and document supported types (Paolo); kind= instead of type= (type shadows a builtin)
- remove direction from the metric example (Paolo)
- document policy processing order (Paolo)
- support producer-selected summary operations, including arbitrary pXX
- label throughput metrics in Gbps
- do not mark the iperf benchmark disruptive
- use 2 GiB udmabuf buffers for kperf devmem
- drop the ncdevmem devmem probe
- use a random kperf control port
- report kperf server cleanup failures

Stanislav Fomichev (4):
selftests: net: py: add metric output
selftests: drv-net: add an iperf performance test
selftests: drv-net: add a kperf runner
selftests: drv-net: measure devmem performance with kperf

 tools/testing/selftests/Makefile              |   2 +-
 .../testing/selftests/drivers/net/README.rst  |  17 ++
 .../selftests/drivers/net/lib/py/__init__.py  |   4 +-
 .../selftests/drivers/net/lib/py/kperf.py     | 181 ++++++++++++++++++
 .../selftests/drivers/net/lib/py/load.py      |  20 +-
 .../selftests/drivers/net/perf/Makefile       |  12 ++
 .../testing/selftests/drivers/net/perf/config |   4 +
 .../selftests/drivers/net/perf/devmem.py      |  96 ++++++++++
 .../selftests/drivers/net/perf/iperf.py       |  23 +++
 .../drivers/net/perf/lib/py/__init__.py       |  59 ++++++
 .../selftests/drivers/net/perf/settings       |   1 +
 .../testing/selftests/net/lib/py/__init__.py  |   9 +-
 tools/testing/selftests/net/lib/py/ksft.py    |  28 +++
 13 files changed, 447 insertions(+), 9 deletions(-)
 create mode 100644 tools/testing/selftests/drivers/net/lib/py/kperf.py
 create mode 100644 tools/testing/selftests/drivers/net/perf/Makefile
 create mode 100644 tools/testing/selftests/drivers/net/perf/config
 create mode 100755 tools/testing/selftests/drivers/net/perf/devmem.py
 create mode 100755 tools/testing/selftests/drivers/net/perf/iperf.py
 create mode 100644 tools/testing/selftests/drivers/net/perf/lib/py/__init__.py
 create mode 100644 tools/testing/selftests/drivers/net/perf/settings
Signature · 1 line
2.53.0-Meta
#1 lore raw

PATCH v3 1/4 selftests: net: py: add metric output

Add ksft_metric() to report a numeric measurement of the current test case as JSON, right before the test result. Each metric states its goal: higher or lower for a performance metric, depending on which way is better, or zero for an error metric, so a consumer can tell wins from regressions.

Values are plain numbers without a timestamp. A helper for other kinds of values, or a timestamp for values sampled over time, can be added when a test needs one.

---
v2: https://lore.kernel.org/netdev/[email protected]/
v1: https://lore.kernel.org/netdev/[email protected]/

---
 .../testing/selftests/drivers/net/README.rst  | 17 +++++++++++
 .../testing/selftests/net/lib/py/__init__.py  |  9 +++---
 tools/testing/selftests/net/lib/py/ksft.py    | 28 +++++++++++++++++++
 3 files changed, 50 insertions(+), 4 deletions(-)
tools/testing/selftests/drivers/net/README.rst +17 -0
index 3fe49bce4f3a..ab61bbc322fd 100644
@@ -259,6 +259,23 @@ ksft_pr()
 
 Use ``ksft_pr()`` instead of ``print()`` to avoid breaking TAP format.
 
+ksft_metric()
+~~~~~~~~~~~~~
+
+Use ``ksft_metric()`` to report a numeric measurement of the current test
+case. Metrics are printed as compact JSON right before the test result. For
+example::
+
+  ksft_metric("throughput", 100.5, goal="higher")
+
+prints::
+
+  # ktap-metric-json: {"goal":"higher","name":"throughput","value":100.5}
+
+``goal`` tells a performance metric, which is better ``higher`` or ``lower``,
+from an error metric, which must be ``zero``. Metrics do not affect the
+result of the test.
+
 ksft_disruptive
 ~~~~~~~~~~~~~~~
 
tools/testing/selftests/net/lib/py/__init__.py +5 -4
index e269a260d58e..b1696f432c7c 100644
@@ -8,8 +8,8 @@ from .consts import KSRC
 from .ksft import KsftFailEx, KsftSkipEx, KsftXfailEx, ksft_pr, ksft_eq, \
     ksft_ne, ksft_true, ksft_not_none, ksft_in, ksft_not_in, ksft_is, \
     ksft_ge, ksft_gt, ksft_lt, ksft_raises, ksft_busy_wait, \
-    ktap_result, ksft_disruptive, ksft_setup, ksft_run, ksft_exit, \
-    ksft_variants, KsftNamedVariant
+    ktap_result, ksft_disruptive, ksft_metric, ksft_setup, ksft_run, \
+    ksft_exit, ksft_variants, KsftNamedVariant
 from .netns import NetNS, NetNSEnter, UserNetNS
 from .nsim import NetdevSim, NetdevSimDev
 from .utils import CmdExitFailure, fd_read_timeout, cmd, bkg, defer, \
@@ -24,8 +24,9 @@ __all__ = ["KSRC",
            "KsftFailEx", "KsftSkipEx", "KsftXfailEx", "ksft_pr", "ksft_eq",
            "ksft_ne", "ksft_true", "ksft_not_none", "ksft_in", "ksft_not_in",
            "ksft_is", "ksft_ge", "ksft_gt", "ksft_lt", "ksft_raises",
-           "ksft_busy_wait", "ktap_result", "ksft_disruptive", "ksft_setup",
-           "ksft_run", "ksft_exit", "ksft_variants", "KsftNamedVariant",
+           "ksft_busy_wait", "ktap_result", "ksft_disruptive", "ksft_metric",
+           "ksft_setup", "ksft_run", "ksft_exit", "ksft_variants",
+           "KsftNamedVariant",
            "NetNS", "NetNSEnter", "UserNetNS",
            "CmdExitFailure", "fd_read_timeout", "cmd", "bkg", "defer",
            "bpftool", "ip", "ethtool", "bpftrace", "rand_port", "rand_ports",
tools/testing/selftests/net/lib/py/ksft.py +28 -0
index 81287c2daff0..3b97bdff4cbb 100644
@@ -4,6 +4,7 @@ import fnmatch
 import functools
 import getopt
 import inspect
+import json
 import os
 import signal
 import sys
@@ -16,6 +17,7 @@ from . import utils
 KSFT_RESULT = None
 KSFT_RESULT_ALL = True
 KSFT_DISRUPTIVE = True
+KSFT_METRICS = []
 
 
 class KsftFailEx(Exception):
@@ -93,6 +95,31 @@ KSFT_DISRUPTIVE = True
     print(pfx, prefixed, **kwargs)
 
 
+def ksft_metric(name, value, *, goal):
+    """
+    Report a numeric measurement of the current test case.
+
+    Metrics are printed right before the result of the test case. They do
+    not affect the result.
+
+    Args:
+      name - name of the metric, e.g. "throughput"
+      value - the measured number
+      goal - "higher" or "lower" for a performance metric, depending on
+             which way is better, "zero" for an error metric, which must
+             be zero
+    """
+    KSFT_METRICS.append({"name": name, "value": value, "goal": goal})
+
+
+def _ksft_flush_metrics():
+    for metric in KSFT_METRICS:
+        payload = json.dumps(metric, allow_nan=False, separators=(",", ":"),
+                             sort_keys=True)
+        ksft_pr(f"ktap-metric-json: {payload}")
+    KSFT_METRICS.clear()
+
+
 def _fail(*args):
     global KSFT_RESULT
     KSFT_RESULT = False
@@ -450,6 +477,7 @@ KsftCaseFunction = namedtuple("KsftCaseFunction",
         if not cnt_key:
             cnt_key = 'pass' if KSFT_RESULT else 'fail'
 
+        _ksft_flush_metrics()
         ktap_result(KSFT_RESULT, cnt, name, comment=comment)
         totals[cnt_key] += 1
 
Signature · 1 line
2.53.0-Meta
Reviewed-by on v3 1/4
#2 lore raw

Re: [PATCH net-next v3 1/4] selftests: net: py: add metric output

Quoted 10 lines · Stanislav Fomichev

Add ksft_metric() to report a numeric measurement of the current test case as JSON, right before the test result. Each metric states its goal: higher or lower for a performance metric, depending on which way is better, or zero for an error metric, so a consumer can tell wins from regressions.

Values are plain numbers without a timestamp. A helper for other kinds of values, or a timestamp for values sampled over time, can be added when a test needs one.

maintainer
#3 lore raw

Re: [PATCH net-next v3 1/4] selftests: net: py: add metric output

In reply to Stanislav Fomichev

tools/testing/selftests/net/lib/py/ksft.py KSFT_DISRUPTIVE = True · line 103

Quoted 2 lines · On Mon, 2 Nov 2026 11:08:24 -0800 Stanislav Fomichev wrote:
tools/testing/selftests/net/lib/py/ksft.py +2 -0
+    Metrics are printed right before the result of the test case. They do
+    not affect the result.

Is there a strong reason to do this?
My intuition is that buffering makes debug harder, the parser can easily extract and sort the metrics on a successful run?

#4 lore raw

PATCH v3 2/4 selftests: drv-net: add an iperf performance test

In reply to Stanislav Fomichev

Add the drivers/net/perf target, with a lib/py of its own like the one of drivers/net/hw. Add Iperf3Runner.measure(), which returns an Iperf3Result that other results can join later, and report its throughput from the test.

Single-stream iperf3 throughput is flaky and can change considerably between back-to-back runs on the same hosts.

Tested on two mlx5 hosts. Captured metric output:

# # ktap-metric-json: {"goal":"higher","name":"throughput","value":49.92071602072054}

---
 tools/testing/selftests/Makefile              |  2 +-
 .../selftests/drivers/net/lib/py/load.py      | 20 ++++++-
 .../selftests/drivers/net/perf/Makefile       | 11 ++++
 .../testing/selftests/drivers/net/perf/config |  1 +
 .../selftests/drivers/net/perf/iperf.py       | 23 ++++++++
 .../drivers/net/perf/lib/py/__init__.py       | 57 +++++++++++++++++++
 .../selftests/drivers/net/perf/settings       |  1 +
 7 files changed, 111 insertions(+), 4 deletions(-)
 create mode 100644 tools/testing/selftests/drivers/net/perf/Makefile
 create mode 100644 tools/testing/selftests/drivers/net/perf/config
 create mode 100755 tools/testing/selftests/drivers/net/perf/iperf.py
 create mode 100644 tools/testing/selftests/drivers/net/perf/lib/py/__init__.py
 create mode 100644 tools/testing/selftests/drivers/net/perf/settings
tools/testing/selftests/Makefile +1 -1
index 07c3719f8b04..c55d7792b27c 100644
@@ -159,7 +159,7 @@ TARGETS_HOTPLUG = cpu-hotplug
 TARGETS_HOTPLUG += memory-hotplug
 
 # Networking tests want the net/lib target, include it automatically
-ifneq ($(filter net drivers/net drivers/net/hw,$(TARGETS)),)
+ifneq ($(filter net drivers/net drivers/net/hw drivers/net/perf,$(TARGETS)),)
 ifeq ($(filter net/lib,$(TARGETS)),)
 	INSTALL_DEP_TARGETS := net/lib
 endif
tools/testing/selftests/drivers/net/lib/py/load.py +17 -3
index e24660e5c27f..f337b576c4b4 100644
@@ -3,10 +3,18 @@
 import re
 import time
 import json
+from dataclasses import dataclass
 
 from lib.py import ksft_pr, cmd, ip, rand_port, wait_port_listen
 
 
+@dataclass
+class Iperf3Result:
+    """Average throughput (Gbps) of an iperf3 run."""
+
+    throughput: float
+
+
 class Iperf3Runner:
     """
     Sets up and runs iperf3 traffic.
@@ -53,9 +61,9 @@ from lib.py import ksft_pr, cmd, ip, rand_port, wait_port_listen
             kwargs["timeout"] = duration + 5
         return cmd(cmdline, **kwargs)
 
-    def measure_bandwidth(self, reverse=False):
+    def measure(self, reverse=False):
         """
-        Runs an iperf3 measurement and returns the average bandwidth (Gbps).
+        Runs an iperf3 measurement and returns an Iperf3Result.
         Discards the first and last few reporting intervals and uses only the
         middle part of the run where throughput is typically stable.
         """
@@ -78,7 +86,13 @@ from lib.py import ksft_pr, cmd, ip, rand_port, wait_port_listen
 
         avg = sum(stable) / len(stable)
 
-        return avg
+        return Iperf3Result(avg)
+
+    def measure_bandwidth(self, reverse=False):
+        """
+        Runs an iperf3 measurement and returns the average bandwidth (Gbps).
+        """
+        return self.measure(reverse=reverse).throughput
 
 
 class GenerateTraffic:
tools/testing/selftests/drivers/net/perf/Makefile new file +11 -0
new file mode 100644
index 000000000000..31b0b60de4f6
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0
+
+TEST_PROGS := \
+	iperf.py \
+# end of TEST_PROGS
+
+TEST_INCLUDES := \
+	$(wildcard lib/py/*.py ../lib/py/*.py) \
+# end of TEST_INCLUDES
+
+include ../../../lib.mk
tools/testing/selftests/drivers/net/perf/config new file +1 -0
new file mode 100644
index 000000000000..6450f34933e6
@@ -0,0 +1 @@
+CONFIG_IPV6=y
tools/testing/selftests/drivers/net/perf/iperf.py new file +23 -0
new file mode 100755
index 000000000000..5b6f0bce2a03
@@ -0,0 +1,23 @@
+#!/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()
tools/testing/selftests/drivers/net/perf/lib/py/__init__.py new file +57 -0

57 lines not on this page · raw message

tools/testing/selftests/drivers/net/perf/settings new file +1 -0
new file mode 100644
index 000000000000..e7b9417537fb
@@ -0,0 +1 @@
+timeout=0
Signature · 1 line
2.53.0-Meta
Reviewed-by on v3 2/4
#5 lore raw

Re: [PATCH net-next v3 2/4] selftests: drv-net: add an iperf performance test

Quoted 196 lines · Stanislav Fomichev

Add the drivers/net/perf target, with a lib/py of its own like the one of drivers/net/hw. Add Iperf3Runner.measure(), which returns an Iperf3Result that other results can join later, and report its throughput from the test.

Single-stream iperf3 throughput is flaky and can change considerably between back-to-back runs on the same hosts.

Tested on two mlx5 hosts. Captured metric output:

# # ktap-metric-json: {"goal":"higher","name":"throughput","value":49.92071602072054}

---
 tools/testing/selftests/Makefile              |  2 +-
 .../selftests/drivers/net/lib/py/load.py      | 20 ++++++-
 .../selftests/drivers/net/perf/Makefile       | 11 ++++
 .../testing/selftests/drivers/net/perf/config |  1 +
 .../selftests/drivers/net/perf/iperf.py       | 23 ++++++++
 .../drivers/net/perf/lib/py/__init__.py       | 57 +++++++++++++++++++
 .../selftests/drivers/net/perf/settings       |  1 +
 7 files changed, 111 insertions(+), 4 deletions(-)
 create mode 100644 tools/testing/selftests/drivers/net/perf/Makefile
 create mode 100644 tools/testing/selftests/drivers/net/perf/config
 create mode 100755 tools/testing/selftests/drivers/net/perf/iperf.py
 create mode 100644 tools/testing/selftests/drivers/net/perf/lib/py/__init__.py
 create mode 100644 tools/testing/selftests/drivers/net/perf/settings
tools/testing/selftests/Makefile +1 -1
index 07c3719f8b04..c55d7792b27c 100644
@@ -159,7 +159,7 @@ TARGETS_HOTPLUG = cpu-hotplug
 TARGETS_HOTPLUG += memory-hotplug
 
 # Networking tests want the net/lib target, include it automatically
-ifneq ($(filter net drivers/net drivers/net/hw,$(TARGETS)),)
+ifneq ($(filter net drivers/net drivers/net/hw drivers/net/perf,$(TARGETS)),)
 ifeq ($(filter net/lib,$(TARGETS)),)
 	INSTALL_DEP_TARGETS := net/lib
 endif
tools/testing/selftests/drivers/net/lib/py/load.py +17 -3
index e24660e5c27f..f337b576c4b4 100644
@@ -3,10 +3,18 @@
 import re
 import time
 import json
+from dataclasses import dataclass
 
 from lib.py import ksft_pr, cmd, ip, rand_port, wait_port_listen
 
 
+@dataclass
+class Iperf3Result:
+    """Average throughput (Gbps) of an iperf3 run."""
+
+    throughput: float
+
+
 class Iperf3Runner:
     """
     Sets up and runs iperf3 traffic.
@@ -53,9 +61,9 @@ from lib.py import ksft_pr, cmd, ip, rand_port, wait_port_listen
             kwargs["timeout"] = duration + 5
         return cmd(cmdline, **kwargs)
 
-    def measure_bandwidth(self, reverse=False):
+    def measure(self, reverse=False):
         """
-        Runs an iperf3 measurement and returns the average bandwidth (Gbps).
+        Runs an iperf3 measurement and returns an Iperf3Result.
         Discards the first and last few reporting intervals and uses only the
         middle part of the run where throughput is typically stable.
         """
@@ -78,7 +86,13 @@ from lib.py import ksft_pr, cmd, ip, rand_port, wait_port_listen
 
         avg = sum(stable) / len(stable)
 
-        return avg
+        return Iperf3Result(avg)
+
+    def measure_bandwidth(self, reverse=False):
+        """
+        Runs an iperf3 measurement and returns the average bandwidth (Gbps).
+        """
+        return self.measure(reverse=reverse).throughput
 
 
 class GenerateTraffic:
tools/testing/selftests/drivers/net/perf/Makefile new file +11 -0
new file mode 100644
index 000000000000..31b0b60de4f6
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0
+
+TEST_PROGS := \
+	iperf.py \
+# end of TEST_PROGS
+
+TEST_INCLUDES := \
+	$(wildcard lib/py/*.py ../lib/py/*.py) \
+# end of TEST_INCLUDES
+
+include ../../../lib.mk
tools/testing/selftests/drivers/net/perf/config new file +1 -0
new file mode 100644
index 000000000000..6450f34933e6
@@ -0,0 +1 @@
+CONFIG_IPV6=y
tools/testing/selftests/drivers/net/perf/iperf.py new file +23 -0
new file mode 100755
index 000000000000..5b6f0bce2a03
@@ -0,0 +1,23 @@
+#!/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()
tools/testing/selftests/drivers/net/perf/lib/py/__init__.py new file +47 -0
new file mode 100644
index 000000000000..2bb2cd08ff7d
@@ -0,0 +1,57 @@
+# SPDX-License-Identifier: GPL-2.0
+
+"""
+Driver test environment (performance tests).
+NetDrvEnv and NetDrvEpEnv are the main environment classes.
+NetDrvContEnv extends NetDrvEpEnv with netkit container support.
+Former is for local host only tests, latter creates / connects
+to a remote endpoint. See NIPA wiki for more information about
+running and writing driver tests.
+"""
+
+import sys
+from pathlib import Path
+
+KSFT_DIR = (Path(__file__).parent / "../../../../..").resolve()
+
+try:
+    sys.path.append(KSFT_DIR.as_posix())
+
+    # Import one by one to avoid pylint false positives
+    from net.lib.py import NetNS, NetNSEnter, NetdevSimDev, UserNetNS
+    from net.lib.py import EthtoolFamily, NetdevFamily, NetshaperFamily, \
+        NlError, RtnlFamily, DevlinkFamily, PSPFamily, Netlink
+    from net.lib.py import CmdExitFailure
+    from net.lib.py import bkg, cmd, bpftool, bpftrace, defer, ethtool, \
+        fd_read_timeout, ip, rand_port, rand_ports, wait_port_listen, \
+        wait_file, ctl_file_write, tool
+    from net.lib.py import bpf_map_set, bpf_map_dump, bpf_prog_map_ids
+    from net.lib.py import KsftSkipEx, KsftFailEx, KsftXfailEx
+    from net.lib.py import ksft_disruptive, ksft_exit, ksft_metric, ksft_pr, \
+        ksft_run, ksft_setup, ksft_variants, KsftNamedVariant
+    from net.lib.py import ksft_eq, ksft_ge, ksft_in, ksft_is, ksft_lt, \
+        ksft_ne, ksft_not_in, ksft_raises, ksft_true, ksft_gt, ksft_not_none
+    from drivers.net.lib.py import set_ethtool_feat
+    from drivers.net.lib.py import GenerateTraffic, Remote, Iperf3Runner
+    from drivers.net.lib.py import NetDrvEnv, NetDrvEpEnv, NetDrvContEnv
+
+    __all__ = ["NetNS", "NetNSEnter", "NetdevSimDev", "UserNetNS",
+               "EthtoolFamily", "NetdevFamily", "NetshaperFamily",
+               "NlError", "RtnlFamily", "DevlinkFamily", "PSPFamily", "Netlink",
+               "CmdExitFailure",
+               "bkg", "cmd", "bpftool", "bpftrace", "defer", "ethtool",
+               "fd_read_timeout", "ip", "rand_port", "rand_ports",
+               "wait_port_listen", "wait_file", "ctl_file_write", "tool",
+               "bpf_map_set", "bpf_map_dump", "bpf_prog_map_ids",
+               "KsftSkipEx", "KsftFailEx", "KsftXfailEx",
+               "ksft_disruptive", "ksft_exit", "ksft_metric", "ksft_pr",

tools/testing/selftests/drivers/net/perf/lib/py/__init__.py line 57

Quoted 10 lines
tools/testing/selftests/drivers/net/perf/lib/py/__init__.py new file +10 -0
+               "ksft_run", "ksft_setup", "ksft_variants", "KsftNamedVariant",
+               "ksft_eq", "ksft_ge", "ksft_in", "ksft_is", "ksft_lt",
+               "ksft_ne", "ksft_not_in", "ksft_raises", "ksft_true", "ksft_gt",
+               "ksft_not_none",
+               "NetDrvEnv", "NetDrvEpEnv", "NetDrvContEnv", "GenerateTraffic",
+               "Remote", "Iperf3Runner", "set_ethtool_feat"]
+except ModuleNotFoundError as e:
+    print("Failed importing `net` library from kernel sources")
+    print(str(e))
+    sys.exit(4)

nit: is there a KSFT_SKIP symbol?

#6 lore raw

Re: [PATCH net-next v3 2/4] selftests: drv-net: add an iperf performance test

Quoted 211 lines · Björn Töpel
Quoted 196 lines · Stanislav Fomichev

Add the drivers/net/perf target, with a lib/py of its own like the one of drivers/net/hw. Add Iperf3Runner.measure(), which returns an Iperf3Result that other results can join later, and report its throughput from the test.

Single-stream iperf3 throughput is flaky and can change considerably between back-to-back runs on the same hosts.

Tested on two mlx5 hosts. Captured metric output:

# # ktap-metric-json: {"goal":"higher","name":"throughput","value":49.92071602072054}

---
 tools/testing/selftests/Makefile              |  2 +-
 .../selftests/drivers/net/lib/py/load.py      | 20 ++++++-
 .../selftests/drivers/net/perf/Makefile       | 11 ++++
 .../testing/selftests/drivers/net/perf/config |  1 +
 .../selftests/drivers/net/perf/iperf.py       | 23 ++++++++
 .../drivers/net/perf/lib/py/__init__.py       | 57 +++++++++++++++++++
 .../selftests/drivers/net/perf/settings       |  1 +
 7 files changed, 111 insertions(+), 4 deletions(-)
 create mode 100644 tools/testing/selftests/drivers/net/perf/Makefile
 create mode 100644 tools/testing/selftests/drivers/net/perf/config
 create mode 100755 tools/testing/selftests/drivers/net/perf/iperf.py
 create mode 100644 tools/testing/selftests/drivers/net/perf/lib/py/__init__.py
 create mode 100644 tools/testing/selftests/drivers/net/perf/settings
tools/testing/selftests/Makefile +1 -1
index 07c3719f8b04..c55d7792b27c 100644
@@ -159,7 +159,7 @@ TARGETS_HOTPLUG = cpu-hotplug
 TARGETS_HOTPLUG += memory-hotplug
 
 # Networking tests want the net/lib target, include it automatically
-ifneq ($(filter net drivers/net drivers/net/hw,$(TARGETS)),)
+ifneq ($(filter net drivers/net drivers/net/hw drivers/net/perf,$(TARGETS)),)
 ifeq ($(filter net/lib,$(TARGETS)),)
 	INSTALL_DEP_TARGETS := net/lib
 endif
tools/testing/selftests/drivers/net/lib/py/load.py +17 -3
index e24660e5c27f..f337b576c4b4 100644
@@ -3,10 +3,18 @@
 import re
 import time
 import json
+from dataclasses import dataclass
 
 from lib.py import ksft_pr, cmd, ip, rand_port, wait_port_listen
 
 
+@dataclass
+class Iperf3Result:
+    """Average throughput (Gbps) of an iperf3 run."""
+
+    throughput: float
+
+
 class Iperf3Runner:
     """
     Sets up and runs iperf3 traffic.
@@ -53,9 +61,9 @@ from lib.py import ksft_pr, cmd, ip, rand_port, wait_port_listen
             kwargs["timeout"] = duration + 5
         return cmd(cmdline, **kwargs)
 
-    def measure_bandwidth(self, reverse=False):
+    def measure(self, reverse=False):
         """
-        Runs an iperf3 measurement and returns the average bandwidth (Gbps).
+        Runs an iperf3 measurement and returns an Iperf3Result.
         Discards the first and last few reporting intervals and uses only the
         middle part of the run where throughput is typically stable.
         """
@@ -78,7 +86,13 @@ from lib.py import ksft_pr, cmd, ip, rand_port, wait_port_listen
 
         avg = sum(stable) / len(stable)
 
-        return avg
+        return Iperf3Result(avg)
+
+    def measure_bandwidth(self, reverse=False):
+        """
+        Runs an iperf3 measurement and returns the average bandwidth (Gbps).
+        """
+        return self.measure(reverse=reverse).throughput
 
 
 class GenerateTraffic:
tools/testing/selftests/drivers/net/perf/Makefile new file +11 -0
new file mode 100644
index 000000000000..31b0b60de4f6
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0
+
+TEST_PROGS := \
+	iperf.py \
+# end of TEST_PROGS
+
+TEST_INCLUDES := \
+	$(wildcard lib/py/*.py ../lib/py/*.py) \
+# end of TEST_INCLUDES
+
+include ../../../lib.mk
tools/testing/selftests/drivers/net/perf/config new file +1 -0
new file mode 100644
index 000000000000..6450f34933e6
@@ -0,0 +1 @@
+CONFIG_IPV6=y
tools/testing/selftests/drivers/net/perf/iperf.py new file +23 -0
new file mode 100755
index 000000000000..5b6f0bce2a03
@@ -0,0 +1,23 @@
+#!/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()
tools/testing/selftests/drivers/net/perf/lib/py/__init__.py new file +47 -0
new file mode 100644
index 000000000000..2bb2cd08ff7d
@@ -0,0 +1,57 @@
+# SPDX-License-Identifier: GPL-2.0
+
+"""
+Driver test environment (performance tests).
+NetDrvEnv and NetDrvEpEnv are the main environment classes.
+NetDrvContEnv extends NetDrvEpEnv with netkit container support.
+Former is for local host only tests, latter creates / connects
+to a remote endpoint. See NIPA wiki for more information about
+running and writing driver tests.
+"""
+
+import sys
+from pathlib import Path
+
+KSFT_DIR = (Path(__file__).parent / "../../../../..").resolve()
+
+try:
+    sys.path.append(KSFT_DIR.as_posix())
+
+    # Import one by one to avoid pylint false positives
+    from net.lib.py import NetNS, NetNSEnter, NetdevSimDev, UserNetNS
+    from net.lib.py import EthtoolFamily, NetdevFamily, NetshaperFamily, \
+        NlError, RtnlFamily, DevlinkFamily, PSPFamily, Netlink
+    from net.lib.py import CmdExitFailure
+    from net.lib.py import bkg, cmd, bpftool, bpftrace, defer, ethtool, \
+        fd_read_timeout, ip, rand_port, rand_ports, wait_port_listen, \
+        wait_file, ctl_file_write, tool
+    from net.lib.py import bpf_map_set, bpf_map_dump, bpf_prog_map_ids
+    from net.lib.py import KsftSkipEx, KsftFailEx, KsftXfailEx
+    from net.lib.py import ksft_disruptive, ksft_exit, ksft_metric, ksft_pr, \
+        ksft_run, ksft_setup, ksft_variants, KsftNamedVariant
+    from net.lib.py import ksft_eq, ksft_ge, ksft_in, ksft_is, ksft_lt, \
+        ksft_ne, ksft_not_in, ksft_raises, ksft_true, ksft_gt, ksft_not_none
+    from drivers.net.lib.py import set_ethtool_feat
+    from drivers.net.lib.py import GenerateTraffic, Remote, Iperf3Runner
+    from drivers.net.lib.py import NetDrvEnv, NetDrvEpEnv, NetDrvContEnv
+
+    __all__ = ["NetNS", "NetNSEnter", "NetdevSimDev", "UserNetNS",
+               "EthtoolFamily", "NetdevFamily", "NetshaperFamily",
+               "NlError", "RtnlFamily", "DevlinkFamily", "PSPFamily", "Netlink",
+               "CmdExitFailure",
+               "bkg", "cmd", "bpftool", "bpftrace", "defer", "ethtool",
+               "fd_read_timeout", "ip", "rand_port", "rand_ports",
+               "wait_port_listen", "wait_file", "ctl_file_write", "tool",
+               "bpf_map_set", "bpf_map_dump", "bpf_prog_map_ids",
+               "KsftSkipEx", "KsftFailEx", "KsftXfailEx",
+               "ksft_disruptive", "ksft_exit", "ksft_metric", "ksft_pr",

tools/testing/selftests/drivers/net/perf/lib/py/__init__.py line 57

Quoted 10 lines
tools/testing/selftests/drivers/net/perf/lib/py/__init__.py new file +10 -0
+               "ksft_run", "ksft_setup", "ksft_variants", "KsftNamedVariant",
+               "ksft_eq", "ksft_ge", "ksft_in", "ksft_is", "ksft_lt",
+               "ksft_ne", "ksft_not_in", "ksft_raises", "ksft_true", "ksft_gt",
+               "ksft_not_none",
+               "NetDrvEnv", "NetDrvEpEnv", "NetDrvContEnv", "GenerateTraffic",
+               "Remote", "Iperf3Runner", "set_ethtool_feat"]
+except ModuleNotFoundError as e:
+    print("Failed importing `net` library from kernel sources")
+    print(str(e))
+    sys.exit(4)

nit: is there a KSFT_SKIP symbol?

Quoted 1 line

It is a copy-paste from selftests/drivers/net/hw/lib/py/__init__.py (and there is a similar code in net/lib/py/ynl.py). I guess I can add "# KSFT_SKIP" here instead of doing the real import.

#7 lore raw

PATCH v3 3/4 selftests: drv-net: add a kperf runner

In reply to Stanislav Fomichev

Add a helper to manage kperf servers, run the client, and return the aggregate throughput of both ends. Use a random control port and a unique PID file per server, as the hosts may share /tmp, and report server cleanup failures. Stopping the servers waits for their sessions to exit, as they may still be releasing devmem and RX steering, which the next test needs. A server which can log does so to a file next to its PID file, and the end of both logs is printed when the client fails, as the client can only tell that a server went away.

---
 .../selftests/drivers/net/lib/py/__init__.py  |   4 +-
 .../selftests/drivers/net/lib/py/kperf.py     | 181 ++++++++++++++++++
 .../drivers/net/perf/lib/py/__init__.py       |   6 +-
 3 files changed, 188 insertions(+), 3 deletions(-)
 create mode 100644 tools/testing/selftests/drivers/net/lib/py/kperf.py
tools/testing/selftests/drivers/net/lib/py/__init__.py +3 -1
index 40ccdcf0c378..7a32f6516a12 100644
@@ -49,11 +49,13 @@ KSFT_DIR = (Path(__file__).parent / "../../../..").resolve()
 
     from .env import NetDrvEnv, NetDrvEpEnv, NetDrvContEnv
     from .feat import set_ethtool_feat
+    from .kperf import KperfResult, KperfRunner
     from .load import GenerateTraffic, Iperf3Runner
     from .remote import Remote
 
     __all__ += ["NetDrvEnv", "NetDrvEpEnv", "NetDrvContEnv", "GenerateTraffic",
-                "Remote", "Iperf3Runner", "set_ethtool_feat"]
+                "Remote", "Iperf3Runner", "KperfResult", "KperfRunner",
+                "set_ethtool_feat"]
 except ModuleNotFoundError as e:
     print("Failed importing `net` library from kernel sources")
     print(str(e))
tools/testing/selftests/drivers/net/lib/py/kperf.py new file +181 -0

181 lines not on this page · raw message

tools/testing/selftests/drivers/net/perf/lib/py/__init__.py +4 -2
index 2bb2cd08ff7d..c07f1ac5e80a 100644
@@ -32,7 +32,8 @@ KSFT_DIR = (Path(__file__).parent / "../../../../..").resolve()
     from net.lib.py import ksft_eq, ksft_ge, ksft_in, ksft_is, ksft_lt, \
         ksft_ne, ksft_not_in, ksft_raises, ksft_true, ksft_gt, ksft_not_none
     from drivers.net.lib.py import set_ethtool_feat
-    from drivers.net.lib.py import GenerateTraffic, Remote, Iperf3Runner
+    from drivers.net.lib.py import GenerateTraffic, Remote, Iperf3Runner, \
+        KperfResult, KperfRunner
     from drivers.net.lib.py import NetDrvEnv, NetDrvEpEnv, NetDrvContEnv
 
     __all__ = ["NetNS", "NetNSEnter", "NetdevSimDev", "UserNetNS",
@@ -50,7 +51,8 @@ KSFT_DIR = (Path(__file__).parent / "../../../../..").resolve()
                "ksft_ne", "ksft_not_in", "ksft_raises", "ksft_true", "ksft_gt",
                "ksft_not_none",
                "NetDrvEnv", "NetDrvEpEnv", "NetDrvContEnv", "GenerateTraffic",
-               "Remote", "Iperf3Runner", "set_ethtool_feat"]
+               "Remote", "Iperf3Runner", "KperfResult", "KperfRunner",
+               "set_ethtool_feat"]
 except ModuleNotFoundError as e:
     print("Failed importing `net` library from kernel sources")
     print(str(e))
Signature · 1 line
2.53.0-Meta
Reviewed-by on v3 3/4
#8 lore raw

Re: [PATCH net-next v3 3/4] selftests: drv-net: add a kperf runner

Quoted 10 lines · Stanislav Fomichev

Add a helper to manage kperf servers, run the client, and return the aggregate throughput of both ends. Use a random control port and a unique PID file per server, as the hosts may share /tmp, and report server cleanup failures. Stopping the servers waits for their sessions to exit, as they may still be releasing devmem and RX steering, which the next test needs. A server which can log does so to a file next to its PID file, and the end of both logs is printed when the client fails, as the client can only tell that a server went away.

maintainer
#9 lore raw

Re: [PATCH net-next v3 3/4] selftests: drv-net: add a kperf runner

In reply to Stanislav Fomichev
Quoted 10 lines · On Mon, 2 Nov 2026 11:08:26 -0800 Stanislav Fomichev wrote:
tools/testing/selftests/drivers/net/lib/py/kperf.py new file +10 -0
+    def _wait_exit(self, remote, timeout=60):
+        """Wait for the sessions of a server to exit.
+
+        Killing the server leaves its sessions, which exit once they have
+        released their devmem and RX steering, which the next test needs.
+        Being forked, they run with the server's command line.  The
+        bracket keeps pgrep from matching the shell which runs it.
+        """
+        host = self.env.remote if remote else None
+        args = ["pgrep", "-f",

tools/testing/selftests/drivers/net/lib/py/kperf.py line 105

Quoted 10 lines
tools/testing/selftests/drivers/net/lib/py/kperf.py new file +10 -0
+                f"[k]perf-server --pid-file {self._pid_file(remote)}"]
+        deadline = time.monotonic() + timeout
+        while True:
+            pgrep = cmd(shlex.join(args) if remote else args, host=host,
+                        fail=False)
+            if pgrep.ret:
+                return None
+            if time.monotonic() > deadline:
+                return pgrep
+            time.sleep(0.1)

bit ugly, can we not make sure kperf --kill does the right thing?

#10 lore raw

PATCH v3 4/4 selftests: drv-net: measure devmem performance with kperf

In reply to Stanislav Fomichev

Add a separate udmabuf-backed devmem performance test using KperfRunner. Keep correctness cases in drivers/net/hw. Skip the test when kperf or /dev/udmabuf is missing, and fail it when the kperf run fails.

Example metric output:

# # ktap-metric-json: {"goal":"higher","name":"throughput","value":389.127}

---
 .../selftests/drivers/net/perf/Makefile       |  1 +
 .../testing/selftests/drivers/net/perf/config |  3 +
 .../selftests/drivers/net/perf/devmem.py      | 96 +++++++++++++++++++
 3 files changed, 100 insertions(+)
 create mode 100755 tools/testing/selftests/drivers/net/perf/devmem.py
tools/testing/selftests/drivers/net/perf/Makefile +1 -0
index 31b0b60de4f6..1a90537d2726 100644
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 
 TEST_PROGS := \
+	devmem.py \
 	iperf.py \
 # end of TEST_PROGS
 
tools/testing/selftests/drivers/net/perf/config +3 -0
index 6450f34933e6..111e9b58610d 100644
@@ -1 +1,4 @@
 CONFIG_IPV6=y
+CONFIG_NET_DEVMEM=y
+CONFIG_SYNC_FILE=y
+CONFIG_UDMABUF=y
tools/testing/selftests/drivers/net/perf/devmem.py new file +96 -0

96 lines not on this page · raw message

Signature · 1 line
2.53.0-Meta
Reviewed-by on v3 4/4
#11 lore raw

Re: [PATCH net-next v3 4/4] selftests: drv-net: measure devmem performance with kperf

Quoted 9 lines · Stanislav Fomichev

Add a separate udmabuf-backed devmem performance test using KperfRunner. Keep correctness cases in drivers/net/hw. Skip the test when kperf or /dev/udmabuf is missing, and fail it when the kperf run fails.

Example metric output:

# # ktap-metric-json: {"goal":"higher","name":"throughput","value":389.127}