From: Scott Mitchell <scott.k.mitch1@gmail.com>
To: dev@dpdk.org
Cc: stephen@networkplumber.org, thomas@monjalon.net,
david.marchand@redhat.com, mb@smartsharesystems.com,
Scott Mitchell <scott.k.mitch1@gmail.com>
Subject: [PATCH v4 3/3] test/af_packet: add io_uring Tx tests
Date: Thu, 3 Dec 2026 09:43:02 -0800 [thread overview]
Message-ID: <20261203174302.1418-4-scott.k.mitch1@gmail.com> (raw)
In-Reply-To: <20261203174302.1418-1-scott.k.mitch1@gmail.com>
Test io_uring Tx through the driver: frames sent with io_uring kicks
arrive on the TAP, also after the SQPOLL thread went idle and with
queues sharing SQPOLL threads; probe fails for io_uring devargs that
can't be honored and when io_uring can't be set up; and creating and
destroying ports leaks no file descriptors. The tests skip when io_uring
SQPOLL is unavailable.
Signed-off-by: Scott Mitchell <scott.k.mitch1@gmail.com>
---
Depends-on: series-40254 ("net/af_packet fixes and Tx features")
app/test/test_pmd_af_packet.c | 357 ++++++++++++++++++++++++++++++++++
1 file changed, 357 insertions(+)
diff --git a/app/test/test_pmd_af_packet.c b/app/test/test_pmd_af_packet.c
index b42121d8ee..6bac72bedd 100644
--- a/app/test/test_pmd_af_packet.c
+++ b/app/test/test_pmd_af_packet.c
@@ -6,6 +6,7 @@
#include <fcntl.h>
#include <inttypes.h>
#include <sys/ioctl.h>
+#include <sys/resource.h>
#include <sys/socket.h>
#include <linux/if.h>
#include <linux/if_packet.h>
@@ -34,6 +35,11 @@
#include "test.h"
+#ifdef RTE_HAS_LIBURING
+#include <sys/syscall.h>
+#include <linux/io_uring.h>
+#endif
+
#ifndef RTE_EXEC_ENV_LINUX
static int
test_pmd_af_packet(void)
@@ -104,6 +110,13 @@ struct tag_count {
#define CKSUM_BAD 0xdead
#define CKSUM_TCI 0x123
+/* io_uring tests */
+#define IDLE_WAKE_ROUNDS 40
+#define IDLE_WAKE_GAP_MS 25 /* > 2 jiffies at HZ=100, so an idle SQ thread sleeps */
+#define SQPOLL_QUEUES 4
+#define FD_LEAK_MARGIN 32 /* free fds left under RLIMIT_NOFILE */
+#define FD_LEAK_ROUNDS (2 * FD_LEAK_MARGIN)
+
static struct rte_mempool *mp;
static uint16_t port_id = RTE_MAX_ETHPORTS;
static int tap_fd = -1;
@@ -2404,6 +2417,344 @@ test_af_packet_tx_cksum(void)
return ret;
}
+/*
+ * Test: io_uring devargs are validated, and ones the port can't honor fail probe
+ */
+static int
+test_af_packet_invalid_io_uring_args(void)
+{
+ static const char * const bad[] = {
+ "tx_io_uring_enabled=2",
+ "tx_io_uring_enabled=1,tx_io_uring_sq_size=0",
+ "tx_io_uring_enabled=1,tx_io_uring_sq_size=40000",
+ "tx_io_uring_enabled=1,tx_io_uring_sq_size=abc",
+ "tx_io_uring_enabled=1,tx_io_uring_sq_thread_idle=-1",
+ "tx_io_uring_enabled=1,tx_io_uring_q_cpu=-1",
+ "tx_io_uring_enabled=1,tx_io_uring_threads=99999",
+ /* other io_uring devargs without tx_io_uring_enabled=1 */
+ "tx_io_uring_sq_size=64",
+ "tx_io_uring_enabled=0,tx_io_uring_threads=1",
+ /* more SQPOLL threads than queues */
+ "tx_io_uring_enabled=1,tx_io_uring_threads=2",
+ /* more CPUs than SQPOLL threads */
+ "tx_io_uring_enabled=1,tx_io_uring_q_cpu=0,tx_io_uring_q_cpu=0",
+ "qpairs=2,tx_io_uring_enabled=1,tx_io_uring_threads=1,"
+ "tx_io_uring_q_cpu=0,tx_io_uring_q_cpu=0",
+ };
+ char devargs[256];
+ unsigned int i;
+ int ret;
+
+ if (!tap_created) {
+ printf("SKIPPED: TAP interface not available (need root)\n");
+ return TEST_SKIPPED;
+ }
+
+ for (i = 0; i < RTE_DIM(bad); i++) {
+ snprintf(devargs, sizeof(devargs), "iface=%s,%s", TAP_DEV_NAME, bad[i]);
+ ret = rte_vdev_init("net_af_packet_uring_bad", devargs);
+ if (ret == 0)
+ rte_vdev_uninit("net_af_packet_uring_bad");
+ TEST_ASSERT(ret != 0, "Expected failure with %s", bad[i]);
+ }
+
+ return TEST_SUCCESS;
+}
+
+/* Helper: Whether this kernel lets the process create an io_uring SQPOLL ring. */
+static bool
+io_uring_sqpoll_testable(void)
+{
+#ifdef RTE_HAS_LIBURING
+ struct io_uring_params p = { .flags = IORING_SETUP_SQPOLL };
+ long fd;
+
+ fd = syscall(__NR_io_uring_setup, 1, &p);
+ if (fd < 0) {
+ printf("SKIPPED: io_uring SQPOLL unavailable: %s\n", strerror(errno));
+ return false;
+ }
+ close((int)fd);
+ return true;
+#else
+ printf("SKIPPED: af_packet built without liburing\n");
+ return false;
+#endif
+}
+
+/*
+ * Helper: Send SEQ_TX_BURST frames on each of nb_queues Tx queues of pid and
+ * check that all of them arrive on the (non-blocking) TAP fd.
+ */
+static int
+check_tx_seq_queues(uint16_t pid, uint16_t nb_queues, size_t frame_len)
+{
+ const unsigned int n = nb_queues * SEQ_TX_BURST;
+ struct rte_mbuf *bufs[SEQ_TX_BURST];
+ unsigned int i, nb_seen = 0;
+ uint16_t q;
+ bool *seen;
+ int ret = TEST_FAILED;
+
+ seen = calloc(n, sizeof(*seen));
+ if (seen == NULL)
+ return TEST_FAILED;
+
+ for (q = 0; q < nb_queues; q++) {
+ if (rte_pktmbuf_alloc_bulk(mp, bufs, SEQ_TX_BURST) != 0)
+ goto out;
+ for (i = 0; i < SEQ_TX_BURST; i++) {
+ uint8_t *data = (uint8_t *)rte_pktmbuf_append(bufs[i], frame_len);
+
+ if (data == NULL) {
+ rte_pktmbuf_free_bulk(bufs, SEQ_TX_BURST);
+ goto out;
+ }
+ fill_seq_frame(data, frame_len, &DEV_MAC_TAG, q * SEQ_TX_BURST + i);
+ }
+ if (do_tx_burst(pid, q, bufs, SEQ_TX_BURST) != SEQ_TX_BURST) {
+ printf("TX burst on queue %u was short\n", q);
+ goto out;
+ }
+ }
+ if (tap_collect_seq(seen, n, &nb_seen, n, frame_len, TAP_READ_TIMEOUT_US) != (int)n) {
+ printf("TX: %u of %u frames arrived intact\n", nb_seen, n);
+ goto out;
+ }
+ ret = TEST_SUCCESS;
+out:
+ free(seen);
+ return ret;
+}
+
+/*
+ * Test: A port that asks for io_uring fails probe if it can't have it
+ */
+static int
+test_af_packet_io_uring_setup_fails(void)
+{
+ const char *name = "net_af_packet_uring_fail";
+ char devargs[256];
+ int ret;
+
+ if (!tap_created) {
+ printf("SKIPPED: TAP interface not available (need root)\n");
+ return TEST_SKIPPED;
+ }
+
+#ifdef RTE_HAS_LIBURING
+ if (!io_uring_sqpoll_testable())
+ return TEST_SKIPPED;
+ /* the kernel rejects an SQPOLL CPU at or above nr_cpu_ids */
+ snprintf(devargs, sizeof(devargs),
+ "iface=%s,tx_io_uring_enabled=1,tx_io_uring_q_cpu=1000000", TAP_DEV_NAME);
+#else
+ snprintf(devargs, sizeof(devargs), "iface=%s,tx_io_uring_enabled=1", TAP_DEV_NAME);
+#endif
+ ret = rte_vdev_init(name, devargs);
+ if (ret == 0)
+ rte_vdev_uninit(name);
+ TEST_ASSERT(ret != 0, "Expected probe failure with %s", devargs);
+ return TEST_SUCCESS;
+}
+
+/*
+ * Test: TX with io_uring kicks
+ */
+static int
+test_af_packet_io_uring_tx(void)
+{
+ const char *name = "net_af_packet_uring";
+ char devargs[256];
+ unsigned int framecnt;
+ uint16_t pid;
+ int flags, ret;
+
+ if (!tap_created) {
+ printf("SKIPPED: TAP interface not available (need root)\n");
+ return TEST_SKIPPED;
+ }
+ if (!io_uring_sqpoll_testable())
+ return TEST_SKIPPED;
+
+ framecnt = layout_devargs(devargs, sizeof(devargs), ",tx_io_uring_enabled=1");
+ ret = create_test_port(name, devargs, 0, &pid);
+ TEST_ASSERT(ret == 0, "Failed to create port");
+
+ flags = fcntl(tap_fd, F_GETFL, 0);
+ fcntl(tap_fd, F_SETFL, flags | O_NONBLOCK);
+ tap_drain();
+
+ ret = check_tx_seq(pid, 3 * framecnt, LAYOUT_FRAME_LEN);
+
+ fcntl(tap_fd, F_SETFL, flags);
+ destroy_test_port(name, pid);
+ return ret;
+}
+
+/*
+ * Test: A frame sent after the SQPOLL thread went idle still goes out.
+ * With a 1 ms idle timeout and an IDLE_WAKE_GAP_MS gap before each frame, every
+ * kick has to wake a sleeping SQ thread; a missed wakeup leaves the frame queued.
+ * This is a smoke test: the race window is small, so a pass is not proof.
+ */
+static int
+test_af_packet_io_uring_idle_wakeup(void)
+{
+ const char *name = "net_af_packet_uring_idle";
+ bool seen[IDLE_WAKE_ROUNDS] = { false };
+ unsigned int round, nb_seen = 0;
+ struct rte_mbuf *m;
+ char devargs[256];
+ uint8_t *data;
+ uint16_t pid;
+ int flags, ret;
+
+ if (!tap_created) {
+ printf("SKIPPED: TAP interface not available (need root)\n");
+ return TEST_SKIPPED;
+ }
+ if (!io_uring_sqpoll_testable())
+ return TEST_SKIPPED;
+
+ snprintf(devargs, sizeof(devargs),
+ "iface=%s,tx_io_uring_enabled=1,tx_io_uring_sq_thread_idle=1",
+ TAP_DEV_NAME);
+ ret = create_test_port(name, devargs, 0, &pid);
+ TEST_ASSERT(ret == 0, "Failed to create port");
+
+ flags = fcntl(tap_fd, F_GETFL, 0);
+ fcntl(tap_fd, F_SETFL, flags | O_NONBLOCK);
+ tap_drain();
+
+ ret = TEST_FAILED;
+ for (round = 0; round < IDLE_WAKE_ROUNDS; round++) {
+ rte_delay_ms(IDLE_WAKE_GAP_MS);
+ m = rte_pktmbuf_alloc(mp);
+ if (m == NULL)
+ goto out;
+ data = (uint8_t *)rte_pktmbuf_append(m, TEST_FRAME_LEN);
+ if (data == NULL) {
+ rte_pktmbuf_free(m);
+ goto out;
+ }
+ fill_seq_frame(data, TEST_FRAME_LEN, &DEV_MAC_TAG, round);
+ if (do_tx_burst(pid, 0, &m, 1) != 1)
+ goto out;
+ if (tap_collect_seq(seen, IDLE_WAKE_ROUNDS, &nb_seen, round + 1,
+ TEST_FRAME_LEN, TAP_READ_TIMEOUT_US) != (int)(round + 1)) {
+ printf("Frame %u not sent after idle (seen %u)\n", round, nb_seen);
+ goto out;
+ }
+ }
+ ret = TEST_SUCCESS;
+out:
+ fcntl(tap_fd, F_SETFL, flags);
+ destroy_test_port(name, pid);
+ return ret;
+}
+
+/*
+ * Test: Creating and destroying an io_uring port with a shared SQPOLL thread
+ * doesn't leak file descriptors. RLIMIT_NOFILE leaves FD_LEAK_MARGIN fds free,
+ * so leaking even one per round makes probe fail before the last round.
+ */
+static int
+test_af_packet_io_uring_create_destroy(void)
+{
+ const char *name = "net_af_packet_uring_cd";
+ struct rlimit saved, lim;
+ char devargs[256];
+ int fd, i, rc, ret = TEST_SUCCESS;
+ uint16_t pid;
+
+ if (!tap_created) {
+ printf("SKIPPED: TAP interface not available (need root)\n");
+ return TEST_SKIPPED;
+ }
+ if (!io_uring_sqpoll_testable())
+ return TEST_SKIPPED;
+
+ snprintf(devargs, sizeof(devargs),
+ "iface=%s,qpairs=2,tx_io_uring_enabled=1,tx_io_uring_threads=1",
+ TAP_DEV_NAME);
+
+ /* the next fd is the lowest free one; allow FD_LEAK_MARGIN above it */
+ fd = open("/dev/null", O_RDONLY);
+ TEST_ASSERT(fd >= 0, "open /dev/null failed");
+ close(fd);
+ TEST_ASSERT(getrlimit(RLIMIT_NOFILE, &saved) == 0, "getrlimit failed");
+ lim = saved;
+ lim.rlim_cur = RTE_MIN((rlim_t)fd + FD_LEAK_MARGIN, saved.rlim_cur);
+ TEST_ASSERT(setrlimit(RLIMIT_NOFILE, &lim) == 0, "setrlimit failed");
+
+ for (i = 0; i < FD_LEAK_ROUNDS; i++) {
+ if (create_af_packet_port(name, devargs, &pid) != 0) {
+ printf("Port creation failed in round %d: fd leak?\n", i);
+ ret = TEST_FAILED;
+ break;
+ }
+ rc = configure_af_packet_port(pid, 2, 2);
+ destroy_test_port(name, pid);
+ if (rc != 0) {
+ printf("Port configuration failed in round %d\n", i);
+ ret = TEST_FAILED;
+ break;
+ }
+ }
+
+ setrlimit(RLIMIT_NOFILE, &saved);
+ return ret;
+}
+
+/*
+ * Test: With queues sharing SQPOLL threads (tx_io_uring_threads below qpairs),
+ * frames sent on every queue arrive.
+ */
+static int
+test_af_packet_io_uring_shared_sqpoll(void)
+{
+ static const unsigned int threads[] = { 1, 2 };
+ const char *name = "net_af_packet_uring_shared";
+ char devargs[256];
+ unsigned int i;
+ uint16_t pid;
+ int flags, ret = TEST_SUCCESS;
+
+ if (!tap_created) {
+ printf("SKIPPED: TAP interface not available (need root)\n");
+ return TEST_SKIPPED;
+ }
+ if (!io_uring_sqpoll_testable())
+ return TEST_SKIPPED;
+
+ flags = fcntl(tap_fd, F_GETFL, 0);
+ fcntl(tap_fd, F_SETFL, flags | O_NONBLOCK);
+
+ for (i = 0; i < RTE_DIM(threads) && ret == TEST_SUCCESS; i++) {
+ snprintf(devargs, sizeof(devargs),
+ "iface=%s,qpairs=%d,tx_io_uring_enabled=1,tx_io_uring_threads=%u",
+ TAP_DEV_NAME, SQPOLL_QUEUES, threads[i]);
+ ret = create_af_packet_port(name, devargs, &pid);
+ if (ret != 0) {
+ printf("Failed to create port with %s\n", devargs);
+ ret = TEST_FAILED;
+ break;
+ }
+ if (configure_af_packet_port(pid, SQPOLL_QUEUES, SQPOLL_QUEUES) != 0 ||
+ rte_eth_dev_start(pid) != 0) {
+ ret = TEST_FAILED;
+ } else {
+ tap_drain();
+ ret = check_tx_seq_queues(pid, SQPOLL_QUEUES, LAYOUT_FRAME_LEN);
+ }
+ destroy_test_port(name, pid);
+ }
+
+ fcntl(tap_fd, F_SETFL, flags);
+ return ret;
+}
+
static struct unit_test_suite af_packet_test_suite = {
.suite_name = "AF_PACKET PMD Unit Test Suite",
.setup = test_af_packet_setup,
@@ -2434,6 +2785,12 @@ static struct unit_test_suite af_packet_test_suite = {
TEST_CASE(test_af_packet_tx_mbuf_accounting),
TEST_CASE(test_af_packet_tx_ring_full),
TEST_CASE(test_af_packet_tx_cksum),
+ TEST_CASE(test_af_packet_invalid_io_uring_args),
+ TEST_CASE(test_af_packet_io_uring_setup_fails),
+ TEST_CASE(test_af_packet_io_uring_tx),
+ TEST_CASE(test_af_packet_io_uring_idle_wakeup),
+ TEST_CASE(test_af_packet_io_uring_create_destroy),
+ TEST_CASE(test_af_packet_io_uring_shared_sqpoll),
TEST_CASE(test_af_packet_qdisc_bypass),
TEST_CASE(test_af_packet_multi_queue),
TEST_CASE(test_af_packet_fanout_modes),
--
2.54.0 (Apple Git-157)
next prev parent reply other threads:[~2026-12-03 17:44 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-04 16:12 [RFC v1] net/af_packet: add io_uring TX acceleration scott.k.mitch1
2026-02-04 16:52 ` Stephen Hemminger
2026-02-05 0:08 ` Scott Mitchell
2026-12-01 22:36 ` [RFC PATCH v2] " Scott Mitchell
2026-12-01 22:44 ` Scott Mitchell
2026-12-02 17:16 ` Stephen Hemminger
2026-12-02 18:52 ` Scott Mitchell
2026-12-02 18:54 ` [PATCH v3 0/2] net/af_packet: add io_uring Tx acceleration Scott Mitchell
2026-12-02 18:54 ` [PATCH v3 1/2] config: detect liburing Scott Mitchell
2026-12-02 18:54 ` [PATCH v3 2/2] net/af_packet: add iouring Tx acceleration Scott Mitchell
2026-12-02 23:43 ` Stephen Hemminger
2026-12-03 0:00 ` [PATCH v3 0/2] net/af_packet: add io_uring " Stephen Hemminger
2026-12-03 0:52 ` Scott Mitchell
2026-12-03 17:42 ` [PATCH v4 0/3] " Scott Mitchell
2026-12-03 17:43 ` [PATCH v4 1/3] config: detect liburing Scott Mitchell
2026-12-03 17:43 ` [PATCH v4 2/3] net/af_packet: add io_uring Tx acceleration Scott Mitchell
2026-12-03 18:10 ` Stephen Hemminger
2026-12-03 19:20 ` Scott Mitchell
2026-12-03 17:43 ` Scott Mitchell [this message]
2026-12-04 16:07 ` [PATCH v5 0/3] " Scott Mitchell
2026-12-04 16:07 ` [PATCH v5 1/3] config: detect liburing Scott Mitchell
2026-12-04 16:07 ` [PATCH v5 2/3] net/af_packet: add io_uring Tx acceleration Scott Mitchell
2026-12-04 20:22 ` Stephen Hemminger
2026-12-04 16:07 ` [PATCH v5 3/3] test/af_packet: add io_uring Tx tests Scott Mitchell
2026-12-02 16:59 ` [RFC v1] net/af_packet: add io_uring TX acceleration Stephen Hemminger
2026-12-02 17:02 ` Stephen Hemminger
2026-12-02 17:03 ` Stephen Hemminger
2026-12-02 17:04 ` Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261203174302.1418-4-scott.k.mitch1@gmail.com \
--to=scott.k.mitch1@gmail.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=mb@smartsharesystems.com \
--cc=stephen@networkplumber.org \
--cc=thomas@monjalon.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.