From: Scott Mitchell <scott.k.mitch1@gmail.com>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
Thomas Monjalon <thomas@monjalon.net>,
David Marchand <david.marchand@redhat.com>,
Scott Mitchell <scott.k.mitch1@gmail.com>
Subject: [PATCH v7 3/4] net/af_packet: tx poll control
Date: Tue, 1 Dec 2026 14:24:04 -0800 [thread overview]
Message-ID: <20261201222405.88922-4-scott.k.mitch1@gmail.com> (raw)
In-Reply-To: <20261201222405.88922-1-scott.k.mitch1@gmail.com>
Add a txpollnotrdy devarg (default 1). When 0, TX returns instead of
blocking in poll() when the ring is full, for applications that must
not block and apply backpressure themselves.
Signed-off-by: Scott Mitchell <scott.k.mitch1@gmail.com>
---
app/test/test_pmd_af_packet.c | 108 ++++++++++++++++++++++
doc/guides/nics/af_packet.rst | 6 +-
doc/guides/rel_notes/release_27_03.rst | 4 +
drivers/net/af_packet/rte_eth_af_packet.c | 34 +++++--
4 files changed, 144 insertions(+), 8 deletions(-)
diff --git a/app/test/test_pmd_af_packet.c b/app/test/test_pmd_af_packet.c
index 93e10f4b77..59a5353cba 100644
--- a/app/test/test_pmd_af_packet.c
+++ b/app/test/test_pmd_af_packet.c
@@ -89,6 +89,9 @@ struct tag_count {
#define LAYOUT_NB_FRAMES (3 * LAYOUT_FRAMECNT)
#define LAYOUT_FRAME_LEN 1400
+/* TX ring size for the txpollnotrdy test */
+#define TXPOLL_FRAMECNT 16
+
static struct rte_mempool *mp;
static uint16_t port_id = RTE_MAX_ETHPORTS;
static int tap_fd = -1;
@@ -1917,6 +1920,109 @@ test_af_packet_tx_mbuf_accounting(void)
return ret;
}
+/*
+ * Test: txpollnotrdy only accepts 0 or 1
+ */
+static int
+test_af_packet_invalid_txpollnotrdy(void)
+{
+ static const char * const bad[] = { "2", "-1", "abc", "" };
+ 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,txpollnotrdy=%s",
+ TAP_DEV_NAME, bad[i]);
+ ret = rte_vdev_init("net_af_packet_txpoll_bad", devargs);
+ if (ret == 0)
+ rte_vdev_uninit("net_af_packet_txpoll_bad");
+ TEST_ASSERT(ret != 0, "Expected failure with txpollnotrdy=%s", bad[i]);
+ }
+
+ return TEST_SUCCESS;
+}
+
+/* Helper: Set or clear IFF_UP on the TAP interface. */
+static int
+set_tap_link(bool up)
+{
+ struct ifreq ifr;
+ int sock, ret = -1;
+
+ sock = socket(AF_INET, SOCK_DGRAM, 0);
+ if (sock < 0)
+ return -1;
+ memset(&ifr, 0, sizeof(ifr));
+ snprintf(ifr.ifr_name, IFNAMSIZ, "%s", TAP_DEV_NAME);
+ if (ioctl(sock, SIOCGIFFLAGS, &ifr) == 0) {
+ if (up)
+ ifr.ifr_flags |= IFF_UP;
+ else
+ ifr.ifr_flags &= ~IFF_UP;
+ ret = ioctl(sock, SIOCSIFFLAGS, &ifr);
+ }
+ close(sock);
+ return ret;
+}
+
+/*
+ * Test: With txpollnotrdy=0, TX returns instead of blocking when the ring
+ * is full. With the link down the kernel leaves frames in SEND_REQUEST, so
+ * the ring fills after framecnt frames.
+ */
+static int
+test_af_packet_txpollnotrdy_nonblocking(void)
+{
+ const char *name = "net_af_packet_txpoll";
+ struct rte_mbuf *bufs[2 * TXPOLL_FRAMECNT];
+ char devargs[256];
+ uint64_t start, elapsed_ms;
+ uint16_t pid, nb_tx, nb_tx2;
+ int ret;
+
+ if (!tap_created) {
+ printf("SKIPPED: TAP interface not available (need root)\n");
+ return TEST_SKIPPED;
+ }
+
+ snprintf(devargs, sizeof(devargs),
+ "iface=%s,blocksz=4096,framesz=2048,framecnt=%d,txpollnotrdy=0",
+ TAP_DEV_NAME, TXPOLL_FRAMECNT);
+ ret = create_test_port(name, devargs, 0, &pid);
+ TEST_ASSERT(ret == 0, "Failed to create port");
+
+ ret = TEST_FAILED;
+ if (set_tap_link(false) != 0) {
+ printf("Could not take %s down\n", TAP_DEV_NAME);
+ goto out;
+ }
+
+ start = rte_get_timer_cycles();
+ if (alloc_tx_mbufs(bufs, RTE_DIM(bufs)) == 0)
+ goto out;
+ nb_tx = do_tx_burst(pid, 0, bufs, RTE_DIM(bufs));
+ if (alloc_tx_mbufs(bufs, RTE_DIM(bufs)) == 0)
+ goto out;
+ nb_tx2 = do_tx_burst(pid, 0, bufs, RTE_DIM(bufs));
+ elapsed_ms = (rte_get_timer_cycles() - start) * MS_PER_S / rte_get_timer_hz();
+
+ printf("Link down: TX %u then %u of %zu in %" PRIu64 " ms\n",
+ nb_tx, nb_tx2, RTE_DIM(bufs), elapsed_ms);
+ if (nb_tx > TXPOLL_FRAMECNT || nb_tx2 != 0 || elapsed_ms > 1000)
+ goto out;
+ ret = TEST_SUCCESS;
+out:
+ set_tap_link(true);
+ destroy_test_port(name, pid);
+ return ret;
+}
+
static struct unit_test_suite af_packet_test_suite = {
.suite_name = "AF_PACKET PMD Unit Test Suite",
.setup = test_af_packet_setup,
@@ -1944,6 +2050,8 @@ static struct unit_test_suite af_packet_test_suite = {
TEST_CASE(test_af_packet_frame_max_size),
TEST_CASE(test_af_packet_tx_vlan_oversize),
TEST_CASE(test_af_packet_tx_mbuf_accounting),
+ TEST_CASE(test_af_packet_invalid_txpollnotrdy),
+ TEST_CASE(test_af_packet_txpollnotrdy_nonblocking),
TEST_CASE(test_af_packet_qdisc_bypass),
TEST_CASE(test_af_packet_multi_queue),
TEST_CASE(test_af_packet_fanout_modes),
diff --git a/doc/guides/nics/af_packet.rst b/doc/guides/nics/af_packet.rst
index d7fb4162fd..7a6cc4ebe9 100644
--- a/doc/guides/nics/af_packet.rst
+++ b/doc/guides/nics/af_packet.rst
@@ -31,6 +31,10 @@ Some of these, in turn, will be used to configure the PACKET_MMAP settings.
* ``framesz`` - PACKET_MMAP frame size (optional, default 2048B; Note: multiple
of 16B);
* ``framecnt`` - PACKET_MMAP frame count (optional, default 512).
+* ``txpollnotrdy`` - Control behavior if tx is attempted but there is no
+ space available to write to the kernel. If 1, call poll() and block until
+ space is available to tx. If 0, don't call poll() and return from tx (optional,
+ default 1).
For details regarding ``fanout_mode`` argument, you can consult the
`PACKET_FANOUT documentation <https://www.man7.org/linux/man-pages/man7/packet.7.html>`_.
@@ -84,7 +88,7 @@ framecnt=512):
.. code-block:: console
- --vdev=eth_af_packet0,iface=tap0,blocksz=4096,framesz=2048,framecnt=512,qpairs=1,qdisc_bypass=1,fanout_mode=hash
+ --vdev=eth_af_packet0,iface=tap0,blocksz=4096,framesz=2048,framecnt=512,qpairs=1,qdisc_bypass=1,fanout_mode=hash,txpollnotrdy=0
Features and Limitations
------------------------
diff --git a/doc/guides/rel_notes/release_27_03.rst b/doc/guides/rel_notes/release_27_03.rst
index a91813faca..01940f9ac6 100644
--- a/doc/guides/rel_notes/release_27_03.rst
+++ b/doc/guides/rel_notes/release_27_03.rst
@@ -55,6 +55,10 @@ New Features
Also, make sure to start the actual text at the margin.
=======================================================
+* **Updated af_packet net driver.**
+
+ * Added ``txpollnotrdy`` devarg to avoid ``poll()`` blocking calls.
+
Removed Items
-------------
diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c
index 72d0dbdd60..5ed0bd73ba 100644
--- a/drivers/net/af_packet/rte_eth_af_packet.c
+++ b/drivers/net/af_packet/rte_eth_af_packet.c
@@ -52,9 +52,11 @@
#define ETH_AF_PACKET_QDISC_BYPASS_ARG "qdisc_bypass"
#define ETH_AF_PACKET_FANOUT_MODE_ARG "fanout_mode"
#define ETH_AF_PACKET_IGNORE_OUTGOING_ARG "ignore_outgoing"
+#define ETH_AF_PACKET_TX_POLL_NOT_READY_ARG "txpollnotrdy"
#define DFLT_FRAME_SIZE (1 << 11)
#define DFLT_FRAME_COUNT (1 << 9)
+#define DFLT_TX_POLL_NOT_RDY 1
#define ETH_AF_PACKET_FRAME_OVERHEAD (TPACKET2_HDRLEN - sizeof(struct sockaddr_ll))
@@ -91,6 +93,9 @@ struct __rte_cache_aligned pkt_tx_queue {
unsigned int framecount;
unsigned int framenum;
+ bool txpollnotrdy;
+ bool sw_cksum;
+
volatile unsigned long tx_pkts;
volatile unsigned long err_pkts;
volatile unsigned long tx_bytes;
@@ -120,6 +125,7 @@ static const char *valid_arguments[] = {
ETH_AF_PACKET_QDISC_BYPASS_ARG,
ETH_AF_PACKET_FANOUT_MODE_ARG,
ETH_AF_PACKET_IGNORE_OUTGOING_ARG,
+ ETH_AF_PACKET_TX_POLL_NOT_READY_ARG,
NULL
};
@@ -353,10 +359,12 @@ eth_af_packet_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
uint32_t num_tx_bytes = 0;
uint16_t i;
- memset(&pfd, 0, sizeof(pfd));
- pfd.fd = pkt_q->sockfd;
- pfd.events = POLLOUT;
- pfd.revents = 0;
+ if (pkt_q->txpollnotrdy) {
+ memset(&pfd, 0, sizeof(pfd));
+ pfd.fd = pkt_q->sockfd;
+ pfd.events = POLLOUT;
+ pfd.revents = 0;
+ }
framecount = pkt_q->framecount;
framenum = pkt_q->framenum;
@@ -385,8 +393,9 @@ eth_af_packet_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
* This results in poll() returning POLLOUT.
*/
if (unlikely(!tx_ring_status_available(tpacket_read_status(&ppd->tp_status)) &&
- (poll(&pfd, 1, -1) < 0 || (pfd.revents & POLLERR) != 0 ||
- !tx_ring_status_available(tpacket_read_status(&ppd->tp_status))))) {
+ (!pkt_q->txpollnotrdy || poll(&pfd, 1, -1) < 0 ||
+ (pfd.revents & POLLERR) != 0 ||
+ !tx_ring_status_available(tpacket_read_status(&ppd->tp_status))))) {
/* Ring is full, stop here. Don't process bufs[i]. */
break;
}
@@ -909,6 +918,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
unsigned int qdisc_bypass,
const char *fanout_mode,
unsigned int ignore_outgoing,
+ bool txpollnotrdy,
struct pmd_internals **internals,
struct rte_eth_dev **eth_dev,
struct rte_kvargs *kvlist)
@@ -1155,6 +1165,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
tx_queue->rd[i].iov_len = req->tp_frame_size;
}
tx_queue->sockfd = qsockfd;
+ tx_queue->txpollnotrdy = txpollnotrdy;
rc = bind(qsockfd, (const struct sockaddr*)&sockaddr, sizeof(sockaddr));
if (rc == -1) {
@@ -1281,6 +1292,7 @@ rte_eth_from_packet(struct rte_vdev_device *dev,
unsigned int qdisc_bypass = 1;
const char *fanout_mode = NULL;
unsigned int ignore_outgoing = 0;
+ unsigned int txpollnotrdy = DFLT_TX_POLL_NOT_RDY;
/* do some parameter checking */
if (*sockfd < 0)
@@ -1350,6 +1362,11 @@ rte_eth_from_packet(struct rte_vdev_device *dev,
return -1;
continue;
}
+ if (strstr(pair->key, ETH_AF_PACKET_TX_POLL_NOT_READY_ARG) != NULL) {
+ if (parse_uint(pair->key, pair->value, &txpollnotrdy, 1) < 0)
+ return -1;
+ continue;
+ }
}
if (framesize > blocksize) {
@@ -1419,6 +1436,7 @@ rte_eth_from_packet(struct rte_vdev_device *dev,
else
PMD_LOG(DEBUG, "%s:\tfanout mode %s", name, "default PACKET_FANOUT_HASH");
PMD_LOG(DEBUG, "%s:\tignore outgoing %u", name, ignore_outgoing);
+ PMD_LOG(DEBUG, "%s:\ttxpollnotrdy %u", name, txpollnotrdy);
if (rte_pmd_init_internals(dev, *sockfd, qpairs,
blocksize, blockcount,
@@ -1426,6 +1444,7 @@ rte_eth_from_packet(struct rte_vdev_device *dev,
qdisc_bypass,
fanout_mode,
ignore_outgoing,
+ txpollnotrdy != 0,
&internals, ð_dev,
kvlist) < 0)
return -1;
@@ -1524,4 +1543,5 @@ RTE_PMD_REGISTER_PARAM_STRING(net_af_packet,
"framecnt=<int> "
"qdisc_bypass=<0|1> "
"fanout_mode=<hash|lb|cpu|rollover|rnd|qm> "
- "ignore_outgoing=<0|1>");
+ "ignore_outgoing=<0|1> "
+ "txpollnotrdy=<0|1>");
--
2.54.0 (Apple Git-157)
next prev parent reply other threads:[~2026-12-01 22:25 UTC|newest]
Thread overview: 74+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-27 18:13 [PATCH v1 0/3] net/af_packet: correctness fixes and improvements scott.k.mitch1
2026-01-27 18:13 ` [PATCH v1 1/3] net/af_packet: fix thread safety and frame calculations scott.k.mitch1
2026-01-27 18:39 ` Stephen Hemminger
2026-01-28 1:35 ` Scott Mitchell
2026-01-27 18:13 ` [PATCH v1 2/3] net/af_packet: RX/TX rte_memcpy, bulk free, prefetch scott.k.mitch1
2026-01-27 18:54 ` Stephen Hemminger
2026-01-28 1:23 ` Scott Mitchell
2026-01-28 9:49 ` Morten Brørup
2026-01-28 15:37 ` Scott Mitchell
2026-01-28 16:57 ` Stephen Hemminger
2026-01-27 18:13 ` [PATCH v1 3/3] net/af_packet: software checksum and tx poll control scott.k.mitch1
2026-01-27 18:57 ` Stephen Hemminger
2026-01-28 7:05 ` Scott Mitchell
2026-01-28 17:36 ` Stephen Hemminger
2026-01-28 18:59 ` Scott Mitchell
2026-01-27 20:45 ` [REVIEW] " Stephen Hemminger
2026-01-28 9:36 ` [PATCH v2 0/4] af_packet correctness, performance, cksum scott.k.mitch1
2026-01-28 9:36 ` [PATCH v2 1/4] net/af_packet: fix thread safety and frame calculations scott.k.mitch1
2026-01-28 16:59 ` Stephen Hemminger
2026-01-28 18:00 ` Scott Mitchell
2026-01-28 18:28 ` Stephen Hemminger
2026-01-28 9:36 ` [PATCH v2 2/4] net/af_packet: RX/TX unlikely, bulk free, prefetch scott.k.mitch1
2026-01-28 9:36 ` [PATCH v2 3/4] net/af_packet: tx poll control scott.k.mitch1
2026-01-28 9:36 ` [PATCH v2 4/4] net/af_packet: software checksum scott.k.mitch1
2026-01-28 18:27 ` Stephen Hemminger
2026-01-28 19:08 ` Scott Mitchell
2026-01-28 19:10 ` [PATCH v3 0/4] af_packet correctness, performance, cksum scott.k.mitch1
2026-01-28 19:10 ` [PATCH v3 1/4] net/af_packet: fix thread safety and frame calculations scott.k.mitch1
2026-01-28 19:10 ` [PATCH v3 2/4] net/af_packet: RX/TX unlikely, bulk free, prefetch scott.k.mitch1
2026-01-29 1:07 ` Stephen Hemminger
2026-02-02 5:29 ` Scott Mitchell
2026-01-28 19:10 ` [PATCH v3 3/4] net/af_packet: tx poll control scott.k.mitch1
2026-01-28 19:10 ` [PATCH v3 4/4] net/af_packet: software checksum scott.k.mitch1
2026-01-28 21:57 ` [REVIEW] " Stephen Hemminger
2026-02-02 7:55 ` Scott Mitchell
2026-02-02 16:58 ` Stephen Hemminger
2026-02-02 8:14 ` [PATCH v4 0/4] af_packet correctness, performance, cksum scott.k.mitch1
2026-02-02 8:14 ` [PATCH v4 1/4] net/af_packet: fix thread safety and frame calculations scott.k.mitch1
2026-02-02 8:14 ` [PATCH v4 2/4] net/af_packet: RX/TX bulk free, unlikely hint scott.k.mitch1
2026-02-02 8:14 ` [PATCH v4 3/4] net/af_packet: tx poll control scott.k.mitch1
2026-02-02 8:14 ` [PATCH v4 4/4] net/af_packet: add software checksum offload support scott.k.mitch1
2026-02-02 17:00 ` Stephen Hemminger
2026-02-02 18:47 ` Stephen Hemminger
2026-02-03 6:41 ` Scott Mitchell
2026-02-02 18:53 ` [PATCH v4 0/4] af_packet correctness, performance, cksum Stephen Hemminger
2026-02-03 7:07 ` [PATCH v5 " scott.k.mitch1
2026-02-03 7:07 ` [PATCH v5 1/4] net/af_packet: fix thread safety and frame calculations scott.k.mitch1
2026-02-03 7:07 ` [PATCH v5 2/4] net/af_packet: RX/TX bulk free, unlikely hint scott.k.mitch1
2026-02-03 7:07 ` [PATCH v5 3/4] net/af_packet: tx poll control scott.k.mitch1
2026-02-03 7:07 ` [PATCH v5 4/4] net/af_packet: add software checksum offload support scott.k.mitch1
2026-02-03 8:20 ` Scott Mitchell
2026-02-03 14:12 ` Stephen Hemminger
2026-02-04 2:59 ` Scott Mitchell
2026-02-03 14:13 ` Stephen Hemminger
2026-02-04 1:39 ` Scott Mitchell
2026-02-05 21:27 ` Stephen Hemminger
2026-02-06 1:11 ` [PATCH v6 0/4] af_packet correctness, performance, cksum scott.k.mitch1
2026-02-06 1:11 ` [PATCH v6 1/4] net/af_packet: fix thread safety and frame calculations scott.k.mitch1
2026-02-06 1:11 ` [PATCH v6 2/4] net/af_packet: RX/TX bulk free, unlikely hint scott.k.mitch1
2026-02-06 1:11 ` [PATCH v6 3/4] net/af_packet: tx poll control scott.k.mitch1
2026-02-06 1:11 ` [PATCH v6 4/4] net/af_packet: add software checksum offload support scott.k.mitch1
2026-02-06 1:49 ` [PATCH v6 0/4] af_packet correctness, performance, cksum Stephen Hemminger
2026-02-06 4:45 ` Scott Mitchell
2026-02-06 14:36 ` Morten Brørup
2026-02-06 16:11 ` Stephen Hemminger
2026-12-01 22:24 ` [PATCH v7 0/4] net/af_packet: " Scott Mitchell
2026-12-01 22:24 ` [PATCH v7 1/4] net/af_packet: fix thread safety and frame calculations Scott Mitchell
2026-12-01 22:24 ` [PATCH v7 2/4] net/af_packet: RX/TX bulk free, unlikely hint Scott Mitchell
2026-12-01 22:24 ` Scott Mitchell [this message]
2026-12-01 22:24 ` [PATCH v7 4/4] net/af_packet: add software checksum offload support Scott Mitchell
2026-12-01 23:22 ` Scott Mitchell
2026-12-01 22:32 ` [PATCH v7 0/4] net/af_packet: correctness, performance, cksum Scott Mitchell
2026-12-02 7:09 ` Stephen Hemminger
2026-12-02 8:01 ` Morten Brørup
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=20261201222405.88922-4-scott.k.mitch1@gmail.com \
--to=scott.k.mitch1@gmail.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--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.