Skip to content

Commit a32bb32

Browse files
committed
selftests: iou-zcrx: test large chunk sizes
Add a test using large chunks for zcrx memory area. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
1 parent f96e1b3 commit a32bb32

2 files changed

Lines changed: 99 additions & 12 deletions

File tree

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

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <unistd.h>
1313

1414
#include <arpa/inet.h>
15+
#include <linux/mman.h>
1516
#include <linux/errqueue.h>
1617
#include <linux/if_packet.h>
1718
#include <linux/ipv6.h>
@@ -37,6 +38,23 @@
3738

3839
#include <liburing.h>
3940

41+
#define SKIP_CODE 42
42+
43+
struct t_io_uring_zcrx_ifq_reg {
44+
__u32 if_idx;
45+
__u32 if_rxq;
46+
__u32 rq_entries;
47+
__u32 flags;
48+
49+
__u64 area_ptr; /* pointer to struct io_uring_zcrx_area_reg */
50+
__u64 region_ptr; /* struct io_uring_region_desc * */
51+
52+
struct io_uring_zcrx_offsets offsets;
53+
__u32 zcrx_id;
54+
__u32 rx_buf_len;
55+
__u64 __resv[3];
56+
};
57+
4058
static long page_size;
4159
#define AREA_SIZE (8192 * page_size)
4260
#define SEND_SIZE (512 * 4096)
@@ -65,6 +83,8 @@ static bool cfg_oneshot;
6583
static int cfg_oneshot_recvs;
6684
static int cfg_send_size = SEND_SIZE;
6785
static struct sockaddr_in6 cfg_addr;
86+
static unsigned int cfg_rx_buf_len;
87+
static bool cfg_dry_run;
6888

6989
static char *payload;
7090
static void *area_ptr;
@@ -128,14 +148,28 @@ static void setup_zcrx(struct io_uring *ring)
128148
if (!ifindex)
129149
error(1, 0, "bad interface name: %s", cfg_ifname);
130150

131-
area_ptr = mmap(NULL,
132-
AREA_SIZE,
133-
PROT_READ | PROT_WRITE,
134-
MAP_ANONYMOUS | MAP_PRIVATE,
135-
0,
136-
0);
137-
if (area_ptr == MAP_FAILED)
138-
error(1, 0, "mmap(): zero copy area");
151+
if (cfg_rx_buf_len && cfg_rx_buf_len != page_size) {
152+
area_ptr = mmap(NULL,
153+
AREA_SIZE,
154+
PROT_READ | PROT_WRITE,
155+
MAP_ANONYMOUS | MAP_PRIVATE |
156+
MAP_HUGETLB | MAP_HUGE_2MB,
157+
-1,
158+
0);
159+
if (area_ptr == MAP_FAILED) {
160+
printf("Can't allocate huge pages\n");
161+
exit(SKIP_CODE);
162+
}
163+
} else {
164+
area_ptr = mmap(NULL,
165+
AREA_SIZE,
166+
PROT_READ | PROT_WRITE,
167+
MAP_ANONYMOUS | MAP_PRIVATE,
168+
0,
169+
0);
170+
if (area_ptr == MAP_FAILED)
171+
error(1, 0, "mmap(): zero copy area");
172+
}
139173

140174
ring_size = get_refill_ring_size(rq_entries);
141175
ring_ptr = mmap(NULL,
@@ -157,17 +191,23 @@ static void setup_zcrx(struct io_uring *ring)
157191
.flags = 0,
158192
};
159193

160-
struct io_uring_zcrx_ifq_reg reg = {
194+
struct t_io_uring_zcrx_ifq_reg reg = {
161195
.if_idx = ifindex,
162196
.if_rxq = cfg_queue_id,
163197
.rq_entries = rq_entries,
164198
.area_ptr = (__u64)(unsigned long)&area_reg,
165199
.region_ptr = (__u64)(unsigned long)&region_reg,
200+
.rx_buf_len = cfg_rx_buf_len,
166201
};
167202

168-
ret = io_uring_register_ifq(ring, &reg);
169-
if (ret)
203+
ret = io_uring_register_ifq(ring, (void *)&reg);
204+
if (cfg_rx_buf_len && (ret == -EINVAL || ret == -EOPNOTSUPP ||
205+
ret == -ERANGE)) {
206+
printf("Large chunks are not supported %i\n", ret);
207+
exit(SKIP_CODE);
208+
} else if (ret) {
170209
error(1, 0, "io_uring_register_ifq(): %d", ret);
210+
}
171211

172212
rq_ring.khead = (unsigned int *)((char *)ring_ptr + reg.offsets.head);
173213
rq_ring.ktail = (unsigned int *)((char *)ring_ptr + reg.offsets.tail);
@@ -323,6 +363,8 @@ static void run_server(void)
323363
io_uring_queue_init(512, &ring, flags);
324364

325365
setup_zcrx(&ring);
366+
if (cfg_dry_run)
367+
return;
326368

327369
add_accept(&ring, fd);
328370

@@ -383,7 +425,7 @@ static void parse_opts(int argc, char **argv)
383425
usage(argv[0]);
384426
cfg_payload_len = max_payload_len;
385427

386-
while ((c = getopt(argc, argv, "sch:p:l:i:q:o:z:")) != -1) {
428+
while ((c = getopt(argc, argv, "sch:p:l:i:q:o:z:x:d")) != -1) {
387429
switch (c) {
388430
case 's':
389431
if (cfg_client)
@@ -418,6 +460,12 @@ static void parse_opts(int argc, char **argv)
418460
case 'z':
419461
cfg_send_size = strtoul(optarg, NULL, 0);
420462
break;
463+
case 'x':
464+
cfg_rx_buf_len = page_size * strtoul(optarg, NULL, 0);
465+
break;
466+
case 'd':
467+
cfg_dry_run = true;
468+
break;
421469
}
422470
}
423471

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from lib.py import NetDrvEpEnv
88
from lib.py import bkg, cmd, defer, ethtool, rand_port, wait_port_listen
99

10+
SKIP_CODE = 42
1011

1112
def _get_current_settings(cfg):
1213
output = ethtool(f"-g {cfg.ifname}", json=True)[0]
@@ -132,6 +133,44 @@ def test_zcrx_rss(cfg) -> None:
132133
cmd(tx_cmd, host=cfg.remote)
133134

134135

136+
def test_zcrx_large_chunks(cfg) -> None:
137+
"""Test zcrx with large buffer chunks."""
138+
139+
cfg.require_ipver('6')
140+
141+
combined_chans = _get_combined_channels(cfg)
142+
if combined_chans < 2:
143+
raise KsftSkipEx('at least 2 combined channels required')
144+
(rx_ring, hds_thresh) = _get_current_settings(cfg)
145+
port = rand_port()
146+
147+
ethtool(f"-G {cfg.ifname} tcp-data-split on")
148+
defer(ethtool, f"-G {cfg.ifname} tcp-data-split auto")
149+
150+
ethtool(f"-G {cfg.ifname} hds-thresh 0")
151+
defer(ethtool, f"-G {cfg.ifname} hds-thresh {hds_thresh}")
152+
153+
ethtool(f"-G {cfg.ifname} rx 64")
154+
defer(ethtool, f"-G {cfg.ifname} rx {rx_ring}")
155+
156+
ethtool(f"-X {cfg.ifname} equal {combined_chans - 1}")
157+
defer(ethtool, f"-X {cfg.ifname} default")
158+
159+
flow_rule_id = _set_flow_rule(cfg, port, combined_chans - 1)
160+
defer(ethtool, f"-N {cfg.ifname} delete {flow_rule_id}")
161+
162+
rx_cmd = f"{cfg.bin_local} -s -p {port} -i {cfg.ifname} -q {combined_chans - 1} -x 2"
163+
tx_cmd = f"{cfg.bin_remote} -c -h {cfg.addr_v['6']} -p {port} -l 12840"
164+
165+
probe = cmd(rx_cmd + " -d", fail=False)
166+
if probe.ret == SKIP_CODE:
167+
raise KsftSkipEx(probe.stdout)
168+
169+
with bkg(rx_cmd, exit_wait=True):
170+
wait_port_listen(port, proto="tcp")
171+
cmd(tx_cmd, host=cfg.remote)
172+
173+
135174
def main() -> None:
136175
with NetDrvEpEnv(__file__) as cfg:
137176
cfg.bin_local = path.abspath(path.dirname(__file__) + "/../../../drivers/net/hw/iou-zcrx")

0 commit comments

Comments
 (0)