Skip to contentSkip to conversation

selftests: net: add performance metric reporting

RFC Superseded Stanislav Fomichev 2 participants 10 messages Oct 5 – Oct 16

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover selftests: net: add performance metric reporting

Add timestamped observations and producer-defined metric policy to Python selftests. Add iperf and kperf performance coverage.

System monitoring can live in either place:

Selftests:
- uses one KTAP format for benchmark and system metrics
- provides system metrics for direct local runs
- lets each test select the exact scope and devices
- adds kernel-side code and maintenance

NIPA:
- keeps generic monitoring out of the kernel tree
- allows collection to evolve without kernel changes
- requires runner-managed test boundaries and local tooling

This version keeps CPU and NIC monitoring in NIPA. NIPA runs each program in drivers/net/hw/performance one subtest per process, giving the runner exact monitoring boundaries.

Note that we still keep metric aggregation policy (ksft_metric_policy) including regression boundaries in the tree. If we were to move it to NIPA we'd have to have per-metric-name configs or something.

NIPA changes at https://github.com/fomichev/nipa/tree/nipa-local-hw-metrics
have a few examples. git clone & ./nipa local view will start an http server on :44109 with two sample runs.

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 (5):
selftests: net: py: add timestamped metric output
selftests: net: py: add metric policy 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  |  57 +++++++
 .../drivers/net/hw/lib/py/__init__.py         |  17 +-
 .../drivers/net/hw/performance/Makefile       |  13 ++
 .../drivers/net/hw/performance/config         |   4 +
 .../drivers/net/hw/performance/devmem.py      |  99 +++++++++++
 .../drivers/net/hw/performance/iperf.py       |  27 +++
 .../drivers/net/hw/performance/settings       |   1 +
 .../selftests/drivers/net/lib/py/__init__.py  |  15 +-
 .../selftests/drivers/net/lib/py/kperf.py     | 161 ++++++++++++++++++
 .../selftests/drivers/net/lib/py/load.py      |  24 ++-
 .../testing/selftests/net/lib/py/__init__.py  |  11 +-
 tools/testing/selftests/net/lib/py/ksft.py    | 159 ++++++++++++++++-
 13 files changed, 571 insertions(+), 19 deletions(-)
 create mode 100644 tools/testing/selftests/drivers/net/hw/performance/Makefile
 create mode 100644 tools/testing/selftests/drivers/net/hw/performance/config
 create mode 100755 tools/testing/selftests/drivers/net/hw/performance/devmem.py
 create mode 100755 tools/testing/selftests/drivers/net/hw/performance/iperf.py
 create mode 100644 tools/testing/selftests/drivers/net/hw/performance/settings
 create mode 100644 tools/testing/selftests/drivers/net/lib/py/kperf.py
Signature · 1 line
2.53.0-Meta
#1 lore raw

RFC v2 1/5 selftests: net: py: add timestamped metric output

Add ksft_metric() to record timestamped JSON observations for the current test case.

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

---
 .../testing/selftests/drivers/net/README.rst  | 28 +++++++++++
 .../drivers/net/hw/lib/py/__init__.py         |  8 +--
 .../selftests/drivers/net/lib/py/__init__.py  |  8 +--
 .../testing/selftests/net/lib/py/__init__.py  |  9 ++--
 tools/testing/selftests/net/lib/py/ksft.py    | 49 ++++++++++++++++++-
 5 files changed, 89 insertions(+), 13 deletions(-)
tools/testing/selftests/drivers/net/README.rst +28 -0
index 3fe49bce4f3a..3e3cc028d77a 100644
@@ -259,6 +259,34 @@ ksft_pr()
 
 Use ``ksft_pr()`` instead of ``print()`` to avoid breaking TAP format.
 
+ksft_metric()
+~~~~~~~~~~~~~
+
+Use ``ksft_metric()`` to report a numeric measurement for the current test
+case. The helper records the time relative to the start of the case and emits
+each observation immediately before the test result as compact JSON. For
+example::
+
+  ksft_metric("throughput", 100.5, kind="scalar")
+
+emits output similar to::
+
+  # ktap-metric-json: {"name":"throughput","time":1.234,"type":"scalar","value":100.5}
+
+When ``run_kselftest.sh`` nests the test output, its diagnostic prefix makes
+this ``# # ktap-metric-json: <json>``. A background sampler can call
+``ksft_metric()`` repeatedly. Pass ``kind`` explicitly; it is emitted as the
+``type`` field. Supported kinds are ``scalar`` for one numeric value and
+``per-cpu`` for an array indexed by CPU number, with ``None`` for a missing or
+offline CPU::
+
+  ksft_metric("cpu.utilization", [75.0, 22.0, None, 100.0],
+              kind="per-cpu", host="local")
+
+The helper does not infer the kind from the Python value, since an array may
+represent something other than per-CPU data. Metrics are measurements only and
+do not affect the pass or fail result.
+
 ksft_disruptive
 ~~~~~~~~~~~~~~~
 
tools/testing/selftests/drivers/net/hw/lib/py/__init__.py +4 -4
index 4077f5f1a1be..77e4ef34f8b9 100644
@@ -27,8 +27,8 @@ KSFT_DIR = (Path(__file__).parent / "../../../../..").resolve()
         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_pr, ksft_run, \
-        ksft_setup, ksft_variants, KsftNamedVariant
+    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
@@ -44,8 +44,8 @@ KSFT_DIR = (Path(__file__).parent / "../../../../..").resolve()
                "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_pr", "ksft_run",
-               "ksft_setup", "ksft_variants", "KsftNamedVariant",
+               "ksft_disruptive", "ksft_exit", "ksft_metric", "ksft_pr",
+               "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", "ksft_not_none",
tools/testing/selftests/drivers/net/lib/py/__init__.py +4 -4
index 40ccdcf0c378..f744280dcc37 100644
@@ -27,8 +27,8 @@ KSFT_DIR = (Path(__file__).parent / "../../../..").resolve()
         wait_file, ctl_file_write
     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_pr, ksft_run, \
-        ksft_setup, ksft_variants, KsftNamedVariant
+    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
 
@@ -41,8 +41,8 @@ KSFT_DIR = (Path(__file__).parent / "../../../..").resolve()
                "wait_port_listen", "wait_file", "ctl_file_write",
                "bpf_map_set", "bpf_map_dump", "bpf_prog_map_ids",
                "KsftSkipEx", "KsftFailEx", "KsftXfailEx",
-               "ksft_disruptive", "ksft_exit", "ksft_pr", "ksft_run",
-               "ksft_setup", "ksft_variants", "KsftNamedVariant",
+               "ksft_disruptive", "ksft_exit", "ksft_metric", "ksft_pr",
+               "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", "ksft_not_none"]
tools/testing/selftests/net/lib/py/__init__.py +5 -4
index 71df5880b356..3d9e6f6b402c 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 +48 -1

88 lines not on this page · raw message

Signature · 1 line
2.53.0-Meta
maintainer
#2 lore raw

Re: [RFC net-next v2 1/5] selftests: net: py: add timestamped metric output

tools/testing/selftests/drivers/net/README.rst ksft_pr() · line 274

Quoted 13 lines · On Mon, 5 Oct 2026 13:11:10 -0700 Stanislav Fomichev wrote:
tools/testing/selftests/drivers/net/README.rst +13 -0
+ksft_metric()
+~~~~~~~~~~~~~
+
+Use ``ksft_metric()`` to report a numeric measurement for the current test
+case. The helper records the time relative to the start of the case and emits
+each observation immediately before the test result as compact JSON. For
+example::
+
+  ksft_metric("throughput", 100.5, kind="scalar")
+
+emits output similar to::
+
+  # ktap-metric-json: {"name":"throughput","time":1.234,"type":"scalar","value":100.5}

Should time be optional? In case some test wants to report single metric not value over time? Maybe just mention that it's an option if someone needs it in the future?

Review

Quoted 2 lines
(quoted diff) +2 -0
+When ``run_kselftest.sh`` nests the test output, its diagnostic prefix makes
+this ``# # ktap-metric-json: <json>``. 

This sentence needs to go, it's out of place and obvious to anyone who worked with ksft.

tools/testing/selftests/drivers/net/README.rst ksft_pr() · line 284

Quoted 8 lines

A background sampler can call
+``ksft_metric()`` repeatedly. Pass ``kind`` explicitly; it is emitted as the +``type`` field. Supported kinds are ``scalar`` for one numeric value and +``per-cpu`` for an array indexed by CPU number, with ``None`` for a missing or

tools/testing/selftests/drivers/net/README.rst +4 -0
+offline CPU::
+
+  ksft_metric("cpu.utilization", [75.0, 22.0, None, 100.0],
+              kind="per-cpu", host="local")

Should we say something about what the values for "kind" are? Or should this be internal - IOW create ksft_metric_X for supported types, like ksft_metric_scalar, which would be more self-documenting?

Quoted 3 lines
tools/testing/selftests/drivers/net/README.rst +3 -0
+The helper does not infer the kind from the Python value, since an array may
+represent something other than per-CPU data. Metrics are measurements only and
+do not affect the pass or fail result.
#3 lore raw

RFC v2 2/5 selftests: net: py: add metric policy output

In reply to Stanislav Fomichev

Add ksft_metric_policy() so producers can describe metric processing, display, and regression policy without name-specific consumer logic.

---
 .../testing/selftests/drivers/net/README.rst  |  21 ++++
 .../drivers/net/hw/lib/py/__init__.py         |  11 +-
 .../selftests/drivers/net/lib/py/__init__.py  |  11 +-
 .../testing/selftests/net/lib/py/__init__.py  |   6 +-
 tools/testing/selftests/net/lib/py/ksft.py    | 114 +++++++++++++++++-
 5 files changed, 151 insertions(+), 12 deletions(-)
tools/testing/selftests/drivers/net/README.rst +21 -0
index 3e3cc028d77a..1b7264d40b79 100644
@@ -287,6 +287,27 @@ The helper does not infer the kind from the Python value, since an array may
 represent something other than per-CPU data. Metrics are measurements only and
 do not affect the pass or fail result.
 
+ksft_metric_policy()
+~~~~~~~~~~~~~~~~~~~~
+
+Use ``ksft_metric_policy()`` before the first matching observation to
+register processing, display, and regression policy for a metric. The policy
+is emitted once per test case rather than repeated in every observation. For
+example::
+
+  ksft_metric_policy("nic.rx.dropped", summarize="max",
+                     transform="rate", display_range={"min": 0})
+  ksft_metric("nic.rx.dropped", 0, kind="scalar", host="local")
+
+emits separate policy and observation records::
+
+  # ktap-metric-policy-json: {"display_range":{"min":0},"name":"nic.rx.dropped","summarize":"max","transform":"rate"}
+  # ktap-metric-json: {"host":"local","name":"nic.rx.dropped","time":1.234,"type":"scalar","value":0}
+
+Consumers apply a policy to observations with the same metric name. The
+function docstring documents the supported summary, transform, aggregation,
+regression, and display options.
+
 ksft_disruptive
 ~~~~~~~~~~~~~~~
 
tools/testing/selftests/drivers/net/hw/lib/py/__init__.py +7 -4
index 77e4ef34f8b9..cd771c00c074 100644
@@ -27,8 +27,9 @@ KSFT_DIR = (Path(__file__).parent / "../../../../..").resolve()
         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_disruptive, ksft_exit, ksft_metric, \
+        ksft_metric_policy, 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
@@ -44,8 +45,10 @@ KSFT_DIR = (Path(__file__).parent / "../../../../..").resolve()
                "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",
-               "ksft_run", "ksft_setup", "ksft_variants", "KsftNamedVariant",
+               "ksft_disruptive", "ksft_exit", "ksft_metric",
+               "ksft_metric_policy", "ksft_pr", "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", "ksft_not_none",
tools/testing/selftests/drivers/net/lib/py/__init__.py +7 -4
index f744280dcc37..58c2877e7928 100644
@@ -27,8 +27,9 @@ KSFT_DIR = (Path(__file__).parent / "../../../..").resolve()
         wait_file, ctl_file_write
     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_disruptive, ksft_exit, ksft_metric, \
+        ksft_metric_policy, 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
 
@@ -41,8 +42,10 @@ KSFT_DIR = (Path(__file__).parent / "../../../..").resolve()
                "wait_port_listen", "wait_file", "ctl_file_write",
                "bpf_map_set", "bpf_map_dump", "bpf_prog_map_ids",
                "KsftSkipEx", "KsftFailEx", "KsftXfailEx",
-               "ksft_disruptive", "ksft_exit", "ksft_metric", "ksft_pr",
-               "ksft_run", "ksft_setup", "ksft_variants", "KsftNamedVariant",
+               "ksft_disruptive", "ksft_exit", "ksft_metric",
+               "ksft_metric_policy", "ksft_pr", "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", "ksft_not_none"]
tools/testing/selftests/net/lib/py/__init__.py +4 -2
index 3d9e6f6b402c..db25602e4d57 100644
@@ -8,7 +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_metric, ksft_setup, ksft_run, \
+    ktap_result, ksft_disruptive, ksft_metric, ksft_metric_policy, \
+    ksft_setup, ksft_run, \
     ksft_exit, ksft_variants, KsftNamedVariant
 from .netns import NetNS, NetNSEnter, UserNetNS
 from .nsim import NetdevSim, NetdevSimDev
@@ -25,7 +26,8 @@ __all__ = ["KSRC",
            "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_metric",
-           "ksft_setup", "ksft_run", "ksft_exit", "ksft_variants",
+           "ksft_metric_policy", "ksft_setup", "ksft_run",
+           "ksft_exit", "ksft_variants",
            "KsftNamedVariant",
            "NetNS", "NetNSEnter", "UserNetNS",
            "CmdExitFailure", "fd_read_timeout", "cmd", "bkg", "defer",
tools/testing/selftests/net/lib/py/ksft.py +112 -2

150 lines not on this page · raw message

Signature · 1 line
2.53.0-Meta
maintainer
#4 lore raw

Re: [RFC net-next v2 2/5] selftests: net: py: add metric policy output

tools/testing/selftests/drivers/net/README.rst The helper does not infer the kind from the Python value, since an array may · line 299

Quoted 2 lines · On Mon, 5 Oct 2026 13:11:11 -0700 Stanislav Fomichev wrote:
tools/testing/selftests/drivers/net/README.rst +2 -0
+  ksft_metric_policy("nic.rx.dropped", summarize="max",
+                     transform="rate", display_range={"min": 0})

IMO we should not be mixing any of this into the test.
We can hard code some heuristics into UI to match on names and create sensible defaults. Here this feels out of place.
I would have expected only what you have as "regression policy" in here. And only a subset of that. Naively we want to know
- if the metric is an error metric or perf metric (error metric must be at 0, perf metric has to be analyzed for expected perf)
- whether it's a badness or goodness metric to distinguish wins from regressions

#5 lore raw

RFC v2 3/5 selftests: drv-net: add an iperf performance test

In reply to Stanislav Fomichev

Add the drivers/net/hw/performance target. Report throughput and retransmits from Iperf3Runner when requested.

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-policy-json: {"display_label":"Gbps","name":"throughput","regression":{"better":"higher","compare":"p50","relative_tolerance":0.05},"summarize":"p50"} # # ktap-metric-policy-json: {"name":"tcp.retransmits","summarize":"max"}
# # ktap-metric-json: {"host":"local","name":"throughput","time":10.685632,"type":"scalar","value":48.561920255183196}
# # ktap-metric-json: {"host":"remote","name":"tcp.retransmits","time":10.68565,"type":"scalar","value":0}

---
 tools/testing/selftests/Makefile              |  2 +-
 .../drivers/net/hw/performance/Makefile       | 10 +++++++
 .../drivers/net/hw/performance/config         |  1 +
 .../drivers/net/hw/performance/iperf.py       | 27 +++++++++++++++++++
 .../drivers/net/hw/performance/settings       |  1 +
 .../selftests/drivers/net/lib/py/load.py      | 24 +++++++++++++++--
 6 files changed, 62 insertions(+), 3 deletions(-)
 create mode 100644 tools/testing/selftests/drivers/net/hw/performance/Makefile
 create mode 100644 tools/testing/selftests/drivers/net/hw/performance/config
 create mode 100755 tools/testing/selftests/drivers/net/hw/performance/iperf.py
 create mode 100644 tools/testing/selftests/drivers/net/hw/performance/settings
tools/testing/selftests/Makefile +1 -1
index 273853937c25..7523f378e026 100644
@@ -152,7 +152,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/hw/performance,$(TARGETS)),)
 ifeq ($(filter net/lib,$(TARGETS)),)
 	INSTALL_DEP_TARGETS := net/lib
 endif
tools/testing/selftests/drivers/net/hw/performance/Makefile new file +10 -0
new file mode 100644
index 000000000000..5d53ef548306
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0
+
+TEST_PROGS := iperf.py
+
+TEST_INCLUDES := \
+	$(wildcard ../lib/py/*.py ../../lib/py/*.py) \
+	$(wildcard ../../../../net/lib/py/*.py) \
+	#
+
+include ../../../../lib.mk
tools/testing/selftests/drivers/net/hw/performance/config new file +1 -0
new file mode 100644
index 000000000000..6450f34933e6
@@ -0,0 +1 @@
+CONFIG_IPV6=y
tools/testing/selftests/drivers/net/hw/performance/iperf.py new file +27 -0
new file mode 100755
index 000000000000..415fb67f4100
@@ -0,0 +1,27 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+"""Measure TCP throughput with iperf3."""
+
+from os import path
+import sys
+
+sys.path.insert(0, path.join(path.dirname(path.abspath(__file__)), ".."))
+
+from lib.py import Iperf3Runner, NetDrvEpEnv, ksft_exit, ksft_run
+
+
+def tcp(cfg):
+    """Measure TCP throughput."""
+    Iperf3Runner(cfg).measure_bandwidth(report=True)
+
+
+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/hw/performance/settings new file +1 -0
new file mode 100644
index 000000000000..e7b9417537fb
@@ -0,0 +1 @@
+timeout=0
tools/testing/selftests/drivers/net/lib/py/load.py +22 -2
index e24660e5c27f..a7da025b4e21 100644
@@ -4,7 +4,8 @@ import re
 import time
 import json
 
-from lib.py import ksft_pr, cmd, ip, rand_port, wait_port_listen
+from lib.py import cmd, ip, ksft_metric, ksft_metric_policy, ksft_pr, \
+    rand_port, wait_port_listen
 
 
 class Iperf3Runner:
@@ -53,12 +54,20 @@ 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_bandwidth(self, reverse=False, report=False):
         """
         Runs an iperf3 measurement and returns the average bandwidth (Gbps).
         Discards the first and last few reporting intervals and uses only the
         middle part of the run where throughput is typically stable.
         """
+        if report:
+            ksft_metric_policy(
+                "throughput", summarize="p50",
+                regression={"compare": "p50", "better": "higher",
+                            "relative_tolerance": 0.05},
+                display_label="Gbps")
+            ksft_metric_policy("tcp.retransmits", summarize="max")
+
         self.start_server()
         result = self.start_client(duration=10, reverse=reverse)
 
@@ -77,6 +86,17 @@ from lib.py import ksft_pr, cmd, ip, rand_port, wait_port_listen
         stable = samples[3:-3]
 
         avg = sum(stable) / len(stable)
+        retransmits = out.get("end", {}).get("sum_sent", {}).get(
+            "retransmits")
+        if report:
+            if not isinstance(retransmits, int) or \
+                    isinstance(retransmits, bool):
+                raise ValueError("iperf3 did not report TCP retransmits")
+            receiver = "remote" if reverse else "local"
+            sender = "local" if reverse else "remote"
+            ksft_metric("throughput", avg, kind="scalar", host=receiver)
+            ksft_metric("tcp.retransmits", retransmits, kind="scalar",
+                        host=sender)
 
         return avg
 
Signature · 1 line
2.53.0-Meta
maintainer
#6 lore raw

Re: [RFC net-next v2 3/5] selftests: drv-net: add an iperf performance test

Quoted 32 lines · On Mon, 5 Oct 2026 13:11:12 -0700 Stanislav Fomichev wrote:

Add the drivers/net/hw/performance target. Report throughput and retransmits from Iperf3Runner when requested.

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-policy-json: {"display_label":"Gbps","name":"throughput","regression":{"better":"higher","compare":"p50","relative_tolerance":0.05},"summarize":"p50"} # # ktap-metric-policy-json: {"name":"tcp.retransmits","summarize":"max"}
# # ktap-metric-json: {"host":"local","name":"throughput","time":10.685632,"type":"scalar","value":48.561920255183196}
# # ktap-metric-json: {"host":"remote","name":"tcp.retransmits","time":10.68565,"type":"scalar","value":0}

---
 tools/testing/selftests/Makefile              |  2 +-
 .../drivers/net/hw/performance/Makefile       | 10 +++++++
 .../drivers/net/hw/performance/config         |  1 +
 .../drivers/net/hw/performance/iperf.py       | 27 +++++++++++++++++++
 .../drivers/net/hw/performance/settings       |  1 +
 .../selftests/drivers/net/lib/py/load.py      | 24 +++++++++++++++--
 6 files changed, 62 insertions(+), 3 deletions(-)
 create mode 100644 tools/testing/selftests/drivers/net/hw/performance/Makefile
 create mode 100644 tools/testing/selftests/drivers/net/hw/performance/config
 create mode 100755 tools/testing/selftests/drivers/net/hw/performance/iperf.py
 create mode 100644 tools/testing/selftests/drivers/net/hw/performance/settings
tools/testing/selftests/Makefile +0 -0
index 273853937c25..7523f378e026 100644

tools/testing/selftests/Makefile TARGETS_HOTPLUG = cpu-hotplug · line 155

Quoted 5 lines
tools/testing/selftests/Makefile +1 -1
@@ -152,7 +152,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/hw/performance,$(TARGETS)),)

long strings, maybe let's s@/hw/perfromance@/perf@ ?

tools/testing/selftests/drivers/net/hw/performance/Makefile line 3

Quoted 12 lines
tools/testing/selftests/Makefile +0 -0
 ifeq ($(filter net/lib,$(TARGETS)),)
 	INSTALL_DEP_TARGETS := net/lib
 endif
tools/testing/selftests/drivers/net/hw/performance/Makefile new file +3 -0
new file mode 100644
index 000000000000..5d53ef548306
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0
+
+TEST_PROGS := iperf.py

here..

tools/testing/selftests/drivers/net/hw/performance/Makefile line 8

Quoted 4 lines
tools/testing/selftests/drivers/net/hw/performance/Makefile new file +4 -0
+TEST_INCLUDES := \
+	$(wildcard ../lib/py/*.py ../../lib/py/*.py) \
+	$(wildcard ../../../../net/lib/py/*.py) \
+	#

.. and here -

not the exact correct format for the Makefile, pls look closer

Quoted 14 lines
tools/testing/selftests/drivers/net/hw/performance/Makefile new file +1 -0
+include ../../../../lib.mk
tools/testing/selftests/drivers/net/hw/performance/config new file +1 -0
new file mode 100644
index 000000000000..6450f34933e6
@@ -0,0 +1 @@
+CONFIG_IPV6=y
tools/testing/selftests/drivers/net/hw/performance/iperf.py new file +0 -0
new file mode 100755
index 000000000000..415fb67f4100

tools/testing/selftests/drivers/net/hw/performance/iperf.py line 9

Quoted 9 lines
tools/testing/selftests/drivers/net/hw/performance/iperf.py new file +9 -0
@@ -0,0 +1,27 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+"""Measure TCP throughput with iperf3."""
+
+from os import path
+import sys
+
+sys.path.insert(0, path.join(path.dirname(path.abspath(__file__)), ".."))

Nasty hacks. Something is not laid out right, mister.

Quoted 65 lines
tools/testing/selftests/drivers/net/hw/performance/iperf.py new file +17 -0
+from lib.py import Iperf3Runner, NetDrvEpEnv, ksft_exit, ksft_run
+
+
+def tcp(cfg):
+    """Measure TCP throughput."""
+    Iperf3Runner(cfg).measure_bandwidth(report=True)
+
+
+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/hw/performance/settings new file +1 -0
new file mode 100644
index 000000000000..e7b9417537fb
@@ -0,0 +1 @@
+timeout=0
tools/testing/selftests/drivers/net/lib/py/load.py +12 -2
index e24660e5c27f..a7da025b4e21 100644
@@ -4,7 +4,8 @@ import re
 import time
 import json
 
-from lib.py import ksft_pr, cmd, ip, rand_port, wait_port_listen
+from lib.py import cmd, ip, ksft_metric, ksft_metric_policy, ksft_pr, \
+    rand_port, wait_port_listen
 
 
 class Iperf3Runner:
@@ -53,12 +54,20 @@ 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_bandwidth(self, reverse=False, report=False):
         """
         Runs an iperf3 measurement and returns the average bandwidth (Gbps).
         Discards the first and last few reporting intervals and uses only the
         middle part of the run where throughput is typically stable.
         """
+        if report:
+            ksft_metric_policy(
+                "throughput", summarize="p50",
+                regression={"compare": "p50", "better": "higher",
+                            "relative_tolerance": 0.05},
+                display_label="Gbps")
+            ksft_metric_policy("tcp.retransmits", summarize="max")
+
         self.start_server()
         result = self.start_client(duration=10, reverse=reverse)
 
@@ -77,6 +86,17 @@ from lib.py import ksft_pr, cmd, ip, rand_port, wait_port_listen
         stable = samples[3:-3]
 
         avg = sum(stable) / len(stable)
+        retransmits = out.get("end", {}).get("sum_sent", {}).get(

tools/testing/selftests/drivers/net/lib/py/load.py from lib.py import ksft_pr, cmd, ip, rand_port, wait_port_listen · line 99

Quoted 10 lines
tools/testing/selftests/drivers/net/lib/py/load.py +10 -0
+            "retransmits")
+        if report:
+            if not isinstance(retransmits, int) or \
+                    isinstance(retransmits, bool):
+                raise ValueError("iperf3 did not report TCP retransmits")
+            receiver = "remote" if reverse else "local"
+            sender = "local" if reverse else "remote"
+            ksft_metric("throughput", avg, kind="scalar", host=receiver)
+            ksft_metric("tcp.retransmits", retransmits, kind="scalar",
+                        host=sender)

I'd be tempted to find a way to pass a callback to the class for result reporting rather than teach the class how to report. But just a thought, not sure which ends up being cleaner.

#7 lore raw

RFC v2 4/5 selftests: drv-net: add a kperf runner

In reply to Stanislav Fomichev

Add a helper to manage kperf servers, run the client, and optionally report aggregate throughput and retransmits. Use a random control port and a unique PID file, and report server cleanup failures.

---
 .../testing/selftests/drivers/net/README.rst  |   8 +
 .../drivers/net/hw/lib/py/__init__.py         |   6 +-
 .../selftests/drivers/net/lib/py/__init__.py  |   4 +-
 .../selftests/drivers/net/lib/py/kperf.py     | 161 ++++++++++++++++++
 4 files changed, 176 insertions(+), 3 deletions(-)
 create mode 100644 tools/testing/selftests/drivers/net/lib/py/kperf.py
tools/testing/selftests/drivers/net/README.rst +8 -0
index 1b7264d40b79..4355d5113ec8 100644
@@ -141,6 +141,14 @@ Arguments used to construct the communication channel.
   for netns - name of the "remote" namespace
   for ssh - name/address of the remote host
 
+kperf
+~~~~~
+
+Performance tests which use kperf expect ``kperf-client`` in ``PATH`` on the
+local host and ``kperf-server`` in ``PATH`` on both endpoints. Kperf is an
+optional dependency; tests which require it are skipped when it is not
+installed.
+
 Example
 =======
 
tools/testing/selftests/drivers/net/hw/lib/py/__init__.py +4 -2
index cd771c00c074..c3d84d0f82b9 100644
@@ -33,7 +33,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",
@@ -53,7 +54,8 @@ KSFT_DIR = (Path(__file__).parent / "../../../../..").resolve()
                "ksft_ne", "ksft_not_in", "ksft_raises", "ksft_true", "ksft_gt",
                "ksft_not_none", "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))
tools/testing/selftests/drivers/net/lib/py/__init__.py +3 -1
index 58c2877e7928..e428d0ac1a09 100644
@@ -52,11 +52,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 +161 -0

161 lines not on this page · raw message

Signature · 1 line
2.53.0-Meta
maintainer
#8 lore raw

Re: [RFC net-next v2 4/5] selftests: drv-net: add a kperf runner

Quoted 18 lines · On Mon, 5 Oct 2026 13:11:13 -0700 Stanislav Fomichev wrote:

Add a helper to manage kperf servers, run the client, and optionally report aggregate throughput and retransmits. Use a random control port and a unique PID file, and report server cleanup failures.

---
 .../testing/selftests/drivers/net/README.rst  |   8 +
 .../drivers/net/hw/lib/py/__init__.py         |   6 +-
 .../selftests/drivers/net/lib/py/__init__.py  |   4 +-
 .../selftests/drivers/net/lib/py/kperf.py     | 161 ++++++++++++++++++
 4 files changed, 176 insertions(+), 3 deletions(-)
 create mode 100644 tools/testing/selftests/drivers/net/lib/py/kperf.py
tools/testing/selftests/drivers/net/README.rst +0 -0
index 1b7264d40b79..4355d5113ec8 100644

tools/testing/selftests/drivers/net/README.rst Arguments used to construct the communication channel. · line 150

Quoted 10 lines
tools/testing/selftests/drivers/net/README.rst +7 -0
@@ -141,6 +141,14 @@ Arguments used to construct the communication channel.
   for netns - name of the "remote" namespace
   for ssh - name/address of the remote host
 
+kperf
+~~~~~
+
+Performance tests which use kperf expect ``kperf-client`` in ``PATH`` on the
+local host and ``kperf-server`` in ``PATH`` on both endpoints. Kperf is an
+optional dependency; tests which require it are skipped when it is not
+installed.

I don't think this belongs in the README.
README needs to be high signal, otherwise nobody will read. People running perf tests will quickly figure out kperf by asking LLM

#9 lore raw

RFC v2 5/5 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-policy-json: {"display_label":"Gbps","name":"throughput","regression":{"better":"higher","compare":"p50","relative_tolerance":0.05},"summarize":"p50"} # # ktap-metric-policy-json: {"name":"tcp.retransmits","summarize":"max"}
# # ktap-metric-json: {"host":"remote","name":"throughput","time":29.786267,"type":"scalar","value":389.29900000000004}
# # ktap-metric-json: {"host":"remote","name":"tcp.retransmits","time":29.786286,"type":"scalar","value":698}
# # ktap-metric-json: {"host":"local","name":"throughput","time":29.786289,"type":"scalar","value":388.772}
# # ktap-metric-json: {"host":"local","name":"tcp.retransmits","time":29.78629,"type":"scalar","value":0}

---
 .../drivers/net/hw/performance/Makefile       |  5 +-
 .../drivers/net/hw/performance/config         |  3 +
 .../drivers/net/hw/performance/devmem.py      | 99 +++++++++++++++++++
 3 files changed, 106 insertions(+), 1 deletion(-)
 create mode 100755 tools/testing/selftests/drivers/net/hw/performance/devmem.py
tools/testing/selftests/drivers/net/hw/performance/Makefile +4 -1
index 5d53ef548306..27afdace92e6 100644
@@ -1,6 +1,9 @@
 # SPDX-License-Identifier: GPL-2.0
 
-TEST_PROGS := iperf.py
+TEST_PROGS := \
+	devmem.py \
+	iperf.py \
+	#
 
 TEST_INCLUDES := \
 	$(wildcard ../lib/py/*.py ../../lib/py/*.py) \
tools/testing/selftests/drivers/net/hw/performance/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/hw/performance/devmem.py new file +99 -0

99 lines not on this page · raw message

Signature · 1 line
2.53.0-Meta