Skip to content

Commit cc17b4b

Browse files
committed
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>
2 parents 4acf6d4 + 5c3524b commit cc17b4b

File tree

1 file changed

+82
-40
lines changed

1 file changed

+82
-40
lines changed

tools/testing/selftests/drivers/net/hw/iou-zcrx.py

Lines changed: 82 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
from os import path
66
from lib.py import ksft_run, ksft_exit
77
from lib.py import NetDrvEpEnv
8-
from lib.py import bkg, cmd, ethtool, wait_port_listen
8+
from lib.py import bkg, cmd, defer, ethtool, wait_port_listen
99

1010

11-
def _get_rx_ring_entries(cfg):
11+
def _get_current_settings(cfg):
1212
output = ethtool(f"-g {cfg.ifname}", host=cfg.remote).stdout
13-
values = re.findall(r'RX:\s+(\d+)', output)
14-
return int(values[1])
13+
rx_ring = re.findall(r'RX:\s+(\d+)', output)
14+
hds_thresh = re.findall(r'HDS thresh:\s+(\d+)', output)
15+
return (int(rx_ring[1]), int(hds_thresh[1]))
1516

1617

1718
def _get_combined_channels(cfg):
@@ -20,36 +21,49 @@ def _get_combined_channels(cfg):
2021
return int(values[1])
2122

2223

24+
def _create_rss_ctx(cfg, chans):
25+
output = ethtool(f"-X {cfg.ifname} context new start {chans - 1} equal 1", host=cfg.remote).stdout
26+
values = re.search(r'New RSS context is (\d+)', output).group(1)
27+
ctx_id = int(values)
28+
return (ctx_id, defer(ethtool, f"-X {cfg.ifname} delete context {ctx_id}", host=cfg.remote))
29+
30+
2331
def _set_flow_rule(cfg, chan):
2432
output = ethtool(f"-N {cfg.ifname} flow-type tcp6 dst-port 9999 action {chan}", host=cfg.remote).stdout
2533
values = re.search(r'ID (\d+)', output).group(1)
2634
return int(values)
2735

2836

37+
def _set_flow_rule_rss(cfg, chan):
38+
output = ethtool(f"-N {cfg.ifname} flow-type tcp6 dst-port 9999 action {chan}", host=cfg.remote).stdout
39+
values = re.search(r'ID (\d+)', output).group(1)
40+
return int(values)
41+
42+
2943
def test_zcrx(cfg) -> None:
3044
cfg.require_ipver('6')
3145

3246
combined_chans = _get_combined_channels(cfg)
3347
if combined_chans < 2:
3448
raise KsftSkipEx('at least 2 combined channels required')
35-
rx_ring = _get_rx_ring_entries(cfg)
36-
37-
try:
38-
ethtool(f"-G {cfg.ifname} tcp-data-split on", host=cfg.remote)
39-
ethtool(f"-G {cfg.ifname} rx 64", host=cfg.remote)
40-
ethtool(f"-X {cfg.ifname} equal {combined_chans - 1}", host=cfg.remote)
41-
flow_rule_id = _set_flow_rule(cfg, combined_chans - 1)
42-
43-
rx_cmd = f"{cfg.bin_remote} -s -p 9999 -i {cfg.ifname} -q {combined_chans - 1}"
44-
tx_cmd = f"{cfg.bin_local} -c -h {cfg.remote_addr_v['6']} -p 9999 -l 12840"
45-
with bkg(rx_cmd, host=cfg.remote, exit_wait=True):
46-
wait_port_listen(9999, proto="tcp", host=cfg.remote)
47-
cmd(tx_cmd)
48-
finally:
49-
ethtool(f"-N {cfg.ifname} delete {flow_rule_id}", host=cfg.remote)
50-
ethtool(f"-X {cfg.ifname} default", host=cfg.remote)
51-
ethtool(f"-G {cfg.ifname} rx {rx_ring}", host=cfg.remote)
52-
ethtool(f"-G {cfg.ifname} tcp-data-split auto", host=cfg.remote)
49+
(rx_ring, hds_thresh) = _get_current_settings(cfg)
50+
51+
ethtool(f"-G {cfg.ifname} tcp-data-split on", host=cfg.remote)
52+
defer(ethtool, f"-G {cfg.ifname} tcp-data-split auto", host=cfg.remote)
53+
ethtool(f"-G {cfg.ifname} hds-thresh 0", host=cfg.remote)
54+
defer(ethtool, f"-G {cfg.ifname} hds-thresh {hds_thresh}", host=cfg.remote)
55+
ethtool(f"-G {cfg.ifname} rx 64", host=cfg.remote)
56+
defer(ethtool, f"-G {cfg.ifname} rx {rx_ring}", host=cfg.remote)
57+
ethtool(f"-X {cfg.ifname} equal {combined_chans - 1}", host=cfg.remote)
58+
defer(ethtool, f"-X {cfg.ifname} default", host=cfg.remote)
59+
flow_rule_id = _set_flow_rule(cfg, combined_chans - 1)
60+
defer(ethtool, f"-N {cfg.ifname} delete {flow_rule_id}", host=cfg.remote)
61+
62+
rx_cmd = f"{cfg.bin_remote} -s -p 9999 -i {cfg.ifname} -q {combined_chans - 1}"
63+
tx_cmd = f"{cfg.bin_local} -c -h {cfg.remote_addr_v['6']} -p 9999 -l 12840"
64+
with bkg(rx_cmd, host=cfg.remote, exit_wait=True):
65+
wait_port_listen(9999, proto="tcp", host=cfg.remote)
66+
cmd(tx_cmd)
5367

5468

5569
def test_zcrx_oneshot(cfg) -> None:
@@ -58,24 +72,52 @@ def test_zcrx_oneshot(cfg) -> None:
5872
combined_chans = _get_combined_channels(cfg)
5973
if combined_chans < 2:
6074
raise KsftSkipEx('at least 2 combined channels required')
61-
rx_ring = _get_rx_ring_entries(cfg)
62-
63-
try:
64-
ethtool(f"-G {cfg.ifname} tcp-data-split on", host=cfg.remote)
65-
ethtool(f"-G {cfg.ifname} rx 64", host=cfg.remote)
66-
ethtool(f"-X {cfg.ifname} equal {combined_chans - 1}", host=cfg.remote)
67-
flow_rule_id = _set_flow_rule(cfg, combined_chans - 1)
68-
69-
rx_cmd = f"{cfg.bin_remote} -s -p 9999 -i {cfg.ifname} -q {combined_chans - 1} -o 4"
70-
tx_cmd = f"{cfg.bin_local} -c -h {cfg.remote_addr_v['6']} -p 9999 -l 4096 -z 16384"
71-
with bkg(rx_cmd, host=cfg.remote, exit_wait=True):
72-
wait_port_listen(9999, proto="tcp", host=cfg.remote)
73-
cmd(tx_cmd)
74-
finally:
75-
ethtool(f"-N {cfg.ifname} delete {flow_rule_id}", host=cfg.remote)
76-
ethtool(f"-X {cfg.ifname} default", host=cfg.remote)
77-
ethtool(f"-G {cfg.ifname} rx {rx_ring}", host=cfg.remote)
78-
ethtool(f"-G {cfg.ifname} tcp-data-split auto", host=cfg.remote)
75+
(rx_ring, hds_thresh) = _get_current_settings(cfg)
76+
77+
ethtool(f"-G {cfg.ifname} tcp-data-split on", host=cfg.remote)
78+
defer(ethtool, f"-G {cfg.ifname} tcp-data-split auto", host=cfg.remote)
79+
ethtool(f"-G {cfg.ifname} hds-thresh 0", host=cfg.remote)
80+
defer(ethtool, f"-G {cfg.ifname} hds-thresh {hds_thresh}", host=cfg.remote)
81+
ethtool(f"-G {cfg.ifname} rx 64", host=cfg.remote)
82+
defer(ethtool, f"-G {cfg.ifname} rx {rx_ring}", host=cfg.remote)
83+
ethtool(f"-X {cfg.ifname} equal {combined_chans - 1}", host=cfg.remote)
84+
defer(ethtool, f"-X {cfg.ifname} default", host=cfg.remote)
85+
flow_rule_id = _set_flow_rule(cfg, combined_chans - 1)
86+
defer(ethtool, f"-N {cfg.ifname} delete {flow_rule_id}", host=cfg.remote)
87+
88+
rx_cmd = f"{cfg.bin_remote} -s -p 9999 -i {cfg.ifname} -q {combined_chans - 1} -o 4"
89+
tx_cmd = f"{cfg.bin_local} -c -h {cfg.remote_addr_v['6']} -p 9999 -l 4096 -z 16384"
90+
with bkg(rx_cmd, host=cfg.remote, exit_wait=True):
91+
wait_port_listen(9999, proto="tcp", host=cfg.remote)
92+
cmd(tx_cmd)
93+
94+
95+
def test_zcrx_rss(cfg) -> None:
96+
cfg.require_ipver('6')
97+
98+
combined_chans = _get_combined_channels(cfg)
99+
if combined_chans < 2:
100+
raise KsftSkipEx('at least 2 combined channels required')
101+
(rx_ring, hds_thresh) = _get_current_settings(cfg)
102+
103+
ethtool(f"-G {cfg.ifname} tcp-data-split on", host=cfg.remote)
104+
defer(ethtool, f"-G {cfg.ifname} tcp-data-split auto", host=cfg.remote)
105+
ethtool(f"-G {cfg.ifname} hds-thresh 0", host=cfg.remote)
106+
defer(ethtool, f"-G {cfg.ifname} hds-thresh {hds_thresh}", host=cfg.remote)
107+
ethtool(f"-G {cfg.ifname} rx 64", host=cfg.remote)
108+
defer(ethtool, f"-G {cfg.ifname} rx {rx_ring}", host=cfg.remote)
109+
ethtool(f"-X {cfg.ifname} equal {combined_chans - 1}", host=cfg.remote)
110+
defer(ethtool, f"-X {cfg.ifname} default", host=cfg.remote)
111+
112+
(ctx_id, delete_ctx) = _create_rss_ctx(cfg, combined_chans)
113+
flow_rule_id = _set_flow_rule_rss(cfg, ctx_id)
114+
defer(ethtool, f"-N {cfg.ifname} delete {flow_rule_id}", host=cfg.remote)
115+
116+
rx_cmd = f"{cfg.bin_remote} -s -p 9999 -i {cfg.ifname} -q {combined_chans - 1}"
117+
tx_cmd = f"{cfg.bin_local} -c -h {cfg.remote_addr_v['6']} -p 9999 -l 12840"
118+
with bkg(rx_cmd, host=cfg.remote, exit_wait=True):
119+
wait_port_listen(9999, proto="tcp", host=cfg.remote)
120+
cmd(tx_cmd)
79121

80122

81123
def main() -> None:

0 commit comments

Comments
 (0)