* [PATCH] net/null: Add fast mbuf release TX offload
@ 2025-06-24 18:14 Morten Brørup
2025-06-26 14:05 ` Stephen Hemminger
0 siblings, 1 reply; 3+ messages in thread
From: Morten Brørup @ 2025-06-24 18:14 UTC (permalink / raw)
To: Tetsuya Mukawa, Stephen Hemminger, dev; +Cc: Morten Brørup
Added fast mbuf release, re-using the existing mbuf pool pointer
in the queue structure.
Signed-off-by: Morten Brørup <mb@smartsharesystems.com>
---
drivers/net/null/rte_eth_null.c | 30 +++++++++++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)
diff --git a/drivers/net/null/rte_eth_null.c b/drivers/net/null/rte_eth_null.c
index 8a9b74a03b..12c0d8d1ff 100644
--- a/drivers/net/null/rte_eth_null.c
+++ b/drivers/net/null/rte_eth_null.c
@@ -34,6 +34,17 @@ struct pmd_internals;
struct null_queue {
struct pmd_internals *internals;
+ /**
+ * For RX queue:
+ * Mempool to allocate mbufs from.
+ *
+ * For TX queue:
+ * Mempool to free mbufs to, if fast release of mbufs is enabled.
+ * UINTPTR_MAX if the mempool for fast release of mbufs has not yet been detected.
+ * NULL if fast release of mbufs is not enabled.
+ *
+ * @see RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE
+ */
struct rte_mempool *mb_pool;
void *dummy_packet;
@@ -151,7 +162,16 @@ eth_null_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs)
for (i = 0; i < nb_bufs; i++)
bytes += rte_pktmbuf_pkt_len(bufs[i]);
- rte_pktmbuf_free_bulk(bufs, nb_bufs);
+ if (h->mb_pool != NULL) { /* RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE */
+ if (unlikely(h->mb_pool == (void *)UINTPTR_MAX)) {
+ if (unlikely(nb_bufs == 0))
+ return 0; /* Do not dereference uninitialized bufs[0]. */
+ h->mb_pool = bufs[0]->pool;
+ }
+ rte_mbuf_raw_free_bulk(h->mb_pool, bufs, nb_bufs);
+ } else {
+ rte_pktmbuf_free_bulk(bufs, nb_bufs);
+ }
rte_atomic_fetch_add_explicit(&h->tx_pkts, nb_bufs, rte_memory_order_relaxed);
rte_atomic_fetch_add_explicit(&h->tx_bytes, bytes, rte_memory_order_relaxed);
@@ -259,7 +279,7 @@ static int
eth_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id,
uint16_t nb_tx_desc __rte_unused,
unsigned int socket_id __rte_unused,
- const struct rte_eth_txconf *tx_conf __rte_unused)
+ const struct rte_eth_txconf *tx_conf)
{
struct rte_mbuf *dummy_packet;
struct pmd_internals *internals;
@@ -284,6 +304,9 @@ eth_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id,
internals->tx_null_queues[tx_queue_id].internals = internals;
internals->tx_null_queues[tx_queue_id].dummy_packet = dummy_packet;
+ internals->tx_null_queues[tx_queue_id].mb_pool =
+ tx_conf->offloads & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE ?
+ (void *)UINTPTR_MAX : NULL;
return 0;
}
@@ -309,7 +332,8 @@ eth_dev_info(struct rte_eth_dev *dev,
dev_info->max_rx_queues = RTE_DIM(internals->rx_null_queues);
dev_info->max_tx_queues = RTE_DIM(internals->tx_null_queues);
dev_info->min_rx_bufsize = 0;
- dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_MULTI_SEGS | RTE_ETH_TX_OFFLOAD_MT_LOCKFREE;
+ dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_MULTI_SEGS |
+ RTE_ETH_TX_OFFLOAD_MT_LOCKFREE | RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
dev_info->reta_size = internals->reta_size;
dev_info->flow_type_rss_offloads = internals->flow_type_rss_offloads;
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] net/null: Add fast mbuf release TX offload
2025-06-24 18:14 [PATCH] net/null: Add fast mbuf release TX offload Morten Brørup
@ 2025-06-26 14:05 ` Stephen Hemminger
2025-06-26 15:44 ` Morten Brørup
0 siblings, 1 reply; 3+ messages in thread
From: Stephen Hemminger @ 2025-06-26 14:05 UTC (permalink / raw)
To: Morten Brørup; +Cc: Tetsuya Mukawa, dev
On Tue, 24 Jun 2025 18:14:16 +0000
Morten Brørup <mb@smartsharesystems.com> wrote:
> Added fast mbuf release, re-using the existing mbuf pool pointer
> in the queue structure.
>
> Signed-off-by: Morten Brørup <mb@smartsharesystems.com>
Makes sense.
> ---
> drivers/net/null/rte_eth_null.c | 30 +++++++++++++++++++++++++++---
> 1 file changed, 27 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/null/rte_eth_null.c b/drivers/net/null/rte_eth_null.c
> index 8a9b74a03b..12c0d8d1ff 100644
> --- a/drivers/net/null/rte_eth_null.c
> +++ b/drivers/net/null/rte_eth_null.c
> @@ -34,6 +34,17 @@ struct pmd_internals;
> struct null_queue {
> struct pmd_internals *internals;
>
> + /**
> + * For RX queue:
> + * Mempool to allocate mbufs from.
> + *
> + * For TX queue:
> + * Mempool to free mbufs to, if fast release of mbufs is enabled.
> + * UINTPTR_MAX if the mempool for fast release of mbufs has not yet been detected.
> + * NULL if fast release of mbufs is not enabled.
> + *
> + * @see RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE
> + */
> struct rte_mempool *mb_pool;
Do all drivers to it this way?
Is it documented in ethdev?
> void *dummy_packet;
>
> @@ -151,7 +162,16 @@ eth_null_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs)
> for (i = 0; i < nb_bufs; i++)
> bytes += rte_pktmbuf_pkt_len(bufs[i]);
>
> - rte_pktmbuf_free_bulk(bufs, nb_bufs);
> + if (h->mb_pool != NULL) { /* RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE */
> + if (unlikely(h->mb_pool == (void *)UINTPTR_MAX)) {
> + if (unlikely(nb_bufs == 0))
> + return 0; /* Do not dereference uninitialized bufs[0]. */
> + h->mb_pool = bufs[0]->pool;
> + }
> + rte_mbuf_raw_free_bulk(h->mb_pool, bufs, nb_bufs);
> + } else {
> + rte_pktmbuf_free_bulk(bufs, nb_bufs);
> + }
> rte_atomic_fetch_add_explicit(&h->tx_pkts, nb_bufs, rte_memory_order_relaxed);
> rte_atomic_fetch_add_explicit(&h->tx_bytes, bytes, rte_memory_order_relaxed);
>
> @@ -259,7 +279,7 @@ static int
> eth_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id,
> uint16_t nb_tx_desc __rte_unused,
> unsigned int socket_id __rte_unused,
> - const struct rte_eth_txconf *tx_conf __rte_unused)
> + const struct rte_eth_txconf *tx_conf)
> {
> struct rte_mbuf *dummy_packet;
> struct pmd_internals *internals;
> @@ -284,6 +304,9 @@ eth_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id,
>
> internals->tx_null_queues[tx_queue_id].internals = internals;
> internals->tx_null_queues[tx_queue_id].dummy_packet = dummy_packet;
> + internals->tx_null_queues[tx_queue_id].mb_pool =
> + tx_conf->offloads & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE ?
> + (void *)UINTPTR_MAX : NULL;
>
> return 0;
> }
> @@ -309,7 +332,8 @@ eth_dev_info(struct rte_eth_dev *dev,
> dev_info->max_rx_queues = RTE_DIM(internals->rx_null_queues);
> dev_info->max_tx_queues = RTE_DIM(internals->tx_null_queues);
> dev_info->min_rx_bufsize = 0;
> - dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_MULTI_SEGS | RTE_ETH_TX_OFFLOAD_MT_LOCKFREE;
> + dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_MULTI_SEGS |
> + RTE_ETH_TX_OFFLOAD_MT_LOCKFREE | RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
>
> dev_info->reta_size = internals->reta_size;
> dev_info->flow_type_rss_offloads = internals->flow_type_rss_offloads;
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [PATCH] net/null: Add fast mbuf release TX offload
2025-06-26 14:05 ` Stephen Hemminger
@ 2025-06-26 15:44 ` Morten Brørup
0 siblings, 0 replies; 3+ messages in thread
From: Morten Brørup @ 2025-06-26 15:44 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: Tetsuya Mukawa, dev
> From: Stephen Hemminger [mailto:stephen@networkplumber.org]
> Sent: Thursday, 26 June 2025 16.06
>
> On Tue, 24 Jun 2025 18:14:16 +0000
> Morten Brørup <mb@smartsharesystems.com> wrote:
>
> > Added fast mbuf release, re-using the existing mbuf pool pointer
> > in the queue structure.
> >
> > Signed-off-by: Morten Brørup <mb@smartsharesystems.com>
>
> Makes sense.
>
> > ---
> > drivers/net/null/rte_eth_null.c | 30 +++++++++++++++++++++++++++---
> > 1 file changed, 27 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/net/null/rte_eth_null.c
> b/drivers/net/null/rte_eth_null.c
> > index 8a9b74a03b..12c0d8d1ff 100644
> > --- a/drivers/net/null/rte_eth_null.c
> > +++ b/drivers/net/null/rte_eth_null.c
> > @@ -34,6 +34,17 @@ struct pmd_internals;
> > struct null_queue {
> > struct pmd_internals *internals;
> >
> > + /**
> > + * For RX queue:
> > + * Mempool to allocate mbufs from.
> > + *
> > + * For TX queue:
> > + * Mempool to free mbufs to, if fast release of mbufs is enabled.
> > + * UINTPTR_MAX if the mempool for fast release of mbufs has not
> yet been detected.
> > + * NULL if fast release of mbufs is not enabled.
> > + *
> > + * @see RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE
> > + */
> > struct rte_mempool *mb_pool;
>
> Do all drivers to it this way?
No, I think most drivers have separate structures for rx and tx queues. This driver doesn't so I'm reusing the existing mempool pointer.
Also, they don't cache the mempool pointer, but look at mbuf[0].pool at every burst; so their tx queue structure doesn't have a mempool pointer field.
And they check an offload flag (either the bit in the raw offload field, or a shadow variable for the relevant offload flag), instead of checking the mempool pointer.
Other drivers can be improved, and I have submitted an optimization patch for the i40e driver with some of the things I do in this patch:
https://inbox.dpdk.org/dev/20250624061238.89259-1-mb@smartsharesystems.com/
> Is it documented in ethdev?
The RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE flag is documented.
How to implement it in the drivers is not.
-Morten
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-06-26 15:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-24 18:14 [PATCH] net/null: Add fast mbuf release TX offload Morten Brørup
2025-06-26 14:05 ` Stephen Hemminger
2025-06-26 15:44 ` Morten Brørup
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).