selftest: net: Add selftest for netpoll
Subsystems (4)
v6 cover selftest: net: Add selftest for netpoll
I am submitting a new selftest for the netpoll subsystem specifically targeting the case where the RX is polling in the TX path, which is a case that we don't have any test in the tree today. This is done when netpoll_poll_dev() called, and this test creates a scenario when that is probably.
The test does the following:
1) Configuring a single RX/TX queue to increase contention on the interface.
2) Generating background traffic to saturate the network, mimicking real-world congestion.
3) Sending netconsole messages to trigger netpoll polling and monitor its behavior.
4) Using dynamic netconsole targets via configfs, with the ability to delete and recreate targets during the test.
5) Running bpftrace in parallel to verify that netpoll_poll_dev() is called when expected. If it is called, then the test passes, otherwise the test is marked as skipped.
In order to achieve it, I stole Jakub's bpftrace helper from [1], and did some small changes that I found useful to use the helper.
So, this patchset basically contains:
1) The code stolen from Jakub
2) Improvements on bpftrace() helper
3) The selftest itself
---
Changes in v6:
- Remove the network toggled (Jakub)
- Set ringsize and queue size (Jakub)
- Some other general improvements (Jakub)
- Link to v5: https://lore.kernel.org/r/[email protected]
Changes in v5:
- Rebased on top of net-next.
- Calling bpftrace_stop using the defer helper. (Willem)
- Link to v4: https://lore.kernel.org/r/[email protected]
Changes in v4:
- Make the test XFail if it doesn't hit the function we are looking for
- Toggle the interface while the traffic is flowing.
- Bumped the number of messages from 10 to 40 per iterations.
* This is hitting ~15 times per run on my vng test.
- Decreased the time from 15 seconds to 10 seconds, given that if
it didn't hit the function in 10 seconds, 5 seconds extra will not
help.
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- Make pylint happy (Simon)
- Remove the unnecessary patch in bpftrace to raise an exception when it fails. (Jakub)
- Improved the bpftrace code (Willem)
- Stop sending messages if bpftrace is not alive anymore.
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Stole Jakub's helper to run bpftrace
- Removed the DEBUG option and moved logs to logging
- Change the code to have a higher chance of calling netpoll_poll_dev().
In my current configuration, it is hitting multiple times during the test.
- Save and restore TX/RX queue size (Jakub)
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Breno Leitao (2):
selftests: drv-net: Strip '@' prefix from bpftrace map keys
selftests: net: add netpoll basic functionality test
Jakub Kicinski (1):
selftests: drv-net: add helper/wrapper for bpftrace
tools/testing/selftests/drivers/net/Makefile | 1 + .../selftests/drivers/net/lib/py/__init__.py | 3 +- .../testing/selftests/drivers/net/netpoll_basic.py | 411 +++++++++++++++++++++ tools/testing/selftests/net/lib/py/utils.py | 35 ++ 4 files changed, 449 insertions(+), 1 deletion(-)
---
base-commit: 0f26870a989bf69957ed69d10c7ffc57ca5a7f52
change-id: 20250612-netpoll_test-a1324d2057c8
Best regards,
Signature · 1 line
Breno Leitao <[email protected]>
PATCH v6 1/3 selftests: drv-net: add helper/wrapper for bpftrace
From: Jakub Kicinski <[email protected]>
bpftrace is very useful for low level driver testing. perf or trace-cmd would also do for collecting data from tracepoints, but they require much more post-processing.
Add a wrapper for running bpftrace and sanitizing its output. bpftrace has JSON output, which is great, but it prints loose objects and in a slightly inconvenient format. We have to read the objects line by line, and while at it return them indexed by the map name.
--- .../selftests/drivers/net/lib/py/__init__.py | 3 +- tools/testing/selftests/net/lib/py/utils.py | 33 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-)
tools/testing/selftests/drivers/net/lib/py/__init__.py +2 -1
@@ -14,7 +14,8 @@ try: from net.lib.py import EthtoolFamily, NetdevFamily, NetshaperFamily, \ NlError, RtnlFamily, DevlinkFamily from net.lib.py import CmdExitFailure - from net.lib.py import bkg, cmd, defer, ethtool, fd_read_timeout, ip, \ + from net.lib.py import bkg, cmd, bpftrace, defer, ethtool, \ + fd_read_timeout, ip, \ rand_port, tool, wait_port_listen from net.lib.py import fd_read_timeout from net.lib.py import KsftSkipEx, KsftFailEx, KsftXfailEx
tools/testing/selftests/net/lib/py/utils.py +33 -0
@@ -185,6 +185,39 @@ def ethtool(args, json=None, ns=None, host=None): return tool('ethtool', args, json=json, ns=ns, host=host) +def bpftrace(expr, json=None, ns=None, host=None, timeout=None): + """ + Run bpftrace and return map data (if json=True). + The output of bpftrace is inconvenient, so the helper converts + to a dict indexed by map name, e.g.: + { + "@": { ... }, + "@map2": { ... }, + } + """ + cmd_arr = ['bpftrace'] + # Throw in --quiet if json, otherwise the output has two objects + if json: + cmd_arr += ['-f', 'json', '-q'] + if timeout: + expr += ' interval:s:' + str(timeout) + ' { exit(); }' + cmd_arr += ['-e', expr] + cmd_obj = cmd(cmd_arr, ns=ns, host=host, shell=False) + if json: + # bpftrace prints objects as lines + ret = {} + for l in cmd_obj.stdout.split('\n'): + if not l.strip(): + continue + one = _json.loads(l) + if one.get('type') != 'map': + continue + for k, v in one["data"].items(): + ret[k] = v + return ret + return cmd_obj + + def rand_port(type=socket.SOCK_STREAM): """ Get a random unprivileged port.
Signature · 1 line
2.47.1
PATCH v6 2/3 selftests: drv-net: Strip '@' prefix from bpftrace map keys
In reply to Breno LeitaoThe '@' prefix in bpftrace map keys is specific to bpftrace and can be safely removed when processing results. This patch modifies the bpftrace utility to strip the '@' from map keys before storing them in the result dictionary, making the keys more consistent with Python conventions.
--- tools/testing/selftests/net/lib/py/utils.py | 2 ++ 1 file changed, 2 insertions(+)
tools/testing/selftests/net/lib/py/utils.py +2 -0
@@ -213,6 +213,8 @@ def bpftrace(expr, json=None, ns=None, host=None, timeout=None): if one.get('type') != 'map': continue for k, v in one["data"].items(): + if k.startswith('@'): + k = k.lstrip('@') ret[k] = v return ret return cmd_obj
Signature · 1 line
2.47.1
PATCH v6 3/3 selftests: net: add netpoll basic functionality test
In reply to Breno LeitaoAdd a basic selftest for the netpoll polling mechanism, specifically targeting the netpoll poll() side.
The test creates a scenario where network transmission is running at maximum speed, and netpoll needs to poll the NIC. This is achieved by:
1. Configuring a single RX/TX queue to create contention
2. Generating background traffic to saturate the interface
3. Sending netconsole messages to trigger netpoll polling
4. Using dynamic netconsole targets via configfs
5. Delete and create new netconsole targets after some messages
6. Start a bpftrace in parallel to make sure netpoll_poll_dev() is called
7. If bpftrace exists and netpoll_poll_dev() was called, stop.
The test validates a critical netpoll code path by monitoring traffic flow and ensuring netpoll_poll_dev() is called when the normal TX path is blocked.
This addresses a gap in netpoll test coverage for a path that is tricky for the network stack.
--- tools/testing/selftests/drivers/net/Makefile | 1 + .../testing/selftests/drivers/net/netpoll_basic.py | 411 +++++++++++++++++++++ 2 files changed, 412 insertions(+)
tools/testing/selftests/drivers/net/Makefile +1 -0
@@ -16,6 +16,7 @@ TEST_PROGS := \ netcons_fragmented_msg.sh \ netcons_overflow.sh \ netcons_sysdata.sh \ + netpoll_basic.py \ ping.py \ queues.py \ stats.py \
tools/testing/selftests/drivers/net/netpoll_basic.py new file +411 -0
411 lines not on this page · raw message
Signature · 1 line
2.47.1
Jakub Kicinski
maintainerRe: [PATCH net-next v6 3/3] selftests: net: add netpoll basic functionality test
tools/testing/selftests/drivers/net/netpoll_basic.py line 83
Quoted 2 lines · On Fri, 11 Jul 2025 09:05:11 -0700 Breno Leitao wrote:
tools/testing/selftests/drivers/net/netpoll_basic.py new file +2
-0+ rxq = ethtool_result["rx"] + txq = ethtool_result["tx"]
Most HW NICs will actually use the "combined" channels (which have both rx and tx ring on one NAPI).
Quoted 1 line
+
logging.debug("calling: ethtool %s", cmdline)
ksft_pr() ?
We had a plan to add a verbose() helper which would still be TAP-compatible, but never finished the patches.
Either way, would you mind respinning the series (without the 24h wait)? It conflicts with another series which adds a bpftool() helper. I applied that patch so you should see a trivial conflict when rebasing.
Re: [PATCH net-next v6 3/3] selftests: net: add netpoll basic functionality test
Hello Jakub,
Quoted 6 lines · Jakub Kicinski
tools/testing/selftests/drivers/net/netpoll_basic.py line 83
Quoted 2 lines · On Fri, 11 Jul 2025 09:05:11 -0700 Breno Leitao wrote:
tools/testing/selftests/drivers/net/netpoll_basic.py new file +2
-0+ rxq = ethtool_result["rx"] + txq = ethtool_result["tx"]Most HW NICs will actually use the "combined" channels (which have both rx and tx ring on one NAPI).
Right. I am getting combined as well. With the JSON output in ethtool, I get;
ethtool_result = ethtool(f"-l {interface_name}", json=True)[0] rxq = ethtool_result.get("rx", -1)
txq = ethtool_result.get("tx", -1)
combined = ethtool_result.get("combined", -1)
Quoted 3 lines
Quoted 1 line
+
logging.debug("calling: ethtool %s", cmdline)
ksft_pr()?
ksft_pr() would make it very verbose. logging.debug() is always disabled, so, the selftest executes cleanly.
Quoted 2 lines
We had a plan to add a
verbose()helper which would still be TAP-compatible, but never finished the patches.
I can try to help. How do you want to set verbose during the test execution? Any shell environment variable?
Quoted 3 lines
Either way, would you mind respinning the series (without the 24h wait)? It conflicts with another series which adds a
bpftool()helper. I applied that patch so you should see a trivial conflict when rebasing.
Thanks. I am sending a new version assuming ethtool -l has the json option. That would make the code simpler, given we don't need that hacky to_int().
Thanks for the review,
--breno