From: "Théo Lebrun" <theo.lebrun@bootlin.com>
To: Nicolas Ferre <nicolas.ferre@microchip.com>,
Claudiu Beznea <claudiu.beznea@tuxon.dev>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Jesper Dangaard Brouer <hawk@kernel.org>,
John Fastabend <john.fastabend@gmail.com>,
Stanislav Fomichev <sdf@fomichev.me>,
Richard Cochran <richardcochran@gmail.com>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
bpf@vger.kernel.org,
"Vladimir Kondratiev" <vladimir.kondratiev@mobileye.com>,
"Gregory CLEMENT" <gregory.clement@bootlin.com>,
"Benoît Monin" <benoit.monin@bootlin.com>,
"Tawfik Bayouk" <tawfik.bayouk@mobileye.com>,
"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
"Maxime Chevallier" <maxime.chevallier@bootlin.com>,
"Théo Lebrun" <theo.lebrun@bootlin.com>
Subject: [PATCH net-next 3/8] net: macb: account for stats in Tx XDP codepaths
Date: Wed, 04 Mar 2026 19:24:26 +0100 [thread overview]
Message-ID: <20260304-macb-xsk-v1-3-ba2ebe2bdaa3@bootlin.com> (raw)
In-Reply-To: <20260304-macb-xsk-v1-0-ba2ebe2bdaa3@bootlin.com>
macb_tx_complete() processing loop assumes a packet is composed of
multiple frames and composes around this idea. However, this is only
true in the SKB case ie `tx_buff->type == MACB_TYPE_SKB`.
Rework macb_tx_complete() to bring the tx_buff->type switch statement
outside and the frame iteration loop now lives only inside the SKB
case.
Fix Tx XDP stats that were not accounted for, in the XDP_TX|NDO cases.
Only increment statistics once per macb_tx_complete() call rather than
once per frame.
The `bytes` and `packets` stack variables now gets incremented for
completed XDP XMIT/TX packets. This implies the DQL subsystem through
netdev_tx_completed_queue() now gets notified of those packets
completing. We must therefore also report those bytes as sent, using
netdev_tx_sent_queue(), in macb_xdp_submit_frame() called by:
- Rx XDP programs returning action XDP_TX and,
- the .ndo_xdp_xmit() callback.
Incrementing `packets` also implies XDP packets are accounted for in our
NAPI budget calculation.
Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
---
drivers/net/ethernet/cadence/macb_main.c | 71 +++++++++++++++-----------------
1 file changed, 33 insertions(+), 38 deletions(-)
diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index 1aa90499343a..c1677f1d8f23 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -1212,7 +1212,7 @@ static int macb_tx_complete(struct macb_queue *queue, int budget)
{
struct macb *bp = queue->bp;
unsigned long flags;
- int skb_packets = 0;
+ int xsk_frames = 0;
unsigned int tail;
unsigned int head;
u16 queue_index;
@@ -1227,7 +1227,6 @@ static int macb_tx_complete(struct macb_queue *queue, int budget)
struct macb_tx_buff *tx_buff;
struct macb_dma_desc *desc;
struct sk_buff *skb;
- void *data = NULL;
u32 ctrl;
desc = macb_tx_desc(queue, tail);
@@ -1243,52 +1242,46 @@ static int macb_tx_complete(struct macb_queue *queue, int budget)
if (!(ctrl & MACB_BIT(TX_USED)))
break;
- /* Process all buffers of the current transmitted frame */
- for (;; tail++) {
- tx_buff = macb_tx_buff(queue, tail);
+ tx_buff = macb_tx_buff(queue, tail);
- if (tx_buff->type != MACB_TYPE_SKB) {
- data = tx_buff->ptr;
- packets++;
- goto unmap;
+ switch (tx_buff->type) {
+ case MACB_TYPE_SKB:
+ /* Process all buffers of the current transmitted frame */
+ while (!tx_buff->ptr) {
+ macb_tx_unmap(bp, tx_buff, budget);
+ tail++;
+ tx_buff = macb_tx_buff(queue, tail);
}
- /* First, update TX stats if needed */
- if (tx_buff->ptr) {
- data = tx_buff->ptr;
- skb = tx_buff->ptr;
+ skb = tx_buff->ptr;
- if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
- !ptp_one_step_sync(skb))
- gem_ptp_do_txstamp(bp, skb, desc);
+ if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
+ !ptp_one_step_sync(skb))
+ gem_ptp_do_txstamp(bp, skb, desc);
- netdev_vdbg(bp->dev, "skb %u (data %p) TX complete\n",
- macb_tx_ring_wrap(bp, tail),
- skb->data);
- bp->dev->stats.tx_packets++;
- queue->stats.tx_packets++;
- bp->dev->stats.tx_bytes += skb->len;
- queue->stats.tx_bytes += skb->len;
- skb_packets++;
- packets++;
- bytes += skb->len;
- }
+ netdev_vdbg(bp->dev, "skb %u (data %p) TX complete\n",
+ macb_tx_ring_wrap(bp, tail),
+ skb->data);
+ bytes += skb->len;
+ break;
-unmap:
- /* Now we can safely release resources */
- macb_tx_unmap(bp, tx_buff, budget);
-
- /* data is set only for the last buffer of the frame.
- * WARNING: at this point the buffer has been freed by
- * macb_tx_unmap().
- */
- if (data)
- break;
+ case MACB_TYPE_XDP_TX:
+ case MACB_TYPE_XDP_NDO:
+ bytes += tx_buff->size;
+ break;
}
+
+ packets++;
+ macb_tx_unmap(bp, tx_buff, budget);
}
+ bp->dev->stats.tx_packets += packets;
+ queue->stats.tx_packets += packets;
+ bp->dev->stats.tx_bytes += bytes;
+ queue->stats.tx_bytes += bytes;
+
netdev_tx_completed_queue(netdev_get_tx_queue(bp->dev, queue_index),
- skb_packets, bytes);
+ packets, bytes);
queue->tx_tail = tail;
if (__netif_subqueue_stopped(bp->dev, queue_index) &&
@@ -1529,6 +1522,8 @@ static int macb_xdp_submit_frame(struct macb *bp, struct xdp_frame *xdpf,
macb_writel(bp, NCR, macb_readl(bp, NCR) | MACB_BIT(TSTART));
spin_unlock(&bp->lock);
+ netdev_tx_sent_queue(netdev_get_tx_queue(bp->dev, queue_index), xdpf->len);
+
if (CIRC_SPACE(queue->tx_head, queue->tx_tail, bp->tx_ring_size) < 1)
netif_stop_subqueue(dev, queue_index);
--
2.53.0
next prev parent reply other threads:[~2026-03-04 18:24 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-04 18:24 [PATCH net-next 0/8] net: macb: add XSK support Théo Lebrun
2026-03-04 18:24 ` [PATCH net-next 1/8] net: macb: make rx error messages rate-limited Théo Lebrun
2026-03-04 18:24 ` [PATCH net-next 2/8] net: macb: account for stats in Rx XDP codepaths Théo Lebrun
2026-03-04 18:24 ` Théo Lebrun [this message]
2026-03-04 18:24 ` [PATCH net-next 4/8] net: macb: drop handling of recycled buffers in gem_rx_refill() Théo Lebrun
2026-03-04 18:24 ` [PATCH net-next 5/8] net: macb: move macb_xdp_submit_frame() body to helper function Théo Lebrun
2026-03-04 18:24 ` [PATCH net-next 6/8] net: macb: add infrastructure for XSK buffer pool Théo Lebrun
2026-03-04 18:24 ` [PATCH net-next 7/8] net: macb: add Rx zero-copy AF_XDP support Théo Lebrun
2026-03-04 18:24 ` [PATCH net-next 8/8] net: macb: add Tx " Théo Lebrun
2026-03-06 12:48 ` Maxime Chevallier
2026-03-06 17:18 ` Théo Lebrun
2026-03-06 17:53 ` Maxime Chevallier
2026-03-09 10:56 ` Théo Lebrun
2026-03-06 3:11 ` [PATCH net-next 0/8] net: macb: add XSK support Jakub Kicinski
-- strict thread matches above, loose matches on Subject: below --
2026-03-04 18:23 Théo Lebrun
2026-03-04 18:23 ` [PATCH net-next 3/8] net: macb: account for stats in Tx XDP codepaths Théo Lebrun
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=20260304-macb-xsk-v1-3-ba2ebe2bdaa3@bootlin.com \
--to=theo.lebrun@bootlin.com \
--cc=andrew+netdev@lunn.ch \
--cc=ast@kernel.org \
--cc=benoit.monin@bootlin.com \
--cc=bpf@vger.kernel.org \
--cc=claudiu.beznea@tuxon.dev \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gregory.clement@bootlin.com \
--cc=hawk@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maxime.chevallier@bootlin.com \
--cc=netdev@vger.kernel.org \
--cc=nicolas.ferre@microchip.com \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
--cc=sdf@fomichev.me \
--cc=tawfik.bayouk@mobileye.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=vladimir.kondratiev@mobileye.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox