Merge branch 'io_uring-zcrx-fix-selftests-and-add-new-test-for-rss-ctx'

David Wei says:

====================
io_uring/zcrx: fix selftests and add new test for rss ctx

Update io_uring zero copy receive selftest. Patch 1 does a requested
cleanup to use defer() for undoing ethtool actions during the test and
restoring the NIC under test back to its original state.

Patch 2 adds a required call to set hds_thresh to 0. This is needed for
the queue API.

Patch 3 adds a new test case for steering into RSS contexts. A real
application using io_uring zero copy receive relies on this working to
shard work across multiple queues. There seems to be some
differences/bugs with steering into RSS contexts and individual queues.
====================

Link: https://patch.msgid.link/20250425022049.3474590-1-dw@davidwei.uk
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Jakub Kicinski 2025-04-25 18:44:11 -07:00
commit cc17b4b9c3

View File

@ -5,13 +5,14 @@ import re
from os import path
from lib.py import ksft_run, ksft_exit
from lib.py import NetDrvEpEnv
from lib.py import bkg, cmd, ethtool, wait_port_listen
from lib.py import bkg, cmd, defer, ethtool, wait_port_listen
def _get_rx_ring_entries(cfg):
def _get_current_settings(cfg):
output = ethtool(f"-g {cfg.ifname}", host=cfg.remote).stdout
values = re.findall(r'RX:\s+(\d+)', output)
return int(values[1])
rx_ring = re.findall(r'RX:\s+(\d+)', output)
hds_thresh = re.findall(r'HDS thresh:\s+(\d+)', output)
return (int(rx_ring[1]), int(hds_thresh[1]))
def _get_combined_channels(cfg):
@ -20,36 +21,49 @@ def _get_combined_channels(cfg):
return int(values[1])
def _create_rss_ctx(cfg, chans):
output = ethtool(f"-X {cfg.ifname} context new start {chans - 1} equal 1", host=cfg.remote).stdout
values = re.search(r'New RSS context is (\d+)', output).group(1)
ctx_id = int(values)
return (ctx_id, defer(ethtool, f"-X {cfg.ifname} delete context {ctx_id}", host=cfg.remote))
def _set_flow_rule(cfg, chan):
output = ethtool(f"-N {cfg.ifname} flow-type tcp6 dst-port 9999 action {chan}", host=cfg.remote).stdout
values = re.search(r'ID (\d+)', output).group(1)
return int(values)
def _set_flow_rule_rss(cfg, chan):
output = ethtool(f"-N {cfg.ifname} flow-type tcp6 dst-port 9999 action {chan}", host=cfg.remote).stdout
values = re.search(r'ID (\d+)', output).group(1)
return int(values)
def test_zcrx(cfg) -> None:
cfg.require_ipver('6')
combined_chans = _get_combined_channels(cfg)
if combined_chans < 2:
raise KsftSkipEx('at least 2 combined channels required')
rx_ring = _get_rx_ring_entries(cfg)
(rx_ring, hds_thresh) = _get_current_settings(cfg)
try:
ethtool(f"-G {cfg.ifname} tcp-data-split on", host=cfg.remote)
ethtool(f"-G {cfg.ifname} rx 64", host=cfg.remote)
ethtool(f"-X {cfg.ifname} equal {combined_chans - 1}", host=cfg.remote)
flow_rule_id = _set_flow_rule(cfg, combined_chans - 1)
ethtool(f"-G {cfg.ifname} tcp-data-split on", host=cfg.remote)
defer(ethtool, f"-G {cfg.ifname} tcp-data-split auto", host=cfg.remote)
ethtool(f"-G {cfg.ifname} hds-thresh 0", host=cfg.remote)
defer(ethtool, f"-G {cfg.ifname} hds-thresh {hds_thresh}", host=cfg.remote)
ethtool(f"-G {cfg.ifname} rx 64", host=cfg.remote)
defer(ethtool, f"-G {cfg.ifname} rx {rx_ring}", host=cfg.remote)
ethtool(f"-X {cfg.ifname} equal {combined_chans - 1}", host=cfg.remote)
defer(ethtool, f"-X {cfg.ifname} default", host=cfg.remote)
flow_rule_id = _set_flow_rule(cfg, combined_chans - 1)
defer(ethtool, f"-N {cfg.ifname} delete {flow_rule_id}", host=cfg.remote)
rx_cmd = f"{cfg.bin_remote} -s -p 9999 -i {cfg.ifname} -q {combined_chans - 1}"
tx_cmd = f"{cfg.bin_local} -c -h {cfg.remote_addr_v['6']} -p 9999 -l 12840"
with bkg(rx_cmd, host=cfg.remote, exit_wait=True):
wait_port_listen(9999, proto="tcp", host=cfg.remote)
cmd(tx_cmd)
finally:
ethtool(f"-N {cfg.ifname} delete {flow_rule_id}", host=cfg.remote)
ethtool(f"-X {cfg.ifname} default", host=cfg.remote)
ethtool(f"-G {cfg.ifname} rx {rx_ring}", host=cfg.remote)
ethtool(f"-G {cfg.ifname} tcp-data-split auto", host=cfg.remote)
rx_cmd = f"{cfg.bin_remote} -s -p 9999 -i {cfg.ifname} -q {combined_chans - 1}"
tx_cmd = f"{cfg.bin_local} -c -h {cfg.remote_addr_v['6']} -p 9999 -l 12840"
with bkg(rx_cmd, host=cfg.remote, exit_wait=True):
wait_port_listen(9999, proto="tcp", host=cfg.remote)
cmd(tx_cmd)
def test_zcrx_oneshot(cfg) -> None:
@ -58,24 +72,52 @@ def test_zcrx_oneshot(cfg) -> None:
combined_chans = _get_combined_channels(cfg)
if combined_chans < 2:
raise KsftSkipEx('at least 2 combined channels required')
rx_ring = _get_rx_ring_entries(cfg)
(rx_ring, hds_thresh) = _get_current_settings(cfg)
try:
ethtool(f"-G {cfg.ifname} tcp-data-split on", host=cfg.remote)
ethtool(f"-G {cfg.ifname} rx 64", host=cfg.remote)
ethtool(f"-X {cfg.ifname} equal {combined_chans - 1}", host=cfg.remote)
flow_rule_id = _set_flow_rule(cfg, combined_chans - 1)
ethtool(f"-G {cfg.ifname} tcp-data-split on", host=cfg.remote)
defer(ethtool, f"-G {cfg.ifname} tcp-data-split auto", host=cfg.remote)
ethtool(f"-G {cfg.ifname} hds-thresh 0", host=cfg.remote)
defer(ethtool, f"-G {cfg.ifname} hds-thresh {hds_thresh}", host=cfg.remote)
ethtool(f"-G {cfg.ifname} rx 64", host=cfg.remote)
defer(ethtool, f"-G {cfg.ifname} rx {rx_ring}", host=cfg.remote)
ethtool(f"-X {cfg.ifname} equal {combined_chans - 1}", host=cfg.remote)
defer(ethtool, f"-X {cfg.ifname} default", host=cfg.remote)
flow_rule_id = _set_flow_rule(cfg, combined_chans - 1)
defer(ethtool, f"-N {cfg.ifname} delete {flow_rule_id}", host=cfg.remote)
rx_cmd = f"{cfg.bin_remote} -s -p 9999 -i {cfg.ifname} -q {combined_chans - 1} -o 4"
tx_cmd = f"{cfg.bin_local} -c -h {cfg.remote_addr_v['6']} -p 9999 -l 4096 -z 16384"
with bkg(rx_cmd, host=cfg.remote, exit_wait=True):
wait_port_listen(9999, proto="tcp", host=cfg.remote)
cmd(tx_cmd)
finally:
ethtool(f"-N {cfg.ifname} delete {flow_rule_id}", host=cfg.remote)
ethtool(f"-X {cfg.ifname} default", host=cfg.remote)
ethtool(f"-G {cfg.ifname} rx {rx_ring}", host=cfg.remote)
ethtool(f"-G {cfg.ifname} tcp-data-split auto", host=cfg.remote)
rx_cmd = f"{cfg.bin_remote} -s -p 9999 -i {cfg.ifname} -q {combined_chans - 1} -o 4"
tx_cmd = f"{cfg.bin_local} -c -h {cfg.remote_addr_v['6']} -p 9999 -l 4096 -z 16384"
with bkg(rx_cmd, host=cfg.remote, exit_wait=True):
wait_port_listen(9999, proto="tcp", host=cfg.remote)
cmd(tx_cmd)
def test_zcrx_rss(cfg) -> None:
cfg.require_ipver('6')
combined_chans = _get_combined_channels(cfg)
if combined_chans < 2:
raise KsftSkipEx('at least 2 combined channels required')
(rx_ring, hds_thresh) = _get_current_settings(cfg)
ethtool(f"-G {cfg.ifname} tcp-data-split on", host=cfg.remote)
defer(ethtool, f"-G {cfg.ifname} tcp-data-split auto", host=cfg.remote)
ethtool(f"-G {cfg.ifname} hds-thresh 0", host=cfg.remote)
defer(ethtool, f"-G {cfg.ifname} hds-thresh {hds_thresh}", host=cfg.remote)
ethtool(f"-G {cfg.ifname} rx 64", host=cfg.remote)
defer(ethtool, f"-G {cfg.ifname} rx {rx_ring}", host=cfg.remote)
ethtool(f"-X {cfg.ifname} equal {combined_chans - 1}", host=cfg.remote)
defer(ethtool, f"-X {cfg.ifname} default", host=cfg.remote)
(ctx_id, delete_ctx) = _create_rss_ctx(cfg, combined_chans)
flow_rule_id = _set_flow_rule_rss(cfg, ctx_id)
defer(ethtool, f"-N {cfg.ifname} delete {flow_rule_id}", host=cfg.remote)
rx_cmd = f"{cfg.bin_remote} -s -p 9999 -i {cfg.ifname} -q {combined_chans - 1}"
tx_cmd = f"{cfg.bin_local} -c -h {cfg.remote_addr_v['6']} -p 9999 -l 12840"
with bkg(rx_cmd, host=cfg.remote, exit_wait=True):
wait_port_listen(9999, proto="tcp", host=cfg.remote)
cmd(tx_cmd)
def main() -> None: