Direct re-arming of buffers on receive side
Subsystems (2)
PATCH v9 2/4 net/i40e: implement mbufs recycle mode
In reply to Feifei WangDefine specific function implementation for i40e driver. Currently, mbufs recycle mode can support 128bit vector path and avx2 path. And can be enabled both in fast free and no fast free mode.
--- drivers/net/i40e/i40e_ethdev.c | 1 + drivers/net/i40e/i40e_ethdev.h | 2 + .../net/i40e/i40e_recycle_mbufs_vec_common.c | 147 ++++++++++++++++++ drivers/net/i40e/i40e_rxtx.c | 32 ++++ drivers/net/i40e/i40e_rxtx.h | 4 + drivers/net/i40e/meson.build | 1 + 6 files changed, 187 insertions(+) create mode 100644 drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
drivers/net/i40e/i40e_ethdev.c +1 -0
@@ -496,6 +496,7 @@ static const struct eth_dev_ops i40e_eth_dev_ops = { .flow_ops_get = i40e_dev_flow_ops_get, .rxq_info_get = i40e_rxq_info_get, .txq_info_get = i40e_txq_info_get, + .recycle_rxq_info_get = i40e_recycle_rxq_info_get, .rx_burst_mode_get = i40e_rx_burst_mode_get, .tx_burst_mode_get = i40e_tx_burst_mode_get, .timesync_enable = i40e_timesync_enable,
drivers/net/i40e/i40e_ethdev.h +2 -0
@@ -1355,6 +1355,8 @@ void i40e_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, struct rte_eth_rxq_info *qinfo);void i40e_txq_info_get (struct rte_eth_dev *dev,uint16_t queue_id,struct rte_eth_txq_info *qinfo); +void i40e_recycle_rxq_info_get (struct rte_eth_dev *dev,uint16_t queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info);int i40e_rx_burst_mode_get (struct rte_eth_dev *dev,uint16_t queue_id,struct rte_eth_burst_mode *mode); int i40e_tx_burst_mode_get(struct rte_eth_dev *dev, uint16_t queue_id,
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +147 -0
147 lines not on this page · raw message
drivers/net/i40e/i40e_rxtx.c +32 -0
@@ -3199,6 +3199,30 @@ i40e_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, qinfo->conf.offloads = txq->offloads; } +void +i40e_recycle_rxq_info_get (struct rte_eth_dev *dev,uint16_t queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info) +{ +struct i40e_rx_queue *rxq; +struct i40e_adapter *ad = +I40E_DEV_PRIVATE_TO_ADAPTER (dev->data->dev_private); + + rxq = dev->data->rx_queues[queue_id]; + + recycle_rxq_info->mbuf_ring = (void *)rxq->sw_ring; + recycle_rxq_info->mp = rxq->mp; + recycle_rxq_info->mbuf_ring_size = rxq->nb_rx_desc; + recycle_rxq_info->receive_tail = &rxq->rx_tail; + +if (ad->rx_vec_allowed) { + recycle_rxq_info->refill_requirement =RTE_I40E_RXQ_REARM_THRESH ; + recycle_rxq_info->refill_head = &rxq->rxrearm_start; + }else { + recycle_rxq_info->refill_requirement = rxq->rx_free_thresh; + recycle_rxq_info->refill_head = &rxq->rx_free_trigger; + } +} +#ifdef RTE_ARCH_X86 static inline bool get_avx_supported (bool request_avx512)
@@ -3293,6 +3317,8 @@ i40e_set_rx_function(struct rte_eth_dev *dev) dev->rx_pkt_burst = ad->rx_use_avx2 ? i40e_recv_scattered_pkts_vec_avx2 : i40e_recv_scattered_pkts_vec; + dev->recycle_rx_descriptors_refill = + i40e_recycle_rx_descriptors_refill_vec; } }else {if (ad->rx_use_avx512) {
@@ -3311,9 +3337,12 @@ i40e_set_rx_function(struct rte_eth_dev *dev) dev->rx_pkt_burst = ad->rx_use_avx2 ? i40e_recv_pkts_vec_avx2 : i40e_recv_pkts_vec; + dev->recycle_rx_descriptors_refill = + i40e_recycle_rx_descriptors_refill_vec; } }#else /* RTE_ARCH_X86 */ + dev->recycle_rx_descriptors_refill = i40e_recycle_rx_descriptors_refill_vec;if (dev->data->scattered_rx) { PMD_INIT_LOG(DEBUG, "Using Vector Scattered Rx (port %d).",
@@ -3481,15 +3510,18 @@ i40e_set_tx_function(struct rte_eth_dev *dev) dev->tx_pkt_burst = ad->tx_use_avx2 ? i40e_xmit_pkts_vec_avx2 : i40e_xmit_pkts_vec; + dev->recycle_tx_mbufs_reuse = i40e_recycle_tx_mbufs_reuse_vec; }#else /* RTE_ARCH_X86 */ PMD_INIT_LOG (DEBUG ,"Using Vector Tx (port %d)." , dev->data->port_id); dev->tx_pkt_burst = i40e_xmit_pkts_vec; + dev->recycle_tx_mbufs_reuse = i40e_recycle_tx_mbufs_reuse_vec;#endif /* RTE_ARCH_X86 */ }else {PMD_INIT_LOG (DEBUG ,"Simple tx finally be used." ); dev->tx_pkt_burst = i40e_xmit_pkts_simple; + dev->recycle_tx_mbufs_reuse = i40e_recycle_tx_mbufs_reuse_vec; } dev->tx_pkt_prepare = i40e_simple_prep_pkts; }else {
drivers/net/i40e/i40e_rxtx.h +4 -0
@@ -236,6 +236,10 @@ uint32_t i40e_dev_rx_queue_count(void *rx_queue);int i40e_dev_rx_descriptor_status (void *rx_queue,uint16_t offset);int i40e_dev_tx_descriptor_status (void *tx_queue,uint16_t offset); +uint16_t i40e_recycle_tx_mbufs_reuse_vec (void *tx_queue, +struct rte_eth_recycle_rxq_info *recycle_rxq_info); +void i40e_recycle_rx_descriptors_refill_vec (void *rx_queue,uint16_t nb_mbufs); +uint16_t i40e_recv_pkts_vec (void *rx_queue,struct rte_mbuf **rx_pkts,uint16_t nb_pkts); uint16_t i40e_recv_scattered_pkts_vec(void *rx_queue,
drivers/net/i40e/meson.build +1 -0
@@ -34,6 +34,7 @@ sources = files( 'i40e_tm.c', 'i40e_hash.c', 'i40e_vf_representor.c', + 'i40e_recycle_mbufs_vec_common.c', 'rte_pmd_i40e.c', )
Signature · 1 line
2.25.1
PATCH v9 3/4 net/ixgbe: implement mbufs recycle mode
In reply to Feifei WangDefine specific function implementation for ixgbe driver. Currently, recycle buffer mode can support 128bit vector path. And can be enabled both in fast free and no fast free mode.
--- drivers/net/ixgbe/ixgbe_ethdev.c | 1 + drivers/net/ixgbe/ixgbe_ethdev.h | 3 + .../ixgbe/ixgbe_recycle_mbufs_vec_common.c | 143 ++++++++++++++++++ drivers/net/ixgbe/ixgbe_rxtx.c | 37 ++++- drivers/net/ixgbe/ixgbe_rxtx.h | 4 + drivers/net/ixgbe/meson.build | 2 + 6 files changed, 188 insertions(+), 2 deletions(-) create mode 100644 drivers/net/ixgbe/ixgbe_recycle_mbufs_vec_common.c
drivers/net/ixgbe/ixgbe_ethdev.c +1 -0
@@ -543,6 +543,7 @@ static const struct eth_dev_ops ixgbe_eth_dev_ops = { .set_mc_addr_list = ixgbe_dev_set_mc_addr_list, .rxq_info_get = ixgbe_rxq_info_get, .txq_info_get = ixgbe_txq_info_get, + .recycle_rxq_info_get = ixgbe_recycle_rxq_info_get, .timesync_enable = ixgbe_timesync_enable, .timesync_disable = ixgbe_timesync_disable, .timesync_read_rx_timestamp = ixgbe_timesync_read_rx_timestamp,
drivers/net/ixgbe/ixgbe_ethdev.h +3 -0
@@ -626,6 +626,9 @@ void ixgbe_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,void ixgbe_txq_info_get (struct rte_eth_dev *dev,uint16_t queue_id,struct rte_eth_txq_info *qinfo); +void ixgbe_recycle_rxq_info_get (struct rte_eth_dev *dev,uint16_t queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info); +int ixgbevf_dev_rx_init (struct rte_eth_dev *dev);void ixgbevf_dev_tx_init (struct rte_eth_dev *dev);
drivers/net/ixgbe/ixgbe_recycle_mbufs_vec_common.c new file +143 -0
143 lines not on this page · raw message
drivers/net/ixgbe/ixgbe_rxtx.c +35 -2
@@ -2552,6 +2552,9 @@ ixgbe_set_tx_function(struct rte_eth_dev *dev, struct ixgbe_tx_queue *txq) (rte_eal_process_type() != RTE_PROC_PRIMARY || ixgbe_txq_vec_setup(txq) == 0)) {PMD_INIT_LOG (DEBUG ,"Vector tx enabled." ); +#if defined(RTE_ARCH_X86 ) || defined(RTE_ARCH_ARM ) + dev->recycle_tx_mbufs_reuse = ixgbe_recycle_tx_mbufs_reuse_vec; +#endif dev->tx_pkt_burst = ixgbe_xmit_pkts_vec; } else dev->tx_pkt_burst = ixgbe_xmit_pkts_simple;
@@ -4890,7 +4893,10 @@ ixgbe_set_rx_function(struct rte_eth_dev *dev)PMD_INIT_LOG (DEBUG ,"Using Vector Scattered Rx " "callback (port=%d)." , dev->data->port_id); - +#if defined(RTE_ARCH_X86 ) || defined(RTE_ARCH_ARM ) + dev->recycle_rx_descriptors_refill = + ixgbe_recycle_rx_descriptors_refill_vec; +#endif dev->rx_pkt_burst = ixgbe_recv_scattered_pkts_vec; }else if (adapter->rx_bulk_alloc_allowed) { PMD_INIT_LOG(DEBUG, "Using a Scattered with bulk "
@@ -4919,7 +4925,9 @@ ixgbe_set_rx_function(struct rte_eth_dev *dev)"burst size no less than %d (port=%d)." ,RTE_IXGBE_DESCS_PER_LOOP , dev->data->port_id); - +#if defined(RTE_ARCH_X86 ) || defined(RTE_ARCH_ARM ) + dev->recycle_rx_descriptors_refill = ixgbe_recycle_rx_descriptors_refill_vec; +#endif dev->rx_pkt_burst = ixgbe_recv_pkts_vec; }else if (adapter->rx_bulk_alloc_allowed) { PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are "
@@ -5691,6 +5699,31 @@ ixgbe_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, qinfo->conf.tx_deferred_start = txq->tx_deferred_start; } +void +ixgbe_recycle_rxq_info_get (struct rte_eth_dev *dev,uint16_t queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info) +{ +struct ixgbe_rx_queue *rxq; +struct ixgbe_adapter *adapter = dev->data->dev_private; + + rxq = dev->data->rx_queues[queue_id]; + + recycle_rxq_info->mbuf_ring = (void *)rxq->sw_ring; + recycle_rxq_info->mp = rxq->mb_pool; + recycle_rxq_info->mbuf_ring_size = rxq->nb_rx_desc; + recycle_rxq_info->receive_tail = &rxq->rx_tail; + +if (adapter->rx_vec_allowed) { +#if defined(RTE_ARCH_X86 ) || defined(RTE_ARCH_ARM ) + recycle_rxq_info->refill_requirement =RTE_IXGBE_RXQ_REARM_THRESH ; + recycle_rxq_info->refill_head = &rxq->rxrearm_start; +#endif + }else { + recycle_rxq_info->refill_requirement = rxq->rx_free_thresh; + recycle_rxq_info->refill_head = &rxq->rx_free_trigger; + } +} +/* * [VF] Initializes Receive Unit. */
drivers/net/ixgbe/ixgbe_rxtx.h +4 -0
@@ -295,6 +295,10 @@ int ixgbe_dev_tx_done_cleanup(void *tx_queue, uint32_t free_cnt);extern const uint32_t ptype_table[IXGBE_PACKET_TYPE_MAX ];extern const uint32_t ptype_table_tn[IXGBE_PACKET_TYPE_TN_MAX ]; +uint16_t ixgbe_recycle_tx_mbufs_reuse_vec (void *tx_queue, +struct rte_eth_recycle_rxq_info *recycle_rxq_info); +void ixgbe_recycle_rx_descriptors_refill_vec (void *rx_queue,uint16_t nb_mbufs); +uint16_t ixgbe_xmit_fixed_burst_vec (void *tx_queue,struct rte_mbuf **tx_pkts,uint16_t nb_pkts);int ixgbe_txq_vec_setup (struct ixgbe_tx_queue *txq);
drivers/net/ixgbe/meson.build +2 -0
@@ -26,11 +26,13 @@ deps += ['hash', 'security'] if arch_subdir == 'x86' sources += files('ixgbe_rxtx_vec_sse.c') + sources += files('ixgbe_recycle_mbufs_vec_common.c') if is_windows and cc.get_id() != 'clang' cflags += ['-fno-asynchronous-unwind-tables'] endif elif arch_subdir == 'arm' sources += files('ixgbe_rxtx_vec_neon.c') + sources += files('ixgbe_recycle_mbufs_vec_common.c') endif includes += include_directories('base')
Signature · 1 line
2.25.1
PATCH v9 4/4 app/testpmd: add recycle mbufs engine
In reply to Feifei WangAdd recycle mbufs engine for testpmd. This engine forward pkts with I/O forward mode. But enable mbufs recycle feature to recycle used txq mbufs for rxq mbuf ring, which can bypass mempool path and save CPU cycles.
--- app/test-pmd/meson.build | 1 + app/test-pmd/recycle_mbufs.c | 58 +++++++++++++++++++++ app/test-pmd/testpmd.c | 1 + app/test-pmd/testpmd.h | 3 ++ doc/guides/testpmd_app_ug/run_app.rst | 1 + doc/guides/testpmd_app_ug/testpmd_funcs.rst | 5 +- 6 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 app/test-pmd/recycle_mbufs.c
app/test-pmd/meson.build +1 -0
@@ -22,6 +22,7 @@ sources = files( 'macswap.c', 'noisy_vnf.c', 'parameters.c', + 'recycle_mbufs.c', 'rxonly.c', 'shared_rxq_fwd.c', 'testpmd.c',
app/test-pmd/recycle_mbufs.c new file +58 -0
58 lines not on this page · raw message
app/test-pmd/testpmd.c +1 -0
@@ -199,6 +199,7 @@ struct fwd_engine * fwd_engines[] = { &icmp_echo_engine, &noisy_vnf_engine, &five_tuple_swap_fwd_engine, + &recycle_mbufs_engine, #ifdef RTE_LIBRTE_IEEE1588 &ieee1588_fwd_engine, #endif
app/test-pmd/testpmd.h +3 -0
@@ -188,6 +188,8 @@ struct fwd_stream {struct pkt_burst_stats rx_burst_stats;struct pkt_burst_stats tx_burst_stats;struct fwd_lcore *lcore;/**< Lcore being scheduled. */ +/**< Rx queue information for recycling mbufs */ +struct rte_eth_recycle_rxq_info recycle_rxq_info; };/**
@@ -449,6 +451,7 @@ extern struct fwd_engine csum_fwd_engine;extern struct fwd_engine icmp_echo_engine;extern struct fwd_engine noisy_vnf_engine;extern struct fwd_engine five_tuple_swap_fwd_engine; +extern struct fwd_engine recycle_mbufs_engine;#ifdef RTE_LIBRTE_IEEE1588 extern struct fwd_engine ieee1588_fwd_engine;#endif
doc/guides/testpmd_app_ug/run_app.rst +1 -0
@@ -232,6 +232,7 @@ The command line options are: noisy 5tswap shared-rxq + recycle_mbufs * ``--rss-ip``
doc/guides/testpmd_app_ug/testpmd_funcs.rst +4 -1
@@ -318,7 +318,7 @@ set fwd Set the packet forwarding mode:: testpmd> set fwd (io|mac|macswap|flowgen| \ - rxonly|txonly|csum|icmpecho|noisy|5tswap|shared-rxq) (""|retry) + rxonly|txonly|csum|icmpecho|noisy|5tswap|shared-rxq|recycle_mbufs) (""|retry) ``retry`` can be specified for forwarding engines except ``rx_only``.
@@ -364,6 +364,9 @@ The available information categories are: * ``shared-rxq``: Receive only for shared Rx queue. Resolve packet source port from mbuf and update stream statistics accordingly. +* ``recycle_mbufs``: Recycle Tx queue used mbufs for Rx queue mbuf ring. + This mode uses fast path mbuf recycle feature and forwards packets in I/O mode. + Example:: testpmd> set fwd rxonly
Signature · 1 line
2.25.1
v10 cover Recycle mbufs from Tx queue into Rx queue
In reply to Feifei WangCurrently, the transmit side frees the buffers into the lcore cache and the receive side allocates buffers from the lcore cache. The transmit side typically frees 32 buffers resulting in 32*8=256B of stores to lcore cache. The receive side allocates 32 buffers and stores them in the receive side software ring, resulting in 32*8=256B of stores and 256B of load from the lcore cache.
This patch proposes a mechanism to avoid freeing to/allocating from the lcore cache. i.e. the receive side will free the buffers from transmit side directly into its software ring. This will avoid the 256B of loads and stores introduced by the lcore cache. It also frees up the cache lines used by the lcore cache. And we can call this mode as mbufs recycle mode.
In the latest version, mbufs recycle mode is packaged as a separate API.
This allows for the users to change rxq/txq pairing in real time in data plane, according to the analysis of the packet flow by the application, for example:
-----------------------------------------------------------------------
Step 1: upper application analyse the flow direction
Step 2: recycle_rxq_info = rte_eth_recycle_rx_queue_info_get(rx_portid, rx_queueid) Step 3: rte_eth_recycle_mbufs(rx_portid, rx_queueid, tx_portid, tx_queueid, recycle_rxq_info); Step 4: rte_eth_rx_burst(rx_portid,rx_queueid);
Step 5: rte_eth_tx_burst(tx_portid,tx_queueid);
-----------------------------------------------------------------------
Above can support user to change rxq/txq pairing at run-time and user does not need to know the direction of flow in advance. This can effectively expand mbufs recycle mode's use scenarios.
Furthermore, mbufs recycle mode is no longer limited to the same pmd,
it can support moving mbufs between different vendor pmds, even can put the mbufs anywhere into your Rx mbuf ring as long as the address of the mbuf ring can be provided. In the latest version, we enable mbufs recycle mode in i40e pmd and ixgbe pmd, and also try to use i40e driver in Rx, ixgbe driver in Tx, and then achieve 7-9% performance improvement by mbufs recycle mode.
Difference between mbuf recycle, ZC API used in mempool and general path
For general path:
Rx: 32 pkts memcpy from mempool cache to rx_sw_ring
Tx: 32 pkts memcpy from tx_sw_ring to temporary variable + 32 pkts memcpy from temporary variable to mempool cache
For ZC API used in mempool:
Rx: 32 pkts memcpy from mempool cache to rx_sw_ring
Tx: 32 pkts memcpy from tx_sw_ring to zero-copy mempool cache
Refer link: http://patches.dpdk.org/project/dpdk/patch/[email protected]/
For mbufs recycle:
Rx/Tx: 32 pkts memcpy from tx_sw_ring to rx_sw_ring
Thus we can see in the one loop, compared to general path, mbufs recycle mode reduces 32+32=64 pkts memcpy; Compared to ZC API used in mempool, we can see mbufs recycle mode reduce 32 pkts memcpy in each loop.
So, mbufs recycle has its own benefits.
Testing status:
(1) dpdk l3fwd test with multiple drivers:
port 0: 82599 NIC port 1: XL710 NIC
-------------------------------------------------------------
Without fast free With fast free
Thunderx2: +7.53% +13.54%
-------------------------------------------------------------
(2) dpdk l3fwd test with same driver:
port 0 && 1: XL710 NIC
-------------------------------------------------------------
Without fast free With fast free
Ampere altra: +12.61% +11.42%
n1sdp: +8.30% +3.85%
x86-sse: +8.43% +3.72%
-------------------------------------------------------------
(3) Performance comparison with ZC_mempool used
port 0 && 1: XL710 NIC
with fast free
-------------------------------------------------------------
With recycle buffer With zc_mempool
Ampere altra: 11.42% 3.54%
-------------------------------------------------------------
Furthermore, we add recycle_mbuf engine in testpmd. Due to XL710 NIC has I/O bottleneck in testpmd in ampere altra, we can not see throughput change compared with I/O fwd engine. However, using record cmd in testpmd:
'$set record-burst-stats on'
we can see the ratio of 'Rx/Tx burst size of 32' is reduced. This indicate mbufs recycle can save CPU cycles.
V2:
1. Use data-plane API to enable direct-rearm (Konstantin, Honnappa)
2. Add 'txq_data_get' API to get txq info for Rx (Konstantin)
3. Use input parameter to enable direct rearm in l3fwd (Konstantin)
4. Add condition detection for direct rearm API (Morten, Andrew Rybchenko)
V3:
1. Seperate Rx and Tx operation with two APIs in direct-rearm (Konstantin)
2. Delete L3fwd change for direct rearm (Jerin)
3. enable direct rearm in ixgbe driver in Arm
v4:
1. Rename direct-rearm as buffer recycle. Based on this, function name and variable name are changed to let this mode more general for all drivers. (Konstantin, Morten)
2. Add ring wrapping check (Konstantin)
v5:
1. some change for ethdev API (Morten)
2. add support for avx2, sse, altivec path
v6:
1. fix ixgbe build issue in ppc
2. remove 'recycle_tx_mbufs_reuse' and 'recycle_rx_descriptors_refill' API wrapper (Tech Board meeting)
3. add recycle_mbufs engine in testpmd (Tech Board meeting)
4. add namespace in the functions related to mbufs recycle(Ferruh)
v7:
1. move 'rxq/txq data' pointers to the beginning of eth_dev structure, in order to keep them in the same cache line as rx/tx_burst function pointers (Morten)
2. add the extra description for 'rte_eth_recycle_mbufs' to show it can support feeding 1 Rx queue from 2 Tx queues in the same thread (Konstantin)
3. For i40e/ixgbe driver, make the previous copied buffers as invalid if there are Tx buffers refcnt > 1 or from unexpected mempool (Konstantin)
4. add check for the return value of 'rte_eth_recycle_rx_queue_info_get' in testpmd fwd engine (Morten)
v8:
1. add arm/x86 build option to fix ixgbe build issue in ppc
v9:
1. delete duplicate file name for ixgbe
v10:
1. fix compile issue on windows
Feifei Wang (4):
ethdev: add API for mbufs recycle mode
net/i40e: implement mbufs recycle mode
net/ixgbe: implement mbufs recycle mode
app/testpmd: add recycle mbufs engine
app/test-pmd/meson.build | 1 + app/test-pmd/recycle_mbufs.c | 58 ++++++ app/test-pmd/testpmd.c | 1 + app/test-pmd/testpmd.h | 3 + doc/guides/rel_notes/release_23_11.rst | 15 ++ doc/guides/testpmd_app_ug/run_app.rst | 1 + doc/guides/testpmd_app_ug/testpmd_funcs.rst | 5 +- drivers/net/i40e/i40e_ethdev.c | 1 + drivers/net/i40e/i40e_ethdev.h | 2 + .../net/i40e/i40e_recycle_mbufs_vec_common.c | 147 ++++++++++++++ drivers/net/i40e/i40e_rxtx.c | 32 ++++ drivers/net/i40e/i40e_rxtx.h | 4 + drivers/net/i40e/meson.build | 1 + drivers/net/ixgbe/ixgbe_ethdev.c | 1 + drivers/net/ixgbe/ixgbe_ethdev.h | 3 + .../ixgbe/ixgbe_recycle_mbufs_vec_common.c | 143 ++++++++++++++ drivers/net/ixgbe/ixgbe_rxtx.c | 37 +++- drivers/net/ixgbe/ixgbe_rxtx.h | 4 + drivers/net/ixgbe/meson.build | 2 + lib/ethdev/ethdev_driver.h | 10 + lib/ethdev/ethdev_private.c | 2 + lib/ethdev/rte_ethdev.c | 31 +++ lib/ethdev/rte_ethdev.h | 181 ++++++++++++++++++ lib/ethdev/rte_ethdev_core.h | 23 ++- lib/ethdev/version.map | 3 + 25 files changed, 702 insertions(+), 9 deletions(-) create mode 100644 app/test-pmd/recycle_mbufs.c create mode 100644 drivers/net/i40e/i40e_recycle_mbufs_vec_common.c create mode 100644 drivers/net/ixgbe/ixgbe_recycle_mbufs_vec_common.c
Signature · 1 line
2.25.1
PATCH v10 1/4 ethdev: add API for mbufs recycle mode
Add 'rte_eth_recycle_rx_queue_info_get' and 'rte_eth_recycle_mbufs' APIs to recycle used mbufs from a transmit queue of an Ethernet device, and move these mbufs into a mbuf ring for a receive queue of an Ethernet device. This can bypass mempool 'put/get' operations hence saving CPU cycles.
For each recycling mbufs, the rte_eth_recycle_mbufs() function performs the following operations:
- Copy used *rte_mbuf* buffer pointers from Tx mbuf ring into Rx mbuf ring.
- Replenish the Rx descriptors with the recycling *rte_mbuf* mbufs freed from the Tx mbuf ring.
--- doc/guides/rel_notes/release_23_11.rst | 15 ++ lib/ethdev/ethdev_driver.h | 10 ++ lib/ethdev/ethdev_private.c | 2 + lib/ethdev/rte_ethdev.c | 31 +++++ lib/ethdev/rte_ethdev.h | 181 +++++++++++++++++++++++++ lib/ethdev/rte_ethdev_core.h | 23 +++- lib/ethdev/version.map | 3 + 7 files changed, 259 insertions(+), 6 deletions(-)
doc/guides/rel_notes/release_23_11.rst +15 -0
@@ -55,6 +55,13 @@ New Features Also, make sure to start the actual text at the margin. ======================================================= +* **Add mbufs recycling support. ** + + Added ``rte_eth_recycle_rx_queue_info_get`` and ``rte_eth_recycle_mbufs`` + APIs which allow the user to copy used mbufs from the Tx mbuf ring + into the Rx mbuf ring. This feature supports the case that the Rx Ethernet + device is different from the Tx Ethernet device with respective driver + callback functions in ``rte_eth_recycle_mbufs``. Removed Items -------------
@@ -100,6 +107,14 @@ ABI Changes Also, make sure to start the actual text at the margin. ======================================================= +* ethdev: Added ``recycle_tx_mbufs_reuse`` and ``recycle_rx_descriptors_refill`` + fields to ``rte_eth_dev`` structure. + +* ethdev: Structure ``rte_eth_fp_ops`` was affected to add + ``recycle_tx_mbufs_reuse`` and ``recycle_rx_descriptors_refill`` + fields, to move ``rxq`` and ``txq`` fields, to change the size of + ``reserved1`` and ``reserved2`` fields. + Known Issues ------------
lib/ethdev/ethdev_driver.h +10 -0
@@ -58,6 +58,10 @@ struct rte_eth_dev {eth_rx_descriptor_status_t rx_descriptor_status;/** Check the status of a Tx descriptor */ eth_tx_descriptor_status_t tx_descriptor_status; +/** Pointer to PMD transmit mbufs reuse function */ +eth_recycle_tx_mbufs_reuse_t recycle_tx_mbufs_reuse; +/** Pointer to PMD receive descriptors refill function */ +eth_recycle_rx_descriptors_refill_t recycle_rx_descriptors_refill;/** * Device data that is shared between primary and secondary processes
@@ -507,6 +511,10 @@ typedef void (*eth_rxq_info_get_t)(struct rte_eth_dev *dev,typedef void (*eth_txq_info_get_t )(struct rte_eth_dev *dev,uint16_t tx_queue_id,struct rte_eth_txq_info *qinfo); +typedef void (*eth_recycle_rxq_info_get_t )(struct rte_eth_dev *dev, +uint16_t rx_queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info); +typedef int (*eth_burst_mode_get_t )(struct rte_eth_dev *dev,uint16_t queue_id,struct rte_eth_burst_mode *mode);
@@ -1250,6 +1258,8 @@ struct eth_dev_ops {eth_rxq_info_get_t rxq_info_get;/** Retrieve Tx queue information */ eth_txq_info_get_t txq_info_get; +/** Retrieve mbufs recycle Rx queue information */ +eth_recycle_rxq_info_get_t recycle_rxq_info_get;eth_burst_mode_get_t rx_burst_mode_get;/**< Get Rx burst mode */ eth_burst_mode_get_t tx_burst_mode_get;/**< Get Tx burst mode */ eth_fw_version_get_t fw_version_get;/**< Get firmware version */
lib/ethdev/ethdev_private.c +2 -0
@@ -277,6 +277,8 @@ eth_dev_fp_ops_setup(struct rte_eth_fp_ops *fpo, fpo->rx_queue_count = dev->rx_queue_count; fpo->rx_descriptor_status = dev->rx_descriptor_status; fpo->tx_descriptor_status = dev->tx_descriptor_status; + fpo->recycle_tx_mbufs_reuse = dev->recycle_tx_mbufs_reuse; + fpo->recycle_rx_descriptors_refill = dev->recycle_rx_descriptors_refill; fpo->rxq.data = dev->data->rx_queues; fpo->rxq.clbk = (void **)(uintptr_t )dev->post_rx_burst_cbs;
lib/ethdev/rte_ethdev.c +31 -0
@@ -5876,6 +5876,37 @@ rte_eth_tx_queue_info_get(uint16_t port_id, uint16_t queue_id,return 0 ; } +int +rte_eth_recycle_rx_queue_info_get (uint16_t port_id,uint16_t queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info) +{ +struct rte_eth_dev *dev; + +RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -ENODEV ); + dev = &rte_eth_devices[port_id]; + +if (queue_id >= dev->data->nb_rx_queues) { +RTE_ETHDEV_LOG (ERR ,"Invalid Rx queue_id=%u\n" , queue_id); +return -EINVAL ; + } + +if (dev->data->rx_queues ==NULL || + dev->data->rx_queues[queue_id] ==NULL ) { +RTE_ETHDEV_LOG (ERR , +"Rx queue %" PRIu16" of device with port_id=%" + PRIu16" has not been setup\n" , + queue_id, port_id); +return -EINVAL ; + } + +if (*dev->dev_ops->recycle_rxq_info_get ==NULL ) +return -ENOTSUP ; + + dev->dev_ops->recycle_rxq_info_get (dev, queue_id, recycle_rxq_info); + +return 0 ; +} +int rte_eth_rx_burst_mode_get (uint16_t port_id,uint16_t queue_id,struct rte_eth_burst_mode *mode)
lib/ethdev/rte_ethdev.h +181 -0
199 lines not on this page · raw message
lib/ethdev/rte_ethdev_core.h +17 -6
@@ -55,6 +55,13 @@ typedef int (*eth_rx_descriptor_status_t)(void *rxq, uint16_t offset);/** @internal Check the status of a Tx descriptor */ typedef int (*eth_tx_descriptor_status_t )(void *txq,uint16_t offset); +/** @internal Copy used mbufs from Tx mbuf ring into Rx mbuf ring */ +typedef uint16_t (*eth_recycle_tx_mbufs_reuse_t )(void *txq, +struct rte_eth_recycle_rxq_info *recycle_rxq_info); + +/** @internal Refill Rx descriptors with the recycling mbufs */ +typedef void (*eth_recycle_rx_descriptors_refill_t )(void *rxq,uint16_t nb); +/** * @internal * Structure used to hold opaque pointers to internal ethdev Rx/Tx
@@ -83,15 +90,17 @@ struct rte_eth_fp_ops {* Rx fast-path functions and related data. * 64-bit systems: occupies first 64B line */ +/** Rx queues data. */ +struct rte_ethdev_qdata rxq;/** PMD receive function. */ eth_rx_burst_t rx_pkt_burst;/** Get the number of used Rx descriptors. */ eth_rx_queue_count_t rx_queue_count;/** Check the status of a Rx descriptor. */ eth_rx_descriptor_status_t rx_descriptor_status; -/** Rx queues data. */ -struct rte_ethdev_qdata rxq; -uintptr_t reserved1[3 ]; +/** Refill Rx descriptors with the recycling mbufs. */ +eth_recycle_rx_descriptors_refill_t recycle_rx_descriptors_refill; +uintptr_t reserved1[2 ];/**@}*/ /**@{*/
@@ -99,15 +108,17 @@ struct rte_eth_fp_ops {* Tx fast-path functions and related data. * 64-bit systems: occupies second 64B line */ +/** Tx queues data. */ +struct rte_ethdev_qdata txq;/** PMD transmit function. */ eth_tx_burst_t tx_pkt_burst;/** PMD transmit prepare function. */ eth_tx_prep_t tx_pkt_prepare;/** Check the status of a Tx descriptor. */ eth_tx_descriptor_status_t tx_descriptor_status; -/** Tx queues data. */ -struct rte_ethdev_qdata txq; -uintptr_t reserved2[3 ]; +/** Copy used mbufs from Tx mbuf ring into Rx. */ +eth_recycle_tx_mbufs_reuse_t recycle_tx_mbufs_reuse; +uintptr_t reserved2[2 ];/**@}*/ } __rte_cache_aligned;
lib/ethdev/version.map +3 -0
@@ -312,6 +312,9 @@ EXPERIMENTAL { rte_flow_async_action_list_handle_query_update; rte_flow_async_actions_update; rte_flow_restore_info_dynflag; + + # added in 23.11 + rte_eth_recycle_rx_queue_info_get; }; INTERNAL {
Signature · 1 line
2.25.1
PATCH v10 2/4 net/i40e: implement mbufs recycle mode
In reply to Feifei WangDefine specific function implementation for i40e driver. Currently, mbufs recycle mode can support 128bit vector path and avx2 path. And can be enabled both in fast free and no fast free mode.
--- drivers/net/i40e/i40e_ethdev.c | 1 + drivers/net/i40e/i40e_ethdev.h | 2 + .../net/i40e/i40e_recycle_mbufs_vec_common.c | 147 ++++++++++++++++++ drivers/net/i40e/i40e_rxtx.c | 32 ++++ drivers/net/i40e/i40e_rxtx.h | 4 + drivers/net/i40e/meson.build | 1 + 6 files changed, 187 insertions(+) create mode 100644 drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
drivers/net/i40e/i40e_ethdev.c +1 -0
@@ -496,6 +496,7 @@ static const struct eth_dev_ops i40e_eth_dev_ops = { .flow_ops_get = i40e_dev_flow_ops_get, .rxq_info_get = i40e_rxq_info_get, .txq_info_get = i40e_txq_info_get, + .recycle_rxq_info_get = i40e_recycle_rxq_info_get, .rx_burst_mode_get = i40e_rx_burst_mode_get, .tx_burst_mode_get = i40e_tx_burst_mode_get, .timesync_enable = i40e_timesync_enable,
drivers/net/i40e/i40e_ethdev.h +2 -0
@@ -1355,6 +1355,8 @@ void i40e_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, struct rte_eth_rxq_info *qinfo);void i40e_txq_info_get (struct rte_eth_dev *dev,uint16_t queue_id,struct rte_eth_txq_info *qinfo); +void i40e_recycle_rxq_info_get (struct rte_eth_dev *dev,uint16_t queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info);int i40e_rx_burst_mode_get (struct rte_eth_dev *dev,uint16_t queue_id,struct rte_eth_burst_mode *mode); int i40e_tx_burst_mode_get(struct rte_eth_dev *dev, uint16_t queue_id,
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +147 -0
147 lines not on this page · raw message
drivers/net/i40e/i40e_rxtx.c +32 -0
@@ -3199,6 +3199,30 @@ i40e_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, qinfo->conf.offloads = txq->offloads; } +void +i40e_recycle_rxq_info_get (struct rte_eth_dev *dev,uint16_t queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info) +{ +struct i40e_rx_queue *rxq; +struct i40e_adapter *ad = +I40E_DEV_PRIVATE_TO_ADAPTER (dev->data->dev_private); + + rxq = dev->data->rx_queues[queue_id]; + + recycle_rxq_info->mbuf_ring = (void *)rxq->sw_ring; + recycle_rxq_info->mp = rxq->mp; + recycle_rxq_info->mbuf_ring_size = rxq->nb_rx_desc; + recycle_rxq_info->receive_tail = &rxq->rx_tail; + +if (ad->rx_vec_allowed) { + recycle_rxq_info->refill_requirement =RTE_I40E_RXQ_REARM_THRESH ; + recycle_rxq_info->refill_head = &rxq->rxrearm_start; + }else { + recycle_rxq_info->refill_requirement = rxq->rx_free_thresh; + recycle_rxq_info->refill_head = &rxq->rx_free_trigger; + } +} +#ifdef RTE_ARCH_X86 static inline bool get_avx_supported (bool request_avx512)
@@ -3293,6 +3317,8 @@ i40e_set_rx_function(struct rte_eth_dev *dev) dev->rx_pkt_burst = ad->rx_use_avx2 ? i40e_recv_scattered_pkts_vec_avx2 : i40e_recv_scattered_pkts_vec; + dev->recycle_rx_descriptors_refill = + i40e_recycle_rx_descriptors_refill_vec; } }else {if (ad->rx_use_avx512) {
@@ -3311,9 +3337,12 @@ i40e_set_rx_function(struct rte_eth_dev *dev) dev->rx_pkt_burst = ad->rx_use_avx2 ? i40e_recv_pkts_vec_avx2 : i40e_recv_pkts_vec; + dev->recycle_rx_descriptors_refill = + i40e_recycle_rx_descriptors_refill_vec; } }#else /* RTE_ARCH_X86 */ + dev->recycle_rx_descriptors_refill = i40e_recycle_rx_descriptors_refill_vec;if (dev->data->scattered_rx) { PMD_INIT_LOG(DEBUG, "Using Vector Scattered Rx (port %d).",
@@ -3481,15 +3510,18 @@ i40e_set_tx_function(struct rte_eth_dev *dev) dev->tx_pkt_burst = ad->tx_use_avx2 ? i40e_xmit_pkts_vec_avx2 : i40e_xmit_pkts_vec; + dev->recycle_tx_mbufs_reuse = i40e_recycle_tx_mbufs_reuse_vec; }#else /* RTE_ARCH_X86 */ PMD_INIT_LOG (DEBUG ,"Using Vector Tx (port %d)." , dev->data->port_id); dev->tx_pkt_burst = i40e_xmit_pkts_vec; + dev->recycle_tx_mbufs_reuse = i40e_recycle_tx_mbufs_reuse_vec;#endif /* RTE_ARCH_X86 */ }else {PMD_INIT_LOG (DEBUG ,"Simple tx finally be used." ); dev->tx_pkt_burst = i40e_xmit_pkts_simple; + dev->recycle_tx_mbufs_reuse = i40e_recycle_tx_mbufs_reuse_vec; } dev->tx_pkt_prepare = i40e_simple_prep_pkts; }else {
drivers/net/i40e/i40e_rxtx.h +4 -0
@@ -236,6 +236,10 @@ uint32_t i40e_dev_rx_queue_count(void *rx_queue);int i40e_dev_rx_descriptor_status (void *rx_queue,uint16_t offset);int i40e_dev_tx_descriptor_status (void *tx_queue,uint16_t offset); +uint16_t i40e_recycle_tx_mbufs_reuse_vec (void *tx_queue, +struct rte_eth_recycle_rxq_info *recycle_rxq_info); +void i40e_recycle_rx_descriptors_refill_vec (void *rx_queue,uint16_t nb_mbufs); +uint16_t i40e_recv_pkts_vec (void *rx_queue,struct rte_mbuf **rx_pkts,uint16_t nb_pkts); uint16_t i40e_recv_scattered_pkts_vec(void *rx_queue,
drivers/net/i40e/meson.build +1 -0
@@ -34,6 +34,7 @@ sources = files( 'i40e_tm.c', 'i40e_hash.c', 'i40e_vf_representor.c', + 'i40e_recycle_mbufs_vec_common.c', 'rte_pmd_i40e.c', )
Signature · 1 line
2.25.1
PATCH v10 3/4 net/ixgbe: implement mbufs recycle mode
In reply to Feifei WangDefine specific function implementation for ixgbe driver. Currently, recycle buffer mode can support 128bit vector path. And can be enabled both in fast free and no fast free mode.
--- drivers/net/ixgbe/ixgbe_ethdev.c | 1 + drivers/net/ixgbe/ixgbe_ethdev.h | 3 + .../ixgbe/ixgbe_recycle_mbufs_vec_common.c | 143 ++++++++++++++++++ drivers/net/ixgbe/ixgbe_rxtx.c | 37 ++++- drivers/net/ixgbe/ixgbe_rxtx.h | 4 + drivers/net/ixgbe/meson.build | 2 + 6 files changed, 188 insertions(+), 2 deletions(-) create mode 100644 drivers/net/ixgbe/ixgbe_recycle_mbufs_vec_common.c
drivers/net/ixgbe/ixgbe_ethdev.c +1 -0
@@ -543,6 +543,7 @@ static const struct eth_dev_ops ixgbe_eth_dev_ops = { .set_mc_addr_list = ixgbe_dev_set_mc_addr_list, .rxq_info_get = ixgbe_rxq_info_get, .txq_info_get = ixgbe_txq_info_get, + .recycle_rxq_info_get = ixgbe_recycle_rxq_info_get, .timesync_enable = ixgbe_timesync_enable, .timesync_disable = ixgbe_timesync_disable, .timesync_read_rx_timestamp = ixgbe_timesync_read_rx_timestamp,
drivers/net/ixgbe/ixgbe_ethdev.h +3 -0
@@ -626,6 +626,9 @@ void ixgbe_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,void ixgbe_txq_info_get (struct rte_eth_dev *dev,uint16_t queue_id,struct rte_eth_txq_info *qinfo); +void ixgbe_recycle_rxq_info_get (struct rte_eth_dev *dev,uint16_t queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info); +int ixgbevf_dev_rx_init (struct rte_eth_dev *dev);void ixgbevf_dev_tx_init (struct rte_eth_dev *dev);
drivers/net/ixgbe/ixgbe_recycle_mbufs_vec_common.c new file +143 -0
143 lines not on this page · raw message
drivers/net/ixgbe/ixgbe_rxtx.c +35 -2
@@ -2552,6 +2552,9 @@ ixgbe_set_tx_function(struct rte_eth_dev *dev, struct ixgbe_tx_queue *txq) (rte_eal_process_type() != RTE_PROC_PRIMARY || ixgbe_txq_vec_setup(txq) == 0)) {PMD_INIT_LOG (DEBUG ,"Vector tx enabled." ); +#if defined(RTE_ARCH_X86 ) || defined(RTE_ARCH_ARM ) + dev->recycle_tx_mbufs_reuse = ixgbe_recycle_tx_mbufs_reuse_vec; +#endif dev->tx_pkt_burst = ixgbe_xmit_pkts_vec; } else dev->tx_pkt_burst = ixgbe_xmit_pkts_simple;
@@ -4890,7 +4893,10 @@ ixgbe_set_rx_function(struct rte_eth_dev *dev)PMD_INIT_LOG (DEBUG ,"Using Vector Scattered Rx " "callback (port=%d)." , dev->data->port_id); - +#if defined(RTE_ARCH_X86 ) || defined(RTE_ARCH_ARM ) + dev->recycle_rx_descriptors_refill = + ixgbe_recycle_rx_descriptors_refill_vec; +#endif dev->rx_pkt_burst = ixgbe_recv_scattered_pkts_vec; }else if (adapter->rx_bulk_alloc_allowed) { PMD_INIT_LOG(DEBUG, "Using a Scattered with bulk "
@@ -4919,7 +4925,9 @@ ixgbe_set_rx_function(struct rte_eth_dev *dev)"burst size no less than %d (port=%d)." ,RTE_IXGBE_DESCS_PER_LOOP , dev->data->port_id); - +#if defined(RTE_ARCH_X86 ) || defined(RTE_ARCH_ARM ) + dev->recycle_rx_descriptors_refill = ixgbe_recycle_rx_descriptors_refill_vec; +#endif dev->rx_pkt_burst = ixgbe_recv_pkts_vec; }else if (adapter->rx_bulk_alloc_allowed) { PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are "
@@ -5691,6 +5699,31 @@ ixgbe_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, qinfo->conf.tx_deferred_start = txq->tx_deferred_start; } +void +ixgbe_recycle_rxq_info_get (struct rte_eth_dev *dev,uint16_t queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info) +{ +struct ixgbe_rx_queue *rxq; +struct ixgbe_adapter *adapter = dev->data->dev_private; + + rxq = dev->data->rx_queues[queue_id]; + + recycle_rxq_info->mbuf_ring = (void *)rxq->sw_ring; + recycle_rxq_info->mp = rxq->mb_pool; + recycle_rxq_info->mbuf_ring_size = rxq->nb_rx_desc; + recycle_rxq_info->receive_tail = &rxq->rx_tail; + +if (adapter->rx_vec_allowed) { +#if defined(RTE_ARCH_X86 ) || defined(RTE_ARCH_ARM ) + recycle_rxq_info->refill_requirement =RTE_IXGBE_RXQ_REARM_THRESH ; + recycle_rxq_info->refill_head = &rxq->rxrearm_start; +#endif + }else { + recycle_rxq_info->refill_requirement = rxq->rx_free_thresh; + recycle_rxq_info->refill_head = &rxq->rx_free_trigger; + } +} +/* * [VF] Initializes Receive Unit. */
drivers/net/ixgbe/ixgbe_rxtx.h +4 -0
@@ -295,6 +295,10 @@ int ixgbe_dev_tx_done_cleanup(void *tx_queue, uint32_t free_cnt);extern const uint32_t ptype_table[IXGBE_PACKET_TYPE_MAX ];extern const uint32_t ptype_table_tn[IXGBE_PACKET_TYPE_TN_MAX ]; +uint16_t ixgbe_recycle_tx_mbufs_reuse_vec (void *tx_queue, +struct rte_eth_recycle_rxq_info *recycle_rxq_info); +void ixgbe_recycle_rx_descriptors_refill_vec (void *rx_queue,uint16_t nb_mbufs); +uint16_t ixgbe_xmit_fixed_burst_vec (void *tx_queue,struct rte_mbuf **tx_pkts,uint16_t nb_pkts);int ixgbe_txq_vec_setup (struct ixgbe_tx_queue *txq);
drivers/net/ixgbe/meson.build +2 -0
@@ -26,11 +26,13 @@ deps += ['hash', 'security'] if arch_subdir == 'x86' sources += files('ixgbe_rxtx_vec_sse.c') + sources += files('ixgbe_recycle_mbufs_vec_common.c') if is_windows and cc.get_id() != 'clang' cflags += ['-fno-asynchronous-unwind-tables'] endif elif arch_subdir == 'arm' sources += files('ixgbe_rxtx_vec_neon.c') + sources += files('ixgbe_recycle_mbufs_vec_common.c') endif includes += include_directories('base')
Signature · 1 line
2.25.1
PATCH v10 4/4 app/testpmd: add recycle mbufs engine
In reply to Feifei WangAdd recycle mbufs engine for testpmd. This engine forward pkts with I/O forward mode. But enable mbufs recycle feature to recycle used txq mbufs for rxq mbuf ring, which can bypass mempool path and save CPU cycles.
--- app/test-pmd/meson.build | 1 + app/test-pmd/recycle_mbufs.c | 58 +++++++++++++++++++++ app/test-pmd/testpmd.c | 1 + app/test-pmd/testpmd.h | 3 ++ doc/guides/testpmd_app_ug/run_app.rst | 1 + doc/guides/testpmd_app_ug/testpmd_funcs.rst | 5 +- 6 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 app/test-pmd/recycle_mbufs.c
app/test-pmd/meson.build +1 -0
@@ -22,6 +22,7 @@ sources = files( 'macswap.c', 'noisy_vnf.c', 'parameters.c', + 'recycle_mbufs.c', 'rxonly.c', 'shared_rxq_fwd.c', 'testpmd.c',
app/test-pmd/recycle_mbufs.c new file +58 -0
58 lines not on this page · raw message
app/test-pmd/testpmd.c +1 -0
@@ -199,6 +199,7 @@ struct fwd_engine * fwd_engines[] = { &icmp_echo_engine, &noisy_vnf_engine, &five_tuple_swap_fwd_engine, + &recycle_mbufs_engine, #ifdef RTE_LIBRTE_IEEE1588 &ieee1588_fwd_engine, #endif
app/test-pmd/testpmd.h +3 -0
@@ -188,6 +188,8 @@ struct fwd_stream {struct pkt_burst_stats rx_burst_stats;struct pkt_burst_stats tx_burst_stats;struct fwd_lcore *lcore;/**< Lcore being scheduled. */ +/**< Rx queue information for recycling mbufs */ +struct rte_eth_recycle_rxq_info recycle_rxq_info; };/**
@@ -449,6 +451,7 @@ extern struct fwd_engine csum_fwd_engine;extern struct fwd_engine icmp_echo_engine;extern struct fwd_engine noisy_vnf_engine;extern struct fwd_engine five_tuple_swap_fwd_engine; +extern struct fwd_engine recycle_mbufs_engine;#ifdef RTE_LIBRTE_IEEE1588 extern struct fwd_engine ieee1588_fwd_engine;#endif
doc/guides/testpmd_app_ug/run_app.rst +1 -0
@@ -232,6 +232,7 @@ The command line options are: noisy 5tswap shared-rxq + recycle_mbufs * ``--rss-ip``
doc/guides/testpmd_app_ug/testpmd_funcs.rst +4 -1
@@ -318,7 +318,7 @@ set fwd Set the packet forwarding mode:: testpmd> set fwd (io|mac|macswap|flowgen| \ - rxonly|txonly|csum|icmpecho|noisy|5tswap|shared-rxq) (""|retry) + rxonly|txonly|csum|icmpecho|noisy|5tswap|shared-rxq|recycle_mbufs) (""|retry) ``retry`` can be specified for forwarding engines except ``rx_only``.
@@ -364,6 +364,9 @@ The available information categories are: * ``shared-rxq``: Receive only for shared Rx queue. Resolve packet source port from mbuf and update stream statistics accordingly. +* ``recycle_mbufs``: Recycle Tx queue used mbufs for Rx queue mbuf ring. + This mode uses fast path mbuf recycle feature and forwards packets in I/O mode. + Example:: testpmd> set fwd rxonly
Signature · 1 line
2.25.1
v11 cover Recycle mbufs from Tx queue into Rx queue
In reply to Feifei Wang Currently, the transmit side frees the buffers into the lcore cache and
the receive side allocates buffers from the lcore cache. The transmit side typically frees 32 buffers resulting in 32*8=256B of stores to lcore cache. The receive side allocates 32 buffers and stores them in the receive side software ring, resulting in 32*8=256B of stores and 256B of load from the lcore cache.
This patch proposes a mechanism to avoid freeing to/allocating from the lcore cache. i.e. the receive side will free the buffers from transmit side directly into its software ring. This will avoid the 256B of loads and stores introduced by the lcore cache. It also frees up the cache lines used by the lcore cache. And we can call this mode as mbufs recycle mode.
In the latest version, mbufs recycle mode is packaged as a separate API.
This allows for the users to change rxq/txq pairing in real time in data plane, according to the analysis of the packet flow by the application, for example:
-----------------------------------------------------------------------
Step 1: upper application analyse the flow direction
Step 2: recycle_rxq_info = rte_eth_recycle_rx_queue_info_get(rx_portid, rx_queueid) Step 3: rte_eth_recycle_mbufs(rx_portid, rx_queueid, tx_portid, tx_queueid, recycle_rxq_info); Step 4: rte_eth_rx_burst(rx_portid,rx_queueid);
Step 5: rte_eth_tx_burst(tx_portid,tx_queueid);
-----------------------------------------------------------------------
Above can support user to change rxq/txq pairing at run-time and user does not need to know the direction of flow in advance. This can effectively expand mbufs recycle mode's use scenarios.
Furthermore, mbufs recycle mode is no longer limited to the same pmd,
it can support moving mbufs between different vendor pmds, even can put the mbufs anywhere into your Rx mbuf ring as long as the address of the mbuf ring can be provided. In the latest version, we enable mbufs recycle mode in i40e pmd and ixgbe pmd, and also try to use i40e driver in Rx, ixgbe driver in Tx, and then achieve 7-9% performance improvement by mbufs recycle mode.
Difference between mbuf recycle, ZC API used in mempool and general path
For general path:
Rx: 32 pkts memcpy from mempool cache to rx_sw_ring
Tx: 32 pkts memcpy from tx_sw_ring to temporary variable + 32 pkts memcpy from temporary variable to mempool cache
For ZC API used in mempool:
Rx: 32 pkts memcpy from mempool cache to rx_sw_ring
Tx: 32 pkts memcpy from tx_sw_ring to zero-copy mempool cache
Refer link: http://patches.dpdk.org/project/dpdk/patch/[email protected]/
For mbufs recycle:
Rx/Tx: 32 pkts memcpy from tx_sw_ring to rx_sw_ring
Thus we can see in the one loop, compared to general path, mbufs recycle mode reduces 32+32=64 pkts memcpy; Compared to ZC API used in mempool, we can see mbufs recycle mode reduce 32 pkts memcpy in each loop.
So, mbufs recycle has its own benefits.
Testing status:
(1) dpdk l3fwd test with multiple drivers:
port 0: 82599 NIC port 1: XL710 NIC
-------------------------------------------------------------
Without fast free With fast free
Thunderx2: +7.53% +13.54%
-------------------------------------------------------------
(2) dpdk l3fwd test with same driver:
port 0 && 1: XL710 NIC
-------------------------------------------------------------
Without fast free With fast free
Ampere altra: +12.61% +11.42%
n1sdp: +8.30% +3.85%
x86-sse: +8.43% +3.72%
-------------------------------------------------------------
(3) Performance comparison with ZC_mempool used
port 0 && 1: XL710 NIC
with fast free
-------------------------------------------------------------
With recycle buffer With zc_mempool
Ampere altra: 11.42% 3.54%
-------------------------------------------------------------
Furthermore, we add recycle_mbuf engine in testpmd. Due to XL710 NIC has I/O bottleneck in testpmd in ampere altra, we can not see throughput change compared with I/O fwd engine. However, using record cmd in testpmd:
'$set record-burst-stats on'
we can see the ratio of 'Rx/Tx burst size of 32' is reduced. This indicate mbufs recycle can save CPU cycles.
V2:
1. Use data-plane API to enable direct-rearm (Konstantin, Honnappa)
2. Add 'txq_data_get' API to get txq info for Rx (Konstantin)
3. Use input parameter to enable direct rearm in l3fwd (Konstantin)
4. Add condition detection for direct rearm API (Morten, Andrew Rybchenko)
V3:
1. Seperate Rx and Tx operation with two APIs in direct-rearm (Konstantin)
2. Delete L3fwd change for direct rearm (Jerin)
3. enable direct rearm in ixgbe driver in Arm
v4:
1. Rename direct-rearm as buffer recycle. Based on this, function name and variable name are changed to let this mode more general for all drivers. (Konstantin, Morten)
2. Add ring wrapping check (Konstantin)
v5:
1. some change for ethdev API (Morten)
2. add support for avx2, sse, altivec path
v6:
1. fix ixgbe build issue in ppc
2. remove 'recycle_tx_mbufs_reuse' and 'recycle_rx_descriptors_refill' API wrapper (Tech Board meeting)
3. add recycle_mbufs engine in testpmd (Tech Board meeting)
4. add namespace in the functions related to mbufs recycle(Ferruh)
v7:
1. move 'rxq/txq data' pointers to the beginning of eth_dev structure, in order to keep them in the same cache line as rx/tx_burst function pointers (Morten)
2. add the extra description for 'rte_eth_recycle_mbufs' to show it can support feeding 1 Rx queue from 2 Tx queues in the same thread (Konstantin)
3. For i40e/ixgbe driver, make the previous copied buffers as invalid if there are Tx buffers refcnt > 1 or from unexpected mempool (Konstantin)
4. add check for the return value of 'rte_eth_recycle_rx_queue_info_get' in testpmd fwd engine (Morten)
v8:
1. add arm/x86 build option to fix ixgbe build issue in ppc
v9:
1. delete duplicate file name for ixgbe
v10:
1. fix compile issue on windows
v11:
1. fix doc warning
Feifei Wang (4):
ethdev: add API for mbufs recycle mode
net/i40e: implement mbufs recycle mode
net/ixgbe: implement mbufs recycle mode
app/testpmd: add recycle mbufs engine
app/test-pmd/meson.build | 1 + app/test-pmd/recycle_mbufs.c | 58 ++++++ app/test-pmd/testpmd.c | 1 + app/test-pmd/testpmd.h | 3 + doc/guides/rel_notes/release_23_11.rst | 15 ++ doc/guides/testpmd_app_ug/run_app.rst | 1 + doc/guides/testpmd_app_ug/testpmd_funcs.rst | 5 +- drivers/net/i40e/i40e_ethdev.c | 1 + drivers/net/i40e/i40e_ethdev.h | 2 + .../net/i40e/i40e_recycle_mbufs_vec_common.c | 147 ++++++++++++++ drivers/net/i40e/i40e_rxtx.c | 32 ++++ drivers/net/i40e/i40e_rxtx.h | 4 + drivers/net/i40e/meson.build | 1 + drivers/net/ixgbe/ixgbe_ethdev.c | 1 + drivers/net/ixgbe/ixgbe_ethdev.h | 3 + .../ixgbe/ixgbe_recycle_mbufs_vec_common.c | 143 ++++++++++++++ drivers/net/ixgbe/ixgbe_rxtx.c | 37 +++- drivers/net/ixgbe/ixgbe_rxtx.h | 4 + drivers/net/ixgbe/meson.build | 2 + lib/ethdev/ethdev_driver.h | 10 + lib/ethdev/ethdev_private.c | 2 + lib/ethdev/rte_ethdev.c | 31 +++ lib/ethdev/rte_ethdev.h | 181 ++++++++++++++++++ lib/ethdev/rte_ethdev_core.h | 23 ++- lib/ethdev/version.map | 3 + 25 files changed, 702 insertions(+), 9 deletions(-) create mode 100644 app/test-pmd/recycle_mbufs.c create mode 100644 drivers/net/i40e/i40e_recycle_mbufs_vec_common.c create mode 100644 drivers/net/ixgbe/ixgbe_recycle_mbufs_vec_common.c
Signature · 1 line
2.25.1
PATCH v11 1/4 ethdev: add API for mbufs recycle mode
Add 'rte_eth_recycle_rx_queue_info_get' and 'rte_eth_recycle_mbufs' APIs to recycle used mbufs from a transmit queue of an Ethernet device, and move these mbufs into a mbuf ring for a receive queue of an Ethernet device. This can bypass mempool 'put/get' operations hence saving CPU cycles.
For each recycling mbufs, the rte_eth_recycle_mbufs() function performs the following operations:
- Copy used *rte_mbuf* buffer pointers from Tx mbuf ring into Rx mbuf ring.
- Replenish the Rx descriptors with the recycling *rte_mbuf* mbufs freed from the Tx mbuf ring.
--- doc/guides/rel_notes/release_23_11.rst | 15 ++ lib/ethdev/ethdev_driver.h | 10 ++ lib/ethdev/ethdev_private.c | 2 + lib/ethdev/rte_ethdev.c | 31 +++++ lib/ethdev/rte_ethdev.h | 181 +++++++++++++++++++++++++ lib/ethdev/rte_ethdev_core.h | 23 +++- lib/ethdev/version.map | 3 + 7 files changed, 259 insertions(+), 6 deletions(-)
doc/guides/rel_notes/release_23_11.rst +15 -0
@@ -72,6 +72,13 @@ New Features Also, make sure to start the actual text at the margin. ======================================================= +* **Add mbufs recycling support.** + + Added ``rte_eth_recycle_rx_queue_info_get`` and ``rte_eth_recycle_mbufs`` + APIs which allow the user to copy used mbufs from the Tx mbuf ring + into the Rx mbuf ring. This feature supports the case that the Rx Ethernet + device is different from the Tx Ethernet device with respective driver + callback functions in ``rte_eth_recycle_mbufs``. Removed Items -------------
@@ -123,6 +130,14 @@ ABI Changes Also, make sure to start the actual text at the margin. ======================================================= +* ethdev: Added ``recycle_tx_mbufs_reuse`` and ``recycle_rx_descriptors_refill`` + fields to ``rte_eth_dev`` structure. + +* ethdev: Structure ``rte_eth_fp_ops`` was affected to add + ``recycle_tx_mbufs_reuse`` and ``recycle_rx_descriptors_refill`` + fields, to move ``rxq`` and ``txq`` fields, to change the size of + ``reserved1`` and ``reserved2`` fields. + Known Issues ------------
lib/ethdev/ethdev_driver.h +10 -0
@@ -58,6 +58,10 @@ struct rte_eth_dev {eth_rx_descriptor_status_t rx_descriptor_status;/** Check the status of a Tx descriptor */ eth_tx_descriptor_status_t tx_descriptor_status; +/** Pointer to PMD transmit mbufs reuse function */ +eth_recycle_tx_mbufs_reuse_t recycle_tx_mbufs_reuse; +/** Pointer to PMD receive descriptors refill function */ +eth_recycle_rx_descriptors_refill_t recycle_rx_descriptors_refill;/** * Device data that is shared between primary and secondary processes
@@ -507,6 +511,10 @@ typedef void (*eth_rxq_info_get_t)(struct rte_eth_dev *dev,typedef void (*eth_txq_info_get_t )(struct rte_eth_dev *dev,uint16_t tx_queue_id,struct rte_eth_txq_info *qinfo); +typedef void (*eth_recycle_rxq_info_get_t )(struct rte_eth_dev *dev, +uint16_t rx_queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info); +typedef int (*eth_burst_mode_get_t )(struct rte_eth_dev *dev,uint16_t queue_id,struct rte_eth_burst_mode *mode);
@@ -1250,6 +1258,8 @@ struct eth_dev_ops {eth_rxq_info_get_t rxq_info_get;/** Retrieve Tx queue information */ eth_txq_info_get_t txq_info_get; +/** Retrieve mbufs recycle Rx queue information */ +eth_recycle_rxq_info_get_t recycle_rxq_info_get;eth_burst_mode_get_t rx_burst_mode_get;/**< Get Rx burst mode */ eth_burst_mode_get_t tx_burst_mode_get;/**< Get Tx burst mode */ eth_fw_version_get_t fw_version_get;/**< Get firmware version */
lib/ethdev/ethdev_private.c +2 -0
@@ -277,6 +277,8 @@ eth_dev_fp_ops_setup(struct rte_eth_fp_ops *fpo, fpo->rx_queue_count = dev->rx_queue_count; fpo->rx_descriptor_status = dev->rx_descriptor_status; fpo->tx_descriptor_status = dev->tx_descriptor_status; + fpo->recycle_tx_mbufs_reuse = dev->recycle_tx_mbufs_reuse; + fpo->recycle_rx_descriptors_refill = dev->recycle_rx_descriptors_refill; fpo->rxq.data = dev->data->rx_queues; fpo->rxq.clbk = (void **)(uintptr_t )dev->post_rx_burst_cbs;
lib/ethdev/rte_ethdev.c +31 -0
@@ -5876,6 +5876,37 @@ rte_eth_tx_queue_info_get(uint16_t port_id, uint16_t queue_id,return 0 ; } +int +rte_eth_recycle_rx_queue_info_get (uint16_t port_id,uint16_t queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info) +{ +struct rte_eth_dev *dev; + +RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -ENODEV ); + dev = &rte_eth_devices[port_id]; + +if (queue_id >= dev->data->nb_rx_queues) { +RTE_ETHDEV_LOG (ERR ,"Invalid Rx queue_id=%u\n" , queue_id); +return -EINVAL ; + } + +if (dev->data->rx_queues ==NULL || + dev->data->rx_queues[queue_id] ==NULL ) { +RTE_ETHDEV_LOG (ERR , +"Rx queue %" PRIu16" of device with port_id=%" + PRIu16" has not been setup\n" , + queue_id, port_id); +return -EINVAL ; + } + +if (*dev->dev_ops->recycle_rxq_info_get ==NULL ) +return -ENOTSUP ; + + dev->dev_ops->recycle_rxq_info_get (dev, queue_id, recycle_rxq_info); + +return 0 ; +} +int rte_eth_rx_burst_mode_get (uint16_t port_id,uint16_t queue_id,struct rte_eth_burst_mode *mode)
lib/ethdev/rte_ethdev.h +181 -0
199 lines not on this page · raw message
lib/ethdev/rte_ethdev_core.h +17 -6
@@ -55,6 +55,13 @@ typedef int (*eth_rx_descriptor_status_t)(void *rxq, uint16_t offset);/** @internal Check the status of a Tx descriptor */ typedef int (*eth_tx_descriptor_status_t )(void *txq,uint16_t offset); +/** @internal Copy used mbufs from Tx mbuf ring into Rx mbuf ring */ +typedef uint16_t (*eth_recycle_tx_mbufs_reuse_t )(void *txq, +struct rte_eth_recycle_rxq_info *recycle_rxq_info); + +/** @internal Refill Rx descriptors with the recycling mbufs */ +typedef void (*eth_recycle_rx_descriptors_refill_t )(void *rxq,uint16_t nb); +/** * @internal * Structure used to hold opaque pointers to internal ethdev Rx/Tx
@@ -83,15 +90,17 @@ struct rte_eth_fp_ops {* Rx fast-path functions and related data. * 64-bit systems: occupies first 64B line */ +/** Rx queues data. */ +struct rte_ethdev_qdata rxq;/** PMD receive function. */ eth_rx_burst_t rx_pkt_burst;/** Get the number of used Rx descriptors. */ eth_rx_queue_count_t rx_queue_count;/** Check the status of a Rx descriptor. */ eth_rx_descriptor_status_t rx_descriptor_status; -/** Rx queues data. */ -struct rte_ethdev_qdata rxq; -uintptr_t reserved1[3 ]; +/** Refill Rx descriptors with the recycling mbufs. */ +eth_recycle_rx_descriptors_refill_t recycle_rx_descriptors_refill; +uintptr_t reserved1[2 ];/**@}*/ /**@{*/
@@ -99,15 +108,17 @@ struct rte_eth_fp_ops {* Tx fast-path functions and related data. * 64-bit systems: occupies second 64B line */ +/** Tx queues data. */ +struct rte_ethdev_qdata txq;/** PMD transmit function. */ eth_tx_burst_t tx_pkt_burst;/** PMD transmit prepare function. */ eth_tx_prep_t tx_pkt_prepare;/** Check the status of a Tx descriptor. */ eth_tx_descriptor_status_t tx_descriptor_status; -/** Tx queues data. */ -struct rte_ethdev_qdata txq; -uintptr_t reserved2[3 ]; +/** Copy used mbufs from Tx mbuf ring into Rx. */ +eth_recycle_tx_mbufs_reuse_t recycle_tx_mbufs_reuse; +uintptr_t reserved2[2 ];/**@}*/ } __rte_cache_aligned;
lib/ethdev/version.map +3 -0
@@ -312,6 +312,9 @@ EXPERIMENTAL { rte_flow_async_action_list_handle_query_update; rte_flow_async_actions_update; rte_flow_restore_info_dynflag; + + # added in 23.11 + rte_eth_recycle_rx_queue_info_get; }; INTERNAL {
Signature · 1 line
2.25.1
Re: [PATCH v11 1/4] ethdev: add API for mbufs recycle mode
lib/ethdev/rte_ethdev.c rte_eth_tx_queue_info_get(uint16_t port_id, uint16_t queue_id, · line 5900
Quoted 13 lines · On Tue, 22 Aug 2023 15:27:07 +0800 Feifei Wang <[email protected]> wrote:
lib/ethdev/rte_ethdev.c +13
-0+if (queue_id >= dev->data->nb_rx_queues) { +RTE_ETHDEV_LOG (ERR ,"Invalid Rx queue_id=%u\n" , queue_id); +return -EINVAL ; + } + +if (dev->data->rx_queues ==NULL || + dev->data->rx_queues[queue_id] ==NULL ) { +RTE_ETHDEV_LOG (ERR , +"Rx queue %" PRIu16" of device with port_id=%" + PRIu16" has not been setup\n" , + queue_id, port_id); +return -EINVAL ; + }
This could be changed to something like:
ret = eth_dev_validate_rx_queue(dev, queue_id); if (unlikely(ret != 0)) return ret;
RE: [PATCH v11 1/4] ethdev: add API for mbufs recycle mode
Quoted 33 lines
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Tuesday, August 22, 2023 10:03 PM
To: Feifei Wang <[email protected]>
Cc: [email protected]; Ferruh Yigit <[email protected]>; Andrew Rybchenko <[email protected]>; [email protected]; nd <[email protected]>; Honnappa Nagarahalli <[email protected]>; Ruifeng Wang <[email protected]>; Morten Brørup <[email protected]>
Subject: Re: [PATCH v11 1/4] ethdev: add API for mbufs recycle modeReview
Quoted 2 lines · On Tue, 22 Aug 2023 15:27:07 +0800 Feifei Wang <[email protected]> wrote:
(quoted diff) +2
-0+ if (queue_id >= dev->data->nb_rx_queues) { + RTE_ETHDEV_LOG(ERR, "Invalid Rx queue_id=%u\n",
queue_id);lib/ethdev/rte_ethdev.c rte_eth_tx_queue_info_get(uint16_t port_id, uint16_t queue_id, · line 5900
Quoted 11 lines
lib/ethdev/rte_ethdev.c +11
-0+return -EINVAL ; + } + +if (dev->data->rx_queues ==NULL || + dev->data->rx_queues[queue_id] ==NULL ) { +RTE_ETHDEV_LOG (ERR , +"Rx queue %" PRIu16" of device with port_id=%" + PRIu16" has not been setup\n" , + queue_id, port_id); +return -EINVAL ; + }This could be changed to something like:
Quoted 4 lines
ret = eth_dev_validate_rx_queue(dev, queue_id); if (unlikely(ret != 0)) return ret;
Good comments, I just know there is an API to check these. Thanks.
Quoted 2 lines
Re: [PATCH v11 1/4] ethdev: add API for mbufs recycle mode
In reply to Feifei WangHi Feifei,
Quoted 306 lines
Add '
rte_eth_recycle_rx_queue_info_get' and 'rte_eth_recycle_mbufs' APIs to recycle used mbufs from a transmit queue of an Ethernet device, and move these mbufs into a mbuf ring for a receive queue of an Ethernet device. This can bypass mempool 'put/get' operations hence saving CPU cycles.For each recycling mbufs, the
rte_eth_recycle_mbufs()function performs the following operations:
- Copy used *rte_mbuf* buffer pointers from Tx mbuf ring into Rx mbuf ring.
- Replenish the Rx descriptors with the recycling *rte_mbuf* mbufs freed from the Tx mbuf ring.Suggested-by Honnappa Nagarahalli <[email protected]>Suggested-by Ruifeng Wang <[email protected]>Signed-off-by Feifei Wang <[email protected]>Reviewed-by Ruifeng Wang <[email protected]>Reviewed-by Honnappa Nagarahalli <[email protected]>Acked-by Morten Brørup <[email protected]>--- doc/guides/rel_notes/release_23_11.rst | 15 ++ lib/ethdev/ethdev_driver.h | 10 ++ lib/ethdev/ethdev_private.c | 2 + lib/ethdev/rte_ethdev.c | 31 +++++ lib/ethdev/rte_ethdev.h | 181 +++++++++++++++++++++++++ lib/ethdev/rte_ethdev_core.h | 23 +++- lib/ethdev/version.map | 3 + 7 files changed, 259 insertions(+), 6 deletions(-)doc/guides/rel_notes/release_23_11.rst +15
-0@@ -72,6 +72,13 @@ New Features Also, make sure to start the actual text at the margin. ======================================================= +* **Add mbufs recycling support.** + + Added ``rte_eth_recycle_rx_queue_info_get`` and ``rte_eth_recycle_mbufs`` + APIs which allow the user to copy used mbufs from the Tx mbuf ring + into the Rx mbuf ring. This feature supports the case that the Rx Ethernet + device is different from the Tx Ethernet device with respective driver + callback functions in ``rte_eth_recycle_mbufs``. Removed Items -------------@@ -123,6 +130,14 @@ ABI Changes Also, make sure to start the actual text at the margin. ======================================================= +* ethdev: Added ``recycle_tx_mbufs_reuse`` and ``recycle_rx_descriptors_refill`` + fields to ``rte_eth_dev`` structure. + +* ethdev: Structure ``rte_eth_fp_ops`` was affected to add + ``recycle_tx_mbufs_reuse`` and ``recycle_rx_descriptors_refill`` + fields, to move ``rxq`` and ``txq`` fields, to change the size of + ``reserved1`` and ``reserved2`` fields. + Known Issues ------------lib/ethdev/ethdev_driver.h +10
-0@@ -58,6 +58,10 @@ struct rte_eth_dev {eth_rx_descriptor_status_t rx_descriptor_status;/** Check the status of a Tx descriptor */ eth_tx_descriptor_status_t tx_descriptor_status; +/** Pointer to PMD transmit mbufs reuse function */ +eth_recycle_tx_mbufs_reuse_t recycle_tx_mbufs_reuse; +/** Pointer to PMD receive descriptors refill function */ +eth_recycle_rx_descriptors_refill_t recycle_rx_descriptors_refill;/** * Device data that is shared between primary and secondary processes @@ -507,6 +511,10 @@ typedef void (*eth_rxq_info_get_t)(struct rte_eth_dev *dev,typedef void (*eth_txq_info_get_t )(struct rte_eth_dev *dev,uint16_t tx_queue_id,struct rte_eth_txq_info *qinfo); +typedef void (*eth_recycle_rxq_info_get_t )(struct rte_eth_dev *dev, +uint16_t rx_queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info); +typedef int (*eth_burst_mode_get_t )(struct rte_eth_dev *dev,uint16_t queue_id,struct rte_eth_burst_mode *mode);@@ -1250,6 +1258,8 @@ struct eth_dev_ops {eth_rxq_info_get_t rxq_info_get;/** Retrieve Tx queue information */ eth_txq_info_get_t txq_info_get; +/** Retrieve mbufs recycle Rx queue information */ +eth_recycle_rxq_info_get_t recycle_rxq_info_get;eth_burst_mode_get_t rx_burst_mode_get;/**< Get Rx burst mode */ eth_burst_mode_get_t tx_burst_mode_get;/**< Get Tx burst mode */ eth_fw_version_get_t fw_version_get;/**< Get firmware version */ lib/ethdev/ethdev_private.c +2
-0@@ -277,6 +277,8 @@ eth_dev_fp_ops_setup(struct rte_eth_fp_ops *fpo, fpo->rx_queue_count = dev->rx_queue_count; fpo->rx_descriptor_status = dev->rx_descriptor_status; fpo->tx_descriptor_status = dev->tx_descriptor_status; + fpo->recycle_tx_mbufs_reuse = dev->recycle_tx_mbufs_reuse; + fpo->recycle_rx_descriptors_refill = dev->recycle_rx_descriptors_refill; fpo->rxq.data = dev->data->rx_queues; fpo->rxq.clbk = (void **)(uintptr_t )dev->post_rx_burst_cbs;lib/ethdev/rte_ethdev.c +31
-0@@ -5876,6 +5876,37 @@ rte_eth_tx_queue_info_get(uint16_t port_id, uint16_t queue_id,return 0 ; } +int +rte_eth_recycle_rx_queue_info_get (uint16_t port_id,uint16_t queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info) +{ +struct rte_eth_dev *dev; + +RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -ENODEV ); + dev = &rte_eth_devices[port_id]; + +if (queue_id >= dev->data->nb_rx_queues) { +RTE_ETHDEV_LOG (ERR ,"Invalid Rx queue_id=%u\n" , queue_id); +return -EINVAL ; + } + +if (dev->data->rx_queues ==NULL || + dev->data->rx_queues[queue_id] ==NULL ) { +RTE_ETHDEV_LOG (ERR , +"Rx queue %" PRIu16" of device with port_id=%" + PRIu16" has not been setup\n" , + queue_id, port_id); +return -EINVAL ; + } + +if (*dev->dev_ops->recycle_rxq_info_get ==NULL ) +return -ENOTSUP ; + + dev->dev_ops->recycle_rxq_info_get (dev, queue_id, recycle_rxq_info); + +return 0 ; +} +int rte_eth_rx_burst_mode_get (uint16_t port_id,uint16_t queue_id,struct rte_eth_burst_mode *mode)lib/ethdev/rte_ethdev.h +132
-0@@ -1820,6 +1820,30 @@ struct rte_eth_txq_info {uint8_t queue_state;/**< one of RTE_ETH_QUEUE_STATE_*. */ } __rte_cache_min_aligned; +/** +* @warning +* @b EXPERIMENTAL: this structure may change without prior notice. +* +* Ethernet device Rx queue information structure for recycling mbufs. +* Used to retrieve Rx queue information when Tx queue reusing mbufs and moving +* them into Rx mbuf ring. +*/ +struct rte_eth_recycle_rxq_info { +struct rte_mbuf **mbuf_ring;/**< mbuf ring of Rx queue. */ +struct rte_mempool *mp;/**< mempool of Rx queue. */ +uint16_t *refill_head;/**< head of Rx queue refilling mbufs. */ +uint16_t *receive_tail;/**< tail of Rx queue receiving pkts. */ +uint16_t mbuf_ring_size;/**< configured number of mbuf ring size. */ +/** +* Requirement on mbuf refilling batch size of Rx mbuf ring. +* For some PMD drivers, the number of Rx mbuf ring refilling mbufs +* should be aligned with mbuf ring size, in order to simplify +* ring wrapping around. +* Value 0 means that PMD drivers have no requirement for this. +*/ +uint16_t refill_requirement; +} __rte_cache_min_aligned; +/* Generic Burst mode flag definition, values can be ORed. */ /** @@ -4853,6 +4877,31 @@ int rte_eth_rx_queue_info_get(uint16_t port_id, uint16_t queue_id,int rte_eth_tx_queue_info_get (uint16_t port_id,uint16_t queue_id,struct rte_eth_txq_info *qinfo); +/** +* @warning +* @b EXPERIMENTAL: this API may change, or be removed, without prior notice +* +* Retrieve information about given ports's Rx queue for recycling mbufs. +* +* @param port_id +* The port identifier of the Ethernet device. +* @param queue_id +* The Rx queue on the Ethernet devicefor which information +* will be retrieved. +* @param recycle_rxq_info +* A pointer to a structure of type *rte_eth_recycle_rxq_info* to be filled. +* +* @return +* - 0: Success +* - -ENODEV: If *port_id* is invalid. +* - -ENOTSUP: routine is not supported by the device PMD. +* - -EINVAL: The queue_id is out of range. +*/ +__rte_experimental +int rte_eth_recycle_rx_queue_info_get(uint16_t port_id, +uint16_t queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info); +/** * Retrieve information about the Rx packet burst mode. * @@ -6527,6 +6576,138 @@ rte_eth_tx_buffer(uint16_t port_id, uint16_t queue_id,return rte_eth_tx_buffer_flush (port_id, queue_id, buffer); } +/** +* @warning +* @b EXPERIMENTAL: this API may change, or be removed, without prior notice +* +* Recycle used mbufs from a transmit queue of an Ethernet device, and move +* these mbufs into a mbuf ring for a receive queue of an Ethernet device. +* This can bypass mempool path to save CPU cycles. +* +* The rte_eth_recycle_mbufs() function loops, with rte_eth_rx_burst() and +* rte_eth_tx_burst() functions, freeing Tx used mbufs and replenishing Rx +* descriptors. The number of recycling mbufs depends on the request of Rx mbuf +* ring, with the constraint of enough used mbufs from Tx mbuf ring. +* +* For each recycling mbufs, the rte_eth_recycle_mbufs() function performs the +* following operations: +* +* - Copy used *rte_mbuf* buffer pointers from Tx mbuf ring into Rx mbuf ring. +* +* - Replenish the Rx descriptors with the recycling *rte_mbuf* mbufs freed +* from the Tx mbuf ring. +* +* This function spilts Rx and Tx path with different callback functions. The +* callback function recycle_tx_mbufs_reuse is for Tx driver. The callback +* function recycle_rx_descriptors_refill is for Rx driver. rte_eth_recycle_mbufs() +* can support the case that Rx Ethernet device is different from Tx Ethernet device. +* +* It is the responsibility of users to select the Rx/Tx queue pair to recycle +* mbufs. Before call this function, users must call rte_eth_recycle_rxq_info_get +* function to retrieve selected Rx queue information. +* @see rte_eth_recycle_rxq_info_get, struct rte_eth_recycle_rxq_info +* +* Currently, the rte_eth_recycle_mbufs() function can support to feed 1 Rx queue from +* 2 Tx queues in the same thread. Do not pair the Rx queue and Tx queue in different +* threads, in order to avoid memory error rewriting. +* +* @param rx_port_id +* Port identifying the receive side. +* @param rx_queue_id +* The index of the receive queue identifying the receive side. +* The value must be in the range [0, nb_rx_queue - 1] previously supplied +* to rte_eth_dev_configure(). +* @param tx_port_id +* Port identifying the transmit side. +* @param tx_queue_id +* The index of the transmit queue identifying the transmit side. +* The value must be in the range [0, nb_tx_queue - 1] previously supplied +* to rte_eth_dev_configure(). +* @param recycle_rxq_info +* A pointer to a structure of type *rte_eth_recycle_rxq_info* which contains +* the information of the Rx queue mbuf ring. +* @return +* The number of recycling mbufs. +*/ +__rte_experimental +static inline uint16_t +rte_eth_recycle_mbufs (uint16_t rx_port_id,uint16_t rx_queue_id, +uint16_t tx_port_id,uint16_t tx_queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info) +{ +struct rte_eth_fp_ops *p; +void *qd; +uint16_t nb_mbufs; + +#ifdef RTE_ETHDEV_DEBUG_TX +if (tx_port_id >=RTE_MAX_ETHPORTS || + tx_queue_id >=RTE_MAX_QUEUES_PER_PORT ) { +RTE_ETHDEV_LOG (ERR , +"Invalid tx_port_id=%u or tx_queue_id=%u\n" , + tx_port_id, tx_queue_id); +return 0 ; + } +#endif + +/* fetch pointer to queue data */ + p = &rte_eth_fp_ops[tx_port_id]; + qd = p->txq.data[tx_queue_id]; + +#ifdef RTE_ETHDEV_DEBUG_TX +RTE_ETH_VALID_PORTID_OR_ERR_RET (tx_port_id,0 ); + +if (qd ==NULL ) { +RTE_ETHDEV_LOG (ERR ,"Invalid Tx queue_id=%u for port_id=%u\n" , + tx_queue_id, tx_port_id);
lib/ethdev/rte_ethdev.h rte_eth_tx_buffer(uint16_t port_id, uint16_t queue_id, · line 6671
Quoted 10 lines
lib/ethdev/rte_ethdev.h +10
-0+ return 0; + } +#endif +if (p->recycle_tx_mbufs_reuse ==NULL ) +return 0 ; + +/* Copy used *rte_mbuf* buffer pointers from Tx mbuf ring +* into Rx mbuf ring. +*/ + nb_mbufs = p->recycle_tx_mbufs_reuse (qd, recycle_rxq_info);
It is probably better to do that call after rx_port_id, rx_queue_id, etc. checks. Otherwise with some errorneous params we can get mbufs, from TXQ, 'rx_refill' would not happen and we will return zero.
With that in place:
Quoted 116 lines
lib/ethdev/rte_ethdev.h +39
-0+ +/* If no recycling mbufs, return 0. */ +if (nb_mbufs ==0 ) +return 0 ; + +#ifdef RTE_ETHDEV_DEBUG_RX +if (rx_port_id >=RTE_MAX_ETHPORTS || + rx_queue_id >=RTE_MAX_QUEUES_PER_PORT ) { +RTE_ETHDEV_LOG (ERR ,"Invalid rx_port_id=%u or rx_queue_id=%u\n" , + rx_port_id, rx_queue_id); +return 0 ; + } +#endif + +/* fetch pointer to queue data */ + p = &rte_eth_fp_ops[rx_port_id]; + qd = p->rxq.data[rx_queue_id]; + +#ifdef RTE_ETHDEV_DEBUG_RX +RTE_ETH_VALID_PORTID_OR_ERR_RET (rx_port_id,0 ); + +if (qd ==NULL ) { +RTE_ETHDEV_LOG (ERR ,"Invalid Rx queue_id=%u for port_id=%u\n" , + rx_queue_id, rx_port_id); +return 0 ; + } +#endif + +if (p->recycle_rx_descriptors_refill ==NULL ) +return 0 ; + +/* Replenish the Rx descriptors with the recycling +* into Rx mbuf ring. +*/ + p->recycle_rx_descriptors_refill (qd, nb_mbufs); + +return nb_mbufs; +} +/** * @warning * @b EXPERIMENTAL: this API may change without prior notice lib/ethdev/rte_ethdev_core.h +17
-6@@ -55,6 +55,13 @@ typedef int (*eth_rx_descriptor_status_t)(void *rxq, uint16_t offset);/** @internal Check the status of a Tx descriptor */ typedef int (*eth_tx_descriptor_status_t )(void *txq,uint16_t offset); +/** @internal Copy used mbufs from Tx mbuf ring into Rx mbuf ring */ +typedef uint16_t (*eth_recycle_tx_mbufs_reuse_t )(void *txq, +struct rte_eth_recycle_rxq_info *recycle_rxq_info); + +/** @internal Refill Rx descriptors with the recycling mbufs */ +typedef void (*eth_recycle_rx_descriptors_refill_t )(void *rxq,uint16_t nb); +/** * @internal * Structure used to hold opaque pointers to internal ethdev Rx/Tx @@ -83,15 +90,17 @@ struct rte_eth_fp_ops {* Rx fast-path functions and related data. * 64-bit systems: occupies first 64B line */ +/** Rx queues data. */ +struct rte_ethdev_qdata rxq;/** PMD receive function. */ eth_rx_burst_t rx_pkt_burst;/** Get the number of used Rx descriptors. */ eth_rx_queue_count_t rx_queue_count;/** Check the status of a Rx descriptor. */ eth_rx_descriptor_status_t rx_descriptor_status; -/** Rx queues data. */ -struct rte_ethdev_qdata rxq; -uintptr_t reserved1[3 ]; +/** Refill Rx descriptors with the recycling mbufs. */ +eth_recycle_rx_descriptors_refill_t recycle_rx_descriptors_refill; +uintptr_t reserved1[2 ];/**@}*/ /**@{*/ @@ -99,15 +108,17 @@ struct rte_eth_fp_ops {* Tx fast-path functions and related data. * 64-bit systems: occupies second 64B line */ +/** Tx queues data. */ +struct rte_ethdev_qdata txq;/** PMD transmit function. */ eth_tx_burst_t tx_pkt_burst;/** PMD transmit prepare function. */ eth_tx_prep_t tx_pkt_prepare;/** Check the status of a Tx descriptor. */ eth_tx_descriptor_status_t tx_descriptor_status; -/** Tx queues data. */ -struct rte_ethdev_qdata txq; -uintptr_t reserved2[3 ]; +/** Copy used mbufs from Tx mbuf ring into Rx. */ +eth_recycle_tx_mbufs_reuse_t recycle_tx_mbufs_reuse; +uintptr_t reserved2[2 ];/**@}*/ } __rte_cache_aligned;lib/ethdev/version.map +3
-0@@ -312,6 +312,9 @@ EXPERIMENTAL { rte_flow_async_action_list_handle_query_update; rte_flow_async_actions_update; rte_flow_restore_info_dynflag; + + # added in 23.11 + rte_eth_recycle_rx_queue_info_get; }; INTERNAL {
RE: [PATCH v11 1/4] ethdev: add API for mbufs recycle mode
In reply to Feifei WangFor Konstantin
Quoted 345 lines
-----Original Message-----
From: Feifei Wang <[email protected]>
Sent: Tuesday, August 22, 2023 3:27 PM
To: [email protected]; Ferruh Yigit <[email protected]>; Andrew Rybchenko <[email protected]>
Cc: [email protected]; nd <[email protected]>; Feifei Wang <[email protected]>; Honnappa Nagarahalli <[email protected]>; Ruifeng Wang <[email protected]>; Morten Brørup <[email protected]>
Subject: [PATCH v11 1/4] ethdev: add API for mbufs recycle modeAdd '
rte_eth_recycle_rx_queue_info_get' and 'rte_eth_recycle_mbufs' APIs to recycle used mbufs from a transmit queue of an Ethernet device, and move these mbufs into a mbuf ring for a receive queue of an Ethernet device. This can bypass mempool 'put/get' operations hence saving CPU cycles.For each recycling mbufs, the
rte_eth_recycle_mbufs()function performs the following operations:
- Copy used *rte_mbuf* buffer pointers from Tx mbuf ring into Rx mbuf ring.
- Replenish the Rx descriptors with the recycling *rte_mbuf* mbufs freed from the Tx mbuf ring.Suggested-by Honnappa Nagarahalli <[email protected]>Suggested-by Ruifeng Wang <[email protected]>Signed-off-by Feifei Wang <[email protected]>Reviewed-by Ruifeng Wang <[email protected]>Reviewed-by Honnappa Nagarahalli <[email protected]>Acked-by Morten Brørup <[email protected]>--- doc/guides/rel_notes/release_23_11.rst | 15 ++ lib/ethdev/ethdev_driver.h | 10 ++ lib/ethdev/ethdev_private.c | 2 + lib/ethdev/rte_ethdev.c | 31 +++++ lib/ethdev/rte_ethdev.h | 181 +++++++++++++++++++++++++ lib/ethdev/rte_ethdev_core.h | 23 +++- lib/ethdev/version.map | 3 + 7 files changed, 259 insertions(+), 6 deletions(-)doc/guides/rel_notes/release_23_11.rst +7
-0@@ -72,6 +72,13 @@ New Features Also, make sure to start the actual text at the margin. ======================================================= +* **Add mbufs recycling support.** + + Added ``rte_eth_recycle_rx_queue_info_get`` and + ``rte_eth_recycle_mbufs`` APIs which allow the user to copy used + mbufs from the Tx mbuf ring into the Rx mbuf ring. This feature + supports the case that the Rx Ethernet device is different from the + Tx Ethernet device with respective driver callback functions in``rte_eth_recycle_mbufs``.
Removed Items
-------------doc/guides/rel_notes/release_23_11.rst +9
-0@@ -123,6 +130,14 @@ ABI Changes Also, make sure to start the actual text at the margin. ======================================================= +* ethdev: Added ``recycle_tx_mbufs_reuse`` and +``recycle_rx_descriptors_refill`` + fields to ``rte_eth_dev`` structure. + +* ethdev: Structure ``rte_eth_fp_ops`` was affected to add + ``recycle_tx_mbufs_reuse`` and ``recycle_rx_descriptors_refill`` + fields, to move ``rxq`` and ``txq`` fields, to change the size of + ``reserved1`` and ``reserved2`` fields. + Known Issues ------------lib/ethdev/ethdev_driver.h index renamed from lib/ethdev/ethdev_driver.h +0
-0
980f837ab6..b0c55a8523100644lib/ethdev/ethdev_driver.h +4
-0@@ -58,6 +58,10 @@ struct rte_eth_dev {eth_rx_descriptor_status_t rx_descriptor_status;/** Check the status of a Tx descriptor */ eth_tx_descriptor_status_t tx_descriptor_status; +/** Pointer to PMD transmit mbufs reuse function */ +eth_recycle_tx_mbufs_reuse_t recycle_tx_mbufs_reuse; +/** Pointer to PMD receive descriptors refill function */ +eth_recycle_rx_descriptors_refill_t recycle_rx_descriptors_refill;/** * Device data that is shared between primary and secondary processes @@ -507,6 +511,10 @@ typedef void (*eth_rxq_info_get_t)(struct
rte_eth_dev*dev, typedef void (*eth_txq_info_get_t)(structrte_eth_dev*dev,lib/ethdev/ethdev_driver.h +6
-0uint16_t tx_queue_id, struct rte_eth_txq_info *qinfo); +typedef void (*eth_recycle_rxq_info_get_t )(struct rte_eth_dev *dev, +uint16_t rx_queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info); +typedef int (*eth_burst_mode_get_t )(struct rte_eth_dev *dev,uint16_t queue_id,struct rte_eth_burst_mode *mode);@@ -1250,6 +1258,8 @@ struct eth_dev_ops {eth_rxq_info_get_t rxq_info_get;/** Retrieve Tx queue information */ eth_txq_info_get_t txq_info_get; +/** Retrieve mbufs recycle Rx queue information */ +eth_recycle_rxq_info_get_t recycle_rxq_info_get;eth_burst_mode_get_t rx_burst_mode_get;/**< Get Rx burst mode */
eth_burst_mode_get_ttx_burst_mode_get; /**< Get Tx burst
mode */
eth_fw_version_get_tfw_version_get; /**< Get firmware version
*/lib/ethdev/ethdev_private.c index renamed from lib/ethdev/ethdev_private.c +0
-0
14ec8c6ccf..f8ab64f195100644lib/ethdev/ethdev_private.c +3
-0@@ -277,6 +277,8 @@ eth_dev_fp_ops_setup(struct rte_eth_fp_ops *fpo, fpo->rx_queue_count = dev->rx_queue_count; fpo->rx_descriptor_status = dev->rx_descriptor_status; fpo->tx_descriptor_status = dev->tx_descriptor_status; + fpo->recycle_tx_mbufs_reuse = dev->recycle_tx_mbufs_reuse; + fpo->recycle_rx_descriptors_refill = +dev->recycle_rx_descriptors_refill; fpo->rxq.data = dev->data->rx_queues; fpo->rxq.clbk = (void **)(uintptr_t )dev->post_rx_burst_cbs;lib/ethdev/rte_ethdev.c index renamed from lib/ethdev/rte_ethdev.c +0
-0
0840d2b594..ea89a101a1100644lib/ethdev/rte_ethdev.c +30
-0@@ -5876,6 +5876,37 @@ rte_eth_tx_queue_info_get(uint16_t port_id,uint16_t queue_id, return 0; } +int +rte_eth_recycle_rx_queue_info_get (uint16_t port_id,uint16_t queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info) { +struct rte_eth_dev *dev; + +RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -ENODEV ); + dev = &rte_eth_devices[port_id]; + +if (queue_id >= dev->data->nb_rx_queues) { +RTE_ETHDEV_LOG (ERR ,"Invalid Rx queue_id=%u\n" , queue_id); +return -EINVAL ; + } + +if (dev->data->rx_queues ==NULL || + dev->data->rx_queues[queue_id] ==NULL ) { +RTE_ETHDEV_LOG (ERR , +"Rx queue %" PRIu16" of device with port_id=%" + PRIu16" has not been setup\n" , + queue_id, port_id); +return -EINVAL ; + } + +if (*dev->dev_ops->recycle_rxq_info_get ==NULL ) +return -ENOTSUP ; + + dev->dev_ops->recycle_rxq_info_get (dev, queue_id, recycle_rxq_info); + +return 0 ; +} +int rte_eth_rx_burst_mode_get (uint16_t port_id,uint16_t queue_id,struct rte_eth_burst_mode *mode)lib/ethdev/rte_ethdev.h index renamed from lib/ethdev/rte_ethdev.h +0
-0
04a2564f22..9dc5749d83100644lib/ethdev/rte_ethdev.h +25
-0@@ -1820,6 +1820,30 @@ struct rte_eth_txq_info {uint8_t queue_state;/**< one of RTE_ETH_QUEUE_STATE_*. */ } __rte_cache_min_aligned; +/** +* @warning +* @b EXPERIMENTAL: this structure may change without prior notice. +* +* Ethernet device Rx queue information structure for recycling mbufs. +* Used to retrieve Rx queue information when Tx queue reusing mbufs +and moving +* them into Rx mbuf ring. +*/ +struct rte_eth_recycle_rxq_info { +struct rte_mbuf **mbuf_ring;/**< mbuf ring of Rx queue. */ +struct rte_mempool *mp;/**< mempool of Rx queue. */ +uint16_t *refill_head;/**< head of Rx queue refilling mbufs. */ +uint16_t *receive_tail;/**< tail of Rx queue receiving pkts. */ +uint16_t mbuf_ring_size;/**< configured number of mbuf ring size. */ +/** +* Requirement on mbuf refilling batch size of Rx mbuf ring. +* For some PMD drivers, the number of Rx mbuf ring refilling mbufs +* should be aligned with mbuf ring size, in order to simplify +* ring wrapping around. +* Value 0 means that PMD drivers have no requirement for this. +*/ +uint16_t refill_requirement; +} __rte_cache_min_aligned; +/* Generic Burst mode flag definition, values can be ORed. */ /** @@ -4853,6 +4877,31 @@ int rte_eth_rx_queue_info_get(uint16_t port_id,
uint16_tqueue_id, int rte_eth_tx_queue_info_get(uint16_tport_id,uint16_tqueue_id,lib/ethdev/rte_ethdev.h +49
-0struct rte_eth_txq_info *qinfo); +/** +* @warning +* @b EXPERIMENTAL: this API may change, or be removed, without prior +notice +* +* Retrieve information about given ports's Rx queue for recycling mbufs. +* +* @param port_id +* The port identifier of the Ethernet device. +* @param queue_id +* The Rx queue on the Ethernet devicefor which information +* will be retrieved. +* @param recycle_rxq_info +* A pointer to a structure of type *rte_eth_recycle_rxq_info* to be filled. +* +* @return +* - 0: Success +* - -ENODEV: If *port_id* is invalid. +* - -ENOTSUP: routine is not supported by the device PMD. +* - -EINVAL: The queue_id is out of range. +*/ +__rte_experimental +int rte_eth_recycle_rx_queue_info_get(uint16_t port_id, +uint16_t queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info); +/** * Retrieve information about the Rx packet burst mode. * @@ -6527,6 +6576,138 @@ rte_eth_tx_buffer(uint16_t port_id, uint16_t queue_id, return rte_eth_tx_buffer_flush(port_id, queue_id, buffer); } +/** +* @warning +* @b EXPERIMENTAL: this API may change, or be removed, without prior +notice +* +* Recycle used mbufs from a transmit queue of an Ethernet device, and +move +* these mbufs into a mbuf ring for a receive queue of an Ethernet device. +* This can bypass mempool path to save CPU cycles. +* +* The rte_eth_recycle_mbufs() function loops, with rte_eth_rx_burst() +and +* rte_eth_tx_burst() functions, freeing Tx used mbufs and replenishing +Rx +* descriptors. The number of recycling mbufs depends on the request of +Rx mbuf +* ring, with the constraint of enough used mbufs from Tx mbuf ring. +* +* For each recycling mbufs, the rte_eth_recycle_mbufs() function +performs the +* following operations: +* +* - Copy used *rte_mbuf* buffer pointers from Tx mbuf ring into Rx mbuf ring.
+ *
+ * - Replenish the Rx descriptors with the recycling *rte_mbuf* mbufs freed
+ * from the Tx mbuf ring.
+ *
+ * This function spilts Rx and Tx path with different callbacklib/ethdev/rte_ethdev.h +6
-0+functions. The + * callback function recycle_tx_mbufs_reuse is for Tx driver. The +callback + * function recycle_rx_descriptors_refill is for Rx driver. +rte_eth_recycle_mbufs () + * can support the case that Rx Ethernet device is different from Tx Ethernetdevice.
+ *
+ * It is the responsibility of users to select the Rx/Tx queue pair tolib/ethdev/rte_ethdev.h +44
-0+recycle +* mbufs. Before call this function, users must call +rte_eth_recycle_rxq_info_get +* function to retrieve selected Rx queue information. +* @see rte_eth_recycle_rxq_info_get, struct rte_eth_recycle_rxq_info +* +* Currently, the rte_eth_recycle_mbufs() function can support to feed +1 Rx queue from +* 2 Tx queues in the same thread. Do not pair the Rx queue and Tx +queue in different +* threads, in order to avoid memory error rewriting. +* +* @param rx_port_id +* Port identifying the receive side. +* @param rx_queue_id +* The index of the receive queue identifying the receive side. +* The value must be in the range [0, nb_rx_queue - 1] previously supplied +* to rte_eth_dev_configure(). +* @param tx_port_id +* Port identifying the transmit side. +* @param tx_queue_id +* The index of the transmit queue identifying the transmit side. +* The value must be in the range [0, nb_tx_queue - 1] previously supplied +* to rte_eth_dev_configure(). +* @param recycle_rxq_info +* A pointer to a structure of type *rte_eth_recycle_rxq_info* which contains +* the information of the Rx queue mbuf ring. +* @return +* The number of recycling mbufs. +*/ +__rte_experimental +static inline uint16_t +rte_eth_recycle_mbufs(uint16_t rx_port_id, uint16_t rx_queue_id, + uint16_t tx_port_id, uint16_t tx_queue_id, + struct rte_eth_recycle_rxq_info *recycle_rxq_info) { + struct rte_eth_fp_ops *p; + void *qd; + uint16_t nb_mbufs; + +#ifdef RTE_ETHDEV_DEBUG_TX + if (tx_port_id >= RTE_MAX_ETHPORTS || + tx_queue_id >= RTE_MAX_QUEUES_PER_PORT) { + RTE_ETHDEV_LOG(ERR, + "Invalid tx_port_id=%u ortx_queue_id=%u\n",
lib/ethdev/rte_ethdev.h +14
-0+ tx_port_id, tx_queue_id); +return 0 ; + } +#endif + +/* fetch pointer to queue data */ + p = &rte_eth_fp_ops[tx_port_id]; + qd = p->txq.data[tx_queue_id]; + +#ifdef RTE_ETHDEV_DEBUG_TX +RTE_ETH_VALID_PORTID_OR_ERR_RET (tx_port_id,0 ); + +if (qd ==NULL ) { + RTE_ETHDEV_LOG(ERR, "Invalid Tx queue_id=%u forport_id=%u\n",
lib/ethdev/rte_ethdev.h +2
-0+ tx_queue_id, tx_port_id); +return 0 ;
lib/ethdev/rte_ethdev.h rte_eth_tx_buffer(uint16_t port_id, uint16_t queue_id, · line 6672
Quoted 10 lines
lib/ethdev/rte_ethdev.h +10
-0+ } +#endif +if (p->recycle_tx_mbufs_reuse ==NULL ) +return 0 ; + +/* Copy used *rte_mbuf* buffer pointers from Tx mbuf ring +* into Rx mbuf ring. +*/ + nb_mbufs = p->recycle_tx_mbufs_reuse (qd, recycle_rxq_info); +
[Konstantin]
It is probably better to do that call after rx_port_id, rx_queue_id, etc. checks.
Otherwise with some errorneous params we can get mbufs, from TXQ, 'rx_refill' would not happen and we will return zero. With that in place:
Thanks for the comments, I will put all check before function call.
Quoted 120 lines
lib/ethdev/rte_ethdev.h +8
-0+/* If no recycling mbufs, return 0. */ +if (nb_mbufs ==0 ) +return 0 ; + +#ifdef RTE_ETHDEV_DEBUG_RX +if (rx_port_id >=RTE_MAX_ETHPORTS || + rx_queue_id >=RTE_MAX_QUEUES_PER_PORT ) { + RTE_ETHDEV_LOG(ERR, "Invalid rx_port_id=%u orrx_queue_id=%u\n",
lib/ethdev/rte_ethdev.h +14
-0+ rx_port_id, rx_queue_id); +return 0 ; + } +#endif + +/* fetch pointer to queue data */ + p = &rte_eth_fp_ops[rx_port_id]; + qd = p->rxq.data[rx_queue_id]; + +#ifdef RTE_ETHDEV_DEBUG_RX +RTE_ETH_VALID_PORTID_OR_ERR_RET (rx_port_id,0 ); + +if (qd ==NULL ) { + RTE_ETHDEV_LOG(ERR, "Invalid Rx queue_id=%u forport_id=%u\n",
lib/ethdev/rte_ethdev.h +16
-0+ rx_queue_id, rx_port_id); + return 0; + } +#endif + +if (p->recycle_rx_descriptors_refill ==NULL ) +return 0 ; + +/* Replenish the Rx descriptors with the recycling +* into Rx mbuf ring. +*/ + p->recycle_rx_descriptors_refill (qd, nb_mbufs); + +return nb_mbufs; +} +/** * @warning * @b EXPERIMENTAL: this API may change without prior notice diff --git
a/lib/ethdev/rte_ethdev_core.hb/lib/ethdev/rte_ethdev_core.hindex46e9721e07..a24ad7a6b2100644lib/ethdev/rte_ethdev_core.h +7
-0@@ -55,6 +55,13 @@ typedef int (*eth_rx_descriptor_status_t)(void *rxq, uint16_t offset);/** @internal Check the status of a Tx descriptor */ typedef int (*eth_tx_descriptor_status_t )(void *txq,uint16_t offset); +/** @internal Copy used mbufs from Tx mbuf ring into Rx mbuf ring */ +typedef uint16_t (*eth_recycle_tx_mbufs_reuse_t )(void *txq, +struct rte_eth_recycle_rxq_info *recycle_rxq_info); + +/** @internal Refill Rx descriptors with the recycling mbufs */ typedef +void (*eth_recycle_rx_descriptors_refill_t )(void *rxq,uint16_t nb); +/** * @internal * Structure used to hold opaque pointers to internal ethdev Rx/Tx @@ -
83,15 +90,17 @@ structrte_eth_fp_ops{lib/ethdev/rte_ethdev_core.h +10
-6* Rx fast-path functions and related data. * 64-bit systems: occupies first 64B line */ +/** Rx queues data. */ +struct rte_ethdev_qdata rxq;/** PMD receive function. */ eth_rx_burst_t rx_pkt_burst;/** Get the number of used Rx descriptors. */ eth_rx_queue_count_t rx_queue_count;/** Check the status of a Rx descriptor. */ eth_rx_descriptor_status_t rx_descriptor_status; -/** Rx queues data. */ -struct rte_ethdev_qdata rxq; -uintptr_t reserved1[3 ]; +/** Refill Rx descriptors with the recycling mbufs. */ +eth_recycle_rx_descriptors_refill_t recycle_rx_descriptors_refill; +uintptr_t reserved1[2 ];/**@}*/ /**@{*/ @@ -99,15 +108,17 @@ struct rte_eth_fp_ops {* Tx fast-path functions and related data. * 64-bit systems: occupies second 64B line */ +/** Tx queues data. */ +struct rte_ethdev_qdata txq;/** PMD transmit function. */ eth_tx_burst_t tx_pkt_burst;/** PMD transmit prepare function. */ eth_tx_prep_t tx_pkt_prepare;/** Check the status of a Tx descriptor. */ eth_tx_descriptor_status_t tx_descriptor_status; -/** Tx queues data. */ -struct rte_ethdev_qdata txq; -uintptr_t reserved2[3 ]; +/** Copy used mbufs from Tx mbuf ring into Rx. */ +eth_recycle_tx_mbufs_reuse_t recycle_tx_mbufs_reuse; +uintptr_t reserved2[2 ];/**@}*/ } __rte_cache_aligned;lib/ethdev/version.map index renamed from lib/ethdev/version.map +0
-0
b965d6aa52..eec159dfdd100644lib/ethdev/version.map +3
-1@@ -312,6 +312,9 @@ EXPERIMENTAL { rte_flow_async_action_list_handle_query_update; rte_flow_async_actions_update; rte_flow_restore_info_dynflag; + + # added in 23.11 + rte_eth_recycle_rx_queue_info_get; }; INTERNAL { --2.25.1
PATCH v11 2/4 net/i40e: implement mbufs recycle mode
In reply to Feifei WangDefine specific function implementation for i40e driver. Currently, mbufs recycle mode can support 128bit vector path and avx2 path. And can be enabled both in fast free and no fast free mode.
--- drivers/net/i40e/i40e_ethdev.c | 1 + drivers/net/i40e/i40e_ethdev.h | 2 + .../net/i40e/i40e_recycle_mbufs_vec_common.c | 147 ++++++++++++++++++ drivers/net/i40e/i40e_rxtx.c | 32 ++++ drivers/net/i40e/i40e_rxtx.h | 4 + drivers/net/i40e/meson.build | 1 + 6 files changed, 187 insertions(+) create mode 100644 drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
drivers/net/i40e/i40e_ethdev.c +1 -0
@@ -496,6 +496,7 @@ static const struct eth_dev_ops i40e_eth_dev_ops = { .flow_ops_get = i40e_dev_flow_ops_get, .rxq_info_get = i40e_rxq_info_get, .txq_info_get = i40e_txq_info_get, + .recycle_rxq_info_get = i40e_recycle_rxq_info_get, .rx_burst_mode_get = i40e_rx_burst_mode_get, .tx_burst_mode_get = i40e_tx_burst_mode_get, .timesync_enable = i40e_timesync_enable,
drivers/net/i40e/i40e_ethdev.h +2 -0
@@ -1355,6 +1355,8 @@ void i40e_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, struct rte_eth_rxq_info *qinfo);void i40e_txq_info_get (struct rte_eth_dev *dev,uint16_t queue_id,struct rte_eth_txq_info *qinfo); +void i40e_recycle_rxq_info_get (struct rte_eth_dev *dev,uint16_t queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info);int i40e_rx_burst_mode_get (struct rte_eth_dev *dev,uint16_t queue_id,struct rte_eth_burst_mode *mode); int i40e_tx_burst_mode_get(struct rte_eth_dev *dev, uint16_t queue_id,
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +147 -0
147 lines not on this page · raw message
drivers/net/i40e/i40e_rxtx.c +32 -0
@@ -3199,6 +3199,30 @@ i40e_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, qinfo->conf.offloads = txq->offloads; } +void +i40e_recycle_rxq_info_get (struct rte_eth_dev *dev,uint16_t queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info) +{ +struct i40e_rx_queue *rxq; +struct i40e_adapter *ad = +I40E_DEV_PRIVATE_TO_ADAPTER (dev->data->dev_private); + + rxq = dev->data->rx_queues[queue_id]; + + recycle_rxq_info->mbuf_ring = (void *)rxq->sw_ring; + recycle_rxq_info->mp = rxq->mp; + recycle_rxq_info->mbuf_ring_size = rxq->nb_rx_desc; + recycle_rxq_info->receive_tail = &rxq->rx_tail; + +if (ad->rx_vec_allowed) { + recycle_rxq_info->refill_requirement =RTE_I40E_RXQ_REARM_THRESH ; + recycle_rxq_info->refill_head = &rxq->rxrearm_start; + }else { + recycle_rxq_info->refill_requirement = rxq->rx_free_thresh; + recycle_rxq_info->refill_head = &rxq->rx_free_trigger; + } +} +#ifdef RTE_ARCH_X86 static inline bool get_avx_supported (bool request_avx512)
@@ -3293,6 +3317,8 @@ i40e_set_rx_function(struct rte_eth_dev *dev) dev->rx_pkt_burst = ad->rx_use_avx2 ? i40e_recv_scattered_pkts_vec_avx2 : i40e_recv_scattered_pkts_vec; + dev->recycle_rx_descriptors_refill = + i40e_recycle_rx_descriptors_refill_vec; } }else {if (ad->rx_use_avx512) {
@@ -3311,9 +3337,12 @@ i40e_set_rx_function(struct rte_eth_dev *dev) dev->rx_pkt_burst = ad->rx_use_avx2 ? i40e_recv_pkts_vec_avx2 : i40e_recv_pkts_vec; + dev->recycle_rx_descriptors_refill = + i40e_recycle_rx_descriptors_refill_vec; } }#else /* RTE_ARCH_X86 */ + dev->recycle_rx_descriptors_refill = i40e_recycle_rx_descriptors_refill_vec;if (dev->data->scattered_rx) { PMD_INIT_LOG(DEBUG, "Using Vector Scattered Rx (port %d).",
@@ -3481,15 +3510,18 @@ i40e_set_tx_function(struct rte_eth_dev *dev) dev->tx_pkt_burst = ad->tx_use_avx2 ? i40e_xmit_pkts_vec_avx2 : i40e_xmit_pkts_vec; + dev->recycle_tx_mbufs_reuse = i40e_recycle_tx_mbufs_reuse_vec; }#else /* RTE_ARCH_X86 */ PMD_INIT_LOG (DEBUG ,"Using Vector Tx (port %d)." , dev->data->port_id); dev->tx_pkt_burst = i40e_xmit_pkts_vec; + dev->recycle_tx_mbufs_reuse = i40e_recycle_tx_mbufs_reuse_vec;#endif /* RTE_ARCH_X86 */ }else {PMD_INIT_LOG (DEBUG ,"Simple tx finally be used." ); dev->tx_pkt_burst = i40e_xmit_pkts_simple; + dev->recycle_tx_mbufs_reuse = i40e_recycle_tx_mbufs_reuse_vec; } dev->tx_pkt_prepare = i40e_simple_prep_pkts; }else {
drivers/net/i40e/i40e_rxtx.h +4 -0
@@ -236,6 +236,10 @@ uint32_t i40e_dev_rx_queue_count(void *rx_queue);int i40e_dev_rx_descriptor_status (void *rx_queue,uint16_t offset);int i40e_dev_tx_descriptor_status (void *tx_queue,uint16_t offset); +uint16_t i40e_recycle_tx_mbufs_reuse_vec (void *tx_queue, +struct rte_eth_recycle_rxq_info *recycle_rxq_info); +void i40e_recycle_rx_descriptors_refill_vec (void *rx_queue,uint16_t nb_mbufs); +uint16_t i40e_recv_pkts_vec (void *rx_queue,struct rte_mbuf **rx_pkts,uint16_t nb_pkts); uint16_t i40e_recv_scattered_pkts_vec(void *rx_queue,
drivers/net/i40e/meson.build +1 -0
@@ -34,6 +34,7 @@ sources = files( 'i40e_tm.c', 'i40e_hash.c', 'i40e_vf_representor.c', + 'i40e_recycle_mbufs_vec_common.c', 'rte_pmd_i40e.c', )
Signature · 1 line
2.25.1
Re: [PATCH v11 2/4] net/i40e: implement mbufs recycle mode
22/08/2023 08:27, Feifei Wang пишет:
Quoted 165 lines
Define specific function implementation for i40e driver. Currently, mbufs recycle mode can support 128bit vector path and avx2 path. And can be enabled both in fast free and no fast free mode.
Suggested-by Honnappa Nagarahalli <[email protected]>Signed-off-by Feifei Wang <[email protected]>Reviewed-by Ruifeng Wang <[email protected]>Reviewed-by Honnappa Nagarahalli <[email protected]>--- drivers/net/i40e/i40e_ethdev.c | 1 + drivers/net/i40e/i40e_ethdev.h | 2 + .../net/i40e/i40e_recycle_mbufs_vec_common.c | 147 ++++++++++++++++++ drivers/net/i40e/i40e_rxtx.c | 32 ++++ drivers/net/i40e/i40e_rxtx.h | 4 + drivers/net/i40e/meson.build | 1 + 6 files changed, 187 insertions(+)create mode 100644
drivers/net/i40e/i40e_recycle_mbufs_vec_common.cdrivers/net/i40e/i40e_ethdev.c +1
-0@@ -496,6 +496,7 @@ static const struct eth_dev_ops i40e_eth_dev_ops = { .flow_ops_get = i40e_dev_flow_ops_get, .rxq_info_get = i40e_rxq_info_get, .txq_info_get = i40e_txq_info_get, + .recycle_rxq_info_get = i40e_recycle_rxq_info_get, .rx_burst_mode_get = i40e_rx_burst_mode_get, .tx_burst_mode_get = i40e_tx_burst_mode_get, .timesync_enable = i40e_timesync_enable,drivers/net/i40e/i40e_ethdev.h +2
-0@@ -1355,6 +1355,8 @@ void i40e_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, struct rte_eth_rxq_info *qinfo);void i40e_txq_info_get (struct rte_eth_dev *dev,uint16_t queue_id,struct rte_eth_txq_info *qinfo); +void i40e_recycle_rxq_info_get (struct rte_eth_dev *dev,uint16_t queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info);int i40e_rx_burst_mode_get (struct rte_eth_dev *dev,uint16_t queue_id,struct rte_eth_burst_mode *mode); int i40e_tx_burst_mode_get(struct rte_eth_dev *dev, uint16_t queue_id,drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +115
-0@@ -0,0 +1,147 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2023 Arm Limited. +*/ + +#include <stdint.h> +#include <ethdev_driver.h> + +#include "base/i40e_prototype.h" +#include "base/i40e_type.h" +#include "i40e_ethdev.h" +#include "i40e_rxtx.h" + +#pragma GCC diagnostic ignored "-Wcast-qual" + +void +i40e_recycle_rx_descriptors_refill_vec (void *rx_queue,uint16_t nb_mbufs) +{ +struct i40e_rx_queue *rxq = rx_queue; +struct i40e_rx_entry *rxep; +volatile union i40e_rx_desc *rxdp; +uint16_t rx_id; +uint64_t paddr; +uint64_t dma_addr; +uint16_t i; + + rxdp = rxq->rx_ring + rxq->rxrearm_start; + rxep = &rxq->sw_ring[rxq->rxrearm_start]; + +for (i =0 ; i < nb_mbufs; i++) { +/* Initialize rxdp descs. */ + paddr = (rxep[i].mbuf)->buf_iova +RTE_PKTMBUF_HEADROOM ; + dma_addr =rte_cpu_to_le_64 (paddr); +/* flush desc with pa dma_addr */ + rxdp[i].read.hdr_addr =0 ; + rxdp[i].read.pkt_addr = dma_addr; + } + +/* Update the descriptor initializer index */ + rxq->rxrearm_start += nb_mbufs; + rx_id = rxq->rxrearm_start -1 ; + +if (unlikely (rxq->rxrearm_start >= rxq->nb_rx_desc)) { + rxq->rxrearm_start =0 ; + rx_id = rxq->nb_rx_desc -1 ; + } + + rxq->rxrearm_nb -= nb_mbufs; + +rte_io_wmb (); +/* Update the tail pointer on the NIC */ +I40E_PCI_REG_WRITE_RELAXED (rxq->qrx_tail, rx_id); +} + +uint16_t +i40e_recycle_tx_mbufs_reuse_vec (void *tx_queue, +struct rte_eth_recycle_rxq_info *recycle_rxq_info) +{ +struct i40e_tx_queue *txq = tx_queue; +struct i40e_tx_entry *txep; +struct rte_mbuf **rxep; +int i, n; +uint16_t nb_recycle_mbufs; +uint16_t avail =0 ; +uint16_t mbuf_ring_size = recycle_rxq_info->mbuf_ring_size; +uint16_t mask = recycle_rxq_info->mbuf_ring_size -1 ; +uint16_t refill_requirement = recycle_rxq_info->refill_requirement; +uint16_t refill_head = *recycle_rxq_info->refill_head; +uint16_t receive_tail = *recycle_rxq_info->receive_tail; + +/* Get available recycling Rx buffers. */ + avail = (mbuf_ring_size - (refill_head - receive_tail)) & mask; + +/* Check Tx free thresh and Rx available space. */ +if (txq->nb_tx_free > txq->tx_free_thresh || avail <= txq->tx_rs_thresh) +return 0 ; + +/* check DD bits on threshold descriptor */ +if ((txq->tx_ring[txq->tx_next_dd].cmd_type_offset_bsz & +rte_cpu_to_le_64 (I40E_TXD_QW1_DTYPE_MASK )) != +rte_cpu_to_le_64 (I40E_TX_DESC_DTYPE_DESC_DONE )) +return 0 ; + + n = txq->tx_rs_thresh; + nb_recycle_mbufs = n; + +/* Mbufs recycle mode can only support no ring buffer wrapping around. +* Two case for this: +* +* case 1: The refill head of Rx buffer ring needs to be aligned with +* mbuf ring size. In this case, the number of Tx freeing buffers +* should be equal to refill_requirement. +* +* case 2: The refill head of Rx ring buffer does not need to be aligned +* with mbuf ring size. In this case, the update of refill head can not +* exceed the Rx mbuf ring size. +*/ +if (refill_requirement != n || + (!refill_requirement && (refill_head + n > mbuf_ring_size))) +return 0 ; + +/* First buffer to free from S/W ring is at index +* tx_next_dd - (tx_rs_thresh-1). +*/ + txep = &txq->sw_ring[txq->tx_next_dd - (n -1 )]; + rxep = recycle_rxq_info->mbuf_ring; + rxep += refill_head; + +if (txq->offloads &RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE ) { +/* Avoid txq contains buffers from unexpected mempool. */ +if (unlikely (recycle_rxq_info->mp + != txep[0 ].mbuf->pool)) +return 0 ; + +/* Directly put mbufs from Tx to Rx. */ +for (i =0 ; i < n; i++)
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c line 125
Quoted 10 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +10
-0+ rxep[i] = txep[i].mbuf; + }else { +for (i =0 ; i < n; i++) { + rxep[i] =rte_pktmbuf_prefree_seg (txep[i].mbuf); + +/* If Tx buffers are not the last reference or from +* unexpected mempool, previous copied buffers are +* considered as invalid. +*/ + if (unlikely((rxep[i] == NULL && refill_requirement) ||
Could you pls remind me why it is ok to have rxep[i]==NULL when refill_requirement is not set?
Quoted 22 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +22
-0+ recycle_rxq_info->mp != txep[i].mbuf->pool)) + nb_recycle_mbufs =0 ; + } +/* If Tx buffers are not the last reference or +* from unexpected mempool, all recycled buffers +* are put into mempool. +*/ +if (nb_recycle_mbufs ==0 ) +for (i =0 ; i < n; i++) { +if (rxep[i] !=NULL ) +rte_mempool_put (rxep[i]->pool, rxep[i]); + } + } + +/* Update counters for Tx. */ + txq->nb_tx_free = (uint16_t )(txq->nb_tx_free + txq->tx_rs_thresh); + txq->tx_next_dd = (uint16_t )(txq->tx_next_dd + txq->tx_rs_thresh); +if (txq->tx_next_dd >= txq->nb_tx_desc) + txq->tx_next_dd = (uint16_t )(txq->tx_rs_thresh -1 ); + +return nb_recycle_mbufs; +}
RE: [PATCH v11 2/4] net/i40e: implement mbufs recycle mode
In reply to Feifei WangFor konstantin
Quoted 180 lines
-----Original Message-----
From: Feifei Wang <[email protected]>
Sent: Tuesday, August 22, 2023 3:27 PM
To: Yuying Zhang <[email protected]>; Beilei Xing <[email protected]>
Cc: [email protected]; nd <[email protected]>; Feifei Wang <[email protected]>; Honnappa Nagarahalli <[email protected]>; Ruifeng Wang <[email protected]>
Subject: [PATCH v11 2/4] net/i40e: implement mbufs recycle modeDefine specific function implementation for i40e driver. Currently, mbufs recycle mode can support 128bit vector path and avx2 path. And can be enabled both in fast free and no fast free mode.
Suggested-by Honnappa Nagarahalli <[email protected]>Signed-off-by Feifei Wang <[email protected]>Reviewed-by Ruifeng Wang <[email protected]>Reviewed-by Honnappa Nagarahalli <[email protected]>--- drivers/net/i40e/i40e_ethdev.c | 1 + drivers/net/i40e/i40e_ethdev.h | 2 + .../net/i40e/i40e_recycle_mbufs_vec_common.c | 147 ++++++++++++++++++ drivers/net/i40e/i40e_rxtx.c | 32 ++++ drivers/net/i40e/i40e_rxtx.h | 4 + drivers/net/i40e/meson.build | 1 + 6 files changed, 187 insertions(+) create mode 100644 drivers/net/i40e/i40e_recycle_mbufs_vec_common.cdrivers/net/i40e/i40e_ethdev.c +1
-0@@ -496,6 +496,7 @@ static const struct eth_dev_ops i40e_eth_dev_ops = { .flow_ops_get = i40e_dev_flow_ops_get, .rxq_info_get = i40e_rxq_info_get, .txq_info_get = i40e_txq_info_get, + .recycle_rxq_info_get = i40e_recycle_rxq_info_get, .rx_burst_mode_get = i40e_rx_burst_mode_get, .tx_burst_mode_get = i40e_tx_burst_mode_get, .timesync_enable = i40e_timesync_enable,drivers/net/i40e/i40e_ethdev.h +2
-0@@ -1355,6 +1355,8 @@ void i40e_rxq_info_get(struct rte_eth_dev *dev,uint16_t queue_id, struct rte_eth_rxq_info *qinfo);void i40e_txq_info_get (struct rte_eth_dev *dev,uint16_t queue_id,struct rte_eth_txq_info *qinfo); +void i40e_recycle_rxq_info_get (struct rte_eth_dev *dev,uint16_t queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info);int i40e_rx_burst_mode_get (struct rte_eth_dev *dev,uint16_t queue_id,struct rte_eth_burst_mode *mode);int i40e_tx_burst_mode_get(struct
rte_eth_dev*dev,uint16_tqueue_id, diff -- gita/drivers/net/i40e/i40e_recycle_mbufs_vec_common.cb/drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
new file mode 100644
index 0000000000..5663ecccdedrivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +31
-0@@ -0,0 +1,147 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2023 Arm Limited. +*/ + +#include <stdint.h> +#include <ethdev_driver.h> + +#include "base/i40e_prototype.h" +#include "base/i40e_type.h" +#include "i40e_ethdev.h" +#include "i40e_rxtx.h" + +#pragma GCC diagnostic ignored "-Wcast-qual" + +void +i40e_recycle_rx_descriptors_refill_vec (void *rx_queue,uint16_t +nb_mbufs) { +struct i40e_rx_queue *rxq = rx_queue; +struct i40e_rx_entry *rxep; +volatile union i40e_rx_desc *rxdp; +uint16_t rx_id; +uint64_t paddr; +uint64_t dma_addr; +uint16_t i; + + rxdp = rxq->rx_ring + rxq->rxrearm_start; + rxep = &rxq->sw_ring[rxq->rxrearm_start]; + +for (i =0 ; i < nb_mbufs; i++) { +/* Initialize rxdp descs. */ + paddr = (rxep[i].mbuf)->buf_iova +
RTE_PKTMBUF_HEADROOM;drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +46
-0+ dma_addr =rte_cpu_to_le_64 (paddr); +/* flush desc with pa dma_addr */ + rxdp[i].read.hdr_addr =0 ; + rxdp[i].read.pkt_addr = dma_addr; + } + +/* Update the descriptor initializer index */ + rxq->rxrearm_start += nb_mbufs; + rx_id = rxq->rxrearm_start -1 ; + +if (unlikely (rxq->rxrearm_start >= rxq->nb_rx_desc)) { + rxq->rxrearm_start =0 ; + rx_id = rxq->nb_rx_desc -1 ; + } + + rxq->rxrearm_nb -= nb_mbufs; + +rte_io_wmb (); +/* Update the tail pointer on the NIC */ +I40E_PCI_REG_WRITE_RELAXED (rxq->qrx_tail, rx_id); } + +uint16_t +i40e_recycle_tx_mbufs_reuse_vec (void *tx_queue, +struct rte_eth_recycle_rxq_info *recycle_rxq_info) { +struct i40e_tx_queue *txq = tx_queue; +struct i40e_tx_entry *txep; +struct rte_mbuf **rxep; +int i, n; +uint16_t nb_recycle_mbufs; +uint16_t avail =0 ; +uint16_t mbuf_ring_size = recycle_rxq_info->mbuf_ring_size; +uint16_t mask = recycle_rxq_info->mbuf_ring_size -1 ; +uint16_t refill_requirement = recycle_rxq_info->refill_requirement; +uint16_t refill_head = *recycle_rxq_info->refill_head; +uint16_t receive_tail = *recycle_rxq_info->receive_tail; + +/* Get available recycling Rx buffers. */ + avail = (mbuf_ring_size - (refill_head - receive_tail)) & mask; + +/* Check Tx free thresh and Rx available space. */ +if (txq->nb_tx_free > txq->tx_free_thresh || avail <= txq->tx_rs_thresh) +return 0 ; + +/* check DD bits on threshold descriptor */ + if ((txq->tx_ring[txq->tx_next_dd].cmd_type_offset_bsz & +rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) != + rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE))drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +6
-0+return 0 ; + + n = txq->tx_rs_thresh; + nb_recycle_mbufs = n; + +/* Mbufs recycle mode can only support no ring buffer wrapping around.
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +29
-0+* Two case for this: +* +* case 1: The refill head of Rx buffer ring needs to be aligned with +* mbuf ring size. In this case, the number of Tx freeing buffers +* should be equal to refill_requirement. +* +* case 2: The refill head of Rx ring buffer does not need to be aligned +* with mbuf ring size. In this case, the update of refill head can not +* exceed the Rx mbuf ring size. +*/ +if (refill_requirement != n || + (!refill_requirement && (refill_head + n > mbuf_ring_size))) +return 0 ; + +/* First buffer to free from S/W ring is at index +* tx_next_dd - (tx_rs_thresh-1). +*/ + txep = &txq->sw_ring[txq->tx_next_dd - (n -1 )]; + rxep = recycle_rxq_info->mbuf_ring; + rxep += refill_head; + +if (txq->offloads &RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE ) { +/* Avoid txq contains buffers from unexpected mempool. */ +if (unlikely (recycle_rxq_info->mp + != txep[0 ].mbuf->pool)) +return 0 ; + +/* Directly put mbufs from Tx to Rx. */ +for (i =0 ; i < n; i++)
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c line 125
Quoted 10 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +10
-0+ rxep[i] = txep[i].mbuf; + }else { +for (i =0 ; i < n; i++) { + rxep[i] =rte_pktmbuf_prefree_seg (txep[i].mbuf); + +/* If Tx buffers are not the last reference or from +* unexpected mempool, previous copied buffers are +* considered as invalid. +*/ + if (unlikely((rxep[i] == NULL && refill_requirement) ||
[Konstantin]
Could you pls remind me why it is ok to have rxep[i]==NULL when refill_requirement is not set?
If reill_requirement is not zero, it means each tx freed buffer must be valid and can be put into Rx sw_ring. Then the refill head of Rx buffer ring can be aligned with mbuf ring size. Briefly speaking the number of Tx valid freed buffer must be equal to Rx refill_requirement. For example, i40e driver.
If reill_requirement is zero, it means that the refill head of Rx buffer ring does not need to be aligned with mbuf ring size, thus if Tx have n valid freed buffers, we just need to put these n buffers into Rx sw-ring, and not to be equal to the Rx setting rearm number. For example, mlx5 driver.
In conclusion, above difference is due to pmd drivers have different strategies to update their Rx rearm(refill) head. For i40e driver, if rearm_head exceed 1024, it will be set as 0 due to the number of each rearm is a fixed value by default. For mlx5 driver. Its rearm_head can exceed 1024, and use mask to achieve real index. Thus its rearm number can be a different value.
Quoted 135 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +1
-0+ recycle_rxq_info->mp != txep[i].mbuf-Quoted 1 line
pool))
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +10
-0+ nb_recycle_mbufs =0 ; + } +/* If Tx buffers are not the last reference or +* from unexpected mempool, all recycled buffers +* are put into mempool. +*/ +if (nb_recycle_mbufs ==0 ) +for (i =0 ; i < n; i++) { +if (rxep[i] !=NULL ) + rte_mempool_put(rxep[i]->pool,rxep[i]);
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +11
-0+ } + } + +/* Update counters for Tx. */ + txq->nb_tx_free = (uint16_t )(txq->nb_tx_free + txq->tx_rs_thresh); + txq->tx_next_dd = (uint16_t )(txq->tx_next_dd + txq->tx_rs_thresh); +if (txq->tx_next_dd >= txq->nb_tx_desc) + txq->tx_next_dd = (uint16_t )(txq->tx_rs_thresh -1 ); + +return nb_recycle_mbufs; +}drivers/net/i40e/i40e_rxtx.c index renamed from drivers/net/i40e/i40e_rxtx.c +0
-0
b4f65b58fa..a9c9eb331c100644drivers/net/i40e/i40e_rxtx.c +30
-1@@ -3199,6 +3199,30 @@ i40e_txq_info_get(struct rte_eth_dev *dev,uint16_t queue_id, qinfo->conf.offloads = txq->offloads; } +void +i40e_recycle_rxq_info_get (struct rte_eth_dev *dev,uint16_t queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info) { +struct i40e_rx_queue *rxq; +struct i40e_adapter *ad = +I40E_DEV_PRIVATE_TO_ADAPTER (dev->data->dev_private); + + rxq = dev->data->rx_queues[queue_id]; + + recycle_rxq_info->mbuf_ring = (void *)rxq->sw_ring; + recycle_rxq_info->mp = rxq->mp; + recycle_rxq_info->mbuf_ring_size = rxq->nb_rx_desc; + recycle_rxq_info->receive_tail = &rxq->rx_tail; + +if (ad->rx_vec_allowed) { + recycle_rxq_info->refill_requirement =RTE_I40E_RXQ_REARM_THRESH ; + recycle_rxq_info->refill_head = &rxq->rxrearm_start; + }else { + recycle_rxq_info->refill_requirement = rxq->rx_free_thresh; + recycle_rxq_info->refill_head = &rxq->rx_free_trigger; + } +} +#ifdef RTE_ARCH_X86 static inline bool get_avx_supported (bool request_avx512)@@ -3293,6 +3317,8 @@ i40e_set_rx_function(struct rte_eth_dev *dev) dev->rx_pkt_burst = ad->rx_use_avx2 ? i40e_recv_scattered_pkts_vec_avx2 : i40e_recv_scattered_pkts_vec; + dev->recycle_rx_descriptors_refill = + i40e_recycle_rx_descriptors_refill_vec; } }else {if (ad->rx_use_avx512) {@@ -3311,9 +3337,12 @@ i40e_set_rx_function(struct rte_eth_dev *dev) dev->rx_pkt_burst = ad->rx_use_avx2 ? i40e_recv_pkts_vec_avx2 : i40e_recv_pkts_vec; + dev->recycle_rx_descriptors_refill = + i40e_recycle_rx_descriptors_refill_vec; } }#else /* RTE_ARCH_X86 */ + dev->recycle_rx_descriptors_refill = +i40e_recycle_rx_descriptors_refill_vec; if (dev->data->scattered_rx) { PMD_INIT_LOG(DEBUG, "Using Vector Scattered Rx (port %d).", @@ -3481,15 +3510,18 @@ i40e_set_tx_function(struct rte_eth_dev *dev) dev->tx_pkt_burst = ad->tx_use_avx2 ? i40e_xmit_pkts_vec_avx2 : i40e_xmit_pkts_vec; + dev->recycle_tx_mbufs_reuse =
i40e_recycle_tx_mbufs_reuse_vec;drivers/net/i40e/i40e_rxtx.c +1
-0}#else /* RTE_ARCH_X86 */ PMD_INIT_LOG (DEBUG ,"Using Vector Tx (port %d)." , dev->data->port_id); dev->tx_pkt_burst = i40e_xmit_pkts_vec; + dev->recycle_tx_mbufs_reuse =
i40e_recycle_tx_mbufs_reuse_vec;
#endif /*RTE_ARCH_X86*/drivers/net/i40e/i40e_rxtx.c +1
-0}else {PMD_INIT_LOG (DEBUG ,"Simple tx finally be used." ); dev->tx_pkt_burst = i40e_xmit_pkts_simple; + dev->recycle_tx_mbufs_reuse =
i40e_recycle_tx_mbufs_reuse_vec;drivers/net/i40e/i40e_rxtx.c +0
-0} dev->tx_pkt_prepare = i40e_simple_prep_pkts; }else {drivers/net/i40e/i40e_rxtx.h index renamed from drivers/net/i40e/i40e_rxtx.h +0
-0
a8686224e5..b191f23e1f100644drivers/net/i40e/i40e_rxtx.h +5
-0@@ -236,6 +236,10 @@ uint32_t i40e_dev_rx_queue_count(void *rx_queue); int i40e_dev_rx_descriptor_status(void *rx_queue, uint16_t offset);int i40e_dev_tx_descriptor_status (void *tx_queue,uint16_t offset); +uint16_t i40e_recycle_tx_mbufs_reuse_vec (void *tx_queue, +struct rte_eth_recycle_rxq_info *recycle_rxq_info);void +i40e_recycle_rx_descriptors_refill_vec (void *rx_queue,uint16_t +nb_mbufs); +uint16_t i40e_recv_pkts_vec (void *rx_queue,struct rte_mbuf **rx_pkts,uint16_t nb_pkts); uint16_t i40e_recv_scattered_pkts_vec(void *rx_queue, diff --gita/drivers/net/i40e/meson.build b/drivers/net/i40e/meson.build index
8e53b87a65..3b1a233c84100644drivers/net/i40e/meson.build +1
-1@@ -34,6 +34,7 @@ sources = files( 'i40e_tm.c', 'i40e_hash.c', 'i40e_vf_representor.c', + 'i40e_recycle_mbufs_vec_common.c', 'rte_pmd_i40e.c', ) --2.25.1
RE: [PATCH v11 2/4] net/i40e: implement mbufs recycle mode
Quoted 190 lines
Quoted 172 lines
Define specific function implementation for i40e driver. Currently, mbufs recycle mode can support 128bit vector path and avx2 path. And can be enabled both in fast free and no fast free mode.
Suggested-by Honnappa Nagarahalli <[email protected]>Signed-off-by Feifei Wang <[email protected]>Reviewed-by Ruifeng Wang <[email protected]>Reviewed-by Honnappa Nagarahalli <[email protected]>--- drivers/net/i40e/i40e_ethdev.c | 1 + drivers/net/i40e/i40e_ethdev.h | 2 + .../net/i40e/i40e_recycle_mbufs_vec_common.c | 147 ++++++++++++++++++ drivers/net/i40e/i40e_rxtx.c | 32 ++++ drivers/net/i40e/i40e_rxtx.h | 4 + drivers/net/i40e/meson.build | 1 + 6 files changed, 187 insertions(+) create mode 100644 drivers/net/i40e/i40e_recycle_mbufs_vec_common.cdrivers/net/i40e/i40e_ethdev.c +1
-0@@ -496,6 +496,7 @@ static const struct eth_dev_ops i40e_eth_dev_ops = { .flow_ops_get = i40e_dev_flow_ops_get, .rxq_info_get = i40e_rxq_info_get, .txq_info_get = i40e_txq_info_get, + .recycle_rxq_info_get = i40e_recycle_rxq_info_get, .rx_burst_mode_get = i40e_rx_burst_mode_get, .tx_burst_mode_get = i40e_tx_burst_mode_get, .timesync_enable = i40e_timesync_enable,drivers/net/i40e/i40e_ethdev.h +2
-0@@ -1355,6 +1355,8 @@ void i40e_rxq_info_get(struct rte_eth_dev *dev,uint16_t queue_id, struct rte_eth_rxq_info *qinfo);void i40e_txq_info_get (struct rte_eth_dev *dev,uint16_t queue_id,struct rte_eth_txq_info *qinfo); +void i40e_recycle_rxq_info_get (struct rte_eth_dev *dev,uint16_t queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info);int i40e_rx_burst_mode_get (struct rte_eth_dev *dev,uint16_t queue_id,struct rte_eth_burst_mode *mode);int i40e_tx_burst_mode_get(struct
rte_eth_dev*dev,uint16_tqueue_id, diff -- gita/drivers/net/i40e/i40e_recycle_mbufs_vec_common.cb/drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
new file mode 100644
index 0000000000..5663ecccdedrivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +31
-0@@ -0,0 +1,147 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2023 Arm Limited. +*/ + +#include <stdint.h> +#include <ethdev_driver.h> + +#include "base/i40e_prototype.h" +#include "base/i40e_type.h" +#include "i40e_ethdev.h" +#include "i40e_rxtx.h" + +#pragma GCC diagnostic ignored "-Wcast-qual" + +void +i40e_recycle_rx_descriptors_refill_vec (void *rx_queue,uint16_t +nb_mbufs) { +struct i40e_rx_queue *rxq = rx_queue; +struct i40e_rx_entry *rxep; +volatile union i40e_rx_desc *rxdp; +uint16_t rx_id; +uint64_t paddr; +uint64_t dma_addr; +uint16_t i; + + rxdp = rxq->rx_ring + rxq->rxrearm_start; + rxep = &rxq->sw_ring[rxq->rxrearm_start]; + +for (i =0 ; i < nb_mbufs; i++) { +/* Initialize rxdp descs. */ + paddr = (rxep[i].mbuf)->buf_iova +
RTE_PKTMBUF_HEADROOM;drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +46
-0+ dma_addr =rte_cpu_to_le_64 (paddr); +/* flush desc with pa dma_addr */ + rxdp[i].read.hdr_addr =0 ; + rxdp[i].read.pkt_addr = dma_addr; + } + +/* Update the descriptor initializer index */ + rxq->rxrearm_start += nb_mbufs; + rx_id = rxq->rxrearm_start -1 ; + +if (unlikely (rxq->rxrearm_start >= rxq->nb_rx_desc)) { + rxq->rxrearm_start =0 ; + rx_id = rxq->nb_rx_desc -1 ; + } + + rxq->rxrearm_nb -= nb_mbufs; + +rte_io_wmb (); +/* Update the tail pointer on the NIC */ +I40E_PCI_REG_WRITE_RELAXED (rxq->qrx_tail, rx_id); } + +uint16_t +i40e_recycle_tx_mbufs_reuse_vec (void *tx_queue, +struct rte_eth_recycle_rxq_info *recycle_rxq_info) { +struct i40e_tx_queue *txq = tx_queue; +struct i40e_tx_entry *txep; +struct rte_mbuf **rxep; +int i, n; +uint16_t nb_recycle_mbufs; +uint16_t avail =0 ; +uint16_t mbuf_ring_size = recycle_rxq_info->mbuf_ring_size; +uint16_t mask = recycle_rxq_info->mbuf_ring_size -1 ; +uint16_t refill_requirement = recycle_rxq_info->refill_requirement; +uint16_t refill_head = *recycle_rxq_info->refill_head; +uint16_t receive_tail = *recycle_rxq_info->receive_tail; + +/* Get available recycling Rx buffers. */ + avail = (mbuf_ring_size - (refill_head - receive_tail)) & mask; + +/* Check Tx free thresh and Rx available space. */ +if (txq->nb_tx_free > txq->tx_free_thresh || avail <= txq->tx_rs_thresh) +return 0 ; + +/* check DD bits on threshold descriptor */ + if ((txq->tx_ring[txq->tx_next_dd].cmd_type_offset_bsz & +rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) != + rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE))drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +6
-0+return 0 ; + + n = txq->tx_rs_thresh; + nb_recycle_mbufs = n; + +/* Mbufs recycle mode can only support no ring buffer wrapping around.
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +29
-0+* Two case for this: +* +* case 1: The refill head of Rx buffer ring needs to be aligned with +* mbuf ring size. In this case, the number of Tx freeing buffers +* should be equal to refill_requirement. +* +* case 2: The refill head of Rx ring buffer does not need to be aligned +* with mbuf ring size. In this case, the update of refill head can not +* exceed the Rx mbuf ring size. +*/ +if (refill_requirement != n || + (!refill_requirement && (refill_head + n > mbuf_ring_size))) +return 0 ; + +/* First buffer to free from S/W ring is at index +* tx_next_dd - (tx_rs_thresh-1). +*/ + txep = &txq->sw_ring[txq->tx_next_dd - (n -1 )]; + rxep = recycle_rxq_info->mbuf_ring; + rxep += refill_head; + +if (txq->offloads &RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE ) { +/* Avoid txq contains buffers from unexpected mempool. */ +if (unlikely (recycle_rxq_info->mp + != txep[0 ].mbuf->pool)) +return 0 ; + +/* Directly put mbufs from Tx to Rx. */ +for (i =0 ; i < n; i++)drivers/net/i40e/i40e_recycle_mbufs_vec_common.c line 125
Quoted 10 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +10
-0+ rxep[i] = txep[i].mbuf; + }else { +for (i =0 ; i < n; i++) { + rxep[i] =rte_pktmbuf_prefree_seg (txep[i].mbuf); + +/* If Tx buffers are not the last reference or from +* unexpected mempool, previous copied buffers are +* considered as invalid. +*/ + if (unlikely((rxep[i] == NULL && refill_requirement) ||[Konstantin]
Could you pls remind me why it is ok to have rxep[i]==NULL whenrefill_requirementis not set?If
reill_requirementis not zero, it means each tx freed buffer must be valid and can be put into Rxsw_ring. Then the refill head of Rx buffer ring can be aligned with mbuf ring size. Briefly speaking the number of Tx valid freed buffer must be equal to Rxrefill_requirement. For example, i40e driver.
Quoted 7 lines
If
reill_requirementis zero, it means that the refill head of Rx buffer ring does not need to be aligned with mbuf ring size, thus if Tx have n valid freed buffers, we just need to put these n buffers into Rx sw-ring, and not to be equal to the Rx setting rearm number. For example, mlx5 driver.In conclusion, above difference is due to pmd drivers have different strategies to update their Rx rearm(refill) head. For i40e driver, if
rearm_headexceed 1024, it will be set as 0 due to the number of each rearm is a fixed value by default. For mlx5 driver. Itsrearm_headcan exceed 1024, and use mask to achieve real index. Thus its rearm number can be a different value.
Ok, but if rte_pktmbuf_prefree_seg(txep[i].mbuf), it means that this mbuf is not free yet and can't be reused. Shouldn't we then set nb_recycle_mbufs = 0 in that case too?
Or probably would be enough to skip that mbuf?
Might be something like that:
for (i = 0, j = 0; i < n; i++) {
rxep[j] = rte_pktmbuf_prefree_seg(txep[i].mbuf);
if (rxep[j] == NULL || recycle_rxq_info->mp != rxep[j].mbuf->pool)) {
if (refill_requirement) {
nb_recycle_mbufs = 0;
break;
}
} else
j++;
}/* now j contains actual number of recycled mbufs */
?
Quoted 136 lines
Quoted 136 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +1
-0+ recycle_rxq_info->mp != txep[i].mbuf-Quoted 1 line
pool))
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +10
-0+ nb_recycle_mbufs =0 ; + } +/* If Tx buffers are not the last reference or +* from unexpected mempool, all recycled buffers +* are put into mempool. +*/ +if (nb_recycle_mbufs ==0 ) +for (i =0 ; i < n; i++) { +if (rxep[i] !=NULL ) + rte_mempool_put(rxep[i]->pool,rxep[i]);
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +11
-0+ } + } + +/* Update counters for Tx. */ + txq->nb_tx_free = (uint16_t )(txq->nb_tx_free + txq->tx_rs_thresh); + txq->tx_next_dd = (uint16_t )(txq->tx_next_dd + txq->tx_rs_thresh); +if (txq->tx_next_dd >= txq->nb_tx_desc) + txq->tx_next_dd = (uint16_t )(txq->tx_rs_thresh -1 ); + +return nb_recycle_mbufs; +}drivers/net/i40e/i40e_rxtx.c index renamed from drivers/net/i40e/i40e_rxtx.c +0
-0
b4f65b58fa..a9c9eb331c100644drivers/net/i40e/i40e_rxtx.c +30
-1@@ -3199,6 +3199,30 @@ i40e_txq_info_get(struct rte_eth_dev *dev,uint16_t queue_id, qinfo->conf.offloads = txq->offloads; } +void +i40e_recycle_rxq_info_get (struct rte_eth_dev *dev,uint16_t queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info) { +struct i40e_rx_queue *rxq; +struct i40e_adapter *ad = +I40E_DEV_PRIVATE_TO_ADAPTER (dev->data->dev_private); + + rxq = dev->data->rx_queues[queue_id]; + + recycle_rxq_info->mbuf_ring = (void *)rxq->sw_ring; + recycle_rxq_info->mp = rxq->mp; + recycle_rxq_info->mbuf_ring_size = rxq->nb_rx_desc; + recycle_rxq_info->receive_tail = &rxq->rx_tail; + +if (ad->rx_vec_allowed) { + recycle_rxq_info->refill_requirement =RTE_I40E_RXQ_REARM_THRESH ; + recycle_rxq_info->refill_head = &rxq->rxrearm_start; + }else { + recycle_rxq_info->refill_requirement = rxq->rx_free_thresh; + recycle_rxq_info->refill_head = &rxq->rx_free_trigger; + } +} +#ifdef RTE_ARCH_X86 static inline bool get_avx_supported (bool request_avx512)@@ -3293,6 +3317,8 @@ i40e_set_rx_function(struct rte_eth_dev *dev) dev->rx_pkt_burst = ad->rx_use_avx2 ? i40e_recv_scattered_pkts_vec_avx2 : i40e_recv_scattered_pkts_vec; + dev->recycle_rx_descriptors_refill = + i40e_recycle_rx_descriptors_refill_vec; } }else {if (ad->rx_use_avx512) {@@ -3311,9 +3337,12 @@ i40e_set_rx_function(struct rte_eth_dev *dev) dev->rx_pkt_burst = ad->rx_use_avx2 ? i40e_recv_pkts_vec_avx2 : i40e_recv_pkts_vec; + dev->recycle_rx_descriptors_refill = + i40e_recycle_rx_descriptors_refill_vec; } }#else /* RTE_ARCH_X86 */ + dev->recycle_rx_descriptors_refill = +i40e_recycle_rx_descriptors_refill_vec; if (dev->data->scattered_rx) { PMD_INIT_LOG(DEBUG, "Using Vector Scattered Rx (port %d).", @@ -3481,15 +3510,18 @@ i40e_set_tx_function(struct rte_eth_dev *dev) dev->tx_pkt_burst = ad->tx_use_avx2 ? i40e_xmit_pkts_vec_avx2 : i40e_xmit_pkts_vec; + dev->recycle_tx_mbufs_reuse =
i40e_recycle_tx_mbufs_reuse_vec;drivers/net/i40e/i40e_rxtx.c +1
-0}#else /* RTE_ARCH_X86 */ PMD_INIT_LOG (DEBUG ,"Using Vector Tx (port %d)." , dev->data->port_id); dev->tx_pkt_burst = i40e_xmit_pkts_vec; + dev->recycle_tx_mbufs_reuse =
i40e_recycle_tx_mbufs_reuse_vec;
#endif /*RTE_ARCH_X86*/drivers/net/i40e/i40e_rxtx.c +1
-0}else {PMD_INIT_LOG (DEBUG ,"Simple tx finally be used." ); dev->tx_pkt_burst = i40e_xmit_pkts_simple; + dev->recycle_tx_mbufs_reuse =
i40e_recycle_tx_mbufs_reuse_vec;drivers/net/i40e/i40e_rxtx.c +0
-0} dev->tx_pkt_prepare = i40e_simple_prep_pkts; }else {drivers/net/i40e/i40e_rxtx.h index renamed from drivers/net/i40e/i40e_rxtx.h +0
-0
a8686224e5..b191f23e1f100644drivers/net/i40e/i40e_rxtx.h +5
-0@@ -236,6 +236,10 @@ uint32_t i40e_dev_rx_queue_count(void *rx_queue); int i40e_dev_rx_descriptor_status(void *rx_queue, uint16_t offset);int i40e_dev_tx_descriptor_status (void *tx_queue,uint16_t offset); +uint16_t i40e_recycle_tx_mbufs_reuse_vec (void *tx_queue, +struct rte_eth_recycle_rxq_info *recycle_rxq_info);void +i40e_recycle_rx_descriptors_refill_vec (void *rx_queue,uint16_t +nb_mbufs); +uint16_t i40e_recv_pkts_vec (void *rx_queue,struct rte_mbuf **rx_pkts,uint16_t nb_pkts); uint16_t i40e_recv_scattered_pkts_vec(void *rx_queue, diff --gita/drivers/net/i40e/meson.build b/drivers/net/i40e/meson.build index
8e53b87a65..3b1a233c84100644drivers/net/i40e/meson.build +1
-1@@ -34,6 +34,7 @@ sources = files( 'i40e_tm.c', 'i40e_hash.c', 'i40e_vf_representor.c', + 'i40e_recycle_mbufs_vec_common.c', 'rte_pmd_i40e.c', ) --2.25.1
Re: [PATCH v11 2/4] net/i40e: implement mbufs recycle mode
31/08/2023 18:24, Konstantin Ananyev пишет:
Quoted 215 lines
Quoted 190 lines
Quoted 172 lines
Define specific function implementation for i40e driver. Currently, mbufs recycle mode can support 128bit vector path and avx2 path. And can be enabled both in fast free and no fast free mode.
Suggested-by Honnappa Nagarahalli <[email protected]>Signed-off-by Feifei Wang <[email protected]>Reviewed-by Ruifeng Wang <[email protected]>Reviewed-by Honnappa Nagarahalli <[email protected]>--- drivers/net/i40e/i40e_ethdev.c | 1 + drivers/net/i40e/i40e_ethdev.h | 2 + .../net/i40e/i40e_recycle_mbufs_vec_common.c | 147 ++++++++++++++++++ drivers/net/i40e/i40e_rxtx.c | 32 ++++ drivers/net/i40e/i40e_rxtx.h | 4 + drivers/net/i40e/meson.build | 1 + 6 files changed, 187 insertions(+)create mode 100644
drivers/net/i40e/i40e_recycle_mbufs_vec_common.cdrivers/net/i40e/i40e_ethdev.c +1
-0@@ -496,6 +496,7 @@ static const struct eth_dev_ops i40e_eth_dev_ops = { .flow_ops_get = i40e_dev_flow_ops_get, .rxq_info_get = i40e_rxq_info_get, .txq_info_get = i40e_txq_info_get, + .recycle_rxq_info_get = i40e_recycle_rxq_info_get, .rx_burst_mode_get = i40e_rx_burst_mode_get, .tx_burst_mode_get = i40e_tx_burst_mode_get, .timesync_enable = i40e_timesync_enable,drivers/net/i40e/i40e_ethdev.h +2
-0@@ -1355,6 +1355,8 @@ void i40e_rxq_info_get(struct rte_eth_dev *dev,uint16_t queue_id, struct rte_eth_rxq_info *qinfo);void i40e_txq_info_get (struct rte_eth_dev *dev,uint16_t queue_id,struct rte_eth_txq_info *qinfo); +void i40e_recycle_rxq_info_get (struct rte_eth_dev *dev,uint16_t queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info);int i40e_rx_burst_mode_get (struct rte_eth_dev *dev,uint16_t queue_id,struct rte_eth_burst_mode *mode);int i40e_tx_burst_mode_get(struct
rte_eth_dev*dev,uint16_tqueue_id, diff -- gita/drivers/net/i40e/i40e_recycle_mbufs_vec_common.cb/drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
new file mode 100644
index 0000000000..5663ecccdedrivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +31
-0@@ -0,0 +1,147 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2023 Arm Limited. +*/ + +#include <stdint.h> +#include <ethdev_driver.h> + +#include "base/i40e_prototype.h" +#include "base/i40e_type.h" +#include "i40e_ethdev.h" +#include "i40e_rxtx.h" + +#pragma GCC diagnostic ignored "-Wcast-qual" + +void +i40e_recycle_rx_descriptors_refill_vec (void *rx_queue,uint16_t +nb_mbufs) { +struct i40e_rx_queue *rxq = rx_queue; +struct i40e_rx_entry *rxep; +volatile union i40e_rx_desc *rxdp; +uint16_t rx_id; +uint64_t paddr; +uint64_t dma_addr; +uint16_t i; + + rxdp = rxq->rx_ring + rxq->rxrearm_start; + rxep = &rxq->sw_ring[rxq->rxrearm_start]; + +for (i =0 ; i < nb_mbufs; i++) { +/* Initialize rxdp descs. */ + paddr = (rxep[i].mbuf)->buf_iova +
RTE_PKTMBUF_HEADROOM;drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +46
-0+ dma_addr =rte_cpu_to_le_64 (paddr); +/* flush desc with pa dma_addr */ + rxdp[i].read.hdr_addr =0 ; + rxdp[i].read.pkt_addr = dma_addr; + } + +/* Update the descriptor initializer index */ + rxq->rxrearm_start += nb_mbufs; + rx_id = rxq->rxrearm_start -1 ; + +if (unlikely (rxq->rxrearm_start >= rxq->nb_rx_desc)) { + rxq->rxrearm_start =0 ; + rx_id = rxq->nb_rx_desc -1 ; + } + + rxq->rxrearm_nb -= nb_mbufs; + +rte_io_wmb (); +/* Update the tail pointer on the NIC */ +I40E_PCI_REG_WRITE_RELAXED (rxq->qrx_tail, rx_id); } + +uint16_t +i40e_recycle_tx_mbufs_reuse_vec (void *tx_queue, +struct rte_eth_recycle_rxq_info *recycle_rxq_info) { +struct i40e_tx_queue *txq = tx_queue; +struct i40e_tx_entry *txep; +struct rte_mbuf **rxep; +int i, n; +uint16_t nb_recycle_mbufs; +uint16_t avail =0 ; +uint16_t mbuf_ring_size = recycle_rxq_info->mbuf_ring_size; +uint16_t mask = recycle_rxq_info->mbuf_ring_size -1 ; +uint16_t refill_requirement = recycle_rxq_info->refill_requirement; +uint16_t refill_head = *recycle_rxq_info->refill_head; +uint16_t receive_tail = *recycle_rxq_info->receive_tail; + +/* Get available recycling Rx buffers. */ + avail = (mbuf_ring_size - (refill_head - receive_tail)) & mask; + +/* Check Tx free thresh and Rx available space. */ +if (txq->nb_tx_free > txq->tx_free_thresh || avail <= txq->tx_rs_thresh) +return 0 ; + +/* check DD bits on threshold descriptor */ + if ((txq->tx_ring[txq->tx_next_dd].cmd_type_offset_bsz & +rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) != + rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE))drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +6
-0+return 0 ; + + n = txq->tx_rs_thresh; + nb_recycle_mbufs = n; + +/* Mbufs recycle mode can only support no ring buffer wrapping around.
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +29
-0+* Two case for this: +* +* case 1: The refill head of Rx buffer ring needs to be aligned with +* mbuf ring size. In this case, the number of Tx freeing buffers +* should be equal to refill_requirement. +* +* case 2: The refill head of Rx ring buffer does not need to be aligned +* with mbuf ring size. In this case, the update of refill head can not +* exceed the Rx mbuf ring size. +*/ +if (refill_requirement != n || + (!refill_requirement && (refill_head + n > mbuf_ring_size))) +return 0 ; + +/* First buffer to free from S/W ring is at index +* tx_next_dd - (tx_rs_thresh-1). +*/ + txep = &txq->sw_ring[txq->tx_next_dd - (n -1 )]; + rxep = recycle_rxq_info->mbuf_ring; + rxep += refill_head; + +if (txq->offloads &RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE ) { +/* Avoid txq contains buffers from unexpected mempool. */ +if (unlikely (recycle_rxq_info->mp + != txep[0 ].mbuf->pool)) +return 0 ; + +/* Directly put mbufs from Tx to Rx. */ +for (i =0 ; i < n; i++)drivers/net/i40e/i40e_recycle_mbufs_vec_common.c line 125
Quoted 10 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +10
-0+ rxep[i] = txep[i].mbuf; + }else { +for (i =0 ; i < n; i++) { + rxep[i] =rte_pktmbuf_prefree_seg (txep[i].mbuf); + +/* If Tx buffers are not the last reference or from +* unexpected mempool, previous copied buffers are +* considered as invalid. +*/ + if (unlikely((rxep[i] == NULL && refill_requirement) ||[Konstantin]
Could you pls remind me why it is ok to have rxep[i]==NULL whenrefill_requirementis not set?If
reill_requirementis not zero, it means each tx freed buffer must be valid and can be put into Rxsw_ring. Then the refill head of Rx buffer ring can be aligned with mbuf ring size. Briefly speaking the number of Tx valid freed buffer must be equal to Rxrefill_requirement. For example, i40e driver.Quoted 7 lines
If
reill_requirementis zero, it means that the refill head of Rx buffer ring does not need to be aligned with mbuf ring size, thus if Tx have n valid freed buffers, we just need to put these n buffers into Rx sw-ring, and not to be equal to the Rx setting rearm number. For example, mlx5 driver.In conclusion, above difference is due to pmd drivers have different strategies to update their Rx rearm(refill) head. For i40e driver, if
rearm_headexceed 1024, it will be set as 0 due to the number of each rearm is a fixed value by default. For mlx5 driver. Itsrearm_headcan exceed 1024, and use mask to achieve real index. Thus its rearm number can be a different value.Ok, but if
rte_pktmbuf_prefree_seg(txep[i].mbuf), it means that this mbuf is not free yet and can't be reused. Shouldn't we then setnb_recycle_mbufs= 0 in that case too?
Or probably would be enough to skip that mbuf?
Might be something like that:for (i = 0, j = 0; i < n; i++) {
rxep[j] = rte_pktmbuf_prefree_seg(txep[i].mbuf); if (rxep[j] == NULL || recycle_rxq_info->mp != rxep[j].mbuf->pool)) { if (refill_requirement) { nb_recycle_mbufs = 0; break; } } else j++; }
Quoted 3 lines
/* now j contains actual number of recycled mbufs */
?
After another thought, it might be easier and cleaner just to:
if (rxep[j] == NULL || recycle_rxq_info->mp != rxep[j].mbuf->pool)
nb_recycle_mbufs = 0;
Anyway, from my understanding - if rte_pktmbuf_prefree_seg(mbuf) returns NULL, then we can't recycle that mbuf.
Quoted 138 lines
Quoted 137 lines
Quoted 137 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +1
-0+ recycle_rxq_info->mp != txep[i].mbuf-Quoted 1 line
pool))
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +10
-0+ nb_recycle_mbufs =0 ; + } +/* If Tx buffers are not the last reference or +* from unexpected mempool, all recycled buffers +* are put into mempool. +*/ +if (nb_recycle_mbufs ==0 ) +for (i =0 ; i < n; i++) { +if (rxep[i] !=NULL ) + rte_mempool_put(rxep[i]->pool,rxep[i]);
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +11
-0+ } + } + +/* Update counters for Tx. */ + txq->nb_tx_free = (uint16_t )(txq->nb_tx_free + txq->tx_rs_thresh); + txq->tx_next_dd = (uint16_t )(txq->tx_next_dd + txq->tx_rs_thresh); +if (txq->tx_next_dd >= txq->nb_tx_desc) + txq->tx_next_dd = (uint16_t )(txq->tx_rs_thresh -1 ); + +return nb_recycle_mbufs; +}drivers/net/i40e/i40e_rxtx.c index renamed from drivers/net/i40e/i40e_rxtx.c +0
-0
b4f65b58fa..a9c9eb331c100644drivers/net/i40e/i40e_rxtx.c +30
-1@@ -3199,6 +3199,30 @@ i40e_txq_info_get(struct rte_eth_dev *dev,uint16_t queue_id, qinfo->conf.offloads = txq->offloads; } +void +i40e_recycle_rxq_info_get (struct rte_eth_dev *dev,uint16_t queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info) { +struct i40e_rx_queue *rxq; +struct i40e_adapter *ad = +I40E_DEV_PRIVATE_TO_ADAPTER (dev->data->dev_private); + + rxq = dev->data->rx_queues[queue_id]; + + recycle_rxq_info->mbuf_ring = (void *)rxq->sw_ring; + recycle_rxq_info->mp = rxq->mp; + recycle_rxq_info->mbuf_ring_size = rxq->nb_rx_desc; + recycle_rxq_info->receive_tail = &rxq->rx_tail; + +if (ad->rx_vec_allowed) { + recycle_rxq_info->refill_requirement =RTE_I40E_RXQ_REARM_THRESH ; + recycle_rxq_info->refill_head = &rxq->rxrearm_start; + }else { + recycle_rxq_info->refill_requirement = rxq->rx_free_thresh; + recycle_rxq_info->refill_head = &rxq->rx_free_trigger; + } +} +#ifdef RTE_ARCH_X86 static inline bool get_avx_supported (bool request_avx512)@@ -3293,6 +3317,8 @@ i40e_set_rx_function(struct rte_eth_dev *dev) dev->rx_pkt_burst = ad->rx_use_avx2 ? i40e_recv_scattered_pkts_vec_avx2 : i40e_recv_scattered_pkts_vec; + dev->recycle_rx_descriptors_refill = + i40e_recycle_rx_descriptors_refill_vec; } }else {if (ad->rx_use_avx512) {@@ -3311,9 +3337,12 @@ i40e_set_rx_function(struct rte_eth_dev *dev) dev->rx_pkt_burst = ad->rx_use_avx2 ? i40e_recv_pkts_vec_avx2 : i40e_recv_pkts_vec; + dev->recycle_rx_descriptors_refill = + i40e_recycle_rx_descriptors_refill_vec; } }#else /* RTE_ARCH_X86 */ + dev->recycle_rx_descriptors_refill = +i40e_recycle_rx_descriptors_refill_vec; if (dev->data->scattered_rx) { PMD_INIT_LOG(DEBUG, "Using Vector Scattered Rx (port %d).", @@ -3481,15 +3510,18 @@ i40e_set_tx_function(struct rte_eth_dev *dev) dev->tx_pkt_burst = ad->tx_use_avx2 ? i40e_xmit_pkts_vec_avx2 : i40e_xmit_pkts_vec; + dev->recycle_tx_mbufs_reuse =
i40e_recycle_tx_mbufs_reuse_vec;
}
#else /*RTE_ARCH_X86*/
PMD_INIT_LOG(DEBUG, "Using Vector Tx (port %d).",
dev->data->port_id);
dev->tx_pkt_burst=i40e_xmit_pkts_vec;drivers/net/i40e/i40e_rxtx.c +1
-0+ dev->recycle_tx_mbufs_reuse =
i40e_recycle_tx_mbufs_reuse_vec;
#endif /*RTE_ARCH_X86*/
} else {
PMD_INIT_LOG(DEBUG, "Simple tx finally be used.");dev->tx_pkt_burst=i40e_xmit_pkts_simple;drivers/net/i40e/i40e_rxtx.c +1
-0+ dev->recycle_tx_mbufs_reuse =
i40e_recycle_tx_mbufs_reuse_vec;
}
dev->tx_pkt_prepare=i40e_simple_prep_pkts;
} else {drivers/net/i40e/i40e_rxtx.h index renamed from drivers/net/i40e/i40e_rxtx.h +0
-0
a8686224e5..b191f23e1f100644drivers/net/i40e/i40e_rxtx.h +5
-0@@ -236,6 +236,10 @@ uint32_t i40e_dev_rx_queue_count(void *rx_queue); int i40e_dev_rx_descriptor_status(void *rx_queue, uint16_t offset);int i40e_dev_tx_descriptor_status (void *tx_queue,uint16_t offset); +uint16_t i40e_recycle_tx_mbufs_reuse_vec (void *tx_queue, +struct rte_eth_recycle_rxq_info *recycle_rxq_info);void +i40e_recycle_rx_descriptors_refill_vec (void *rx_queue,uint16_t +nb_mbufs); +uint16_t i40e_recv_pkts_vec (void *rx_queue,struct rte_mbuf **rx_pkts,uint16_t nb_pkts); uint16_t i40e_recv_scattered_pkts_vec(void *rx_queue, diff --gita/drivers/net/i40e/meson.build b/drivers/net/i40e/meson.build index
8e53b87a65..3b1a233c84100644drivers/net/i40e/meson.build +1
-1@@ -34,6 +34,7 @@ sources = files( 'i40e_tm.c', 'i40e_hash.c', 'i40e_vf_representor.c', + 'i40e_recycle_mbufs_vec_common.c', 'rte_pmd_i40e.c', ) --2.25.1
RE: [PATCH v11 2/4] net/i40e: implement mbufs recycle mode
In reply to Konstantin AnanyevQuoted 246 lines
-----Original Message-----
From: Konstantin Ananyev <[email protected]>
Sent: Friday, September 1, 2023 1:25 AM
To: Feifei Wang <[email protected]>; Konstantin Ananyev <[email protected]>
Cc: [email protected]; nd <[email protected]>; Honnappa Nagarahalli <[email protected]>; Ruifeng Wang <[email protected]>; Yuying Zhang <[email protected]>; Beilei Xing <[email protected]>; nd <[email protected]>
Subject: RE: [PATCH v11 2/4] net/i40e: implement mbufs recycle modeQuoted 3 lines
Quoted 3 lines
Define specific function implementation for i40e driver. Currently, mbufs recycle mode can support 128bit vector path and avx2
path.
Quoted 17 lines
Quoted 17 lines
And can be enabled both in fast free and no fast free mode.
Suggested-by Honnappa Nagarahalli <[email protected]>Signed-off-by Feifei Wang <[email protected]>Reviewed-by Ruifeng Wang <[email protected]>Reviewed-by Honnappa Nagarahalli <[email protected]>--- drivers/net/i40e/i40e_ethdev.c | 1 + drivers/net/i40e/i40e_ethdev.h | 2 + .../net/i40e/i40e_recycle_mbufs_vec_common.c | 147 ++++++++++++++++++ drivers/net/i40e/i40e_rxtx.c | 32 ++++ drivers/net/i40e/i40e_rxtx.h | 4 + drivers/net/i40e/meson.build | 1 + 6 files changed, 187 insertions(+) create mode 100644 drivers/net/i40e/i40e_recycle_mbufs_vec_common.cQuoted 5 lines
drivers/net/i40e/i40e_ethdev.c static const struct eth_dev_ops i40e_eth_dev_ops
Quoted 5 lines
(quoted diff) +0
-0
b/drivers/net/i40e/i40e_ethdev.cindex8271bbb394..50ba9aac94100644drivers/net/i40e/i40e_ethdev.c +0
-0@@ -496,6 +496,7 @@ static const struct eth_dev_ops i40e_eth_dev_ops= {
Quoted 9 lines
Quoted 9 lines
drivers/net/i40e/i40e_ethdev.c +1
-0.flow_ops_get = i40e_dev_flow_ops_get, .rxq_info_get = i40e_rxq_info_get, .txq_info_get = i40e_txq_info_get, + .recycle_rxq_info_get = i40e_recycle_rxq_info_get, .rx_burst_mode_get = i40e_rx_burst_mode_get, .tx_burst_mode_get = i40e_tx_burst_mode_get, .timesync_enable = i40e_timesync_enable,(quoted diff) +0
-0
b/drivers/net/i40e/i40e_ethdev.hindex6f65d5e0ac..af758798e1100644Quoted 8 lines
drivers/net/i40e/i40e_ethdev.h void i40e_rxq_info_get(struct rte_eth_dev · line 1359
Quoted 8 lines
drivers/net/i40e/i40e_ethdev.h +1
-0@@ -1355,6 +1355,8 @@ void i40e_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, struct rte_eth_rxq_info *qinfo);void i40e_txq_info_get (struct rte_eth_dev *dev,uint16_t queue_id,struct rte_eth_txq_info *qinfo); +void i40e_recycle_rxq_info_get(struct rte_eth_dev *dev, uint16_t
queue_id,Quoted 142 lines
Quoted 128 lines
drivers/net/i40e/i40e_ethdev.h +1
-0+ struct rte_eth_recycle_rxq_info *recycle_rxq_info);int i40e_rx_burst_mode_get (struct rte_eth_dev *dev,uint16_t queue_id,struct rte_eth_burst_mode *mode);int i40e_tx_burst_mode_get(struct
rte_eth_dev*dev,uint16_tqueue_id, diff -- gita/drivers/net/i40e/i40e_recycle_mbufs_vec_common.cb/drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
new file mode 100644
index 0000000000..5663ecccdedrivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +31
-0@@ -0,0 +1,147 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2023 Arm Limited. +*/ + +#include <stdint.h> +#include <ethdev_driver.h> + +#include "base/i40e_prototype.h" +#include "base/i40e_type.h" +#include "i40e_ethdev.h" +#include "i40e_rxtx.h" + +#pragma GCC diagnostic ignored "-Wcast-qual" + +void +i40e_recycle_rx_descriptors_refill_vec (void *rx_queue,uint16_t +nb_mbufs) { +struct i40e_rx_queue *rxq = rx_queue; +struct i40e_rx_entry *rxep; +volatile union i40e_rx_desc *rxdp; +uint16_t rx_id; +uint64_t paddr; +uint64_t dma_addr; +uint16_t i; + + rxdp = rxq->rx_ring + rxq->rxrearm_start; + rxep = &rxq->sw_ring[rxq->rxrearm_start]; + +for (i =0 ; i < nb_mbufs; i++) { +/* Initialize rxdp descs. */ + paddr = (rxep[i].mbuf)->buf_iova +
RTE_PKTMBUF_HEADROOM;drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +46
-0+ dma_addr =rte_cpu_to_le_64 (paddr); +/* flush desc with pa dma_addr */ + rxdp[i].read.hdr_addr =0 ; + rxdp[i].read.pkt_addr = dma_addr; + } + +/* Update the descriptor initializer index */ + rxq->rxrearm_start += nb_mbufs; + rx_id = rxq->rxrearm_start -1 ; + +if (unlikely (rxq->rxrearm_start >= rxq->nb_rx_desc)) { + rxq->rxrearm_start =0 ; + rx_id = rxq->nb_rx_desc -1 ; + } + + rxq->rxrearm_nb -= nb_mbufs; + +rte_io_wmb (); +/* Update the tail pointer on the NIC */ +I40E_PCI_REG_WRITE_RELAXED (rxq->qrx_tail, rx_id); } + +uint16_t +i40e_recycle_tx_mbufs_reuse_vec (void *tx_queue, +struct rte_eth_recycle_rxq_info *recycle_rxq_info) { +struct i40e_tx_queue *txq = tx_queue; +struct i40e_tx_entry *txep; +struct rte_mbuf **rxep; +int i, n; +uint16_t nb_recycle_mbufs; +uint16_t avail =0 ; +uint16_t mbuf_ring_size = recycle_rxq_info->mbuf_ring_size; +uint16_t mask = recycle_rxq_info->mbuf_ring_size -1 ; +uint16_t refill_requirement = recycle_rxq_info->refill_requirement; +uint16_t refill_head = *recycle_rxq_info->refill_head; +uint16_t receive_tail = *recycle_rxq_info->receive_tail; + +/* Get available recycling Rx buffers. */ + avail = (mbuf_ring_size - (refill_head - receive_tail)) & mask; + +/* Check Tx free thresh and Rx available space. */ +if (txq->nb_tx_free > txq->tx_free_thresh || avail <= txq->tx_rs_thresh) +return 0 ; + +/* check DD bits on threshold descriptor */ + if ((txq->tx_ring[txq->tx_next_dd].cmd_type_offset_bsz & +rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) != + rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE))drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +6
-0+return 0 ; + + n = txq->tx_rs_thresh; + nb_recycle_mbufs = n; + +/* Mbufs recycle mode can only support no ring buffer wrapping around.
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +29
-0+* Two case for this: +* +* case 1: The refill head of Rx buffer ring needs to be aligned with +* mbuf ring size. In this case, the number of Tx freeing buffers +* should be equal to refill_requirement. +* +* case 2: The refill head of Rx ring buffer does not need to be aligned +* with mbuf ring size. In this case, the update of refill head can not +* exceed the Rx mbuf ring size. +*/ +if (refill_requirement != n || + (!refill_requirement && (refill_head + n > mbuf_ring_size))) +return 0 ; + +/* First buffer to free from S/W ring is at index +* tx_next_dd - (tx_rs_thresh-1). +*/ + txep = &txq->sw_ring[txq->tx_next_dd - (n -1 )]; + rxep = recycle_rxq_info->mbuf_ring; + rxep += refill_head; + +if (txq->offloads &RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE ) { +/* Avoid txq contains buffers from unexpected mempool. */ +if (unlikely (recycle_rxq_info->mp + != txep[0 ].mbuf->pool)) +return 0 ; + +/* Directly put mbufs from Tx to Rx. */ +for (i =0 ; i < n; i++)drivers/net/i40e/i40e_recycle_mbufs_vec_common.c line 125
Quoted 10 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +10
-0+ rxep[i] = txep[i].mbuf; + }else { +for (i =0 ; i < n; i++) { + rxep[i] =rte_pktmbuf_prefree_seg (txep[i].mbuf); + +/* If Tx buffers are not the last reference or from +* unexpected mempool, previous copied buffers are +* considered as invalid. +*/ + if (unlikely((rxep[i] == NULL && refill_requirement) ||[Konstantin]
Could you pls remind me why it is ok to have rxep[i]==NULL whenrefill_requirementis not set?Quoted 3 lines
If
reill_requirementis not zero, it means each tx freed buffer must be valid and can be put into Rxsw_ring. Then the refill head of Rx buffer ring can be aligned with mbuf ring size. Briefly speaking the numberof Tx valid freed buffer must be equal to Rx
refill_requirement. For example, i40e driver.Quoted 4 lines
If
reill_requirementis zero, it means that the refill head of Rx buffer ring does not need to be aligned with mbuf ring size, thus if Tx have n valid freed buffers, we just need to put these n buffers into Rx sw-ring, and not to be equal to the Rx setting rearm number. For example, mlx5 driver.
Quoted 2 lines
In conclusion, above difference is due to pmd drivers have different
strategies to update their Rx rearm(refill) head.
Quoted 1 line
For i40e driver, if
rearm_headexceed 1024, it will be set as 0 due to thenumber of each rearm is a fixed value by default.
Quoted 1 line
For mlx5 driver. Its
rearm_headcan exceed 1024, and use mask to achievereal index. Thus its rearm number can be a different value.
Ok, but if
rte_pktmbuf_prefree_seg(txep[i].mbuf), it means that this mbuf is not free yet and can't be reused.
Shouldn't we then setnb_recycle_mbufs= 0 in that case too?
Or probably would be enough to skip that mbuf?
Might be something like that:for (i = 0, j = 0; i < n; i++) {
rxep[j] = rte_pktmbuf_prefree_seg(txep[i].mbuf); if (rxep[j] == NULL || recycle_rxq_info->mp != rxep[j].mbuf->pool)) { if (refill_requirement) { nb_recycle_mbufs = 0; break; } } else j++; }/* now j contains actual number of recycled mbufs */
?
Quoted 3 lines
Quoted 3 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +1
-0+ recycle_rxq_info->mp != txep[i].mbuf-Quoted 1 line
pool))
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +6
-0+ nb_recycle_mbufs =0 ; + } +/* If Tx buffers are not the last reference or +* from unexpected mempool, all recycled buffers +* are put into mempool. +*/ Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c line 46
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +4
-0+if (nb_recycle_mbufs ==0 ) +for (i =0 ; i < n; i++) { +if (rxep[i] !=NULL ) + rte_mempool_put(rxep[i]->pool,rxep[i]);
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +3
-0+ } + } +
[Konstantin] After another thought, it might be easier and cleaner just to:
if (rxep[j] == NULL || recycle_rxq_info->mp != rxep[j].mbuf->pool)
nb_recycle_mbufs = 0;
Anyway, from my understanding - if rte_pktmbuf_prefree_seg(mbuf) returns NULL, then we can't recycle that mbuf.
[Feifei] Agree with that 'rte_pktmbuf_prefree_seg(mbuf) returns NULL, then we can't recycle that mbuf'.
Firstly, we should know for i40e driver, the number of free mbufs is fixed, it must equal to 'tx_rs_thresh' This means if we start to free Tx mbufs, it cannot be interrupted until the given amount of mbufs are freed. In the meanwhile, doing prefree operation for a Tx mbuf can be looked at this mbuf is freed from this TX sw-ring
if the API returns NULL. This is due to that call 'prefree_seg' function means update the mbuf refcnt.
So let's come back our recycle mbuf case.
Here we consider that the case if we have 32 mbufs need to be freed, and we firstly do the pre-free. And then first 8 mbufs is good and return value is not none. But the 9th mbuf is bad, its refcnt is more than 1. So we just update its refcnt and cannot put it into Rx sw-ring. For Tx sw-ring, this mbuf has been freed. Then we should continue to do pre-free operation for the next Tx mbufs to ensure the given amount of mbufs are freed.
Do a conclusion for this, this is because if we start to do pre-free operation, the Tx mbuf refcnt value maybe changed, so we cannot stop or break until finish all the pre-free operation.
Finally, in the case that Rx refill_request is not zero, but the valid mbuf amount is less than this value, we must put back this Tx mbufs into mempool.
Above is the reason why I do not directly jump out of the loop if some mbuf return value is NULL.
Quoted 119 lines
Quoted 119 lines
Quoted 119 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +8
-0+/* Update counters for Tx. */ + txq->nb_tx_free = (uint16_t )(txq->nb_tx_free + txq->tx_rs_thresh); + txq->tx_next_dd = (uint16_t )(txq->tx_next_dd + txq->tx_rs_thresh); +if (txq->tx_next_dd >= txq->nb_tx_desc) + txq->tx_next_dd = (uint16_t )(txq->tx_rs_thresh -1 ); + +return nb_recycle_mbufs; +}(quoted diff) +0
-0
b/drivers/net/i40e/i40e_rxtx.cindexb4f65b58fa..a9c9eb331c100644drivers/net/i40e/i40e_rxtx.c +23
-0@@ -3199,6 +3199,30 @@ i40e_txq_info_get(struct rte_eth_dev *dev,uint16_t queue_id, qinfo->conf.offloads = txq->offloads; } +void +i40e_recycle_rxq_info_get (struct rte_eth_dev *dev,uint16_t queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info) { +struct i40e_rx_queue *rxq; +struct i40e_adapter *ad = +I40E_DEV_PRIVATE_TO_ADAPTER (dev->data->dev_private); + + rxq = dev->data->rx_queues[queue_id]; + + recycle_rxq_info->mbuf_ring = (void *)rxq->sw_ring; + recycle_rxq_info->mp = rxq->mp; + recycle_rxq_info->mbuf_ring_size = rxq->nb_rx_desc; + recycle_rxq_info->receive_tail = &rxq->rx_tail; + +if (ad->rx_vec_allowed) { + recycle_rxq_info->refill_requirement =RTE_I40E_RXQ_REARM_THRESH ; + recycle_rxq_info->refill_head = &rxq->rxrearm_start; + }else { + recycle_rxq_info->refill_requirement = rxq->rx_free_thresh; + recycle_rxq_info->refill_head = &rxq->rx_free_trigger; + } +} +#ifdef RTE_ARCH_X86 static inline bool get_avx_supported(bool request_avx512) @@ -3293,6 +3317,8 @@
i40e_set_rx_function(struct rte_eth_dev *dev)drivers/net/i40e/i40e_rxtx.c +7
-1dev->rx_pkt_burst = ad->rx_use_avx2 ? i40e_recv_scattered_pkts_vec_avx2 : i40e_recv_scattered_pkts_vec; + dev->recycle_rx_descriptors_refill = + i40e_recycle_rx_descriptors_refill_vec; } }else {if (ad->rx_use_avx512) {@@ -3311,9 +3337,12 @@ i40e_set_rx_function(struct rte_eth_dev *dev) dev->rx_pkt_burst = ad->rx_use_avx2 ? i40e_recv_pkts_vec_avx2 : i40e_recv_pkts_vec; + dev->recycle_rx_descriptors_refill = + i40e_recycle_rx_descriptors_refill_vec; } }#else /* RTE_ARCH_X86 */ + dev->recycle_rx_descriptors_refill = +i40e_recycle_rx_descriptors_refill_vec; if (dev->data->scattered_rx) { PMD_INIT_LOG(DEBUG, "Using Vector Scattered Rx (port %d).", @@ -3481,15 +3510,18 @@ i40e_set_tx_function(struct rte_eth_dev *dev) dev->tx_pkt_burst = ad->tx_use_avx2 ? i40e_xmit_pkts_vec_avx2 : i40e_xmit_pkts_vec; + dev->recycle_tx_mbufs_reuse =
i40e_recycle_tx_mbufs_reuse_vec;drivers/net/i40e/i40e_rxtx.c +1
-0}#else /* RTE_ARCH_X86 */ PMD_INIT_LOG (DEBUG ,"Using Vector Tx (port %d)." , dev->data->port_id); dev->tx_pkt_burst = i40e_xmit_pkts_vec; + dev->recycle_tx_mbufs_reuse =
i40e_recycle_tx_mbufs_reuse_vec;
#endif /*RTE_ARCH_X86*/drivers/net/i40e/i40e_rxtx.c +1
-0}else {PMD_INIT_LOG (DEBUG ,"Simple tx finally be used." ); dev->tx_pkt_burst = i40e_xmit_pkts_simple; + dev->recycle_tx_mbufs_reuse =
i40e_recycle_tx_mbufs_reuse_vec;drivers/net/i40e/i40e_rxtx.c +0
-0} dev->tx_pkt_prepare = i40e_simple_prep_pkts; }else {(quoted diff) +0
-0
b/drivers/net/i40e/i40e_rxtx.hindexa8686224e5..b191f23e1f100644drivers/net/i40e/i40e_rxtx.h +5
-0@@ -236,6 +236,10 @@ uint32_t i40e_dev_rx_queue_count(void *rx_queue); int i40e_dev_rx_descriptor_status(void *rx_queue,uint16_t offset);int i40e_dev_tx_descriptor_status (void *tx_queue,uint16_t offset); +uint16_t i40e_recycle_tx_mbufs_reuse_vec (void *tx_queue, +struct rte_eth_recycle_rxq_info *recycle_rxq_info);void +i40e_recycle_rx_descriptors_refill_vec (void *rx_queue,uint16_t +nb_mbufs); +uint16_t i40e_recv_pkts_vec (void *rx_queue,struct rte_mbuf **rx_pkts,uint16_t nb_pkts); uint16_t i40e_recv_scattered_pkts_vec(void *rx_queue, diff --gita/drivers/net/i40e/meson.build b/drivers/net/i40e/meson.build index
8e53b87a65..3b1a233c84100644drivers/net/i40e/meson.build +1
-1@@ -34,6 +34,7 @@ sources = files( 'i40e_tm.c', 'i40e_hash.c', 'i40e_vf_representor.c', + 'i40e_recycle_mbufs_vec_common.c', 'rte_pmd_i40e.c', ) --2.25.1
RE: [PATCH v11 2/4] net/i40e: implement mbufs recycle mode
Quoted 268 lines
Quoted 233 lines
Quoted 5 lines
Quoted 5 lines
Define specific function implementation for i40e driver. Currently, mbufs recycle mode can support 128bit vector path and avx2
path.
Quoted 17 lines
Quoted 17 lines
And can be enabled both in fast free and no fast free mode.
Suggested-by Honnappa Nagarahalli <[email protected]>Signed-off-by Feifei Wang <[email protected]>Reviewed-by Ruifeng Wang <[email protected]>Reviewed-by Honnappa Nagarahalli <[email protected]>--- drivers/net/i40e/i40e_ethdev.c | 1 + drivers/net/i40e/i40e_ethdev.h | 2 + .../net/i40e/i40e_recycle_mbufs_vec_common.c | 147 ++++++++++++++++++ drivers/net/i40e/i40e_rxtx.c | 32 ++++ drivers/net/i40e/i40e_rxtx.h | 4 + drivers/net/i40e/meson.build | 1 + 6 files changed, 187 insertions(+) create mode 100644 drivers/net/i40e/i40e_recycle_mbufs_vec_common.cQuoted 5 lines
drivers/net/i40e/i40e_ethdev.c static const struct eth_dev_ops i40e_eth_dev_ops
Quoted 5 lines
(quoted diff) +0
-0
b/drivers/net/i40e/i40e_ethdev.cindex8271bbb394..50ba9aac94100644drivers/net/i40e/i40e_ethdev.c +0
-0@@ -496,6 +496,7 @@ static const struct eth_dev_ops i40e_eth_dev_ops= {
Quoted 9 lines
Quoted 9 lines
drivers/net/i40e/i40e_ethdev.c +1
-0.flow_ops_get = i40e_dev_flow_ops_get, .rxq_info_get = i40e_rxq_info_get, .txq_info_get = i40e_txq_info_get, + .recycle_rxq_info_get = i40e_recycle_rxq_info_get, .rx_burst_mode_get = i40e_rx_burst_mode_get, .tx_burst_mode_get = i40e_tx_burst_mode_get, .timesync_enable = i40e_timesync_enable,(quoted diff) +0
-0
b/drivers/net/i40e/i40e_ethdev.hindex6f65d5e0ac..af758798e1100644Quoted 8 lines
drivers/net/i40e/i40e_ethdev.h void i40e_rxq_info_get(struct rte_eth_dev · line 1359
Quoted 8 lines
drivers/net/i40e/i40e_ethdev.h +1
-0@@ -1355,6 +1355,8 @@ void i40e_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, struct rte_eth_rxq_info *qinfo);void i40e_txq_info_get (struct rte_eth_dev *dev,uint16_t queue_id,struct rte_eth_txq_info *qinfo); +void i40e_recycle_rxq_info_get(struct rte_eth_dev *dev, uint16_t
queue_id,Quoted 142 lines
Quoted 128 lines
drivers/net/i40e/i40e_ethdev.h +1
-0+ struct rte_eth_recycle_rxq_info *recycle_rxq_info);int i40e_rx_burst_mode_get (struct rte_eth_dev *dev,uint16_t queue_id,struct rte_eth_burst_mode *mode);int i40e_tx_burst_mode_get(struct
rte_eth_dev*dev,uint16_tqueue_id, diff -- gita/drivers/net/i40e/i40e_recycle_mbufs_vec_common.cb/drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
new file mode 100644
index 0000000000..5663ecccdedrivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +31
-0@@ -0,0 +1,147 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2023 Arm Limited. +*/ + +#include <stdint.h> +#include <ethdev_driver.h> + +#include "base/i40e_prototype.h" +#include "base/i40e_type.h" +#include "i40e_ethdev.h" +#include "i40e_rxtx.h" + +#pragma GCC diagnostic ignored "-Wcast-qual" + +void +i40e_recycle_rx_descriptors_refill_vec (void *rx_queue,uint16_t +nb_mbufs) { +struct i40e_rx_queue *rxq = rx_queue; +struct i40e_rx_entry *rxep; +volatile union i40e_rx_desc *rxdp; +uint16_t rx_id; +uint64_t paddr; +uint64_t dma_addr; +uint16_t i; + + rxdp = rxq->rx_ring + rxq->rxrearm_start; + rxep = &rxq->sw_ring[rxq->rxrearm_start]; + +for (i =0 ; i < nb_mbufs; i++) { +/* Initialize rxdp descs. */ + paddr = (rxep[i].mbuf)->buf_iova +
RTE_PKTMBUF_HEADROOM;drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +46
-0+ dma_addr =rte_cpu_to_le_64 (paddr); +/* flush desc with pa dma_addr */ + rxdp[i].read.hdr_addr =0 ; + rxdp[i].read.pkt_addr = dma_addr; + } + +/* Update the descriptor initializer index */ + rxq->rxrearm_start += nb_mbufs; + rx_id = rxq->rxrearm_start -1 ; + +if (unlikely (rxq->rxrearm_start >= rxq->nb_rx_desc)) { + rxq->rxrearm_start =0 ; + rx_id = rxq->nb_rx_desc -1 ; + } + + rxq->rxrearm_nb -= nb_mbufs; + +rte_io_wmb (); +/* Update the tail pointer on the NIC */ +I40E_PCI_REG_WRITE_RELAXED (rxq->qrx_tail, rx_id); } + +uint16_t +i40e_recycle_tx_mbufs_reuse_vec (void *tx_queue, +struct rte_eth_recycle_rxq_info *recycle_rxq_info) { +struct i40e_tx_queue *txq = tx_queue; +struct i40e_tx_entry *txep; +struct rte_mbuf **rxep; +int i, n; +uint16_t nb_recycle_mbufs; +uint16_t avail =0 ; +uint16_t mbuf_ring_size = recycle_rxq_info->mbuf_ring_size; +uint16_t mask = recycle_rxq_info->mbuf_ring_size -1 ; +uint16_t refill_requirement = recycle_rxq_info->refill_requirement; +uint16_t refill_head = *recycle_rxq_info->refill_head; +uint16_t receive_tail = *recycle_rxq_info->receive_tail; + +/* Get available recycling Rx buffers. */ + avail = (mbuf_ring_size - (refill_head - receive_tail)) & mask; + +/* Check Tx free thresh and Rx available space. */ +if (txq->nb_tx_free > txq->tx_free_thresh || avail <= txq->tx_rs_thresh) +return 0 ; + +/* check DD bits on threshold descriptor */ + if ((txq->tx_ring[txq->tx_next_dd].cmd_type_offset_bsz & +rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) != + rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE))drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +6
-0+return 0 ; + + n = txq->tx_rs_thresh; + nb_recycle_mbufs = n; + +/* Mbufs recycle mode can only support no ring buffer wrapping around.
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +29
-0+* Two case for this: +* +* case 1: The refill head of Rx buffer ring needs to be aligned with +* mbuf ring size. In this case, the number of Tx freeing buffers +* should be equal to refill_requirement. +* +* case 2: The refill head of Rx ring buffer does not need to be aligned +* with mbuf ring size. In this case, the update of refill head can not +* exceed the Rx mbuf ring size. +*/ +if (refill_requirement != n || + (!refill_requirement && (refill_head + n > mbuf_ring_size))) +return 0 ; + +/* First buffer to free from S/W ring is at index +* tx_next_dd - (tx_rs_thresh-1). +*/ + txep = &txq->sw_ring[txq->tx_next_dd - (n -1 )]; + rxep = recycle_rxq_info->mbuf_ring; + rxep += refill_head; + +if (txq->offloads &RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE ) { +/* Avoid txq contains buffers from unexpected mempool. */ +if (unlikely (recycle_rxq_info->mp + != txep[0 ].mbuf->pool)) +return 0 ; + +/* Directly put mbufs from Tx to Rx. */ +for (i =0 ; i < n; i++)drivers/net/i40e/i40e_recycle_mbufs_vec_common.c line 125
Quoted 10 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +10
-0+ rxep[i] = txep[i].mbuf; + }else { +for (i =0 ; i < n; i++) { + rxep[i] =rte_pktmbuf_prefree_seg (txep[i].mbuf); + +/* If Tx buffers are not the last reference or from +* unexpected mempool, previous copied buffers are +* considered as invalid. +*/ + if (unlikely((rxep[i] == NULL && refill_requirement) ||[Konstantin]
Could you pls remind me why it is ok to have rxep[i]==NULL whenrefill_requirementis not set?Quoted 3 lines
If
reill_requirementis not zero, it means each tx freed buffer must be valid and can be put into Rxsw_ring. Then the refill head of Rx buffer ring can be aligned with mbuf ring size. Briefly speaking the numberof Tx valid freed buffer must be equal to Rx
refill_requirement. For example, i40e driver.Quoted 4 lines
If
reill_requirementis zero, it means that the refill head of Rx buffer ring does not need to be aligned with mbuf ring size, thus if Tx have n valid freed buffers, we just need to put these n buffers into Rx sw-ring, and not to be equal to the Rx setting rearm number. For example, mlx5 driver.
Quoted 2 lines
In conclusion, above difference is due to pmd drivers have different
strategies to update their Rx rearm(refill) head.
Quoted 1 line
For i40e driver, if
rearm_headexceed 1024, it will be set as 0 due to thenumber of each rearm is a fixed value by default.
Quoted 1 line
For mlx5 driver. Its
rearm_headcan exceed 1024, and use mask to achievereal index. Thus its rearm number can be a different value.
Ok, but if
rte_pktmbuf_prefree_seg(txep[i].mbuf), it means that this mbuf is not free yet and can't be reused.
Shouldn't we then setnb_recycle_mbufs= 0 in that case too?
Or probably would be enough to skip that mbuf?
Might be something like that:for (i = 0, j = 0; i < n; i++) {
rxep[j] = rte_pktmbuf_prefree_seg(txep[i].mbuf); if (rxep[j] == NULL || recycle_rxq_info->mp != rxep[j].mbuf->pool)) { if (refill_requirement) { nb_recycle_mbufs = 0; break; } } else j++; }/* now j contains actual number of recycled mbufs */
?
Quoted 3 lines
Quoted 3 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +1
-0+ recycle_rxq_info->mp != txep[i].mbuf-Quoted 1 line
pool))
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +6
-0+ nb_recycle_mbufs =0 ; + } +/* If Tx buffers are not the last reference or +* from unexpected mempool, all recycled buffers +* are put into mempool. +*/ Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c line 46
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +4
-0+if (nb_recycle_mbufs ==0 ) +for (i =0 ; i < n; i++) { +if (rxep[i] !=NULL ) + rte_mempool_put(rxep[i]->pool,rxep[i]);
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +3
-0+ } + } +[Konstantin] After another thought, it might be easier and cleaner just to:
if (rxep[j] == NULL ||recycle_rxq_info->mp!= rxep[j].mbuf->pool)nb_recycle_mbufs = 0;Anyway, from my understanding - if
rte_pktmbuf_prefree_seg(mbuf)returns NULL, then we can't recycle that mbuf.[Feifei] Agree with that '
rte_pktmbuf_prefree_seg(mbuf)returns NULL, then we can't recycle that mbuf'.Firstly, we should know for i40e driver, the number of free mbufs is fixed, it must equal to '
tx_rs_thresh' This means if we start to free Tx mbufs, it cannot be interrupted until the given amount of mbufs are freed. In the meanwhile, doing prefree operation for a Tx mbuf can be looked at this mbuf is freed from this TX sw-ring
if the API returns NULL. This is due to that call 'prefree_seg' function means update the mbuf refcnt.So let's come back our recycle mbuf case.
Here we consider that the case if we have 32 mbufs need to be freed, and we firstly do the pre-free. And then first 8 mbufs is good and return value is not none. But the 9th mbuf is bad, its refcnt is more than 1. So we just update its refcnt and cannot put it into Rx sw-ring. For Tx sw-ring, this mbuf has been freed. Then we should continue to do pre-free operation for the next Tx mbufs to ensure the given amount of mbufs are freed.
Quoted 7 lines
Do a conclusion for this, this is because if we start to do pre-free operation, the Tx mbuf refcnt value maybe changed, so we cannot stop or break until finish all the pre-free operation.
Finally, in the case that Rx
refill_requestis not zero, but the valid mbuf amount is less than this value, we must put back this Tx mbufs into mempool.Above is the reason why I do not directly jump out of the loop if some mbuf return value is NULL.
Yep, I already realized that it is a bit more complicated and we need to continue with prefree() for all packets even when we get NULL in the middle.
Anyway the code has to be changed, right?
Quoted 120 lines
Quoted 120 lines
Quoted 120 lines
Quoted 120 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +8
-0+/* Update counters for Tx. */ + txq->nb_tx_free = (uint16_t )(txq->nb_tx_free + txq->tx_rs_thresh); + txq->tx_next_dd = (uint16_t )(txq->tx_next_dd + txq->tx_rs_thresh); +if (txq->tx_next_dd >= txq->nb_tx_desc) + txq->tx_next_dd = (uint16_t )(txq->tx_rs_thresh -1 ); + +return nb_recycle_mbufs; +}(quoted diff) +0
-0
b/drivers/net/i40e/i40e_rxtx.cindexb4f65b58fa..a9c9eb331c100644drivers/net/i40e/i40e_rxtx.c +23
-0@@ -3199,6 +3199,30 @@ i40e_txq_info_get(struct rte_eth_dev *dev,uint16_t queue_id, qinfo->conf.offloads = txq->offloads; } +void +i40e_recycle_rxq_info_get (struct rte_eth_dev *dev,uint16_t queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info) { +struct i40e_rx_queue *rxq; +struct i40e_adapter *ad = +I40E_DEV_PRIVATE_TO_ADAPTER (dev->data->dev_private); + + rxq = dev->data->rx_queues[queue_id]; + + recycle_rxq_info->mbuf_ring = (void *)rxq->sw_ring; + recycle_rxq_info->mp = rxq->mp; + recycle_rxq_info->mbuf_ring_size = rxq->nb_rx_desc; + recycle_rxq_info->receive_tail = &rxq->rx_tail; + +if (ad->rx_vec_allowed) { + recycle_rxq_info->refill_requirement =RTE_I40E_RXQ_REARM_THRESH ; + recycle_rxq_info->refill_head = &rxq->rxrearm_start; + }else { + recycle_rxq_info->refill_requirement = rxq->rx_free_thresh; + recycle_rxq_info->refill_head = &rxq->rx_free_trigger; + } +} +#ifdef RTE_ARCH_X86 static inline bool get_avx_supported(bool request_avx512) @@ -3293,6 +3317,8 @@
i40e_set_rx_function(struct rte_eth_dev *dev)drivers/net/i40e/i40e_rxtx.c +7
-1dev->rx_pkt_burst = ad->rx_use_avx2 ? i40e_recv_scattered_pkts_vec_avx2 : i40e_recv_scattered_pkts_vec; + dev->recycle_rx_descriptors_refill = + i40e_recycle_rx_descriptors_refill_vec; } }else {if (ad->rx_use_avx512) {@@ -3311,9 +3337,12 @@ i40e_set_rx_function(struct rte_eth_dev *dev) dev->rx_pkt_burst = ad->rx_use_avx2 ? i40e_recv_pkts_vec_avx2 : i40e_recv_pkts_vec; + dev->recycle_rx_descriptors_refill = + i40e_recycle_rx_descriptors_refill_vec; } }#else /* RTE_ARCH_X86 */ + dev->recycle_rx_descriptors_refill = +i40e_recycle_rx_descriptors_refill_vec; if (dev->data->scattered_rx) { PMD_INIT_LOG(DEBUG, "Using Vector Scattered Rx (port %d).", @@ -3481,15 +3510,18 @@ i40e_set_tx_function(struct rte_eth_dev *dev) dev->tx_pkt_burst = ad->tx_use_avx2 ? i40e_xmit_pkts_vec_avx2 : i40e_xmit_pkts_vec; + dev->recycle_tx_mbufs_reuse =
i40e_recycle_tx_mbufs_reuse_vec;drivers/net/i40e/i40e_rxtx.c +1
-0}#else /* RTE_ARCH_X86 */ PMD_INIT_LOG (DEBUG ,"Using Vector Tx (port %d)." , dev->data->port_id); dev->tx_pkt_burst = i40e_xmit_pkts_vec; + dev->recycle_tx_mbufs_reuse =
i40e_recycle_tx_mbufs_reuse_vec;
#endif /*RTE_ARCH_X86*/drivers/net/i40e/i40e_rxtx.c +1
-0}else {PMD_INIT_LOG (DEBUG ,"Simple tx finally be used." ); dev->tx_pkt_burst = i40e_xmit_pkts_simple; + dev->recycle_tx_mbufs_reuse =
i40e_recycle_tx_mbufs_reuse_vec;drivers/net/i40e/i40e_rxtx.c +0
-0} dev->tx_pkt_prepare = i40e_simple_prep_pkts; }else {(quoted diff) +0
-0
b/drivers/net/i40e/i40e_rxtx.hindexa8686224e5..b191f23e1f100644drivers/net/i40e/i40e_rxtx.h +5
-0@@ -236,6 +236,10 @@ uint32_t i40e_dev_rx_queue_count(void *rx_queue); int i40e_dev_rx_descriptor_status(void *rx_queue,uint16_t offset);int i40e_dev_tx_descriptor_status (void *tx_queue,uint16_t offset); +uint16_t i40e_recycle_tx_mbufs_reuse_vec (void *tx_queue, +struct rte_eth_recycle_rxq_info *recycle_rxq_info);void +i40e_recycle_rx_descriptors_refill_vec (void *rx_queue,uint16_t +nb_mbufs); +uint16_t i40e_recv_pkts_vec (void *rx_queue,struct rte_mbuf **rx_pkts,uint16_t nb_pkts); uint16_t i40e_recv_scattered_pkts_vec(void *rx_queue, diff --gita/drivers/net/i40e/meson.build b/drivers/net/i40e/meson.build index
8e53b87a65..3b1a233c84100644drivers/net/i40e/meson.build +1
-1@@ -34,6 +34,7 @@ sources = files( 'i40e_tm.c', 'i40e_hash.c', 'i40e_vf_representor.c', + 'i40e_recycle_mbufs_vec_common.c', 'rte_pmd_i40e.c', ) --2.25.1
RE: [PATCH v11 2/4] net/i40e: implement mbufs recycle mode
Quoted 323 lines
-----Original Message-----
From: Konstantin Ananyev <[email protected]>
Sent: Friday, September 1, 2023 10:23 PM
To: Feifei Wang <[email protected]>; Konstantin Ananyev <[email protected]>
Cc: [email protected]; nd <[email protected]>; Honnappa Nagarahalli <[email protected]>; Ruifeng Wang <[email protected]>; Yuying Zhang <[email protected]>; Beilei Xing <[email protected]>; nd <[email protected]>; nd <[email protected]>
Subject: RE: [PATCH v11 2/4] net/i40e: implement mbufs recycle modeQuoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Define specific function implementation for i40e driver. Currently, mbufs recycle mode can support 128bit vector path and avx2
Quoted 8 lines
Quoted 8 lines
path.
Quoted 7 lines
Quoted 7 lines
And can be enabled both in fast free and no fast free mode.
Suggested-by: Honnappa Nagarahalli
<[email protected]>Signed-off-by Feifei Wang <[email protected]>Reviewed-by Ruifeng Wang <[email protected]>Reviewed-by Honnappa NagarahalliQuoted 39 lines
Quoted 39 lines
Quoted 11 lines
Quoted 11 lines
--- drivers/net/i40e/i40e_ethdev.c | 1 + drivers/net/i40e/i40e_ethdev.h | 2 + .../net/i40e/i40e_recycle_mbufs_vec_common.c | 147 ++++++++++++++++++ drivers/net/i40e/i40e_rxtx.c | 32 ++++ drivers/net/i40e/i40e_rxtx.h | 4 + drivers/net/i40e/meson.build | 1 + 6 files changed, 187 insertions(+) create mode 100644
drivers/net/i40e/i40e_recycle_mbufs_vec_common.cQuoted 7 lines
Quoted 7 lines
(quoted diff) +0
-0
b/drivers/net/i40e/i40e_ethdev.cindex8271bbb394..50ba9aac94100644drivers/net/i40e/i40e_ethdev.c +0
-0@@ -496,6 +496,7 @@ static const struct eth_dev_ops
i40e_eth_dev_ops= {
Quoted 11 lines
Quoted 11 lines
drivers/net/i40e/i40e_ethdev.c +1
-0.flow_ops_get = i40e_dev_flow_ops_get, .rxq_info_get = i40e_rxq_info_get, .txq_info_get = i40e_txq_info_get, + .recycle_rxq_info_get = i40e_recycle_rxq_info_get, .rx_burst_mode_get = i40e_rx_burst_mode_get, .tx_burst_mode_get = i40e_tx_burst_mode_get, .timesync_enable = i40e_timesync_enable,(quoted diff) +0
-0
b/drivers/net/i40e/i40e_ethdev.hindex6f65d5e0ac..af758798e1100644
---a/drivers/net/i40e/i40e_ethdev.hQuoted 8 lines
Review void i40e_rxq_info_get(struct rte_eth_dev · line 1360
Quoted 8 lines
+++
b/drivers/net/i40e/i40e_ethdev.h(quoted diff) +2
-0@@ -1355,6 +1355,8 @@ void i40e_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, struct rte_eth_rxq_info *qinfo); void i40e_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, struct rte_eth_txq_info *qinfo); +void i40e_recycle_rxq_info_get(struct rte_eth_dev *dev, +uint16_t
queue_id,Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Review void i40e_rxq_info_get(struct rte_eth_dev · line 1362
Quoted 2 lines
(quoted diff) +1
-0+ struct rte_eth_recycle_rxq_info *recycle_rxq_info); int i40e_rx_burst_mode_get(struct rte_eth_dev *dev, uint16_t
queue_id,Quoted 86 lines
Quoted 67 lines
Quoted 67 lines
Quoted 67 lines
struct
rte_eth_burst_mode*mode); int
i40e_tx_burst_mode_get(structrte_eth_dev*dev,uint16_tqueue_id, diff -- gita/drivers/net/i40e/i40e_recycle_mbufs_vec_common.cb/drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
new file mode 100644
index 0000000000..5663ecccdedrivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +31
-0@@ -0,0 +1,147 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2023 Arm Limited. +*/ + +#include <stdint.h> +#include <ethdev_driver.h> + +#include "base/i40e_prototype.h" +#include "base/i40e_type.h" +#include "i40e_ethdev.h" +#include "i40e_rxtx.h" + +#pragma GCC diagnostic ignored "-Wcast-qual" + +void +i40e_recycle_rx_descriptors_refill_vec (void *rx_queue,uint16_t +nb_mbufs) { +struct i40e_rx_queue *rxq = rx_queue; +struct i40e_rx_entry *rxep; +volatile union i40e_rx_desc *rxdp; +uint16_t rx_id; +uint64_t paddr; +uint64_t dma_addr; +uint16_t i; + + rxdp = rxq->rx_ring + rxq->rxrearm_start; + rxep = &rxq->sw_ring[rxq->rxrearm_start]; + +for (i =0 ; i < nb_mbufs; i++) { +/* Initialize rxdp descs. */ + paddr = (rxep[i].mbuf)->buf_iova +
RTE_PKTMBUF_HEADROOM;drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +25
-0+ dma_addr =rte_cpu_to_le_64 (paddr); +/* flush desc with pa dma_addr */ + rxdp[i].read.hdr_addr =0 ; + rxdp[i].read.pkt_addr = dma_addr; + } + +/* Update the descriptor initializer index */ + rxq->rxrearm_start += nb_mbufs; + rx_id = rxq->rxrearm_start -1 ; + +if (unlikely (rxq->rxrearm_start >= rxq->nb_rx_desc)) { + rxq->rxrearm_start =0 ; + rx_id = rxq->nb_rx_desc -1 ; + } + + rxq->rxrearm_nb -= nb_mbufs; + +rte_io_wmb (); +/* Update the tail pointer on the NIC */ +I40E_PCI_REG_WRITE_RELAXED (rxq->qrx_tail, rx_id); } + +uint16_t +i40e_recycle_tx_mbufs_reuse_vec (void *tx_queue, +struct rte_eth_recycle_rxq_info *recycle_rxq_info) { +struct i40e_tx_queue *txq = tx_queue;Quoted 8 lines
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +8
-0+struct i40e_tx_entry *txep; +struct rte_mbuf **rxep; +int i, n; +uint16_t nb_recycle_mbufs; +uint16_t avail =0 ; +uint16_t mbuf_ring_size = recycle_rxq_info->mbuf_ring_size; +uint16_t mask = recycle_rxq_info->mbuf_ring_size -1 ; + uint16_t refill_requirement = recycle_rxq_info-
refill_requirement;Quoted 9 lines
Quoted 9 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 9 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +9
-0+uint16_t refill_head = *recycle_rxq_info->refill_head; +uint16_t receive_tail = *recycle_rxq_info->receive_tail; + +/* Get available recycling Rx buffers. */ + avail = (mbuf_ring_size - (refill_head - receive_tail)) & +mask; + +/* Check Tx free thresh and Rx available space. */ + if (txq->nb_tx_free > txq->tx_free_thresh || avail <= txq-
tx_rs_thresh)Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +5
-0+return 0 ; + +/* check DD bits on threshold descriptor */ + if ((txq->tx_ring[txq->tx_next_dd].cmd_type_offset_bsz & +rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) !=Quoted 8 lines
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 8 lines
+
rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE))drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +6
-0+return 0 ; + + n = txq->tx_rs_thresh; + nb_recycle_mbufs = n; + +/* Mbufs recycle mode can only support no ring buffer wrapping
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 4 lines
around.
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +3
-0+* Two case for this: +* +* case 1: The refill head of Rx buffer ring needs to be aligned with
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +4
-0+* mbuf ring size. In this case, the number of Tx freeing buffers +* should be equal to refill_requirement. +* +* case 2: The refill head of Rx ring buffer does not need to be aligned
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +1
-0+* with mbuf ring size. In this case, the update of refill head can not
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +4
-0+* exceed the Rx mbuf ring size. +*/ + if (refill_requirement != n || + (!refill_requirement && (refill_head + n >
mbuf_ring_size)))Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 11 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +11
-0+return 0 ; + +/* First buffer to free from S/W ring is at index +* tx_next_dd - (tx_rs_thresh-1). +*/ + txep = &txq->sw_ring[txq->tx_next_dd - (n -1 )]; + rxep = recycle_rxq_info->mbuf_ring; + rxep += refill_head; + +if (txq->offloads &RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE ) { +/* Avoid txq contains buffers from unexpected mempool. */
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 10 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +10
-0+if (unlikely (recycle_rxq_info->mp + != txep[0 ].mbuf->pool)) +return 0 ; + +/* Directly put mbufs from Tx to Rx. */ +for (i =0 ; i < n; i++) + rxep[i] = txep[i].mbuf; + }else { +for (i =0 ; i < n; i++) { + rxep[i] =
rte_pktmbuf_prefree_seg(txep[i].mbuf);Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +2
-0+ +/* If Tx buffers are not the last reference or from
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +1
-0+* unexpected mempool, previous copied buffers are
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 3 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +3
-0+* considered as invalid. +*/ + if (unlikely((rxep[i] == NULL &&
refill_requirement) ||Quoted 46 lines
Quoted 46 lines
Quoted 8 lines
[Konstantin]
Could you pls remind me why it is ok to have rxep[i]==NULL whenrefill_requirementis not set?If
reill_requirementis not zero, it means each tx freed buffer must be valid and can be put into Rxsw_ring. Then the refill head of Rx buffer ring can be aligned with mbuf ring size. Briefly speaking the numberof Tx valid freed buffer must be equal to Rx
refill_requirement. For example, i40e driver.Quoted 5 lines
If
reill_requirementis zero, it means that the refill head of Rx buffer ring does not need to be aligned with mbuf ring size, thus if Tx have n valid freed buffers, we just need to put these n buffers into Rx sw-ring, and not to be equal to the Rx setting rearm number. For example, mlx5 driver.
Quoted 3 lines
In conclusion, above difference is due to pmd drivers have different
strategies to update their Rx rearm(refill) head.
Quoted 2 lines
For i40e driver, if
rearm_headexceed 1024, it will be set as 0 due to thenumber of each rearm is a fixed value by default.
Quoted 2 lines
For mlx5 driver. Its
rearm_headcan exceed 1024, and use mask to achievereal index. Thus its rearm number can be a different value.
Ok, but if
rte_pktmbuf_prefree_seg(txep[i].mbuf), it means that this mbuf is not free yet and can't be reused.
Shouldn't we then setnb_recycle_mbufs= 0 in that case too? Or probably would be enough to skip that mbuf?
Might be something like that:for (i = 0, j = 0; i < n; i++) {
rxep[j] = rte_pktmbuf_prefree_seg(txep[i].mbuf); if (rxep[j] == NULL || recycle_rxq_info->mp != rxep[j].mbuf->pool)) { if (refill_requirement) { nb_recycle_mbufs = 0; break; } } else j++; }Quoted 6 lines
Quoted 6 lines
/* now j contains actual number of recycled mbufs */
?
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +1
-0+ recycle_rxq_info->mp !=txep[i].mbuf-
Quoted 18 lines
Quoted 11 lines
Quoted 11 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 11 lines
Quoted 1 line
pool))
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +10
-0+ nb_recycle_mbufs =0 ; + } +/* If Tx buffers are not the last reference or +* from unexpected mempool, all recycled buffers +* are put into mempool. +*/ +if (nb_recycle_mbufs ==0 ) +for (i =0 ; i < n; i++) { +if (rxep[i] !=NULL ) + rte_mempool_put(rxep[i]-pool,
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c line 46
Quoted 4 lines
rxep[i]);
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +3
-0+ } + } +[Konstantin] After another thought, it might be easier and cleaner just to:
if (rxep[j] == NULL ||recycle_rxq_info->mp!= rxep[j].mbuf->pool)Quoted 6 lines
nb_recycle_mbufs = 0;Anyway, from my understanding - if
rte_pktmbuf_prefree_seg(mbuf)returns NULL, then we can't recycle that mbuf.[Feifei] Agree with that '
rte_pktmbuf_prefree_seg(mbuf)returns NULL, thenwe can't recycle that mbuf'.
Quoted 2 lines
Firstly, we should know for i40e driver, the number of free mbufs is fixed, it
must equal to '
tx_rs_thresh'Quoted 1 line
This means if we start to free Tx mbufs, it cannot be interrupted until the
given amount of mbufs are freed.
Quoted 2 lines
In the meanwhile, doing prefree operation for a Tx mbuf can be looked at this mbuf is freed from this TX sw-ring if the API returns NULL. This is due
to that call '
prefree_seg' function means update the mbuf refcnt.Quoted 3 lines
So let's come back our recycle mbuf case.
Here we consider that the case if we have 32 mbufs need to be freed, andwe firstly do the pre-free.
Quoted 1 line
And then first 8 mbufs is good and return value is not none. But the 9th
mbuf is bad, its refcnt is more than 1.
Quoted 1 line
So we just update its refcnt and cannot put it into Rx sw-ring. For Tx sw-ring,
this mbuf has been freed.
Quoted 5 lines
Then we should continue to do pre-free operation for the next Tx mbufs to ensure the given amount of mbufs are freed.
Do a conclusion for this, this is because if we start to do pre-free operation, the Tx mbuf refcnt value maybe changed, so we cannot stop or
break until finish all the pre-free operation.
Quoted 3 lines
Finally, in the case that Rx
refill_requestis not zero, but the valid mbuf amount is less than this value, we must put back this Tx mbufs into
Quoted 9 lines
mempool.
Quoted 2 lines
Above is the reason why I do not directly jump out of the loop if some mbuf
return value is NULL.
Yep, I already realized that it is a bit more complicated and we need to continue with
prefree()for all packets even when we get NULL in the middle. Anyway the code has to be changed, right?
Sorry, I think for the code, it is unnecessary to be changed.
For no fast free path, currently:
1. We check whether each mbuf is Ok and call pre_free function
------------------------------------------------------------------------------------------------------------------------------------
2.1 For the mbuf return value is not NULL, it is put into Rx sw-ring.
2.2 For the mbuf return value is zero and refill-request, it will also firstly put into Rx sw-ring, and we set nb_recycle = 0
------------------------------------------------------------------------------------------------------------------------------------
3.1 We check nb_recycle, if it is not 0, we will continue to rearm Rx descs and update its index by call descs_refill function. 3.2 if nb_recycle is 0, we will put valid recycle mbufs back into mempool as general path. This is necessary, because we need to ensure the freed Tx number is fixed.(Some buffers return is null can be seen as freed, others need to be put into mempool)
Or maybe I ignore something?
Quoted 132 lines
Quoted 20 lines
Quoted 3 lines
Quoted 3 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 3 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +2
-0+/* Update counters for Tx. */ + txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + txq-
tx_rs_thresh);Quoted 1 line
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +1
-0+ txq->tx_next_dd = (uint16_t)(txq->tx_next_dd + txq-
tx_rs_thresh);Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +5
-0+if (txq->tx_next_dd >= txq->nb_tx_desc) + txq->tx_next_dd = (uint16_t )(txq->tx_rs_thresh -1 ); + +return nb_recycle_mbufs; +}(quoted diff) +0
-0
b/drivers/net/i40e/i40e_rxtx.cindexb4f65b58fa..a9c9eb331c100644drivers/net/i40e/i40e_rxtx.c +0
-0@@ -3199,6 +3199,30 @@ i40e_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, qinfo->conf.offloads = txq->offloads; }Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/i40e/i40e_rxtx.c i40e_txq_info_get(struct rte_eth_dev · line 3203
Quoted 2 lines
drivers/net/i40e/i40e_rxtx.c +2
-0+void +i40e_recycle_rxq_info_get(struct rte_eth_dev *dev, uint16_t
queue_id,Quoted 20 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_rxtx.c i40e_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
Quoted 4 lines
drivers/net/i40e/i40e_rxtx.c +4
-0+ struct rte_eth_recycle_rxq_info *recycle_rxq_info) { +struct i40e_rx_queue *rxq; +struct i40e_adapter *ad = + I40E_DEV_PRIVATE_TO_ADAPTER(dev->data-
dev_private);Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/i40e/i40e_rxtx.c +6
-0+ + rxq = dev->data->rx_queues[queue_id]; + + recycle_rxq_info->mbuf_ring = (void *)rxq->sw_ring; + recycle_rxq_info->mp = rxq->mp; + recycle_rxq_info->mbuf_ring_size = rxq->nb_rx_desc;Quoted 8 lines
Quoted 8 lines
drivers/net/i40e/i40e_rxtx.c i40e_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
Quoted 8 lines
drivers/net/i40e/i40e_rxtx.c +7
-0+ recycle_rxq_info->receive_tail = &rxq->rx_tail; + +if (ad->rx_vec_allowed) { + recycle_rxq_info->refill_requirement =RTE_I40E_RXQ_REARM_THRESH ; + recycle_rxq_info->refill_head = &rxq->rxrearm_start; + }else { + recycle_rxq_info->refill_requirement = rxq-
rx_free_thresh;Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/i40e/i40e_rxtx.c +4
-0+ recycle_rxq_info->refill_head = &rxq->rx_free_trigger; + } +} +#ifdef RTE_ARCH_X86 Quoted 8 lines
Quoted 8 lines
drivers/net/i40e/i40e_rxtx.c i40e_set_rx_function(struct rte_eth_dev *dev)
Quoted 8 lines
drivers/net/i40e/i40e_rxtx.c +0
-0static inline bool get_avx_supported(bool request_avx512) @@ -3293,6 +3317,8 @@
i40e_set_rx_function(struct rte_eth_dev *dev)drivers/net/i40e/i40e_rxtx.c +2
-0dev->rx_pkt_burst = ad->rx_use_avx2 ? i40e_recv_scattered_pkts_vec_avx2 : i40e_recv_scattered_pkts_vec; + dev->recycle_rx_descriptors_refill = +i40e_recycle_rx_descriptors_refill_vec;Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_rxtx.c i40e_set_rx_function(struct rte_eth_dev
Quoted 4 lines
drivers/net/i40e/i40e_rxtx.c +0
-0} }else {if (ad->rx_use_avx512) {@@ -3311,9 +3337,12 @@ i40e_set_rx_function(struct rte_eth_dev*dev)
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/i40e/i40e_rxtx.c i40e_set_rx_function(struct rte_eth_dev *dev)
Quoted 5 lines
drivers/net/i40e/i40e_rxtx.c +2
-0dev->rx_pkt_burst = ad->rx_use_avx2 ? i40e_recv_pkts_vec_avx2 : i40e_recv_pkts_vec; + dev->recycle_rx_descriptors_refill = +i40e_recycle_rx_descriptors_refill_vec;Quoted 39 lines
Quoted 39 lines
Quoted 39 lines
Quoted 39 lines
drivers/net/i40e/i40e_rxtx.c +3
-1} }#else /* RTE_ARCH_X86 */ + dev->recycle_rx_descriptors_refill = +i40e_recycle_rx_descriptors_refill_vec; if (dev->data->scattered_rx) { PMD_INIT_LOG(DEBUG, "Using Vector Scattered Rx (port %d).", @@ -3481,15 +3510,18 @@ i40e_set_tx_function(struct rte_eth_dev *dev) dev->tx_pkt_burst = ad->tx_use_avx2 ? i40e_xmit_pkts_vec_avx2 : i40e_xmit_pkts_vec; + dev->recycle_tx_mbufs_reuse =
i40e_recycle_tx_mbufs_reuse_vec;drivers/net/i40e/i40e_rxtx.c +1
-0}#else /* RTE_ARCH_X86 */ PMD_INIT_LOG (DEBUG ,"Using Vector Tx (port %d)." , dev->data->port_id); dev->tx_pkt_burst = i40e_xmit_pkts_vec; + dev->recycle_tx_mbufs_reuse =
i40e_recycle_tx_mbufs_reuse_vec; #endif /*RTE_ARCH_X86*/drivers/net/i40e/i40e_rxtx.c +1
-0}else {PMD_INIT_LOG (DEBUG ,"Simple tx finally be used." ); dev->tx_pkt_burst = i40e_xmit_pkts_simple; + dev->recycle_tx_mbufs_reuse =
i40e_recycle_tx_mbufs_reuse_vec;drivers/net/i40e/i40e_rxtx.c +0
-0} dev->tx_pkt_prepare = i40e_simple_prep_pkts; }else {(quoted diff) +0
-0
b/drivers/net/i40e/i40e_rxtx.hindexa8686224e5..b191f23e1f100644drivers/net/i40e/i40e_rxtx.h +0
-0@@ -236,6 +236,10 @@ uint32_t i40e_dev_rx_queue_count(void *rx_queue); int i40e_dev_rx_descriptor_status(void *rx_queue,
uint16_toffset); inti40e_dev_tx_descriptor_status(void *tx_queue, uint16_t offset);Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/i40e/i40e_rxtx.h uint32_t i40e_dev_rx_queue_count(void *rx_queue); · line 240
Quoted 2 lines
drivers/net/i40e/i40e_rxtx.h +2
-0+uint16_t i40e_recycle_tx_mbufs_reuse_vec (void *tx_queue, +struct rte_eth_recycle_rxq_info *recycle_rxq_info);void
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_rxtx.h
Quoted 4 lines
drivers/net/i40e/i40e_rxtx.h +3
-0+i40e_recycle_rx_descriptors_refill_vec (void *rx_queue, uint16_t +nb_mbufs); + uint16_t i40e_recv_pkts_vec(void *rx_queue, struct rte_mbuf**rx_pkts,
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
uint16_tnb_pkts);
uint16_ti40e_recv_scattered_pkts_vec(void*rx_queue, diff
--git a/drivers/net/i40e/meson.build b/drivers/net/i40e/meson.build index8e53b87a65..3b1a233c84100644drivers/net/i40e/meson.build +1
-1@@ -34,6 +34,7 @@ sources = files( 'i40e_tm.c', 'i40e_hash.c', 'i40e_vf_representor.c', + 'i40e_recycle_mbufs_vec_common.c', 'rte_pmd_i40e.c', ) --2.25.1
RE: [PATCH v11 2/4] net/i40e: implement mbufs recycle mode
Hi Feifei,
Quoted 327 lines
Quoted 307 lines
Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
Quoted 3 lines
Define specific function implementation for i40e driver. Currently, mbufs recycle mode can support 128bit vector path and avx2
path.
Quoted 7 lines
Quoted 7 lines
And can be enabled both in fast free and no fast free mode.
Suggested-by: Honnappa Nagarahalli
<[email protected]>Signed-off-by Feifei Wang <[email protected]>Reviewed-by Ruifeng Wang <[email protected]>Reviewed-by Honnappa NagarahalliQuoted 39 lines
Quoted 39 lines
Quoted 11 lines
Quoted 11 lines
--- drivers/net/i40e/i40e_ethdev.c | 1 + drivers/net/i40e/i40e_ethdev.h | 2 + .../net/i40e/i40e_recycle_mbufs_vec_common.c | 147 ++++++++++++++++++ drivers/net/i40e/i40e_rxtx.c | 32 ++++ drivers/net/i40e/i40e_rxtx.h | 4 + drivers/net/i40e/meson.build | 1 + 6 files changed, 187 insertions(+) create mode 100644
drivers/net/i40e/i40e_recycle_mbufs_vec_common.cQuoted 7 lines
Quoted 7 lines
(quoted diff) +0
-0
b/drivers/net/i40e/i40e_ethdev.cindex8271bbb394..50ba9aac94100644drivers/net/i40e/i40e_ethdev.c +0
-0@@ -496,6 +496,7 @@ static const struct eth_dev_ops
i40e_eth_dev_ops= {
Quoted 11 lines
Quoted 11 lines
drivers/net/i40e/i40e_ethdev.c +1
-0.flow_ops_get = i40e_dev_flow_ops_get, .rxq_info_get = i40e_rxq_info_get, .txq_info_get = i40e_txq_info_get, + .recycle_rxq_info_get = i40e_recycle_rxq_info_get, .rx_burst_mode_get = i40e_rx_burst_mode_get, .tx_burst_mode_get = i40e_tx_burst_mode_get, .timesync_enable = i40e_timesync_enable,(quoted diff) +0
-0
b/drivers/net/i40e/i40e_ethdev.hindex6f65d5e0ac..af758798e1100644
---a/drivers/net/i40e/i40e_ethdev.hQuoted 8 lines
Review void i40e_rxq_info_get(struct rte_eth_dev · line 1360
Quoted 8 lines
+++
b/drivers/net/i40e/i40e_ethdev.h(quoted diff) +2
-0@@ -1355,6 +1355,8 @@ void i40e_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, struct rte_eth_rxq_info *qinfo); void i40e_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, struct rte_eth_txq_info *qinfo); +void i40e_recycle_rxq_info_get(struct rte_eth_dev *dev, +uint16_t
queue_id,Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Review void i40e_rxq_info_get(struct rte_eth_dev · line 1362
Quoted 2 lines
(quoted diff) +1
-0+ struct rte_eth_recycle_rxq_info *recycle_rxq_info); int i40e_rx_burst_mode_get(struct rte_eth_dev *dev, uint16_t
queue_id,Quoted 86 lines
Quoted 67 lines
Quoted 67 lines
Quoted 67 lines
struct
rte_eth_burst_mode*mode); int
i40e_tx_burst_mode_get(structrte_eth_dev*dev,uint16_tqueue_id, diff -- gita/drivers/net/i40e/i40e_recycle_mbufs_vec_common.cb/drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
new file mode 100644
index 0000000000..5663ecccdedrivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +31
-0@@ -0,0 +1,147 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2023 Arm Limited. +*/ + +#include <stdint.h> +#include <ethdev_driver.h> + +#include "base/i40e_prototype.h" +#include "base/i40e_type.h" +#include "i40e_ethdev.h" +#include "i40e_rxtx.h" + +#pragma GCC diagnostic ignored "-Wcast-qual" + +void +i40e_recycle_rx_descriptors_refill_vec (void *rx_queue,uint16_t +nb_mbufs) { +struct i40e_rx_queue *rxq = rx_queue; +struct i40e_rx_entry *rxep; +volatile union i40e_rx_desc *rxdp; +uint16_t rx_id; +uint64_t paddr; +uint64_t dma_addr; +uint16_t i; + + rxdp = rxq->rx_ring + rxq->rxrearm_start; + rxep = &rxq->sw_ring[rxq->rxrearm_start]; + +for (i =0 ; i < nb_mbufs; i++) { +/* Initialize rxdp descs. */ + paddr = (rxep[i].mbuf)->buf_iova +
RTE_PKTMBUF_HEADROOM;drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +25
-0+ dma_addr =rte_cpu_to_le_64 (paddr); +/* flush desc with pa dma_addr */ + rxdp[i].read.hdr_addr =0 ; + rxdp[i].read.pkt_addr = dma_addr; + } + +/* Update the descriptor initializer index */ + rxq->rxrearm_start += nb_mbufs; + rx_id = rxq->rxrearm_start -1 ; + +if (unlikely (rxq->rxrearm_start >= rxq->nb_rx_desc)) { + rxq->rxrearm_start =0 ; + rx_id = rxq->nb_rx_desc -1 ; + } + + rxq->rxrearm_nb -= nb_mbufs; + +rte_io_wmb (); +/* Update the tail pointer on the NIC */ +I40E_PCI_REG_WRITE_RELAXED (rxq->qrx_tail, rx_id); } + +uint16_t +i40e_recycle_tx_mbufs_reuse_vec (void *tx_queue, +struct rte_eth_recycle_rxq_info *recycle_rxq_info) { +struct i40e_tx_queue *txq = tx_queue;Quoted 8 lines
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +8
-0+struct i40e_tx_entry *txep; +struct rte_mbuf **rxep; +int i, n; +uint16_t nb_recycle_mbufs; +uint16_t avail =0 ; +uint16_t mbuf_ring_size = recycle_rxq_info->mbuf_ring_size; +uint16_t mask = recycle_rxq_info->mbuf_ring_size -1 ; + uint16_t refill_requirement = recycle_rxq_info-
refill_requirement;Quoted 9 lines
Quoted 9 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 9 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +9
-0+uint16_t refill_head = *recycle_rxq_info->refill_head; +uint16_t receive_tail = *recycle_rxq_info->receive_tail; + +/* Get available recycling Rx buffers. */ + avail = (mbuf_ring_size - (refill_head - receive_tail)) & +mask; + +/* Check Tx free thresh and Rx available space. */ + if (txq->nb_tx_free > txq->tx_free_thresh || avail <= txq-
tx_rs_thresh)Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +5
-0+return 0 ; + +/* check DD bits on threshold descriptor */ + if ((txq->tx_ring[txq->tx_next_dd].cmd_type_offset_bsz & +rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) !=Quoted 8 lines
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 8 lines
+
rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE))drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +6
-0+return 0 ; + + n = txq->tx_rs_thresh; + nb_recycle_mbufs = n; + +/* Mbufs recycle mode can only support no ring buffer wrapping
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 4 lines
around.
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +3
-0+* Two case for this: +* +* case 1: The refill head of Rx buffer ring needs to be aligned with
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +4
-0+* mbuf ring size. In this case, the number of Tx freeing buffers +* should be equal to refill_requirement. +* +* case 2: The refill head of Rx ring buffer does not need to be aligned
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +1
-0+* with mbuf ring size. In this case, the update of refill head can not
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +4
-0+* exceed the Rx mbuf ring size. +*/ + if (refill_requirement != n || + (!refill_requirement && (refill_head + n >
mbuf_ring_size)))Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 11 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +11
-0+return 0 ; + +/* First buffer to free from S/W ring is at index +* tx_next_dd - (tx_rs_thresh-1). +*/ + txep = &txq->sw_ring[txq->tx_next_dd - (n -1 )]; + rxep = recycle_rxq_info->mbuf_ring; + rxep += refill_head; + +if (txq->offloads &RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE ) { +/* Avoid txq contains buffers from unexpected mempool. */
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 10 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +10
-0+if (unlikely (recycle_rxq_info->mp + != txep[0 ].mbuf->pool)) +return 0 ; + +/* Directly put mbufs from Tx to Rx. */ +for (i =0 ; i < n; i++) + rxep[i] = txep[i].mbuf; + }else { +for (i =0 ; i < n; i++) { + rxep[i] =
rte_pktmbuf_prefree_seg(txep[i].mbuf);Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +2
-0+ +/* If Tx buffers are not the last reference or from
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +1
-0+* unexpected mempool, previous copied buffers are
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 3 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +3
-0+* considered as invalid. +*/ + if (unlikely((rxep[i] == NULL &&
refill_requirement) ||Quoted 46 lines
Quoted 46 lines
Quoted 8 lines
[Konstantin]
Could you pls remind me why it is ok to have rxep[i]==NULL whenrefill_requirementis not set?If
reill_requirementis not zero, it means each tx freed buffer must be valid and can be put into Rxsw_ring. Then the refill head of Rx buffer ring can be aligned with mbuf ring size. Briefly speaking the numberof Tx valid freed buffer must be equal to Rx
refill_requirement. For example, i40e driver.Quoted 5 lines
If
reill_requirementis zero, it means that the refill head of Rx buffer ring does not need to be aligned with mbuf ring size, thus if Tx have n valid freed buffers, we just need to put these n buffers into Rx sw-ring, and not to be equal to the Rx setting rearm number. For example, mlx5 driver.
Quoted 3 lines
In conclusion, above difference is due to pmd drivers have different
strategies to update their Rx rearm(refill) head.
Quoted 2 lines
For i40e driver, if
rearm_headexceed 1024, it will be set as 0 due to thenumber of each rearm is a fixed value by default.
Quoted 2 lines
For mlx5 driver. Its
rearm_headcan exceed 1024, and use mask to achievereal index. Thus its rearm number can be a different value.
Ok, but if
rte_pktmbuf_prefree_seg(txep[i].mbuf), it means that this mbuf is not free yet and can't be reused.
Shouldn't we then setnb_recycle_mbufs= 0 in that case too? Or probably would be enough to skip that mbuf?
Might be something like that:for (i = 0, j = 0; i < n; i++) {
rxep[j] = rte_pktmbuf_prefree_seg(txep[i].mbuf); if (rxep[j] == NULL || recycle_rxq_info->mp != rxep[j].mbuf->pool)) { if (refill_requirement) { nb_recycle_mbufs = 0; break; } } else j++; }Quoted 6 lines
Quoted 6 lines
/* now j contains actual number of recycled mbufs */
?
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +1
-0+ recycle_rxq_info->mp !=txep[i].mbuf-
Quoted 18 lines
Quoted 11 lines
Quoted 11 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 11 lines
Quoted 1 line
pool))
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +10
-0+ nb_recycle_mbufs =0 ; + } +/* If Tx buffers are not the last reference or +* from unexpected mempool, all recycled buffers +* are put into mempool. +*/ +if (nb_recycle_mbufs ==0 ) +for (i =0 ; i < n; i++) { +if (rxep[i] !=NULL ) + rte_mempool_put(rxep[i]-pool,
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c line 46
Quoted 4 lines
rxep[i]);
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +3
-0+ } + } +[Konstantin] After another thought, it might be easier and cleaner just to:
if (rxep[j] == NULL ||recycle_rxq_info->mp!= rxep[j].mbuf->pool)Quoted 6 lines
nb_recycle_mbufs = 0;Anyway, from my understanding - if
rte_pktmbuf_prefree_seg(mbuf)returns NULL, then we can't recycle that mbuf.[Feifei] Agree with that '
rte_pktmbuf_prefree_seg(mbuf)returns NULL, thenwe can't recycle that mbuf'.
Quoted 2 lines
Firstly, we should know for i40e driver, the number of free mbufs is fixed, it
must equal to '
tx_rs_thresh'Quoted 1 line
This means if we start to free Tx mbufs, it cannot be interrupted until the
given amount of mbufs are freed.
Quoted 2 lines
In the meanwhile, doing prefree operation for a Tx mbuf can be looked at this mbuf is freed from this TX sw-ring if the API returns NULL. This is due
to that call '
prefree_seg' function means update the mbuf refcnt.Quoted 3 lines
So let's come back our recycle mbuf case.
Here we consider that the case if we have 32 mbufs need to be freed, andwe firstly do the pre-free.
Quoted 1 line
And then first 8 mbufs is good and return value is not none. But the 9th
mbuf is bad, its refcnt is more than 1.
Quoted 1 line
So we just update its refcnt and cannot put it into Rx sw-ring. For Tx sw-ring,
this mbuf has been freed.
Quoted 5 lines
Then we should continue to do pre-free operation for the next Tx mbufs to ensure the given amount of mbufs are freed.
Do a conclusion for this, this is because if we start to do pre-free operation, the Tx mbuf refcnt value maybe changed, so we cannot stop or
break until finish all the pre-free operation.
Quoted 3 lines
Finally, in the case that Rx
refill_requestis not zero, but the valid mbuf amount is less than this value, we must put back this Tx mbufs intoQuoted 9 lines
mempool.
Quoted 2 lines
Above is the reason why I do not directly jump out of the loop if some mbuf
return value is NULL.
Yep, I already realized that it is a bit more complicated and we need to continue with
prefree()for all packets even when we get NULL in the middle. Anyway the code has to be changed, right?Sorry, I think for the code, it is unnecessary to be changed.
For no fast free path, currently:
1. We check whether each mbuf is Ok and callpre_freefunction
------------------------------------------------------------------------------------------------------------------------------------
2.1 For the mbuf return value is not NULL, it is put into Rx sw-ring.
2.2 For the mbuf return value is zero and refill-request, it will also firstly put into Rx sw-ring, and we setnb_recycle= 0
------------------------------------------------------------------------------------------------------------------------------------
3.1 We checknb_recycle, if it is not 0, we will continue to rearm Rx descs and update its index by calldescs_refillfunction. 3.2 ifnb_recycleis 0, we will put valid recycle mbufs back into mempool as general path. This is necessary, because we need to ensure the freed Tx number is fixed.(Some buffers return is null can be seen as freed, others need to be put into mempool)
Quoted 1 line
Or maybe I ignore something?
I am talking about the case when both refill_requirement and mbuf return values iare zero:
if (unlikely((rxep[i] == NULL && refill_requirement) || // ??? rxep[i] == 0 AND refill_requirement == 0 ???
recycle_rxq_info->mp != txep[i].mbuf->pool))
nb_recycle_mbufs = 0;
As I can read the code you treat such situation as valid, while I think we should reset nb_recycle_mbufs to zero when rxep[i] == NULL, no matter what value refill_requirement is. .
Quoted 132 lines
Quoted 132 lines
Quoted 20 lines
Quoted 3 lines
Quoted 3 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 3 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +2
-0+/* Update counters for Tx. */ + txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + txq-
tx_rs_thresh);Quoted 1 line
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +1
-0+ txq->tx_next_dd = (uint16_t)(txq->tx_next_dd + txq-
tx_rs_thresh);Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +5
-0+if (txq->tx_next_dd >= txq->nb_tx_desc) + txq->tx_next_dd = (uint16_t )(txq->tx_rs_thresh -1 ); + +return nb_recycle_mbufs; +}(quoted diff) +0
-0
b/drivers/net/i40e/i40e_rxtx.cindexb4f65b58fa..a9c9eb331c100644drivers/net/i40e/i40e_rxtx.c +0
-0@@ -3199,6 +3199,30 @@ i40e_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, qinfo->conf.offloads = txq->offloads; }Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/i40e/i40e_rxtx.c i40e_txq_info_get(struct rte_eth_dev · line 3203
Quoted 2 lines
drivers/net/i40e/i40e_rxtx.c +2
-0+void +i40e_recycle_rxq_info_get(struct rte_eth_dev *dev, uint16_t
queue_id,Quoted 20 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_rxtx.c i40e_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
Quoted 4 lines
drivers/net/i40e/i40e_rxtx.c +4
-0+ struct rte_eth_recycle_rxq_info *recycle_rxq_info) { +struct i40e_rx_queue *rxq; +struct i40e_adapter *ad = + I40E_DEV_PRIVATE_TO_ADAPTER(dev->data-
dev_private);Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/i40e/i40e_rxtx.c +6
-0+ + rxq = dev->data->rx_queues[queue_id]; + + recycle_rxq_info->mbuf_ring = (void *)rxq->sw_ring; + recycle_rxq_info->mp = rxq->mp; + recycle_rxq_info->mbuf_ring_size = rxq->nb_rx_desc;Quoted 8 lines
Quoted 8 lines
drivers/net/i40e/i40e_rxtx.c i40e_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
Quoted 8 lines
drivers/net/i40e/i40e_rxtx.c +7
-0+ recycle_rxq_info->receive_tail = &rxq->rx_tail; + +if (ad->rx_vec_allowed) { + recycle_rxq_info->refill_requirement =RTE_I40E_RXQ_REARM_THRESH ; + recycle_rxq_info->refill_head = &rxq->rxrearm_start; + }else { + recycle_rxq_info->refill_requirement = rxq-
rx_free_thresh;Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/i40e/i40e_rxtx.c +4
-0+ recycle_rxq_info->refill_head = &rxq->rx_free_trigger; + } +} +#ifdef RTE_ARCH_X86 Quoted 8 lines
Quoted 8 lines
drivers/net/i40e/i40e_rxtx.c i40e_set_rx_function(struct rte_eth_dev *dev)
Quoted 8 lines
drivers/net/i40e/i40e_rxtx.c +0
-0static inline bool get_avx_supported(bool request_avx512) @@ -3293,6 +3317,8 @@
i40e_set_rx_function(struct rte_eth_dev *dev)drivers/net/i40e/i40e_rxtx.c +2
-0dev->rx_pkt_burst = ad->rx_use_avx2 ? i40e_recv_scattered_pkts_vec_avx2 : i40e_recv_scattered_pkts_vec; + dev->recycle_rx_descriptors_refill = +i40e_recycle_rx_descriptors_refill_vec;Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_rxtx.c i40e_set_rx_function(struct rte_eth_dev
Quoted 4 lines
drivers/net/i40e/i40e_rxtx.c +0
-0} }else {if (ad->rx_use_avx512) {@@ -3311,9 +3337,12 @@ i40e_set_rx_function(struct rte_eth_dev*dev)
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/i40e/i40e_rxtx.c i40e_set_rx_function(struct rte_eth_dev *dev)
Quoted 5 lines
drivers/net/i40e/i40e_rxtx.c +2
-0dev->rx_pkt_burst = ad->rx_use_avx2 ? i40e_recv_pkts_vec_avx2 : i40e_recv_pkts_vec; + dev->recycle_rx_descriptors_refill = +i40e_recycle_rx_descriptors_refill_vec;Quoted 39 lines
Quoted 39 lines
Quoted 39 lines
Quoted 39 lines
drivers/net/i40e/i40e_rxtx.c +3
-1} }#else /* RTE_ARCH_X86 */ + dev->recycle_rx_descriptors_refill = +i40e_recycle_rx_descriptors_refill_vec; if (dev->data->scattered_rx) { PMD_INIT_LOG(DEBUG, "Using Vector Scattered Rx (port %d).", @@ -3481,15 +3510,18 @@ i40e_set_tx_function(struct rte_eth_dev *dev) dev->tx_pkt_burst = ad->tx_use_avx2 ? i40e_xmit_pkts_vec_avx2 : i40e_xmit_pkts_vec; + dev->recycle_tx_mbufs_reuse =
i40e_recycle_tx_mbufs_reuse_vec;drivers/net/i40e/i40e_rxtx.c +1
-0}#else /* RTE_ARCH_X86 */ PMD_INIT_LOG (DEBUG ,"Using Vector Tx (port %d)." , dev->data->port_id); dev->tx_pkt_burst = i40e_xmit_pkts_vec; + dev->recycle_tx_mbufs_reuse =
i40e_recycle_tx_mbufs_reuse_vec; #endif /*RTE_ARCH_X86*/drivers/net/i40e/i40e_rxtx.c +1
-0}else {PMD_INIT_LOG (DEBUG ,"Simple tx finally be used." ); dev->tx_pkt_burst = i40e_xmit_pkts_simple; + dev->recycle_tx_mbufs_reuse =
i40e_recycle_tx_mbufs_reuse_vec;drivers/net/i40e/i40e_rxtx.c +0
-0} dev->tx_pkt_prepare = i40e_simple_prep_pkts; }else {(quoted diff) +0
-0
b/drivers/net/i40e/i40e_rxtx.hindexa8686224e5..b191f23e1f100644drivers/net/i40e/i40e_rxtx.h +0
-0@@ -236,6 +236,10 @@ uint32_t i40e_dev_rx_queue_count(void *rx_queue); int i40e_dev_rx_descriptor_status(void *rx_queue,
uint16_toffset); inti40e_dev_tx_descriptor_status(void *tx_queue, uint16_t offset);Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/i40e/i40e_rxtx.h uint32_t i40e_dev_rx_queue_count(void *rx_queue); · line 240
Quoted 2 lines
drivers/net/i40e/i40e_rxtx.h +2
-0+uint16_t i40e_recycle_tx_mbufs_reuse_vec (void *tx_queue, +struct rte_eth_recycle_rxq_info *recycle_rxq_info);void
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_rxtx.h
Quoted 4 lines
drivers/net/i40e/i40e_rxtx.h +3
-0+i40e_recycle_rx_descriptors_refill_vec (void *rx_queue, uint16_t +nb_mbufs); + uint16_t i40e_recv_pkts_vec(void *rx_queue, struct rte_mbuf**rx_pkts,
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
uint16_tnb_pkts);
uint16_ti40e_recv_scattered_pkts_vec(void*rx_queue, diff
--git a/drivers/net/i40e/meson.build b/drivers/net/i40e/meson.build index8e53b87a65..3b1a233c84100644drivers/net/i40e/meson.build +1
-1@@ -34,6 +34,7 @@ sources = files( 'i40e_tm.c', 'i40e_hash.c', 'i40e_vf_representor.c', + 'i40e_recycle_mbufs_vec_common.c', 'rte_pmd_i40e.c', ) --2.25.1
RE: [PATCH v11 2/4] net/i40e: implement mbufs recycle mode
Quoted 377 lines
-----Original Message-----
From: Konstantin Ananyev <[email protected]>
Sent: Monday, September 4, 2023 3:50 PM
To: Feifei Wang <[email protected]>; Konstantin Ananyev <[email protected]>
Cc: [email protected]; nd <[email protected]>; Honnappa Nagarahalli <[email protected]>; Ruifeng Wang <[email protected]>; Yuying Zhang <[email protected]>; Beilei Xing <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>
Subject: RE: [PATCH v11 2/4] net/i40e: implement mbufs recycle modeHi Feifei,
Quoted 324 lines
Quoted 324 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Define specific function implementation for i40e driver. Currently, mbufs recycle mode can support 128bit vector path and
avx2Quoted 8 lines
Quoted 8 lines
path.
Quoted 7 lines
Quoted 7 lines
And can be enabled both in fast free and no fast free mode.
Suggested-by: Honnappa Nagarahalli
<[email protected]>Signed-off-by Feifei Wang <[email protected]>Reviewed-by Ruifeng Wang <[email protected]>Reviewed-by Honnappa NagarahalliQuoted 41 lines
Quoted 41 lines
Quoted 11 lines
Quoted 11 lines
--- drivers/net/i40e/i40e_ethdev.c | 1 + drivers/net/i40e/i40e_ethdev.h | 2 + .../net/i40e/i40e_recycle_mbufs_vec_common.c | 147 ++++++++++++++++++ drivers/net/i40e/i40e_rxtx.c | 32 ++++ drivers/net/i40e/i40e_rxtx.h | 4 + drivers/net/i40e/meson.build | 1 + 6 files changed, 187 insertions(+) create mode 100644
drivers/net/i40e/i40e_recycle_mbufs_vec_common.cQuoted 8 lines
Quoted 8 lines
(quoted diff) +0
-0
b/drivers/net/i40e/i40e_ethdev.cindex8271bbb394..50ba9aac94
100644drivers/net/i40e/i40e_ethdev.c +0
-0@@ -496,6 +496,7 @@ static const struct eth_dev_ops
i40e_eth_dev_ops= {
Quoted 12 lines
Quoted 12 lines
drivers/net/i40e/i40e_ethdev.c +1
-0.flow_ops_get = i40e_dev_flow_ops_get, .rxq_info_get = i40e_rxq_info_get, .txq_info_get = i40e_txq_info_get, + .recycle_rxq_info_get = i40e_recycle_rxq_info_get, .rx_burst_mode_get = i40e_rx_burst_mode_get, .tx_burst_mode_get = i40e_tx_burst_mode_get, .timesync_enable = i40e_timesync_enable,(quoted diff) +0
-0
b/drivers/net/i40e/i40e_ethdev.hindex6f65d5e0ac..af758798e1
100644
---a/drivers/net/i40e/i40e_ethdev.hQuoted 8 lines
Review void i40e_rxq_info_get(struct · line 1360
Quoted 8 lines
+++
b/drivers/net/i40e/i40e_ethdev.h(quoted diff) +2
-0@@ -1355,6 +1355,8 @@ void i40e_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, struct rte_eth_rxq_info *qinfo); void i40e_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, struct rte_eth_txq_info *qinfo); +void i40e_recycle_rxq_info_get(struct rte_eth_dev *dev, +uint16_t
queue_id,Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
(quoted diff) +1
-0+ struct rte_eth_recycle_rxq_info *recycle_rxq_info); int i40e_rx_burst_mode_get(struct rte_eth_dev *dev,
uint16_t
queue_id,Quoted 87 lines
Quoted 68 lines
Quoted 68 lines
Quoted 68 lines
struct
rte_eth_burst_mode*mode); int
i40e_tx_burst_mode_get(structrte_eth_dev*dev,uint16_tqueue_id, diff -- gita/drivers/net/i40e/i40e_recycle_mbufs_vec_common.cb/drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
new file mode 100644
index 0000000000..5663ecccdedrivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +32
-0@@ -0,0 +1,147 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2023 Arm Limited. +*/ + +#include <stdint.h> +#include <ethdev_driver.h> + +#include "base/i40e_prototype.h" +#include "base/i40e_type.h" +#include "i40e_ethdev.h" +#include "i40e_rxtx.h" + +#pragma GCC diagnostic ignored "-Wcast-qual" + +void +i40e_recycle_rx_descriptors_refill_vec (void *rx_queue, +uint16_t +nb_mbufs) { +struct i40e_rx_queue *rxq = rx_queue; +struct i40e_rx_entry *rxep; +volatile union i40e_rx_desc *rxdp; +uint16_t rx_id; +uint64_t paddr; +uint64_t dma_addr; +uint16_t i; + + rxdp = rxq->rx_ring + rxq->rxrearm_start; + rxep = &rxq->sw_ring[rxq->rxrearm_start]; + +for (i =0 ; i < nb_mbufs; i++) { +/* Initialize rxdp descs. */ + paddr = (rxep[i].mbuf)->buf_iova +
RTE_PKTMBUF_HEADROOM;drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +25
-0+ dma_addr =rte_cpu_to_le_64 (paddr); +/* flush desc with pa dma_addr */ + rxdp[i].read.hdr_addr =0 ; + rxdp[i].read.pkt_addr = dma_addr; + } + +/* Update the descriptor initializer index */ + rxq->rxrearm_start += nb_mbufs; + rx_id = rxq->rxrearm_start -1 ; + +if (unlikely (rxq->rxrearm_start >= rxq->nb_rx_desc)) { + rxq->rxrearm_start =0 ; + rx_id = rxq->nb_rx_desc -1 ; + } + + rxq->rxrearm_nb -= nb_mbufs; + +rte_io_wmb (); +/* Update the tail pointer on the NIC */ +I40E_PCI_REG_WRITE_RELAXED (rxq->qrx_tail, rx_id); } + +uint16_t +i40e_recycle_tx_mbufs_reuse_vec (void *tx_queue, +struct rte_eth_recycle_rxq_info *recycle_rxq_info) { +struct i40e_tx_queue *txq = tx_queue;Quoted 8 lines
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +8
-0+struct i40e_tx_entry *txep; +struct rte_mbuf **rxep; +int i, n; +uint16_t nb_recycle_mbufs; +uint16_t avail =0 ; +uint16_t mbuf_ring_size = recycle_rxq_info->mbuf_ring_size; +uint16_t mask = recycle_rxq_info->mbuf_ring_size -1 ; + uint16_t refill_requirement = recycle_rxq_info-
refill_requirement;Quoted 9 lines
Quoted 9 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 9 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +9
-0+uint16_t refill_head = *recycle_rxq_info->refill_head; +uint16_t receive_tail = *recycle_rxq_info->receive_tail; + +/* Get available recycling Rx buffers. */ + avail = (mbuf_ring_size - (refill_head - receive_tail)) & +mask; + +/* Check Tx free thresh and Rx available space. */ + if (txq->nb_tx_free > txq->tx_free_thresh || avail <= txq-
tx_rs_thresh)Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +5
-0+return 0 ; + +/* check DD bits on threshold descriptor */ + if ((txq->tx_ring[txq->tx_next_dd].cmd_type_offset_bsz & +rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) !=Quoted 8 lines
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 8 lines
+
rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE))drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +6
-0+return 0 ; + + n = txq->tx_rs_thresh; + nb_recycle_mbufs = n; + +/* Mbufs recycle mode can only support no ring buffer wrapping
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 5 lines
around.
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +4
-0+* Two case for this: +* +* case 1: The refill head of Rx buffer ring needs to be +aligned with
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 5 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +5
-0+* mbuf ring size. In this case, the number of Tx freeing buffers +* should be equal to refill_requirement. +* +* case 2: The refill head of Rx ring buffer does not need +to be aligned
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +2
-0+ * with mbuf ring size. In this case, the update of refill +headcan not
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +4
-0+* exceed the Rx mbuf ring size. +*/ + if (refill_requirement != n || + (!refill_requirement && (refill_head + n >
mbuf_ring_size)))Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 11 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +11
-0+return 0 ; + +/* First buffer to free from S/W ring is at index +* tx_next_dd - (tx_rs_thresh-1). +*/ + txep = &txq->sw_ring[txq->tx_next_dd - (n -1 )]; + rxep = recycle_rxq_info->mbuf_ring; + rxep += refill_head; + +if (txq->offloads &RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE ) { +/* Avoid txq contains buffers from unexpected mempool. */
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 10 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +10
-0+if (unlikely (recycle_rxq_info->mp + != txep[0 ].mbuf->pool)) +return 0 ; + +/* Directly put mbufs from Tx to Rx. */ +for (i =0 ; i < n; i++) + rxep[i] = txep[i].mbuf; + }else { +for (i =0 ; i < n; i++) { + rxep[i] =
rte_pktmbuf_prefree_seg(txep[i].mbuf);Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +2
-0+ +/* If Tx buffers are not the last reference or from
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +1
-0+* unexpected mempool, previous copied buffers are
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 3 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +3
-0+* considered as invalid. +*/ + if (unlikely((rxep[i] == NULL &&
refill_requirement) ||Quoted 46 lines
Quoted 46 lines
Quoted 8 lines
[Konstantin]
Could you pls remind me why it is ok to have rxep[i]==NULL whenrefill_requirementis not set?If
reill_requirementis not zero, it means each tx freed buffer must be valid and can be put into Rxsw_ring. Then the refill head of Rx buffer ring can be aligned with mbuf ring size. Briefly speaking the numberof Tx valid freed buffer must be equal to Rx
refill_requirement. For example, i40e driver.Quoted 5 lines
If
reill_requirementis zero, it means that the refill head of Rx buffer ring does not need to be aligned with mbuf ring size, thus if Tx have n valid freed buffers, we just need to put these n buffers into Rx sw-ring, and not to be equal to the Rx setting rearm number. For example, mlx5 driver.
Quoted 3 lines
In conclusion, above difference is due to pmd drivers have different
strategies to update their Rx rearm(refill) head.
Quoted 2 lines
For i40e driver, if
rearm_headexceed 1024, it will be set as 0 due to thenumber of each rearm is a fixed value by default.
Quoted 2 lines
For mlx5 driver. Its
rearm_headcan exceed 1024, and use mask to achievereal index. Thus its rearm number can be a different value.
Ok, but if
rte_pktmbuf_prefree_seg(txep[i].mbuf), it means that this mbuf is not free yet and can't be reused. Shouldn't we then setnb_recycle_mbufs= 0 in that case too? Or probably would be enough to skip that mbuf?
Might be something like that:for (i = 0, j = 0; i < n; i++) {
rxep[j] = rte_pktmbuf_prefree_seg(txep[i].mbuf); if (rxep[j] == NULL || recycle_rxq_info->mp != rxep[j].mbuf->pool)) { if (refill_requirement) { nb_recycle_mbufs = 0; break; } } else j++; }Quoted 6 lines
Quoted 6 lines
/* now j contains actual number of recycled mbufs */
?
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +1
-0+ recycle_rxq_info->mp !=txep[i].mbuf-
Quoted 18 lines
Quoted 11 lines
Quoted 11 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 11 lines
Quoted 1 line
pool))
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +10
-0+ nb_recycle_mbufs =0 ; + } +/* If Tx buffers are not the last reference or +* from unexpected mempool, all recycled buffers +* are put into mempool. +*/ +if (nb_recycle_mbufs ==0 ) +for (i =0 ; i < n; i++) { +if (rxep[i] !=NULL ) + rte_mempool_put(rxep[i]-pool,
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 4 lines
rxep[i]);
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +3
-0+ } + } +[Konstantin] After another thought, it might be easier and cleaner just to:
if (rxep[j] == NULL ||recycle_rxq_info->mp!= rxep[j].mbuf->pool)Quoted 7 lines
nb_recycle_mbufs = 0;Anyway, from my understanding - if
rte_pktmbuf_prefree_seg(mbuf)returns NULL, then we can't recycle that mbuf.[Feifei] Agree with that '
rte_pktmbuf_prefree_seg(mbuf)returns NULL, thenwe can't recycle that mbuf'.
Quoted 3 lines
Firstly, we should know for i40e driver, the number of free mbufs is fixed, it
must equal to '
tx_rs_thresh'Quoted 2 lines
This means if we start to free Tx mbufs, it cannot be interrupted until the
given amount of mbufs are freed.
Quoted 3 lines
In the meanwhile, doing prefree operation for a Tx mbuf can be looked at this mbuf is freed from this TX sw-ring if the API returns NULL. This is due
to that call '
prefree_seg' function means update the mbuf refcnt.Quoted 4 lines
So let's come back our recycle mbuf case.
Here we consider that the case if we have 32 mbufs need to be freed, andwe firstly do the pre-free.
Quoted 2 lines
And then first 8 mbufs is good and return value is not none. But the 9th
mbuf is bad, its refcnt is more than 1.
Quoted 2 lines
So we just update its refcnt and cannot put it into Rx sw-ring. For Tx sw-ring,
this mbuf has been freed.
Quoted 6 lines
Then we should continue to do pre-free operation for the next Tx mbufs to ensure the given amount of mbufs are freed.
Do a conclusion for this, this is because if we start to do pre-free operation, the Tx mbuf refcnt value maybe changed, so we cannot stop or
break until finish all the pre-free operation.
Quoted 4 lines
Finally, in the case that Rx
refill_requestis not zero, but the valid mbuf amount is less than this value, we must put back this Tx mbufs intoQuoted 8 lines
Quoted 8 lines
mempool.
Quoted 3 lines
Above is the reason why I do not directly jump out of the loop if some mbuf
return value is NULL.
Yep, I already realized that it is a bit more complicated and we need to continue with
prefree()for all packets even when we get NULL inthe middle.
Quoted 13 lines
Quoted 2 lines
Anyway the code has to be changed, right?
Sorry, I think for the code, it is unnecessary to be changed. For no fast free path, currently:
1. We check whether each mbuf is Ok and callpre_freefunction
----------------------------------------------------------------------
--------------------------------------------------------------
2.1 For the mbuf return value is not NULL, it is put into Rx sw-ring. 2.2 For the mbuf return value is zero and refill-request, it will also firstly put into Rx sw-ring, and we setnb_recycle= 0
----------------------------------------------------------------------
--------------------------------------------------------------
3.1 We checknb_recycle, if it is not 0, we will continue to rearm Rx descsand update its index by call
descs_refillfunction.Quoted 6 lines
3.2 if
nb_recycleis 0, we will put valid recycle mbufs back into mempool as general path. This is necessary, because we need to ensure the freed Tx number is fixed.(Some buffers return is null can be seen as freed, others need to be put into mempool)Or maybe I ignore something?
I am talking about the case when both
refill_requirementand mbuf return values iare zero:
if (unlikely((rxep[i] == NULL &&refill_requirement) || // ??? rxep[i] == 0
ANDrefill_requirement== 0 ???
recycle_rxq_info->mp!= txep[i].mbuf->pool))
Quoted 5 lines
nb_recycle_mbufs = 0;As I can read the code you treat such situation as valid, while I think we should reset
nb_recycle_mbufsto zero when rxep[i] == NULL, no matter what valuerefill_requirementis.
So this means for maybe MLX5 driver, its refill_request = 0. And if some mbufs return value is zero, the other mbufs can not be recycled into Rx sw-ring? Because nb_recycle=0, and they need to be put into mempool.
I think for such as MLX5 driver, we can allow recycle some valid mbufs into Rx ring. Because no constraint for its refill number. Is my suggestion reasonable?
Quoted 146 lines
.
Quoted 43 lines
Quoted 43 lines
Quoted 20 lines
Quoted 3 lines
Quoted 3 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 3 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +2
-0+/* Update counters for Tx. */ + txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + txq-
tx_rs_thresh);Quoted 1 line
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +1
-0+ txq->tx_next_dd = (uint16_t)(txq->tx_next_dd + txq-
tx_rs_thresh);Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +5
-0+if (txq->tx_next_dd >= txq->nb_tx_desc) + txq->tx_next_dd = (uint16_t )(txq->tx_rs_thresh -1 ); + +return nb_recycle_mbufs; +}(quoted diff) +0
-0
b/drivers/net/i40e/i40e_rxtx.cindexb4f65b58fa..a9c9eb331c100644drivers/net/i40e/i40e_rxtx.c +0
-0@@ -3199,6 +3199,30 @@ i40e_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, qinfo->conf.offloads = txq->offloads; }Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/i40e/i40e_rxtx.c i40e_txq_info_get(struct rte_eth_dev · line 3203
Quoted 2 lines
drivers/net/i40e/i40e_rxtx.c +2
-0+void +i40e_recycle_rxq_info_get(struct rte_eth_dev *dev, uint16_t
queue_id,Quoted 20 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_rxtx.c i40e_txq_info_get(struct rte_eth_dev · line 3207
Quoted 4 lines
drivers/net/i40e/i40e_rxtx.c +4
-0+ struct rte_eth_recycle_rxq_info *recycle_rxq_info) { +struct i40e_rx_queue *rxq; +struct i40e_adapter *ad = + I40E_DEV_PRIVATE_TO_ADAPTER(dev->data-
dev_private);Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/i40e/i40e_rxtx.c +6
-0+ + rxq = dev->data->rx_queues[queue_id]; + + recycle_rxq_info->mbuf_ring = (void *)rxq->sw_ring; + recycle_rxq_info->mp = rxq->mp; + recycle_rxq_info->mbuf_ring_size = rxq->nb_rx_desc;Quoted 8 lines
Quoted 8 lines
drivers/net/i40e/i40e_rxtx.c i40e_txq_info_get(struct rte_eth_dev · line 3221
Quoted 8 lines
drivers/net/i40e/i40e_rxtx.c +7
-0+ recycle_rxq_info->receive_tail = &rxq->rx_tail; + +if (ad->rx_vec_allowed) { + recycle_rxq_info->refill_requirement =RTE_I40E_RXQ_REARM_THRESH ; + recycle_rxq_info->refill_head = &rxq->rxrearm_start; + }else { + recycle_rxq_info->refill_requirement = rxq-
rx_free_thresh;Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/net/i40e/i40e_rxtx.c i40e_txq_info_get(struct rte_eth_dev
Quoted 7 lines
drivers/net/i40e/i40e_rxtx.c +4
-0+ recycle_rxq_info->refill_head = &rxq->rx_free_trigger; + } +} +#ifdef RTE_ARCH_X86 static inline bool get_avx_supported(bool request_avx512) @@ -3293,6 +3317,8@@
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
i40e_set_rx_function(struct rte_eth_dev *dev)
dev->rx_pkt_burst= ad-
rx_use_avx2?Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
i40e_recv_scattered_pkts_vec_avx2 :Quoted 16 lines
Quoted 10 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/net/i40e/i40e_rxtx.c
Quoted 3 lines
drivers/net/i40e/i40e_rxtx.c +2
-0i40e_recv_scattered_pkts_vec ; + dev->recycle_rx_descriptors_refill = +i40e_recycle_rx_descriptors_refill_vec;Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_rxtx.c i40e_set_rx_function(struct rte_eth_dev
Quoted 4 lines
drivers/net/i40e/i40e_rxtx.c +0
-0} }else {if (ad->rx_use_avx512) {@@ -3311,9 +3337,12 @@ i40e_set_rx_function(struct rte_eth_dev*dev)
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/i40e/i40e_rxtx.c +0
-0dev->rx_pkt_burst = ad-
rx_use_avx2?Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_rxtx.c i40e_set_rx_function(struct rte_eth_dev · line 3341
Quoted 4 lines
drivers/net/i40e/i40e_rxtx.c +2
-0i40e_recv_pkts_vec_avx2 : i40e_recv_pkts_vec; + dev->recycle_rx_descriptors_refill = +i40e_recycle_rx_descriptors_refill_vec;Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/net/i40e/i40e_rxtx.c i40e_set_rx_function(struct rte_eth_dev
Quoted 8 lines
drivers/net/i40e/i40e_rxtx.c +2
-0} }#else /* RTE_ARCH_X86 */ + dev->recycle_rx_descriptors_refill = +i40e_recycle_rx_descriptors_refill_vec;if (dev->data->scattered_rx) { PMD_INIT_LOG(DEBUG, "Using Vector Scattered Rx(port %d).", @@
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
-3481,15 +3510,18 @@ i40e_set_tx_function(struct
rte_eth_dev*dev)
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
dev->tx_pkt_burst= ad-
tx_use_avx2?Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
i40e_xmit_pkts_vec_avx2:Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
i40e_xmit_pkts_vec;Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/i40e/i40e_rxtx.c
Quoted 5 lines
drivers/net/i40e/i40e_rxtx.c +1
-0+ dev->recycle_tx_mbufs_reuse =
i40e_recycle_tx_mbufs_reuse_vec;drivers/net/i40e/i40e_rxtx.c +0
-0}#else /* RTE_ARCH_X86 */ PMD_INIT_LOG(DEBUG, "Using Vector Tx(port %d).",
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/i40e/i40e_rxtx.c
Quoted 6 lines
drivers/net/i40e/i40e_rxtx.c +1
-0dev->data->port_id); dev->tx_pkt_burst = i40e_xmit_pkts_vec; + dev->recycle_tx_mbufs_reuse =
i40e_recycle_tx_mbufs_reuse_vec; #endif /*RTE_ARCH_X86*/drivers/net/i40e/i40e_rxtx.c +0
-0}else { PMD_INIT_LOG(DEBUG, "Simple tx finally beused.");
Quoted 41 lines
Quoted 41 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
drivers/net/i40e/i40e_rxtx.c +1
-0dev->tx_pkt_burst = i40e_xmit_pkts_simple; + dev->recycle_tx_mbufs_reuse =
i40e_recycle_tx_mbufs_reuse_vec;drivers/net/i40e/i40e_rxtx.c +0
-0} dev->tx_pkt_prepare = i40e_simple_prep_pkts; }else {(quoted diff) +0
-0
b/drivers/net/i40e/i40e_rxtx.hindexa8686224e5..b191f23e1f100644drivers/net/i40e/i40e_rxtx.h +0
-0@@ -236,6 +236,10 @@ uint32_t i40e_dev_rx_queue_count(void *rx_queue); int i40e_dev_rx_descriptor_status(void *rx_queue,
uint16_toffset); inti40e_dev_tx_descriptor_status(void *tx_queue, uint16_t offset);Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/i40e/i40e_rxtx.h
Quoted 2 lines
drivers/net/i40e/i40e_rxtx.h +2
-0+uint16_t i40e_recycle_tx_mbufs_reuse_vec (void *tx_queue, +struct rte_eth_recycle_rxq_info *recycle_rxq_info);void
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_rxtx.h
Quoted 4 lines
drivers/net/i40e/i40e_rxtx.h +3
-0+i40e_recycle_rx_descriptors_refill_vec (void *rx_queue, uint16_t +nb_mbufs); + uint16_t i40e_recv_pkts_vec(void *rx_queue, struct rte_mbuf**rx_pkts,
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
uint16_tnb_pkts);
uint16_ti40e_recv_scattered_pkts_vec(void*rx_queue, diff
--git a/drivers/net/i40e/meson.build b/drivers/net/i40e/meson.build index8e53b87a65..3b1a233c84100644drivers/net/i40e/meson.build +1
-1@@ -34,6 +34,7 @@ sources = files( 'i40e_tm.c', 'i40e_hash.c', 'i40e_vf_representor.c', + 'i40e_recycle_mbufs_vec_common.c', 'rte_pmd_i40e.c', ) --2.25.1
RE: [PATCH v11 2/4] net/i40e: implement mbufs recycle mode
Quoted 368 lines
Quoted 362 lines
Quoted 326 lines
Quoted 326 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Define specific function implementation for i40e driver. Currently, mbufs recycle mode can support 128bit vector path and
avx2Quoted 8 lines
Quoted 8 lines
path.
Quoted 7 lines
Quoted 7 lines
And can be enabled both in fast free and no fast free mode.
Suggested-by: Honnappa Nagarahalli
<[email protected]>Signed-off-by Feifei Wang <[email protected]>Reviewed-by Ruifeng Wang <[email protected]>Reviewed-by Honnappa NagarahalliQuoted 41 lines
Quoted 41 lines
Quoted 11 lines
Quoted 11 lines
--- drivers/net/i40e/i40e_ethdev.c | 1 + drivers/net/i40e/i40e_ethdev.h | 2 + .../net/i40e/i40e_recycle_mbufs_vec_common.c | 147 ++++++++++++++++++ drivers/net/i40e/i40e_rxtx.c | 32 ++++ drivers/net/i40e/i40e_rxtx.h | 4 + drivers/net/i40e/meson.build | 1 + 6 files changed, 187 insertions(+) create mode 100644
drivers/net/i40e/i40e_recycle_mbufs_vec_common.cQuoted 8 lines
Quoted 8 lines
(quoted diff) +0
-0
b/drivers/net/i40e/i40e_ethdev.cindex8271bbb394..50ba9aac94
100644drivers/net/i40e/i40e_ethdev.c +0
-0@@ -496,6 +496,7 @@ static const struct eth_dev_ops
i40e_eth_dev_ops= {
Quoted 12 lines
Quoted 12 lines
drivers/net/i40e/i40e_ethdev.c +1
-0.flow_ops_get = i40e_dev_flow_ops_get, .rxq_info_get = i40e_rxq_info_get, .txq_info_get = i40e_txq_info_get, + .recycle_rxq_info_get = i40e_recycle_rxq_info_get, .rx_burst_mode_get = i40e_rx_burst_mode_get, .tx_burst_mode_get = i40e_tx_burst_mode_get, .timesync_enable = i40e_timesync_enable,(quoted diff) +0
-0
b/drivers/net/i40e/i40e_ethdev.hindex6f65d5e0ac..af758798e1
100644
---a/drivers/net/i40e/i40e_ethdev.hQuoted 8 lines
Review void i40e_rxq_info_get(struct · line 1360
Quoted 8 lines
+++
b/drivers/net/i40e/i40e_ethdev.h(quoted diff) +2
-0@@ -1355,6 +1355,8 @@ void i40e_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, struct rte_eth_rxq_info *qinfo); void i40e_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, struct rte_eth_txq_info *qinfo); +void i40e_recycle_rxq_info_get(struct rte_eth_dev *dev, +uint16_t
queue_id,Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
(quoted diff) +1
-0+ struct rte_eth_recycle_rxq_info *recycle_rxq_info); int i40e_rx_burst_mode_get(struct rte_eth_dev *dev,
uint16_t
queue_id,Quoted 87 lines
Quoted 68 lines
Quoted 68 lines
Quoted 68 lines
struct
rte_eth_burst_mode*mode); int
i40e_tx_burst_mode_get(structrte_eth_dev*dev,uint16_tqueue_id, diff -- gita/drivers/net/i40e/i40e_recycle_mbufs_vec_common.cb/drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
new file mode 100644
index 0000000000..5663ecccdedrivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +32
-0@@ -0,0 +1,147 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2023 Arm Limited. +*/ + +#include <stdint.h> +#include <ethdev_driver.h> + +#include "base/i40e_prototype.h" +#include "base/i40e_type.h" +#include "i40e_ethdev.h" +#include "i40e_rxtx.h" + +#pragma GCC diagnostic ignored "-Wcast-qual" + +void +i40e_recycle_rx_descriptors_refill_vec (void *rx_queue, +uint16_t +nb_mbufs) { +struct i40e_rx_queue *rxq = rx_queue; +struct i40e_rx_entry *rxep; +volatile union i40e_rx_desc *rxdp; +uint16_t rx_id; +uint64_t paddr; +uint64_t dma_addr; +uint16_t i; + + rxdp = rxq->rx_ring + rxq->rxrearm_start; + rxep = &rxq->sw_ring[rxq->rxrearm_start]; + +for (i =0 ; i < nb_mbufs; i++) { +/* Initialize rxdp descs. */ + paddr = (rxep[i].mbuf)->buf_iova +
RTE_PKTMBUF_HEADROOM;drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +25
-0+ dma_addr =rte_cpu_to_le_64 (paddr); +/* flush desc with pa dma_addr */ + rxdp[i].read.hdr_addr =0 ; + rxdp[i].read.pkt_addr = dma_addr; + } + +/* Update the descriptor initializer index */ + rxq->rxrearm_start += nb_mbufs; + rx_id = rxq->rxrearm_start -1 ; + +if (unlikely (rxq->rxrearm_start >= rxq->nb_rx_desc)) { + rxq->rxrearm_start =0 ; + rx_id = rxq->nb_rx_desc -1 ; + } + + rxq->rxrearm_nb -= nb_mbufs; + +rte_io_wmb (); +/* Update the tail pointer on the NIC */ +I40E_PCI_REG_WRITE_RELAXED (rxq->qrx_tail, rx_id); } + +uint16_t +i40e_recycle_tx_mbufs_reuse_vec (void *tx_queue, +struct rte_eth_recycle_rxq_info *recycle_rxq_info) { +struct i40e_tx_queue *txq = tx_queue;Quoted 8 lines
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +8
-0+struct i40e_tx_entry *txep; +struct rte_mbuf **rxep; +int i, n; +uint16_t nb_recycle_mbufs; +uint16_t avail =0 ; +uint16_t mbuf_ring_size = recycle_rxq_info->mbuf_ring_size; +uint16_t mask = recycle_rxq_info->mbuf_ring_size -1 ; + uint16_t refill_requirement = recycle_rxq_info-
refill_requirement;Quoted 9 lines
Quoted 9 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 9 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +9
-0+uint16_t refill_head = *recycle_rxq_info->refill_head; +uint16_t receive_tail = *recycle_rxq_info->receive_tail; + +/* Get available recycling Rx buffers. */ + avail = (mbuf_ring_size - (refill_head - receive_tail)) & +mask; + +/* Check Tx free thresh and Rx available space. */ + if (txq->nb_tx_free > txq->tx_free_thresh || avail <= txq-
tx_rs_thresh)Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +5
-0+return 0 ; + +/* check DD bits on threshold descriptor */ + if ((txq->tx_ring[txq->tx_next_dd].cmd_type_offset_bsz & +rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) !=Quoted 8 lines
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 8 lines
+
rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE))drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +6
-0+return 0 ; + + n = txq->tx_rs_thresh; + nb_recycle_mbufs = n; + +/* Mbufs recycle mode can only support no ring buffer wrapping
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 5 lines
around.
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +4
-0+* Two case for this: +* +* case 1: The refill head of Rx buffer ring needs to be +aligned with
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 5 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +5
-0+* mbuf ring size. In this case, the number of Tx freeing buffers +* should be equal to refill_requirement. +* +* case 2: The refill head of Rx ring buffer does not need +to be aligned
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +2
-0+ * with mbuf ring size. In this case, the update of refill +headcan not
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +4
-0+* exceed the Rx mbuf ring size. +*/ + if (refill_requirement != n || + (!refill_requirement && (refill_head + n >
mbuf_ring_size)))Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 11 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +11
-0+return 0 ; + +/* First buffer to free from S/W ring is at index +* tx_next_dd - (tx_rs_thresh-1). +*/ + txep = &txq->sw_ring[txq->tx_next_dd - (n -1 )]; + rxep = recycle_rxq_info->mbuf_ring; + rxep += refill_head; + +if (txq->offloads &RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE ) { +/* Avoid txq contains buffers from unexpected mempool. */
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 10 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +10
-0+if (unlikely (recycle_rxq_info->mp + != txep[0 ].mbuf->pool)) +return 0 ; + +/* Directly put mbufs from Tx to Rx. */ +for (i =0 ; i < n; i++) + rxep[i] = txep[i].mbuf; + }else { +for (i =0 ; i < n; i++) { + rxep[i] =
rte_pktmbuf_prefree_seg(txep[i].mbuf);Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +2
-0+ +/* If Tx buffers are not the last reference or from
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +1
-0+* unexpected mempool, previous copied buffers are
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 3 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +3
-0+* considered as invalid. +*/ + if (unlikely((rxep[i] == NULL &&
refill_requirement) ||Quoted 46 lines
Quoted 46 lines
Quoted 8 lines
[Konstantin]
Could you pls remind me why it is ok to have rxep[i]==NULL whenrefill_requirementis not set?If
reill_requirementis not zero, it means each tx freed buffer must be valid and can be put into Rxsw_ring. Then the refill head of Rx buffer ring can be aligned with mbuf ring size. Briefly speaking the numberof Tx valid freed buffer must be equal to Rx
refill_requirement. For example, i40e driver.Quoted 5 lines
If
reill_requirementis zero, it means that the refill head of Rx buffer ring does not need to be aligned with mbuf ring size, thus if Tx have n valid freed buffers, we just need to put these n buffers into Rx sw-ring, and not to be equal to the Rx setting rearm number. For example, mlx5 driver.
Quoted 3 lines
In conclusion, above difference is due to pmd drivers have different
strategies to update their Rx rearm(refill) head.
Quoted 2 lines
For i40e driver, if
rearm_headexceed 1024, it will be set as 0 due to thenumber of each rearm is a fixed value by default.
Quoted 2 lines
For mlx5 driver. Its
rearm_headcan exceed 1024, and use mask to achievereal index. Thus its rearm number can be a different value.
Ok, but if
rte_pktmbuf_prefree_seg(txep[i].mbuf), it means that this mbuf is not free yet and can't be reused. Shouldn't we then setnb_recycle_mbufs= 0 in that case too? Or probably would be enough to skip that mbuf?
Might be something like that:for (i = 0, j = 0; i < n; i++) {
rxep[j] = rte_pktmbuf_prefree_seg(txep[i].mbuf); if (rxep[j] == NULL || recycle_rxq_info->mp != rxep[j].mbuf->pool)) { if (refill_requirement) { nb_recycle_mbufs = 0; break; } } else j++; }Quoted 6 lines
Quoted 6 lines
/* now j contains actual number of recycled mbufs */
?
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +1
-0+ recycle_rxq_info->mp !=txep[i].mbuf-
Quoted 18 lines
Quoted 11 lines
Quoted 11 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 11 lines
Quoted 1 line
pool))
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +10
-0+ nb_recycle_mbufs =0 ; + } +/* If Tx buffers are not the last reference or +* from unexpected mempool, all recycled buffers +* are put into mempool. +*/ +if (nb_recycle_mbufs ==0 ) +for (i =0 ; i < n; i++) { +if (rxep[i] !=NULL ) + rte_mempool_put(rxep[i]-pool,
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 4 lines
rxep[i]);
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +3
-0+ } + } +[Konstantin] After another thought, it might be easier and cleaner just to:
if (rxep[j] == NULL ||recycle_rxq_info->mp!= rxep[j].mbuf->pool)Quoted 7 lines
nb_recycle_mbufs = 0;Anyway, from my understanding - if
rte_pktmbuf_prefree_seg(mbuf)returns NULL, then we can't recycle that mbuf.[Feifei] Agree with that '
rte_pktmbuf_prefree_seg(mbuf)returns NULL, thenwe can't recycle that mbuf'.
Quoted 3 lines
Firstly, we should know for i40e driver, the number of free mbufs is fixed, it
must equal to '
tx_rs_thresh'Quoted 2 lines
This means if we start to free Tx mbufs, it cannot be interrupted until the
given amount of mbufs are freed.
Quoted 3 lines
In the meanwhile, doing prefree operation for a Tx mbuf can be looked at this mbuf is freed from this TX sw-ring if the API returns NULL. This is due
to that call '
prefree_seg' function means update the mbuf refcnt.Quoted 4 lines
So let's come back our recycle mbuf case.
Here we consider that the case if we have 32 mbufs need to be freed, andwe firstly do the pre-free.
Quoted 2 lines
And then first 8 mbufs is good and return value is not none. But the 9th
mbuf is bad, its refcnt is more than 1.
Quoted 2 lines
So we just update its refcnt and cannot put it into Rx sw-ring. For Tx sw-ring,
this mbuf has been freed.
Quoted 6 lines
Then we should continue to do pre-free operation for the next Tx mbufs to ensure the given amount of mbufs are freed.
Do a conclusion for this, this is because if we start to do pre-free operation, the Tx mbuf refcnt value maybe changed, so we cannot stop or
break until finish all the pre-free operation.
Quoted 4 lines
Finally, in the case that Rx
refill_requestis not zero, but the valid mbuf amount is less than this value, we must put back this Tx mbufs intoQuoted 8 lines
Quoted 8 lines
mempool.
Quoted 3 lines
Above is the reason why I do not directly jump out of the loop if some mbuf
return value is NULL.
Yep, I already realized that it is a bit more complicated and we need to continue with
prefree()for all packets even when we get NULL inthe middle.
Quoted 13 lines
Quoted 2 lines
Anyway the code has to be changed, right?
Sorry, I think for the code, it is unnecessary to be changed. For no fast free path, currently:
1. We check whether each mbuf is Ok and callpre_freefunction
----------------------------------------------------------------------
--------------------------------------------------------------
2.1 For the mbuf return value is not NULL, it is put into Rx sw-ring. 2.2 For the mbuf return value is zero and refill-request, it will also firstly put into Rx sw-ring, and we setnb_recycle= 0
----------------------------------------------------------------------
--------------------------------------------------------------
3.1 We checknb_recycle, if it is not 0, we will continue to rearm Rx descsand update its index by call
descs_refillfunction.Quoted 6 lines
3.2 if
nb_recycleis 0, we will put valid recycle mbufs back into mempool as general path. This is necessary, because we need to ensure the freed Tx number is fixed.(Some buffers return is null can be seen as freed, others need to be put into mempool)Or maybe I ignore something?
I am talking about the case when both
refill_requirementand mbuf return values iare zero:
if (unlikely((rxep[i] == NULL &&refill_requirement) || // ??? rxep[i] == 0
ANDrefill_requirement== 0 ???
recycle_rxq_info->mp!= txep[i].mbuf->pool))Quoted 5 lines
nb_recycle_mbufs = 0;As I can read the code you treat such situation as valid, while I think we should reset
nb_recycle_mbufsto zero when rxep[i] == NULL, no matter what valuerefill_requirementis.
Quoted 6 lines
So this means for maybe MLX5 driver, its
refill_request= 0. And if some mbufs return value is zero, the other mbufs can not be recycled into Rx sw-ring? Because nb_recycle=0, and they need to be put into mempool.I think for such as MLX5 driver, we can allow recycle some valid mbufs into Rx ring. Because no constraint for its refill number. Is my suggestion reasonable?
I suppose yes: if refill_request is zero we potentially can skip 'bad' mbufs and continue with recycling for remaining ones.
It would probably require more changes in current code, but sounds ok to me in general.
Quoted 145 lines
Quoted 145 lines
Quoted 45 lines
Quoted 45 lines
Quoted 22 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 5 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +2
-0+/* Update counters for Tx. */ + txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + txq-
tx_rs_thresh);Quoted 1 line
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +1
-0+ txq->tx_next_dd = (uint16_t)(txq->tx_next_dd + txq-
tx_rs_thresh);Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +5
-0+if (txq->tx_next_dd >= txq->nb_tx_desc) + txq->tx_next_dd = (uint16_t )(txq->tx_rs_thresh -1 ); + +return nb_recycle_mbufs; +}(quoted diff) +0
-0
b/drivers/net/i40e/i40e_rxtx.cindexb4f65b58fa..a9c9eb331c100644drivers/net/i40e/i40e_rxtx.c +0
-0@@ -3199,6 +3199,30 @@ i40e_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, qinfo->conf.offloads = txq->offloads; }Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/i40e/i40e_rxtx.c i40e_txq_info_get(struct rte_eth_dev · line 3203
Quoted 2 lines
drivers/net/i40e/i40e_rxtx.c +2
-0+void +i40e_recycle_rxq_info_get(struct rte_eth_dev *dev, uint16_t
queue_id,Quoted 20 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_rxtx.c i40e_txq_info_get(struct rte_eth_dev · line 3207
Quoted 4 lines
drivers/net/i40e/i40e_rxtx.c +4
-0+ struct rte_eth_recycle_rxq_info *recycle_rxq_info) { +struct i40e_rx_queue *rxq; +struct i40e_adapter *ad = + I40E_DEV_PRIVATE_TO_ADAPTER(dev->data-
dev_private);Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/i40e/i40e_rxtx.c +6
-0+ + rxq = dev->data->rx_queues[queue_id]; + + recycle_rxq_info->mbuf_ring = (void *)rxq->sw_ring; + recycle_rxq_info->mp = rxq->mp; + recycle_rxq_info->mbuf_ring_size = rxq->nb_rx_desc;Quoted 8 lines
Quoted 8 lines
drivers/net/i40e/i40e_rxtx.c i40e_txq_info_get(struct rte_eth_dev · line 3221
Quoted 8 lines
drivers/net/i40e/i40e_rxtx.c +7
-0+ recycle_rxq_info->receive_tail = &rxq->rx_tail; + +if (ad->rx_vec_allowed) { + recycle_rxq_info->refill_requirement =RTE_I40E_RXQ_REARM_THRESH ; + recycle_rxq_info->refill_head = &rxq->rxrearm_start; + }else { + recycle_rxq_info->refill_requirement = rxq-
rx_free_thresh;Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/net/i40e/i40e_rxtx.c i40e_txq_info_get(struct rte_eth_dev
Quoted 7 lines
drivers/net/i40e/i40e_rxtx.c +4
-0+ recycle_rxq_info->refill_head = &rxq->rx_free_trigger; + } +} +#ifdef RTE_ARCH_X86 static inline bool get_avx_supported(bool request_avx512) @@ -3293,6 +3317,8@@
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
i40e_set_rx_function(struct rte_eth_dev *dev)
dev->rx_pkt_burst= ad-
rx_use_avx2?Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
i40e_recv_scattered_pkts_vec_avx2 :Quoted 16 lines
Quoted 10 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/net/i40e/i40e_rxtx.c
Quoted 3 lines
drivers/net/i40e/i40e_rxtx.c +2
-0i40e_recv_scattered_pkts_vec ; + dev->recycle_rx_descriptors_refill = +i40e_recycle_rx_descriptors_refill_vec;Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_rxtx.c i40e_set_rx_function(struct rte_eth_dev
Quoted 4 lines
drivers/net/i40e/i40e_rxtx.c +0
-0} }else {if (ad->rx_use_avx512) {@@ -3311,9 +3337,12 @@ i40e_set_rx_function(struct rte_eth_dev*dev)
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/i40e/i40e_rxtx.c +0
-0dev->rx_pkt_burst = ad-
rx_use_avx2?Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_rxtx.c i40e_set_rx_function(struct rte_eth_dev · line 3341
Quoted 4 lines
drivers/net/i40e/i40e_rxtx.c +2
-0i40e_recv_pkts_vec_avx2 : i40e_recv_pkts_vec; + dev->recycle_rx_descriptors_refill = +i40e_recycle_rx_descriptors_refill_vec;Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/net/i40e/i40e_rxtx.c i40e_set_rx_function(struct rte_eth_dev
Quoted 8 lines
drivers/net/i40e/i40e_rxtx.c +2
-0} }#else /* RTE_ARCH_X86 */ + dev->recycle_rx_descriptors_refill = +i40e_recycle_rx_descriptors_refill_vec;if (dev->data->scattered_rx) { PMD_INIT_LOG(DEBUG, "Using Vector Scattered Rx(port %d).", @@
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
-3481,15 +3510,18 @@ i40e_set_tx_function(struct
rte_eth_dev*dev)
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
dev->tx_pkt_burst= ad-
tx_use_avx2?Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
i40e_xmit_pkts_vec_avx2:Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
i40e_xmit_pkts_vec;Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/i40e/i40e_rxtx.c
Quoted 5 lines
drivers/net/i40e/i40e_rxtx.c +1
-0+ dev->recycle_tx_mbufs_reuse =
i40e_recycle_tx_mbufs_reuse_vec;drivers/net/i40e/i40e_rxtx.c +0
-0}#else /* RTE_ARCH_X86 */ PMD_INIT_LOG(DEBUG, "Using Vector Tx(port %d).",
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/i40e/i40e_rxtx.c
Quoted 6 lines
drivers/net/i40e/i40e_rxtx.c +1
-0dev->data->port_id); dev->tx_pkt_burst = i40e_xmit_pkts_vec; + dev->recycle_tx_mbufs_reuse =
i40e_recycle_tx_mbufs_reuse_vec; #endif /*RTE_ARCH_X86*/drivers/net/i40e/i40e_rxtx.c +0
-0}else { PMD_INIT_LOG(DEBUG, "Simple tx finally beused.");
Quoted 41 lines
Quoted 41 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
drivers/net/i40e/i40e_rxtx.c +1
-0dev->tx_pkt_burst = i40e_xmit_pkts_simple; + dev->recycle_tx_mbufs_reuse =
i40e_recycle_tx_mbufs_reuse_vec;drivers/net/i40e/i40e_rxtx.c +0
-0} dev->tx_pkt_prepare = i40e_simple_prep_pkts; }else {(quoted diff) +0
-0
b/drivers/net/i40e/i40e_rxtx.hindexa8686224e5..b191f23e1f100644drivers/net/i40e/i40e_rxtx.h +0
-0@@ -236,6 +236,10 @@ uint32_t i40e_dev_rx_queue_count(void *rx_queue); int i40e_dev_rx_descriptor_status(void *rx_queue,
uint16_toffset); inti40e_dev_tx_descriptor_status(void *tx_queue, uint16_t offset);Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/i40e/i40e_rxtx.h
Quoted 2 lines
drivers/net/i40e/i40e_rxtx.h +2
-0+uint16_t i40e_recycle_tx_mbufs_reuse_vec (void *tx_queue, +struct rte_eth_recycle_rxq_info *recycle_rxq_info);void
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_rxtx.h
Quoted 4 lines
drivers/net/i40e/i40e_rxtx.h +3
-0+i40e_recycle_rx_descriptors_refill_vec (void *rx_queue, uint16_t +nb_mbufs); + uint16_t i40e_recv_pkts_vec(void *rx_queue, struct rte_mbuf**rx_pkts,
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
uint16_tnb_pkts);
uint16_ti40e_recv_scattered_pkts_vec(void*rx_queue, diff
--git a/drivers/net/i40e/meson.build b/drivers/net/i40e/meson.build index8e53b87a65..3b1a233c84100644drivers/net/i40e/meson.build +1
-1@@ -34,6 +34,7 @@ sources = files( 'i40e_tm.c', 'i40e_hash.c', 'i40e_vf_representor.c', + 'i40e_recycle_mbufs_vec_common.c', 'rte_pmd_i40e.c', ) --2.25.1
RE: [PATCH v11 2/4] net/i40e: implement mbufs recycle mode
Quoted 399 lines
-----Original Message-----
From: Konstantin Ananyev <[email protected]>
Sent: Monday, September 4, 2023 6:22 PM
To: Feifei Wang <[email protected]>; Konstantin Ananyev <[email protected]>
Cc: [email protected]; nd <[email protected]>; Honnappa Nagarahalli <[email protected]>; Ruifeng Wang <[email protected]>; Yuying Zhang <[email protected]>; Beilei Xing <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>
Subject: RE: [PATCH v11 2/4] net/i40e: implement mbufs recycle modeQuoted 250 lines
Quoted 250 lines
Quoted 250 lines
Quoted 250 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Define specific function implementation for i40e driver. Currently, mbufs recycle mode can support 128bit vector path and
avx2Quoted 8 lines
Quoted 8 lines
path.
Quoted 7 lines
Quoted 7 lines
And can be enabled both in fast free and no fast free mode.
Suggested-by: Honnappa Nagarahalli
<[email protected]>Signed-off-by Feifei Wang <[email protected]>Reviewed-by Ruifeng Wang <[email protected]>Reviewed-by Honnappa NagarahalliQuoted 41 lines
Quoted 41 lines
Quoted 11 lines
Quoted 11 lines
--- drivers/net/i40e/i40e_ethdev.c | 1 + drivers/net/i40e/i40e_ethdev.h | 2 + .../net/i40e/i40e_recycle_mbufs_vec_common.c | 147 ++++++++++++++++++ drivers/net/i40e/i40e_rxtx.c | 32 ++++ drivers/net/i40e/i40e_rxtx.h | 4 + drivers/net/i40e/meson.build | 1 + 6 files changed, 187 insertions(+) create mode 100644
drivers/net/i40e/i40e_recycle_mbufs_vec_common.cQuoted 8 lines
Quoted 8 lines
(quoted diff) +0
-0
b/drivers/net/i40e/i40e_ethdev.cindex8271bbb394..50ba9aac94
100644drivers/net/i40e/i40e_ethdev.c +0
-0@@ -496,6 +496,7 @@ static const struct eth_dev_ops
i40e_eth_dev_ops= {
Quoted 12 lines
Quoted 12 lines
drivers/net/i40e/i40e_ethdev.c +1
-0.flow_ops_get = i40e_dev_flow_ops_get, .rxq_info_get = i40e_rxq_info_get, .txq_info_get = i40e_txq_info_get, + .recycle_rxq_info_get = i40e_recycle_rxq_info_get, .rx_burst_mode_get = i40e_rx_burst_mode_get, .tx_burst_mode_get = i40e_tx_burst_mode_get, .timesync_enable = i40e_timesync_enable,(quoted diff) +0
-0
b/drivers/net/i40e/i40e_ethdev.hindex6f65d5e0ac..af758798e1
100644
---a/drivers/net/i40e/i40e_ethdev.hQuoted 8 lines
Review void i40e_rxq_info_get(struct · line 1360
Quoted 8 lines
+++
b/drivers/net/i40e/i40e_ethdev.h(quoted diff) +2
-0@@ -1355,6 +1355,8 @@ void i40e_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, struct rte_eth_rxq_info *qinfo); void i40e_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, struct rte_eth_txq_info *qinfo); +void i40e_recycle_rxq_info_get(struct rte_eth_dev *dev, +uint16_t
queue_id,Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
(quoted diff) +1
-0+ struct rte_eth_recycle_rxq_info *recycle_rxq_info); int i40e_rx_burst_mode_get(struct rte_eth_dev *dev,
uint16_t
queue_id,Quoted 89 lines
Quoted 68 lines
Quoted 68 lines
Quoted 68 lines
struct
rte_eth_burst_mode*mode); int
i40e_tx_burst_mode_get(structrte_eth_dev*dev,uint16_tqueue_id, diff -- gita/drivers/net/i40e/i40e_recycle_mbufs_vec_common.cb/drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
new file mode 100644
index 0000000000..5663ecccdedrivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +32
-0@@ -0,0 +1,147 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2023 Arm Limited. +*/ + +#include <stdint.h> +#include <ethdev_driver.h> + +#include "base/i40e_prototype.h" +#include "base/i40e_type.h" +#include "i40e_ethdev.h" +#include "i40e_rxtx.h" + +#pragma GCC diagnostic ignored "-Wcast-qual" + +void +i40e_recycle_rx_descriptors_refill_vec (void *rx_queue, +uint16_t +nb_mbufs) { +struct i40e_rx_queue *rxq = rx_queue; +struct i40e_rx_entry *rxep; +volatile union i40e_rx_desc *rxdp; +uint16_t rx_id; +uint64_t paddr; +uint64_t dma_addr; +uint16_t i; + + rxdp = rxq->rx_ring + rxq->rxrearm_start; + rxep = &rxq->sw_ring[rxq->rxrearm_start]; + +for (i =0 ; i < nb_mbufs; i++) { +/* Initialize rxdp descs. */ + paddr = (rxep[i].mbuf)->buf_iova +
RTE_PKTMBUF_HEADROOM;drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +25
-0+ dma_addr =rte_cpu_to_le_64 (paddr); +/* flush desc with pa dma_addr */ + rxdp[i].read.hdr_addr =0 ; + rxdp[i].read.pkt_addr = dma_addr; + } + +/* Update the descriptor initializer index */ + rxq->rxrearm_start += nb_mbufs; + rx_id = rxq->rxrearm_start -1 ; + +if (unlikely (rxq->rxrearm_start >= rxq->nb_rx_desc)) { + rxq->rxrearm_start =0 ; + rx_id = rxq->nb_rx_desc -1 ; + } + + rxq->rxrearm_nb -= nb_mbufs; + +rte_io_wmb (); +/* Update the tail pointer on the NIC */ +I40E_PCI_REG_WRITE_RELAXED (rxq->qrx_tail, rx_id); } + +uint16_t +i40e_recycle_tx_mbufs_reuse_vec (void *tx_queue, +struct rte_eth_recycle_rxq_info *recycle_rxq_info) { +struct i40e_tx_queue *txq = tx_queue;Quoted 8 lines
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +8
-0+struct i40e_tx_entry *txep; +struct rte_mbuf **rxep; +int i, n; +uint16_t nb_recycle_mbufs; +uint16_t avail =0 ; +uint16_t mbuf_ring_size = recycle_rxq_info->mbuf_ring_size; +uint16_t mask = recycle_rxq_info->mbuf_ring_size -1 ; + uint16_t refill_requirement = recycle_rxq_info-
refill_requirement;Quoted 11 lines
Quoted 11 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 11 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +11
-0+uint16_t refill_head = *recycle_rxq_info->refill_head; +uint16_t receive_tail = +*recycle_rxq_info->receive_tail; + +/* Get available recycling Rx buffers. */ + avail = (mbuf_ring_size - (refill_head - +receive_tail)) & mask; + +/* Check Tx free thresh and Rx available space. */ +if (txq->nb_tx_free > txq->tx_free_thresh || avail <= +txq-
tx_rs_thresh)Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +6
-0+return 0 ; + +/* check DD bits on threshold descriptor */ + if ((txq->tx_ring[txq->tx_next_dd].cmd_type_offset_bsz +& +rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) !=Quoted 8 lines
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 8 lines
+
rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE))drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +6
-0+return 0 ; + + n = txq->tx_rs_thresh; + nb_recycle_mbufs = n; + +/* Mbufs recycle mode can only support no ring buffer wrapping
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 5 lines
around.
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +4
-0+* Two case for this: +* +* case 1: The refill head of Rx buffer ring needs to +be aligned with
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 5 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +5
-0+* mbuf ring size. In this case, the number of Tx freeing buffers +* should be equal to refill_requirement. +* +* case 2: The refill head of Rx ring buffer does not +need to be aligned
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +2
-0+ * with mbuf ring size. In this case, the update of +refill headcan not
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +4
-0+* exceed the Rx mbuf ring size. +*/ + if (refill_requirement != n || + (!refill_requirement && (refill_head + n >
mbuf_ring_size)))Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 11 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +11
-0+return 0 ; + +/* First buffer to free from S/W ring is at index +* tx_next_dd - (tx_rs_thresh-1). +*/ + txep = &txq->sw_ring[txq->tx_next_dd - (n -1 )]; + rxep = recycle_rxq_info->mbuf_ring; + rxep += refill_head; + +if (txq->offloads &RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE ) { +/* Avoid txq contains buffers from unexpected mempool. */
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 10 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +10
-0+if (unlikely (recycle_rxq_info->mp + != txep[0 ].mbuf->pool)) +return 0 ; + +/* Directly put mbufs from Tx to Rx. */ +for (i =0 ; i < n; i++) + rxep[i] = txep[i].mbuf; + }else { +for (i =0 ; i < n; i++) { + rxep[i] =
rte_pktmbuf_prefree_seg(txep[i].mbuf);Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +2
-0+ +/* If Tx buffers are not the last reference or from
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +1
-0+* unexpected mempool, previous copied buffers are
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 3 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +3
-0+* considered as invalid. +*/ + if (unlikely((rxep[i] == NULL &&
refill_requirement) ||Quoted 35 lines
Quoted 35 lines
Quoted 8 lines
[Konstantin]
Could you pls remind me why it is ok to have rxep[i]==NULL whenrefill_requirementis not set?If
reill_requirementis not zero, it means each tx freed buffer must be valid and can be put into Rxsw_ring. Then the refill head of Rx buffer ring can be aligned with mbuf ring size. Briefly speaking the numberof Tx valid freed buffer must be equal to Rx
refill_requirement. For example, i40e driver.Quoted 5 lines
If
reill_requirementis zero, it means that the refill head of Rx buffer ring does not need to be aligned with mbuf ring size, thus if Tx have n valid freed buffers, we just need to put these n buffers into Rx sw-ring, and not to be equal to the Rx setting rearm number. For example, mlx5 driver.
Quoted 3 lines
In conclusion, above difference is due to pmd drivers have different
strategies to update their Rx rearm(refill) head.
Quoted 3 lines
For i40e driver, if
rearm_headexceed 1024, it will be set as
0 due to thenumber of each rearm is a fixed value by default.
Quoted 2 lines
For mlx5 driver. Its
rearm_headcan exceed 1024, and use mask to achievereal index. Thus its rearm number can be a different value.
Ok, but if
rte_pktmbuf_prefree_seg(txep[i].mbuf), it means that this mbuf is not free yet and can't be reused. Shouldn't we then setnb_recycle_mbufs= 0 in that case too? Or probably would be enough to skip that mbuf? Might be something like that:Quoted 37 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
for (i = 0, j = 0; i < n; i++) {
rxep[j] = rte_pktmbuf_prefree_seg(txep[i].mbuf); if (rxep[j] == NULL || recycle_rxq_info->mp != rxep[j].mbuf-pool)) {
Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
Quoted 8 lines
Quoted 8 lines
if (refill_requirement) { nb_recycle_mbufs = 0; break; } } else j++; }Quoted 6 lines
Quoted 6 lines
/* now j contains actual number of recycled mbufs */
?
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +1
-0+ recycle_rxq_info->mp !=txep[i].mbuf-
Quoted 17 lines
Quoted 11 lines
Quoted 11 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 11 lines
Quoted 1 line
pool))
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +10
-0+ nb_recycle_mbufs =0 ; + } +/* If Tx buffers are not the last reference or +* from unexpected mempool, all recycled buffers +* are put into mempool. +*/ +if (nb_recycle_mbufs ==0 ) +for (i =0 ; i < n; i++) { +if (rxep[i] !=NULL ) + rte_mempool_put(rxep[i]-pool,
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 4 lines
rxep[i]);
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +3
-0+ } + } +[Konstantin] After another thought, it might be easier and cleaner
just to:
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
if (rxep[j] == NULL ||
recycle_rxq_info->mp!= rxep[j].mbuf->pool)nb_recycle_mbufs = 0;Anyway, from my understanding - if
rte_pktmbuf_prefree_seg(mbuf)returns NULL, then we can't recyclethat mbuf.
Quoted 69 lines
Quoted 69 lines
Quoted 39 lines
Quoted 39 lines
Quoted 3 lines
[Feifei] Agree with that '
rte_pktmbuf_prefree_seg(mbuf)returns NULL, thenwe can't recycle that mbuf'.
Quoted 3 lines
Firstly, we should know for i40e driver, the number of free mbufs is fixed, it
must equal to '
tx_rs_thresh'Quoted 2 lines
This means if we start to free Tx mbufs, it cannot be interrupted until the
given amount of mbufs are freed.
Quoted 3 lines
In the meanwhile, doing prefree operation for a Tx mbuf can be looked at this mbuf is freed from this TX sw-ring if the API returns NULL. This is due
to that call '
prefree_seg' function means update the mbuf refcnt.Quoted 4 lines
So let's come back our recycle mbuf case.
Here we consider that the case if we have 32 mbufs need to be freed, andwe firstly do the pre-free.
Quoted 2 lines
And then first 8 mbufs is good and return value is not none. But the 9th
mbuf is bad, its refcnt is more than 1.
Quoted 2 lines
So we just update its refcnt and cannot put it into Rx sw-ring. For Tx sw-ring,
this mbuf has been freed.
Quoted 6 lines
Then we should continue to do pre-free operation for the next Tx mbufs to ensure the given amount of mbufs are freed.
Do a conclusion for this, this is because if we start to do pre-free operation, the Tx mbuf refcnt value maybe changed, so we cannot stop or
break until finish all the pre-free operation.
Quoted 4 lines
Finally, in the case that Rx
refill_requestis not zero, but the valid mbuf amount is less than this value, we must put back this Tx mbufs intomempool.
Quoted 1 line
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Above is the reason why I do not directly jump out of the loop if some mbuf
return value is NULL.
Yep, I already realized that it is a bit more complicated and we need to continue with
prefree()for all packets even when we get NULL inthe middle.
Quoted 16 lines
Quoted 2 lines
Anyway the code has to be changed, right?
Sorry, I think for the code, it is unnecessary to be changed. For no fast free path, currently:
1. We check whether each mbuf is Ok and callpre_freefunction
------------------------------------------------------------------
----
--------------------------------------------------------------
2.1 For the mbuf return value is not NULL, it is put into Rx sw-ring. 2.2 For the mbuf return value is zero and refill-request, it will also firstly put into Rx sw-ring, and we setnb_recycle= 0
------------------------------------------------------------------
----
--------------------------------------------------------------
3.1 We checknb_recycle, if it is not 0, we will continue to rearm Rx descsand update its index by call
descs_refillfunction.Quoted 5 lines
3.2 if
nb_recycleis 0, we will put valid recycle mbufs back into mempool as general path. This is necessary, because we need to ensure the freed Tx number is fixed.(Some buffers return is null can be seen as freed, others need to be put into mempool)Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Or maybe I ignore something?
I am talking about the case when both
refill_requirementand mbuf return values iare zero:
if (unlikely((rxep[i] == NULL &&refill_requirement) || // ??? rxep[i] ==0
Quoted 11 lines
Quoted 7 lines
AND
refill_requirement== 0 ???
recycle_rxq_info->mp!= txep[i].mbuf->pool))nb_recycle_mbufs = 0;As I can read the code you treat such situation as valid, while I think we should reset
nb_recycle_mbufsto zero when rxep[i] == NULL, no matter what valuerefill_requirementis.So this means for maybe MLX5 driver, its
refill_request= 0. And if some mbufs return value is zero, the other mbufs can not be recycled into Rx sw-ring? Because nb_recycle=0, and they need to be put intomempool.
Quoted 1 line
Quoted 8 lines
Quoted 1 line
I think for such as MLX5 driver, we can allow recycle some valid mbufs into
Rx ring.
Quoted 1 line
Because no constraint for its refill number. Is my suggestion reasonable?
I suppose yes: if
refill_requestis zero we potentially can skip 'bad' mbufs and continue with recycling for remaining ones.
It would probably require more changes in current code, but sounds ok to me in general.
That's Ok. Thanks for your careful reviewing.
Quoted 153 lines
Quoted 60 lines
Quoted 60 lines
Quoted 47 lines
Quoted 47 lines
Quoted 23 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 6 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +2
-0+/* Update counters for Tx. */ + txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + txq-
tx_rs_thresh);Quoted 1 line
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +1
-0+ txq->tx_next_dd = (uint16_t)(txq->tx_next_dd + txq-
tx_rs_thresh);Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +4
-0+if (txq->tx_next_dd >= txq->nb_tx_desc) + txq->tx_next_dd = (uint16_t )(txq->tx_rs_thresh -1 ); + +return nb_recycle_mbufs; }(quoted diff) +0
-0
b/drivers/net/i40e/i40e_rxtx.cindexb4f65b58fa..a9c9eb331c
100644drivers/net/i40e/i40e_rxtx.c +0
-0@@ -3199,6 +3199,30 @@ i40e_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, qinfo->conf.offloads = txq->offloads; }Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/net/i40e/i40e_rxtx.c i40e_txq_info_get(struct · line 3204
Quoted 3 lines
drivers/net/i40e/i40e_rxtx.c +3
-0+void +i40e_recycle_rxq_info_get (struct rte_eth_dev *dev, +uint16_t
queue_id,Quoted 20 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_rxtx.c i40e_txq_info_get(struct · line 3208
Quoted 4 lines
drivers/net/i40e/i40e_rxtx.c +4
-0+ struct rte_eth_recycle_rxq_info *recycle_rxq_info) { +struct i40e_rx_queue *rxq; +struct i40e_adapter *ad = + I40E_DEV_PRIVATE_TO_ADAPTER(dev->data-
dev_private);Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/i40e/i40e_rxtx.c +6
-0+ + rxq = dev->data->rx_queues[queue_id]; + + recycle_rxq_info->mbuf_ring = (void *)rxq->sw_ring; + recycle_rxq_info->mp = rxq->mp; + recycle_rxq_info->mbuf_ring_size = rxq->nb_rx_desc;Quoted 8 lines
Quoted 8 lines
drivers/net/i40e/i40e_rxtx.c i40e_txq_info_get(struct · line 3222
Quoted 8 lines
drivers/net/i40e/i40e_rxtx.c +7
-0+ recycle_rxq_info->receive_tail = &rxq->rx_tail; + +if (ad->rx_vec_allowed) { + recycle_rxq_info->refill_requirement =RTE_I40E_RXQ_REARM_THRESH ; + recycle_rxq_info->refill_head = &rxq->rxrearm_start; + }else { + recycle_rxq_info->refill_requirement = rxq-
rx_free_thresh;Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/net/i40e/i40e_rxtx.c +4
-0+ recycle_rxq_info->refill_head = &rxq->rx_free_trigger; + } +} +#ifdef RTE_ARCH_X86 static inline bool
get_avx_supported(bool request_avx512)@@ -3293,6
+3317,8@@
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
i40e_set_rx_function(struct rte_eth_dev *dev)
dev->rx_pkt_burst= ad-
rx_use_avx2?Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 8 lines
Quoted 8 lines
i40e_recv_scattered_pkts_vec_avx2 :Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/net/i40e/i40e_rxtx.c
Quoted 3 lines
drivers/net/i40e/i40e_rxtx.c +2
-0i40e_recv_scattered_pkts_vec ; + dev->recycle_rx_descriptors_refill = +i40e_recycle_rx_descriptors_refill_vec;Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/net/i40e/i40e_rxtx.c +0
-0} }else { if (ad->rx_use_avx512) { @@ -3311,9 +3337,12@@
Quoted 84 lines
Quoted 84 lines
Quoted 9 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
i40e_set_rx_function(struct
rte_eth_dev*dev)
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
dev->rx_pkt_burst= ad-
rx_use_avx2?Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_rxtx.c
Quoted 4 lines
drivers/net/i40e/i40e_rxtx.c +2
-0i40e_recv_pkts_vec_avx2 : i40e_recv_pkts_vec; + dev->recycle_rx_descriptors_refill = +i40e_recycle_rx_descriptors_refill_vec;Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/net/i40e/i40e_rxtx.c
Quoted 8 lines
drivers/net/i40e/i40e_rxtx.c +2
-0} }#else /* RTE_ARCH_X86 */ + dev->recycle_rx_descriptors_refill = +i40e_recycle_rx_descriptors_refill_vec;if (dev->data->scattered_rx) { PMD_INIT_LOG(DEBUG, "Using Vector Scattered Rx(port %d).", @@
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
-3481,15 +3510,18 @@ i40e_set_tx_function(struct
rte_eth_dev*dev)
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
dev->tx_pkt_burst= ad-
tx_use_avx2?Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
i40e_xmit_pkts_vec_avx2:Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
i40e_xmit_pkts_vec;Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/i40e/i40e_rxtx.c
Quoted 5 lines
drivers/net/i40e/i40e_rxtx.c +1
-0+ dev->recycle_tx_mbufs_reuse =
i40e_recycle_tx_mbufs_reuse_vec;drivers/net/i40e/i40e_rxtx.c +0
-0}#else /* RTE_ARCH_X86 */ PMD_INIT_LOG(DEBUG, "Using Vector Tx(port %d).",
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/i40e/i40e_rxtx.c
Quoted 6 lines
drivers/net/i40e/i40e_rxtx.c +1
-0dev->data->port_id); dev->tx_pkt_burst = i40e_xmit_pkts_vec; + dev->recycle_tx_mbufs_reuse =
i40e_recycle_tx_mbufs_reuse_vec; #endif /*RTE_ARCH_X86*/drivers/net/i40e/i40e_rxtx.c +0
-0}else { PMD_INIT_LOG(DEBUG, "Simple tx finally beused.");
Quoted 44 lines
Quoted 44 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
drivers/net/i40e/i40e_rxtx.c +1
-0dev->tx_pkt_burst = i40e_xmit_pkts_simple; + dev->recycle_tx_mbufs_reuse =
i40e_recycle_tx_mbufs_reuse_vec;drivers/net/i40e/i40e_rxtx.c +0
-0} dev->tx_pkt_prepare = i40e_simple_prep_pkts; }else {(quoted diff) +0
-0
b/drivers/net/i40e/i40e_rxtx.hindexa8686224e5..b191f23e1f
100644drivers/net/i40e/i40e_rxtx.h +0
-0@@ -236,6 +236,10 @@ uint32_t
i40e_dev_rx_queue_count(void *rx_queue); inti40e_dev_rx_descriptor_status(void *rx_queue, uint16_t offset); inti40e_dev_tx_descriptor_status(void *tx_queue, uint16_t offset);Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/i40e/i40e_rxtx.h
Quoted 2 lines
drivers/net/i40e/i40e_rxtx.h +2
-0+uint16_t i40e_recycle_tx_mbufs_reuse_vec (void *tx_queue, +struct rte_eth_recycle_rxq_info *recycle_rxq_info);void
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/i40e/i40e_rxtx.h +3
-0+i40e_recycle_rx_descriptors_refill_vec (void *rx_queue, +uint16_t nb_mbufs); + uint16_t i40e_recv_pkts_vec(void *rx_queue, struct
rte_mbuf**rx_pkts,
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
uint16_tnb_pkts);uint16_t
i40e_recv_scattered_pkts_vec(void*rx_queue, diff --git a/drivers/net/i40e/meson.build b/drivers/net/i40e/meson.build index8e53b87a65..3b1a233c84100644drivers/net/i40e/meson.build +1
-1@@ -34,6 +34,7 @@ sources = files( 'i40e_tm.c', 'i40e_hash.c', 'i40e_vf_representor.c', + 'i40e_recycle_mbufs_vec_common.c', 'rte_pmd_i40e.c', ) --2.25.1
RE: [PATCH v11 2/4] net/i40e: implement mbufs recycle mode
Hi, Konstantin
Quoted 437 lines
-----Original Message-----
From: Feifei Wang
Sent: Tuesday, September 5, 2023 11:11 AM
To: Konstantin Ananyev <[email protected]>; Konstantin Ananyev <[email protected]>
Cc: [email protected]; nd <[email protected]>; Honnappa Nagarahalli <[email protected]>; Ruifeng Wang <[email protected]>; Yuying Zhang <[email protected]>; Beilei Xing <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>
Subject: RE: [PATCH v11 2/4] net/i40e: implement mbufs recycle modeQuoted 7 lines
-----Original Message-----
From: Konstantin Ananyev <[email protected]>
Sent: Monday, September 4, 2023 6:22 PM
To: Feifei Wang <[email protected]>; Konstantin Ananyev <[email protected]>
Cc: [email protected]; nd <[email protected]>; Honnappa Nagarahalli <[email protected]>; Ruifeng WangQuoted 41 lines
Yuying Zhang <[email protected]>; Beilei Xing <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>
Subject: RE: [PATCH v11 2/4] net/i40e: implement mbufs recycle modeQuoted 34 lines
Quoted 34 lines
Quoted 34 lines
Quoted 34 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Define specific function implementation for i40e driver. Currently, mbufs recycle mode can support 128bit vector path and
avx2Quoted 8 lines
Quoted 8 lines
path.
Quoted 7 lines
Quoted 7 lines
And can be enabled both in fast free and no fast free mode.
Suggested-by: Honnappa Nagarahalli
<[email protected]>Signed-off-by Feifei Wang <[email protected]>Reviewed-by Ruifeng Wang <[email protected]>Reviewed-by Honnappa NagarahalliQuoted 21 lines
Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
--- drivers/net/i40e/i40e_ethdev.c | 1 + drivers/net/i40e/i40e_ethdev.h | 2 + .../net/i40e/i40e_recycle_mbufs_vec_common.c | 147 ++++++++++++++++++ drivers/net/i40e/i40e_rxtx.c | 32 ++++ drivers/net/i40e/i40e_rxtx.h | 4 + drivers/net/i40e/meson.build | 1 + 6 files changed, 187 insertions(+) create mode100644
drivers/net/i40e/i40e_recycle_mbufs_vec_common.cQuoted 8 lines
Quoted 8 lines
(quoted diff) +0
-0
b/drivers/net/i40e/i40e_ethdev.cindex8271bbb394..50ba9aac94
100644drivers/net/i40e/i40e_ethdev.c +0
-0@@ -496,6 +496,7 @@ static const struct eth_dev_ops
i40e_eth_dev_ops= {
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_ethdev.c
Quoted 4 lines
drivers/net/i40e/i40e_ethdev.c +1
-0.flow_ops_get = i40e_dev_flow_ops_get, .rxq_info_get = i40e_rxq_info_get, .txq_info_get = i40e_txq_info_get, + .recycle_rxq_info_get =
i40e_recycle_rxq_info_get,Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
.rx_burst_mode_get =
i40e_rx_burst_mode_get,Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
.tx_burst_mode_get =
i40e_tx_burst_mode_get,Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/i40e/i40e_ethdev.c +0
-0.timesync_enable = i40e_timesync_enable,(quoted diff) +0
-0
b/drivers/net/i40e/i40e_ethdev.hindex6f65d5e0ac..af758798e1
100644
---a/drivers/net/i40e/i40e_ethdev.hQuoted 8 lines
Review void i40e_rxq_info_get(struct · line 1360
Quoted 8 lines
+++
b/drivers/net/i40e/i40e_ethdev.h(quoted diff) +2
-0@@ -1355,6 +1355,8 @@ void i40e_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, struct rte_eth_rxq_info *qinfo); void i40e_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, struct rte_eth_txq_info *qinfo); +void i40e_recycle_rxq_info_get(struct rte_eth_dev +*dev, uint16_t
queue_id,Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
(quoted diff) +1
-0+ struct rte_eth_recycle_rxq_info *recycle_rxq_info); int i40e_rx_burst_mode_get(struct rte_eth_dev *dev,
uint16_t
queue_id,Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
struct
rte_eth_burst_mode*mode);int
Quoted 108 lines
Quoted 65 lines
Quoted 65 lines
Quoted 65 lines
Quoted 65 lines
Quoted 65 lines
Quoted 65 lines
Quoted 65 lines
Quoted 65 lines
i40e_tx_burst_mode_get(struct
rte_eth_dev*dev,uint16_tqueue_id, diff -- gita/drivers/net/i40e/i40e_recycle_mbufs_vec_common.cb/drivers/net/i40e/i40e_recycle_mbufs_vec_common.cnew file mode 100644
index 0000000000..5663ecccdedrivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +32
-0@@ -0,0 +1,147 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2023 Arm Limited. +*/ + +#include <stdint.h> +#include <ethdev_driver.h> + +#include "base/i40e_prototype.h" +#include "base/i40e_type.h" +#include "i40e_ethdev.h" +#include "i40e_rxtx.h" + +#pragma GCC diagnostic ignored "-Wcast-qual" + +void +i40e_recycle_rx_descriptors_refill_vec (void +*rx_queue,uint16_t +nb_mbufs) { +struct i40e_rx_queue *rxq = rx_queue; +struct i40e_rx_entry *rxep; +volatile union i40e_rx_desc *rxdp; +uint16_t rx_id; +uint64_t paddr; +uint64_t dma_addr; +uint16_t i; + + rxdp = rxq->rx_ring + rxq->rxrearm_start; + rxep = &rxq->sw_ring[rxq->rxrearm_start]; + +for (i =0 ; i < nb_mbufs; i++) { +/* Initialize rxdp descs. */ + paddr = (rxep[i].mbuf)->buf_iova +
RTE_PKTMBUF_HEADROOM;drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +23
-0+ dma_addr =rte_cpu_to_le_64 (paddr); +/* flush desc with pa dma_addr */ + rxdp[i].read.hdr_addr =0 ; + rxdp[i].read.pkt_addr = dma_addr; + } + +/* Update the descriptor initializer index */ + rxq->rxrearm_start += nb_mbufs; + rx_id = rxq->rxrearm_start -1 ; + +if (unlikely (rxq->rxrearm_start >= rxq->nb_rx_desc)) { + rxq->rxrearm_start =0 ; + rx_id = rxq->nb_rx_desc -1 ; + } + + rxq->rxrearm_nb -= nb_mbufs; + +rte_io_wmb (); +/* Update the tail pointer on the NIC */ +I40E_PCI_REG_WRITE_RELAXED (rxq->qrx_tail, rx_id); } + +uint16_t +i40e_recycle_tx_mbufs_reuse_vec(void *tx_queue,Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +8
-0+ struct rte_eth_recycle_rxq_info *recycle_rxq_info) { +struct i40e_tx_queue *txq = tx_queue; +struct i40e_tx_entry *txep; +struct rte_mbuf **rxep; +int i, n; +uint16_t nb_recycle_mbufs; +uint16_t avail =0 ; + uint16_t mbuf_ring_size = recycle_rxq_info-
mbuf_ring_size;Quoted 34 lines
Quoted 34 lines
Quoted 34 lines
Quoted 34 lines
Quoted 25 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +2
-0+uint16_t mask = recycle_rxq_info->mbuf_ring_size -1 ; + uint16_t refill_requirement = recycle_rxq_info-
refill_requirement;Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +4
-0+uint16_t refill_head = *recycle_rxq_info->refill_head; +uint16_t receive_tail = +*recycle_rxq_info->receive_tail; +Quoted 8 lines
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +8
-0+/* Get available recycling Rx buffers. */ + avail = (mbuf_ring_size - (refill_head - +receive_tail)) & mask; + +/* Check Tx free thresh and Rx available space. */ +if (txq->nb_tx_free > txq->tx_free_thresh || avail +<= +txq-
tx_rs_thresh)Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +7
-0+return 0 ; + +/* check DD bits on threshold descriptor */ + if +((txq->tx_ring[txq->tx_next_dd].cmd_type_offset_bsz +& +rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) !=+
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 8 lines
rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE))drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +7
-0+return 0 ; + + n = txq->tx_rs_thresh; + nb_recycle_mbufs = n; + +/* Mbufs recycle mode can only support no ring +buffer wrapping
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 5 lines
around.
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +4
-0+* Two case for this: +* +* case 1: The refill head of Rx buffer ring needs +to be aligned with
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +1
-0+* mbuf ring size. In this case, the number of Tx freeing buffers
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +4
-0+* should be equal to refill_requirement. +* +* case 2: The refill head of Rx ring buffer does +not need to be aligned
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +2
-0+ * with mbuf ring size. In this case, the update of +refill headcan not
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +4
-0+* exceed the Rx mbuf ring size. +*/ + if (refill_requirement != n || + (!refill_requirement && (refill_head + n >
mbuf_ring_size)))Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 10 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +10
-0+return 0 ; + +/* First buffer to free from S/W ring is at index +* tx_next_dd - (tx_rs_thresh-1). +*/ + txep = &txq->sw_ring[txq->tx_next_dd - (n -1 )]; + rxep = recycle_rxq_info->mbuf_ring; + rxep += refill_head; + + if (txq->offloads &
RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE) {Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +1
-0+/* Avoid txq contains buffers from unexpected mempool. */
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +2
-0+ if (unlikely(recycle_rxq_info->mp + != txep[0].mbuf-pool))
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +8
-0+return 0 ; + +/* Directly put mbufs from Tx to Rx. */ +for (i =0 ; i < n; i++)Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
rte_pktmbuf_prefree_seg(txep[i].mbuf);Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +2
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
reference or
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
from
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +1
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
copied
Quoted 59 lines
Quoted 59 lines
Quoted 40 lines
Quoted 40 lines
Quoted 40 lines
buffers are
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 3 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +3
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
refill_requirement) ||Quoted 35 lines
Quoted 35 lines
Quoted 8 lines
[Konstantin]
Could you pls remind me why it is ok to have rxep[i]==NULL whenrefill_requirementis not set?If
reill_requirementis not zero, it means each tx freed buffer must be valid and can be put into Rxsw_ring. Then the refill head of Rx buffer ring can be aligned with mbuf ring size. Briefly speaking the numberof Tx valid freed buffer must be equal to Rx
refill_requirement. For example, i40e driver.Quoted 5 lines
If
reill_requirementis zero, it means that the refill head of Rx buffer ring does not need to be aligned with mbuf ring size, thus if Tx have n valid freed buffers, we just need to put these n buffers into Rx sw-ring, and not to be equal to the Rx setting rearm number. For example, mlx5 driver.
Quoted 3 lines
In conclusion, above difference is due to pmd drivers have different
strategies to update their Rx rearm(refill) head.
Quoted 3 lines
For i40e driver, if
rearm_headexceed 1024, it will be set as
0 due to thenumber of each rearm is a fixed value by default.
Quoted 2 lines
For mlx5 driver. Its
rearm_headcan exceed 1024, and use mask to achievereal index. Thus its rearm number can be a different value.
Ok, but if
rte_pktmbuf_prefree_seg(txep[i].mbuf), it means that this mbuf is not free yet and can't be reused. Shouldn't we then setnb_recycle_mbufs= 0 in that case too? Or probably would be enough to skip that mbuf? Might be something like that:Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
for (i = 0, j = 0; i < n; i++) {
rxep[j] = rte_pktmbuf_prefree_seg(txep[i].mbuf); if (rxep[j] == NULL || recycle_rxq_info->mp !=rxep[j].mbuf-
pool)) {
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
if (refill_requirement) { nb_recycle_mbufs = 0; break; } } else j++; }/* now j contains actual number of recycled mbufs */
?
Quoted 1 line
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +1
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
mp !=
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
txep[i].mbuf-
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 5 lines
Quoted 1 line
pool))
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +4
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
buffers
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 6 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +6
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
rte_mempool_put(rxep[i]-
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
pool,
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
Quoted 4 lines
rxep[i]);
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +3
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
[Konstantin] After another thought, it might be easier and cleaner
Quoted 85 lines
just to:
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
if (rxep[j] == NULL ||
recycle_rxq_info->mp!= rxep[j].mbuf->pool)nb_recycle_mbufs = 0;Anyway, from my understanding - if
rte_pktmbuf_prefree_seg(mbuf)returns NULL, then we can't recyclethat mbuf.
Quoted 77 lines
Quoted 77 lines
Quoted 39 lines
Quoted 39 lines
Quoted 3 lines
[Feifei] Agree with that '
rte_pktmbuf_prefree_seg(mbuf)returns NULL, thenwe can't recycle that mbuf'.
Quoted 3 lines
Firstly, we should know for i40e driver, the number of free mbufs is fixed, it
must equal to '
tx_rs_thresh'Quoted 2 lines
This means if we start to free Tx mbufs, it cannot be interrupted until the
given amount of mbufs are freed.
Quoted 3 lines
In the meanwhile, doing prefree operation for a Tx mbuf can be looked at this mbuf is freed from this TX sw-ring if the API returns NULL. This is due
to that call '
prefree_seg' function means update the mbuf refcnt.Quoted 4 lines
So let's come back our recycle mbuf case.
Here we consider that the case if we have 32 mbufs need to be freed, andwe firstly do the pre-free.
Quoted 2 lines
And then first 8 mbufs is good and return value is not none. But the 9th
mbuf is bad, its refcnt is more than 1.
Quoted 2 lines
So we just update its refcnt and cannot put it into Rx sw-ring. For Tx sw-ring,
this mbuf has been freed.
Quoted 6 lines
Then we should continue to do pre-free operation for the next Tx mbufs to ensure the given amount of mbufs are freed.
Do a conclusion for this, this is because if we start to do pre-free operation, the Tx mbuf refcnt value maybe changed, so we cannot stop or
break until finish all the pre-free operation.
Quoted 4 lines
Finally, in the case that Rx
refill_requestis not zero, but the valid mbuf amount is less than this value, we must put back this Tx mbufs into2 lines not shown · raw message
Quoted 7 lines
7 lines not shown · raw message
29 lines not shown · raw message
17 lines not shown · raw message
Quoted 8 lines
8 lines not shown · raw message
183 lines not shown · raw message
Parts of this message are not shown here. View the raw message.
RE: [PATCH v11 2/4] net/i40e: implement mbufs recycle mode
Quoted 489 lines
-----Original Message-----
From: Feifei Wang
Sent: Friday, September 22, 2023 10:59 PM
To: Konstantin Ananyev <[email protected]>; Konstantin Ananyev <[email protected]>
Cc: [email protected]; nd <[email protected]>; Honnappa Nagarahalli <[email protected]>; Ruifeng Wang <[email protected]>; Yuying Zhang <[email protected]>; Beilei Xing <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>
Subject: RE: [PATCH v11 2/4] net/i40e: implement mbufs recycle modeHi, Konstantin
Quoted 7 lines
-----Original Message-----
From: Feifei Wang
Sent: Tuesday, September 5, 2023 11:11 AM
To: Konstantin Ananyev <[email protected]>; Konstantin Ananyev <[email protected]>
Cc: [email protected]; nd <[email protected]>; Honnappa Nagarahalli <[email protected]>; Ruifeng WangQuoted 65 lines
Yuying Zhang <[email protected]>; Beilei Xing <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>
Subject: RE: [PATCH v11 2/4] net/i40e: implement mbufs recycle modeQuoted 7 lines
-----Original Message-----
From: Konstantin Ananyev <[email protected]>
Sent: Monday, September 4, 2023 6:22 PM
To: Feifei Wang <[email protected]>; Konstantin Ananyev <[email protected]>
Cc: [email protected]; nd <[email protected]>; Honnappa Nagarahalli <[email protected]>; Ruifeng WangQuoted 41 lines
Yuying Zhang <[email protected]>; Beilei Xing <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>
Subject: RE: [PATCH v11 2/4] net/i40e: implement mbufs recycle modeQuoted 34 lines
Quoted 34 lines
Quoted 34 lines
Quoted 34 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Define specific function implementation for i40e driver. Currently, mbufs recycle mode can support 128bit vector path and
avx2Quoted 8 lines
Quoted 8 lines
path.
Quoted 7 lines
Quoted 7 lines
And can be enabled both in fast free and no fast free mode.
Suggested-by: Honnappa Nagarahalli
<[email protected]>Signed-off-by Feifei Wang <[email protected]>Reviewed-by Ruifeng Wang <[email protected]>Reviewed-by Honnappa NagarahalliQuoted 21 lines
Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
--- drivers/net/i40e/i40e_ethdev.c | 1 + drivers/net/i40e/i40e_ethdev.h | 2 + .../net/i40e/i40e_recycle_mbufs_vec_common.c | 147 ++++++++++++++++++ drivers/net/i40e/i40e_rxtx.c | 32 ++++ drivers/net/i40e/i40e_rxtx.h | 4 + drivers/net/i40e/meson.build | 1 + 6 files changed, 187 insertions(+) create mode100644
drivers/net/i40e/i40e_recycle_mbufs_vec_common.cQuoted 8 lines
Quoted 8 lines
(quoted diff) +0
-0
b/drivers/net/i40e/i40e_ethdev.cindex8271bbb394..50ba9aac94
100644drivers/net/i40e/i40e_ethdev.c +0
-0@@ -496,6 +496,7 @@ static const struct eth_dev_ops
i40e_eth_dev_ops= {
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_ethdev.c
Quoted 4 lines
drivers/net/i40e/i40e_ethdev.c +1
-0.flow_ops_get = i40e_dev_flow_ops_get, .rxq_info_get = i40e_rxq_info_get, .txq_info_get = i40e_txq_info_get, + .recycle_rxq_info_get =
i40e_recycle_rxq_info_get,Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
.rx_burst_mode_get =
i40e_rx_burst_mode_get,Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
.tx_burst_mode_get =
i40e_tx_burst_mode_get,Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
drivers/net/i40e/i40e_ethdev.c +0
-0.timesync_enable = i40e_timesync_enable,(quoted diff) +0
-0
b/drivers/net/i40e/i40e_ethdev.hindex6f65d5e0ac..af758798e1
100644drivers/net/i40e/i40e_ethdev.h +0
-0@@ -1355,6 +1355,8 @@ void i40e_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, struct rte_eth_rxq_info *qinfo); voidi40e_txq_info_get(struct
rte_eth_dev*dev,uint16_t
queue_id,Quoted 240 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
drivers/net/i40e/i40e_ethdev.h
Quoted 3 lines
drivers/net/i40e/i40e_ethdev.h +2
-0struct rte_eth_txq_info *qinfo); +void i40e_recycle_rxq_info_get (struct rte_eth_dev +*dev, uint16_t
queue_id,Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_ethdev.h +2
-0+struct rte_eth_recycle_rxq_info +*recycle_rxq_info); int i40e_rx_burst_mode_get(struct rte_eth_dev *dev,
uint16_t
queue_id,Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
struct
rte_eth_burst_mode*mode);int
Quoted 108 lines
Quoted 65 lines
Quoted 65 lines
Quoted 65 lines
Quoted 65 lines
Quoted 65 lines
Quoted 65 lines
Quoted 65 lines
Quoted 65 lines
i40e_tx_burst_mode_get(struct
rte_eth_dev*dev,uint16_tqueue_id, diff -- gita/drivers/net/i40e/i40e_recycle_mbufs_vec_common.cb/drivers/net/i40e/i40e_recycle_mbufs_vec_common.cnew file mode 100644 index 0000000000..5663ecccdedrivers/net/i40e/i40e_recycle_mbufs_vec_common new file +32
-0+++ .c@@ -0,0 +1,147 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2023 Arm Limited. + */ + +#include <stdint.h> #include <ethdev_driver.h> + +#include "base/i40e_prototype.h" +#include "base/i40e_type.h" +#include "i40e_ethdev.h" +#include "i40e_rxtx.h" + +#pragma GCC diagnostic ignored "-Wcast-qual" + +void +i40e_recycle_rx_descriptors_refill_vec(void +*rx_queue, uint16_t +nb_mbufs) { + struct i40e_rx_queue *rxq = rx_queue; + struct i40e_rx_entry *rxep; + volatile union i40e_rx_desc *rxdp; + uint16_t rx_id; + uint64_t paddr; + uint64_t dma_addr; + uint16_t i; + + rxdp = rxq->rx_ring + rxq->rxrearm_start; + rxep = &rxq->sw_ring[rxq->rxrearm_start]; + + for (i = 0; i < nb_mbufs; i++) { + /* Initialize rxdp descs. */ + paddr = (rxep[i].mbuf)->buf_iova +
RTE_PKTMBUF_HEADROOM;drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +24
-0+ dma_addr = rte_cpu_to_le_64(paddr); + /* flush desc with pa dma_addr */ + rxdp[i].read.hdr_addr = 0; + rxdp[i].read.pkt_addr = dma_addr; + } + + /* Update the descriptor initializer index */ + rxq->rxrearm_start += nb_mbufs; + rx_id = rxq->rxrearm_start - 1; + + if (unlikely(rxq->rxrearm_start >= rxq->nb_rx_desc)) { + rxq->rxrearm_start = 0; + rx_id = rxq->nb_rx_desc - 1; + } + + rxq->rxrearm_nb -= nb_mbufs; + + rte_io_wmb(); + /* Update the tail pointer on the NIC */ + I40E_PCI_REG_WRITE_RELAXED(rxq->qrx_tail, rx_id); +} + +uint16_t +i40e_recycle_tx_mbufs_reuse_vec(void *tx_queue,Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +8
-0+ struct rte_eth_recycle_rxq_info *recycle_rxq_info) { + struct i40e_tx_queue *txq = tx_queue; + struct i40e_tx_entry *txep; + struct rte_mbuf **rxep; + int i, n; + uint16_t nb_recycle_mbufs; + uint16_t avail = 0; + uint16_t mbuf_ring_size = recycle_rxq_info-
mbuf_ring_size;Quoted 34 lines
Quoted 34 lines
Quoted 34 lines
Quoted 34 lines
Quoted 25 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +2
-0+ uint16_t mask = recycle_rxq_info->mbuf_ring_size - 1; + uint16_t refill_requirement = recycle_rxq_info-
refill_requirement;Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +4
-0+ uint16_t refill_head = *recycle_rxq_info->refill_head; + uint16_t receive_tail = +*recycle_rxq_info->receive_tail; +Quoted 8 lines
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +8
-0+ /* Get available recycling Rx buffers. */ + avail = (mbuf_ring_size - (refill_head - +receive_tail)) & mask; + + /* Check Tx free thresh and Rx available space. */ + if (txq->nb_tx_free > txq->tx_free_thresh || avail +<= +txq-
tx_rs_thresh)Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +7
-0+ return 0; + + /* check DD bits on threshold descriptor */ + if +((txq->tx_ring[txq->tx_next_dd].cmd_type_offset_bsz +& +rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) !=+
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 8 lines
rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE))drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +7
-0+ return 0; + + n = txq->tx_rs_thresh; + nb_recycle_mbufs = n; + + /* Mbufs recycle mode can only support no ring +bufferwrapping
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 5 lines
around.
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +4
-0+ * Two case for this: + * + * case 1: The refill head of Rx buffer ring needs +to be alignedwith
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +1
-0+ * mbuf ring size. In this case, the number of Txfreeing buffers
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +4
-0+ * should be equal to refill_requirement. + * + * case 2: The refill head of Rx ring buffer does +not need to bealigned
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +2
-0+ * with mbuf ring size. In this case, the update +of refill headcan not
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +4
-0+ * exceed the Rx mbuf ring size. + */ + if (refill_requirement != n || + (!refill_requirement && (refill_head + n >
mbuf_ring_size)))Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 10 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +10
-0+ return 0; + + /* First buffer to free from S/W ring is at index + * tx_next_dd - (tx_rs_thresh-1). + */ + txep = &txq->sw_ring[txq->tx_next_dd - (n - 1)]; + rxep = recycle_rxq_info->mbuf_ring; + rxep += refill_head; + + if (txq->offloads &
RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE) {Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +1
-0+ /* Avoid txq contains buffers from unexpectedmempool. */
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +2
-0+ if (unlikely(recycle_rxq_info->mp + != txep[0].mbuf-pool))
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +8
-0+ return 0;Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
rte_pktmbuf_prefree_seg(txep[i].mbuf);Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +2
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
reference or
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
from
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +1
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
copied
Quoted 60 lines
Quoted 60 lines
Quoted 41 lines
Quoted 41 lines
Quoted 41 lines
buffers are
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 3 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +3
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
refill_requirement) ||Quoted 36 lines
Quoted 36 lines
Quoted 8 lines
[Konstantin]
Could you pls remind me why it is ok to have rxep[i]==NULL whenrefill_requirementis not set?If
reill_requirementis not zero, it means each tx freed buffer must be valid and can be put into Rxsw_ring. Then the refill head of Rx buffer ring can be aligned with mbuf ring size. Briefly speaking the numberof Tx valid freed buffer must be equal to Rx
refill_requirement. For example, i40e driver.Quoted 6 lines
If
reill_requirementis zero, it means that the refill head of Rx buffer ring does not need to be aligned with mbuf ring size, thus if Tx have n valid freed buffers, we just need to put these n buffers into Rx sw-ring, and not to be equal to the Rx setting rearm number. For example, mlx5 driver.
Quoted 3 lines
In conclusion, above difference is due to pmd drivers have different
strategies to update their Rx rearm(refill) head.
Quoted 3 lines
For i40e driver, if
rearm_headexceed 1024, it will be set as
0 due to thenumber of each rearm is a fixed value by default.
Quoted 2 lines
For mlx5 driver. Its
rearm_headcan exceed 1024, and use mask to achievereal index. Thus its rearm number can be a different value.
Ok, but if
rte_pktmbuf_prefree_seg(txep[i].mbuf), it means that this mbuf is not free yet and can't be reused. Shouldn't we then setnb_recycle_mbufs= 0 in that case too? Or probably would be enough to skip that mbuf? Might be something like that:Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
for (i = 0, j = 0; i < n; i++) {
rxep[j] = rte_pktmbuf_prefree_seg(txep[i].mbuf); if (rxep[j] == NULL || recycle_rxq_info->mp !=rxep[j].mbuf-
pool)) {
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
if (refill_requirement) { nb_recycle_mbufs = 0; break; } } else j++; }/* now j contains actual number of recycled mbufs */
?
Quoted 1 line
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +1
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
mp !=
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
txep[i].mbuf-
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 5 lines
Quoted 1 line
pool))
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +4
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
buffers
Quoted 103 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 6 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +6
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
rte_mempool_put(rxep[i]-
Quoted 96 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
pool,
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 4 lines
rxep[i]);
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +3
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
[Konstantin] After another thought, it might be easier and cleaner
just to:
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
if (rxep[j] == NULL ||
recycle_rxq_info->mp!= rxep[j].mbuf->pool)nb_recycle_mbufs = 0;Anyway, from my understanding - if
rte_pktmbuf_prefree_seg(mbuf)returns NULL, then we can't recyclethat mbuf.
Quoted 81 lines
Quoted 81 lines
Quoted 39 lines
Quoted 39 lines
Quoted 3 lines
[Feifei] Agree with that '
rte_pktmbuf_prefree_seg(mbuf)returns NULL, thenwe can't recycle that mbuf'.
Quoted 3 lines
Firstly, we should know for i40e driver, the number of free mbufs is fixed, it
must equal to '
tx_rs_thresh'Quoted 2 lines
This means if we start to free Tx mbufs, it cannot be interrupted until the
given amount of mbufs are freed.
Quoted 3 lines
In the meanwhile, doing prefree operation for a Tx mbuf can be looked at this mbuf is freed from this TX sw-ring if the API returns NULL. This is due
to that call '
prefree_seg' function means update the mbuf refcnt.Quoted 4 lines
So let's come back our recycle mbuf case.
Here we consider that the case if we have 32 mbufs need to be freed, andwe firstly do the pre-free.
Quoted 2 lines
And then first 8 mbufs is good and return value is not none. But the 9th
mbuf is bad, its refcnt is more than 1.
Quoted 2 lines
So we just update its refcnt and cannot put it into Rx sw-ring. For Tx sw-ring,
this mbuf has been freed.
Quoted 6 lines
Then we should continue to do pre-free operation for the next Tx mbufs to ensure the given amount of mbufs are freed.
Do a conclusion for this, this is because if we start to do pre-free operation, the Tx mbuf refcnt value maybe changed, so we cannot stop or
break until finish all the pre-free operation.
Quoted 4 lines
Finally, in the case that Rx
refill_requestis not zero, but the valid mbuf amount is less than this value, we must put back this Tx mbufs intomempool.
Quoted 1 line
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Above is the reason why I do not directly jump out of the loop if some mbuf
return value is NULL.
3 lines not shown · raw message
33 lines not shown · raw message
40 lines not shown · raw message
Quoted 2 lines
1 line not shown · raw message
193 lines not shown · raw message
Parts of this message are not shown here. View the raw message.
RE: [PATCH v11 2/4] net/i40e: implement mbufs recycle mode
Hi Feifei,
Quoted 450 lines
Quoted 450 lines
Quoted 7 lines
-----Original Message-----
From: Feifei Wang
Sent: Tuesday, September 5, 2023 11:11 AM
To: Konstantin Ananyev <[email protected]>; Konstantin Ananyev <[email protected]>
Cc: [email protected]; nd <[email protected]>; Honnappa Nagarahalli <[email protected]>; Ruifeng WangQuoted 65 lines
Yuying Zhang <[email protected]>; Beilei Xing <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>
Subject: RE: [PATCH v11 2/4] net/i40e: implement mbufs recycle modeQuoted 7 lines
-----Original Message-----
From: Konstantin Ananyev <[email protected]>
Sent: Monday, September 4, 2023 6:22 PM
To: Feifei Wang <[email protected]>; Konstantin Ananyev <[email protected]>
Cc: [email protected]; nd <[email protected]>; Honnappa Nagarahalli <[email protected]>; Ruifeng WangQuoted 41 lines
Yuying Zhang <[email protected]>; Beilei Xing <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>
Subject: RE: [PATCH v11 2/4] net/i40e: implement mbufs recycle modeQuoted 34 lines
Quoted 34 lines
Quoted 34 lines
Quoted 34 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Define specific function implementation for i40e driver. Currently, mbufs recycle mode can support 128bit vector path and
avx2Quoted 8 lines
Quoted 8 lines
path.
Quoted 7 lines
Quoted 7 lines
And can be enabled both in fast free and no fast free mode.
Suggested-by: Honnappa Nagarahalli
<[email protected]>Signed-off-by Feifei Wang <[email protected]>Reviewed-by Ruifeng Wang <[email protected]>Reviewed-by Honnappa NagarahalliQuoted 21 lines
Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
--- drivers/net/i40e/i40e_ethdev.c | 1 + drivers/net/i40e/i40e_ethdev.h | 2 + .../net/i40e/i40e_recycle_mbufs_vec_common.c | 147 ++++++++++++++++++ drivers/net/i40e/i40e_rxtx.c | 32 ++++ drivers/net/i40e/i40e_rxtx.h | 4 + drivers/net/i40e/meson.build | 1 + 6 files changed, 187 insertions(+) create mode100644
drivers/net/i40e/i40e_recycle_mbufs_vec_common.cQuoted 8 lines
Quoted 8 lines
(quoted diff) +0
-0
b/drivers/net/i40e/i40e_ethdev.cindex8271bbb394..50ba9aac94
100644drivers/net/i40e/i40e_ethdev.c +0
-0@@ -496,6 +496,7 @@ static const struct eth_dev_ops
i40e_eth_dev_ops= {
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_ethdev.c
Quoted 4 lines
drivers/net/i40e/i40e_ethdev.c +1
-0.flow_ops_get = i40e_dev_flow_ops_get, .rxq_info_get = i40e_rxq_info_get, .txq_info_get = i40e_txq_info_get, + .recycle_rxq_info_get =
i40e_recycle_rxq_info_get,Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
.rx_burst_mode_get =
i40e_rx_burst_mode_get,Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
.tx_burst_mode_get =
i40e_tx_burst_mode_get,Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
drivers/net/i40e/i40e_ethdev.c +0
-0.timesync_enable = i40e_timesync_enable,(quoted diff) +0
-0
b/drivers/net/i40e/i40e_ethdev.hindex6f65d5e0ac..af758798e1
100644drivers/net/i40e/i40e_ethdev.h +0
-0@@ -1355,6 +1355,8 @@ void i40e_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, struct rte_eth_rxq_info *qinfo); voidi40e_txq_info_get(struct
rte_eth_dev*dev,uint16_t
queue_id,Quoted 240 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
drivers/net/i40e/i40e_ethdev.h
Quoted 3 lines
drivers/net/i40e/i40e_ethdev.h +2
-0struct rte_eth_txq_info *qinfo); +void i40e_recycle_rxq_info_get (struct rte_eth_dev +*dev, uint16_t
queue_id,Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_ethdev.h +2
-0+struct rte_eth_recycle_rxq_info +*recycle_rxq_info); int i40e_rx_burst_mode_get(struct rte_eth_dev *dev,
uint16_t
queue_id,Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
struct
rte_eth_burst_mode*mode);int
Quoted 108 lines
Quoted 65 lines
Quoted 65 lines
Quoted 65 lines
Quoted 65 lines
Quoted 65 lines
Quoted 65 lines
Quoted 65 lines
Quoted 65 lines
i40e_tx_burst_mode_get(struct
rte_eth_dev*dev,uint16_tqueue_id, diff -- gita/drivers/net/i40e/i40e_recycle_mbufs_vec_common.cb/drivers/net/i40e/i40e_recycle_mbufs_vec_common.cnew file mode 100644 index 0000000000..5663ecccdedrivers/net/i40e/i40e_recycle_mbufs_vec_common new file +32
-0+++ .c@@ -0,0 +1,147 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2023 Arm Limited. + */ + +#include <stdint.h> #include <ethdev_driver.h> + +#include "base/i40e_prototype.h" +#include "base/i40e_type.h" +#include "i40e_ethdev.h" +#include "i40e_rxtx.h" + +#pragma GCC diagnostic ignored "-Wcast-qual" + +void +i40e_recycle_rx_descriptors_refill_vec(void +*rx_queue, uint16_t +nb_mbufs) { + struct i40e_rx_queue *rxq = rx_queue; + struct i40e_rx_entry *rxep; + volatile union i40e_rx_desc *rxdp; + uint16_t rx_id; + uint64_t paddr; + uint64_t dma_addr; + uint16_t i; + + rxdp = rxq->rx_ring + rxq->rxrearm_start; + rxep = &rxq->sw_ring[rxq->rxrearm_start]; + + for (i = 0; i < nb_mbufs; i++) { + /* Initialize rxdp descs. */ + paddr = (rxep[i].mbuf)->buf_iova +
RTE_PKTMBUF_HEADROOM;drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +24
-0+ dma_addr = rte_cpu_to_le_64(paddr); + /* flush desc with pa dma_addr */ + rxdp[i].read.hdr_addr = 0; + rxdp[i].read.pkt_addr = dma_addr; + } + + /* Update the descriptor initializer index */ + rxq->rxrearm_start += nb_mbufs; + rx_id = rxq->rxrearm_start - 1; + + if (unlikely(rxq->rxrearm_start >= rxq->nb_rx_desc)) { + rxq->rxrearm_start = 0; + rx_id = rxq->nb_rx_desc - 1; + } + + rxq->rxrearm_nb -= nb_mbufs; + + rte_io_wmb(); + /* Update the tail pointer on the NIC */ + I40E_PCI_REG_WRITE_RELAXED(rxq->qrx_tail, rx_id); +} + +uint16_t +i40e_recycle_tx_mbufs_reuse_vec(void *tx_queue,Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +8
-0+ struct rte_eth_recycle_rxq_info *recycle_rxq_info) { + struct i40e_tx_queue *txq = tx_queue; + struct i40e_tx_entry *txep; + struct rte_mbuf **rxep; + int i, n; + uint16_t nb_recycle_mbufs; + uint16_t avail = 0; + uint16_t mbuf_ring_size = recycle_rxq_info-
mbuf_ring_size;Quoted 34 lines
Quoted 34 lines
Quoted 34 lines
Quoted 34 lines
Quoted 25 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +2
-0+ uint16_t mask = recycle_rxq_info->mbuf_ring_size - 1; + uint16_t refill_requirement = recycle_rxq_info-
refill_requirement;Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +4
-0+ uint16_t refill_head = *recycle_rxq_info->refill_head; + uint16_t receive_tail = +*recycle_rxq_info->receive_tail; +Quoted 8 lines
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +8
-0+ /* Get available recycling Rx buffers. */ + avail = (mbuf_ring_size - (refill_head - +receive_tail)) & mask; + + /* Check Tx free thresh and Rx available space. */ + if (txq->nb_tx_free > txq->tx_free_thresh || avail +<= +txq-
tx_rs_thresh)Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +7
-0+ return 0; + + /* check DD bits on threshold descriptor */ + if +((txq->tx_ring[txq->tx_next_dd].cmd_type_offset_bsz +& +rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) !=+
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 8 lines
rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE))drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +7
-0+ return 0; + + n = txq->tx_rs_thresh; + nb_recycle_mbufs = n; + + /* Mbufs recycle mode can only support no ring +bufferwrapping
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 5 lines
around.
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +4
-0+ * Two case for this: + * + * case 1: The refill head of Rx buffer ring needs +to be alignedwith
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +1
-0+ * mbuf ring size. In this case, the number of Txfreeing buffers
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +4
-0+ * should be equal to refill_requirement. + * + * case 2: The refill head of Rx ring buffer does +not need to bealigned
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +2
-0+ * with mbuf ring size. In this case, the update +of refill headcan not
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +4
-0+ * exceed the Rx mbuf ring size. + */ + if (refill_requirement != n || + (!refill_requirement && (refill_head + n >
mbuf_ring_size)))Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 10 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +10
-0+ return 0; + + /* First buffer to free from S/W ring is at index + * tx_next_dd - (tx_rs_thresh-1). + */ + txep = &txq->sw_ring[txq->tx_next_dd - (n - 1)]; + rxep = recycle_rxq_info->mbuf_ring; + rxep += refill_head; + + if (txq->offloads &
RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE) {Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +1
-0+ /* Avoid txq contains buffers from unexpectedmempool. */
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +2
-0+ if (unlikely(recycle_rxq_info->mp + != txep[0].mbuf-pool))
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 8 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +8
-0+ return 0;Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
rte_pktmbuf_prefree_seg(txep[i].mbuf);Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 2 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +2
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
reference or
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
from
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +1
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
copied
Quoted 60 lines
Quoted 60 lines
Quoted 41 lines
Quoted 41 lines
Quoted 41 lines
buffers are
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 3 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +3
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
refill_requirement) ||Quoted 36 lines
Quoted 36 lines
Quoted 8 lines
[Konstantin]
Could you pls remind me why it is ok to have rxep[i]==NULL whenrefill_requirementis not set?If
reill_requirementis not zero, it means each tx freed buffer must be valid and can be put into Rxsw_ring. Then the refill head of Rx buffer ring can be aligned with mbuf ring size. Briefly speaking the numberof Tx valid freed buffer must be equal to Rx
refill_requirement. For example, i40e driver.Quoted 6 lines
If
reill_requirementis zero, it means that the refill head of Rx buffer ring does not need to be aligned with mbuf ring size, thus if Tx have n valid freed buffers, we just need to put these n buffers into Rx sw-ring, and not to be equal to the Rx setting rearm number. For example, mlx5 driver.
Quoted 3 lines
In conclusion, above difference is due to pmd drivers have different
strategies to update their Rx rearm(refill) head.
Quoted 3 lines
For i40e driver, if
rearm_headexceed 1024, it will be set as
0 due to thenumber of each rearm is a fixed value by default.
Quoted 2 lines
For mlx5 driver. Its
rearm_headcan exceed 1024, and use mask to achievereal index. Thus its rearm number can be a different value.
Ok, but if
rte_pktmbuf_prefree_seg(txep[i].mbuf), it means that this mbuf is not free yet and can't be reused. Shouldn't we then setnb_recycle_mbufs= 0 in that case too? Or probably would be enough to skip that mbuf? Might be something like that:Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
for (i = 0, j = 0; i < n; i++) {
rxep[j] = rte_pktmbuf_prefree_seg(txep[i].mbuf); if (rxep[j] == NULL || recycle_rxq_info->mp !=rxep[j].mbuf-
pool)) {
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
if (refill_requirement) { nb_recycle_mbufs = 0; break; } } else j++; }/* now j contains actual number of recycled mbufs */
?
Quoted 1 line
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 1 line
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +1
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
mp !=
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
txep[i].mbuf-
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 5 lines
Quoted 1 line
pool))
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +4
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
buffers
Quoted 103 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 6 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +6
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
rte_mempool_put(rxep[i]-
Quoted 96 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
pool,
Quoted 4 lines
Quoted 4 lines
drivers/net/i40e/i40e_recycle_mbufs_vec_common
Quoted 4 lines
rxep[i]);
drivers/net/i40e/i40e_recycle_mbufs_vec_common new file +3
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
[Konstantin] After another thought, it might be easier and cleaner
just to:
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
if (rxep[j] == NULL ||
recycle_rxq_info->mp!= rxep[j].mbuf->pool)nb_recycle_mbufs = 0;Anyway, from my understanding - if
rte_pktmbuf_prefree_seg(mbuf)returns NULL, then we can't recyclethat mbuf.
Quoted 81 lines
Quoted 81 lines
Quoted 39 lines
Quoted 39 lines
Quoted 3 lines
[Feifei] Agree with that '
rte_pktmbuf_prefree_seg(mbuf)returns NULL, thenwe can't recycle that mbuf'.
Quoted 3 lines
Firstly, we should know for i40e driver, the number of free mbufs is fixed, it
must equal to '
tx_rs_thresh'Quoted 2 lines
This means if we start to free Tx mbufs, it cannot be interrupted until the
given amount of mbufs are freed.
Quoted 3 lines
In the meanwhile, doing prefree operation for a Tx mbuf can be looked at this mbuf is freed from this TX sw-ring if the API returns NULL. This is due
to that call '
prefree_seg' function means update the mbuf refcnt.Quoted 4 lines
So let's come back our recycle mbuf case.
Here we consider that the case if we have 32 mbufs need to be freed, andwe firstly do the pre-free.
Quoted 2 lines
And then first 8 mbufs is good and return value is not none. But the 9th
mbuf is bad, its refcnt is more than 1.
Quoted 2 lines
So we just update its refcnt and cannot put it into Rx sw-ring. For Tx sw-ring,
this mbuf has been freed.
Quoted 6 lines
Then we should continue to do pre-free operation for the next Tx mbufs to ensure the given amount of mbufs are freed.
Do a conclusion for this, this is because if we start to do pre-free operation, the Tx mbuf refcnt value maybe changed, so we cannot stop or
break until finish all the pre-free operation.
Quoted 4 lines
Finally, in the case that Rx
refill_requestis not zero, but the valid mbuf amount is less than this value, we must put back this Tx mbufs intomempool.
Quoted 1 line
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Above is the reason why I do not directly jump out of the loop if some mbuf
return value is NULL.
Yep, I already realized that it is a bit more complicated and we need to continue with
prefree()for all packets even when we get NULL inthe middle.
Quoted 13 lines
Quoted 2 lines
Anyway the code has to be changed, right?
11 lines not shown · raw message
Quoted 8 lines
8 lines not shown · raw message
11 lines not shown · raw message
22 lines not shown · raw message
Quoted 8 lines
8 lines not shown · raw message
225 lines not shown · raw message
Parts of this message are not shown here. View the raw message.
RE: [PATCH v11 2/4] net/i40e: implement mbufs recycle mode
Quoted 559 lines
-----Original Message-----
From: Konstantin Ananyev <[email protected]>
Sent: Saturday, September 23, 2023 12:41 AM
To: Feifei Wang <[email protected]>; Konstantin Ananyev <[email protected]>
Cc: [email protected]; nd <[email protected]>; Honnappa Nagarahalli <[email protected]>; Ruifeng Wang <[email protected]>; Yuying Zhang <[email protected]>; Beilei Xing <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>
Subject: RE: [PATCH v11 2/4] net/i40e: implement mbufs recycle modeHi Feifei,
Quoted 32 lines
Quoted 32 lines
Quoted 7 lines
-----Original Message-----
From: Feifei Wang
Sent: Tuesday, September 5, 2023 11:11 AM
To: Konstantin Ananyev <[email protected]>; Konstantin Ananyev <[email protected]>
Cc: [email protected]; nd <[email protected]>; Honnappa Nagarahalli <[email protected]>; Ruifeng WangQuoted 24 lines
Yuying Zhang <[email protected]>; Beilei Xing <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>
Subject: RE: [PATCH v11 2/4] net/i40e: implement mbufs recycle modeQuoted 7 lines
-----Original Message-----
From: Konstantin Ananyev <[email protected]>
Sent: Monday, September 4, 2023 6:22 PM
To: Feifei Wang <[email protected]>; Konstantin Ananyev <[email protected]>
Cc: [email protected]; nd <[email protected]>; Honnappa Nagarahalli <[email protected]>; Ruifeng WangQuoted 8 lines
Yuying Zhang <[email protected]>; Beilei Xing <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>
Subject: RE: [PATCH v11 2/4] net/i40e: implement mbufs recycle modeQuoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
Define specific function implementation for i40e driver.
Currently, mbufs recycle mode can support 128bit
vector path and
avx2path.
Quoted 1 line
Quoted 1 line
And can be enabled both in fast free and no fast free
mode.
Quoted 39 lines
Quoted 39 lines
Quoted 39 lines
Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Suggested-by: Honnappa Nagarahalli
<[email protected]>
Signed-off-by: Feifei Wang
<[email protected]>
Reviewed-by: Ruifeng Wang <[email protected]>
Reviewed-by: Honnappa NagarahalliQuoted 22 lines
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
---
drivers/net/i40e/i40e_ethdev.c | 1 +
drivers/net/i40e/i40e_ethdev.h | 2 +
.../net/i40e/i40e_recycle_mbufs_vec_common.c |
147
++++++++++++++++++
drivers/net/i40e/i40e_rxtx.c | 32 ++++
drivers/net/i40e/i40e_rxtx.h | 4 +
drivers/net/i40e/meson.build | 1 +
6 files changed, 187 insertions(+) create mode
100644
drivers/net/i40e/i40e_recycle_mbufs_vec_common.cQuoted 8 lines
Quoted 8 lines
diff --git a/drivers/net/i40e/i40e_ethdev.c
b/drivers/net/i40e/i40e_ethdev.c index
8271bbb394..50ba9aac94
100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -496,6 +496,7 @@ static const struct
eth_dev_ops i40e_eth_dev_ops= {
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
.flow_ops_get = i40e_dev_flow_ops_get,
.rxq_info_get = i40e_rxq_info_get,
.txq_info_get = i40e_txq_info_get,
+ .recycle_rxq_info_get =
i40e_recycle_rxq_info_get,Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
.rx_burst_mode_get =
i40e_rx_burst_mode_get,Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
.tx_burst_mode_get =
i40e_tx_burst_mode_get,Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
.timesync_enable = i40e_timesync_enable,
diff --git a/drivers/net/i40e/i40e_ethdev.h
b/drivers/net/i40e/i40e_ethdev.h index
6f65d5e0ac..af758798e1
100644
--- a/drivers/net/i40e/i40e_ethdev.h
+++ b/drivers/net/i40e/i40e_ethdev.h
@@ -1355,6 +1355,8 @@ void
i40e_rxq_info_get(struct rte_eth_dev *dev, uint16_t
queue_id,Quoted 190 lines
Quoted 190 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
struct rte_eth_rxq_info *qinfo); void
i40e_txq_info_get(struct rte_eth_dev *dev,
uint16_t
queue_id,Quoted 186 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
struct rte_eth_txq_info *qinfo);
+void i40e_recycle_rxq_info_get(struct
+rte_eth_dev *dev, uint16_t
queue_id,Quoted 4 lines
Quoted 4 lines
+ struct rte_eth_recycle_rxq_info
+*recycle_rxq_info);
int i40e_rx_burst_mode_get(struct rte_eth_dev
*dev, uint16_t
queue_id,Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
struct rte_eth_burst_mode *mode);
int
Quoted 113 lines
Quoted 68 lines
Quoted 68 lines
Quoted 68 lines
Quoted 68 lines
Quoted 68 lines
Quoted 68 lines
Quoted 68 lines
Quoted 68 lines
i40e_tx_burst_mode_get(struct rte_eth_dev *dev,
uint16_t queue_id, diff -- git
a/drivers/net/i40e/i40e_recycle_mbufs_vec_common
.c
b/drivers/net/i40e/i40e_recycle_mbufs_vec_common
.c new file mode 100644 index
0000000000..5663ecccde
--- /dev/null
+++ b/drivers/net/i40e/i40e_recycle_mbufs_vec_co
+++ mmon
+++ .c
@@ -0,0 +1,147 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2023 Arm Limited.
+ */
+
+#include <stdint.h> #include <ethdev_driver.h>
+
+#include "base/i40e_prototype.h"
+#include "base/i40e_type.h"
+#include "i40e_ethdev.h"
+#include "i40e_rxtx.h"
+
+#pragma GCC diagnostic ignored "-Wcast-qual"
+
+void
+i40e_recycle_rx_descriptors_refill_vec(void
+*rx_queue, uint16_t
+nb_mbufs) {
+ struct i40e_rx_queue *rxq = rx_queue;
+ struct i40e_rx_entry *rxep;
+ volatile union i40e_rx_desc *rxdp;
+ uint16_t rx_id;
+ uint64_t paddr;
+ uint64_t dma_addr;
+ uint16_t i;
+
+ rxdp = rxq->rx_ring + rxq->rxrearm_start;
+ rxep = &rxq->sw_ring[rxq->rxrearm_start];
+
+ for (i = 0; i < nb_mbufs; i++) {
+ /* Initialize rxdp descs. */
+ paddr = (rxep[i].mbuf)->buf_iova +
RTE_PKTMBUF_HEADROOM;
+ dma_addr = rte_cpu_to_le_64(paddr);
+ /* flush desc with pa dma_addr */
+ rxdp[i].read.hdr_addr = 0;
+ rxdp[i].read.pkt_addr = dma_addr;
+ }
+
+ /* Update the descriptor initializer index */
+ rxq->rxrearm_start += nb_mbufs;
+ rx_id = rxq->rxrearm_start - 1;
+
+ if (unlikely(rxq->rxrearm_start >= rxq->nb_rx_desc)) {
+ rxq->rxrearm_start = 0;
+ rx_id = rxq->nb_rx_desc - 1;
+ }
+
+ rxq->rxrearm_nb -= nb_mbufs;
+
+ rte_io_wmb();
+ /* Update the tail pointer on the NIC */
+ I40E_PCI_REG_WRITE_RELAXED(rxq->qrx_tail,
+rx_id); }
+
+uint16_t
+i40e_recycle_tx_mbufs_reuse_vec(void *tx_queue,Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
+ struct rte_eth_recycle_rxq_info *recycle_rxq_info) {
+ struct i40e_tx_queue *txq = tx_queue;
+ struct i40e_tx_entry *txep;
+ struct rte_mbuf **rxep;
+ int i, n;
+ uint16_t nb_recycle_mbufs;
+ uint16_t avail = 0;
+ uint16_t mbuf_ring_size = recycle_rxq_info-
mbuf_ring_size;Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Quoted 27 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
+ uint16_t mask = recycle_rxq_info->mbuf_ring_size - 1;
+ uint16_t refill_requirement =
+recycle_rxq_info-
refill_requirement;Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
+ uint16_t refill_head = *recycle_rxq_info->refill_head;
+ uint16_t receive_tail =
+*recycle_rxq_info->receive_tail;
+Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
+ /* Get available recycling Rx buffers. */
+ avail = (mbuf_ring_size - (refill_head -
+receive_tail)) & mask;
+
+ /* Check Tx free thresh and Rx available space. */
+ if (txq->nb_tx_free > txq->tx_free_thresh ||
+avail <=
+txq-
tx_rs_thresh)Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
+ return 0;
+
+ /* check DD bits on threshold descriptor */
+ if
+((txq->tx_ring[txq->tx_next_dd].cmd_type_offset
+_bsz
+&
+
rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) !=
+Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE))
+ return 0;
+
+ n = txq->tx_rs_thresh;
+ nb_recycle_mbufs = n;
+
+ /* Mbufs recycle mode can only support no ring
+bufferwrapping
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
around.
+ * Two case for this:
+ *
+ * case 1: The refill head of Rx buffer ring
+needs to be alignedwith
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
+ * mbuf ring size. In this case, the number of
+Txfreeing buffers
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
+ * should be equal to refill_requirement.
+ *
+ * case 2: The refill head of Rx ring buffer
+does not need to bealigned
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
+ * with mbuf ring size. In this case, the
+update of refill headcan not
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
+ * exceed the Rx mbuf ring size.
+ */
+ if (refill_requirement != n ||
+ (!refill_requirement && (refill_head + n >
mbuf_ring_size)))Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
+ return 0;
+
+ /* First buffer to free from S/W ring is at index
+ * tx_next_dd - (tx_rs_thresh-1).
+ */
+ txep = &txq->sw_ring[txq->tx_next_dd - (n - 1)];
+ rxep = recycle_rxq_info->mbuf_ring;
+ rxep += refill_head;
+
+ if (txq->offloads &
RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE) {Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ /* Avoid txq contains buffers from unexpected
mempool. */
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
+ if (unlikely(recycle_rxq_info->mp
+ != txep[0].mbuf-pool))
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
+ return 0;
+
+ /* Directly put mbufs from Tx to Rx. */
+ for (i = 0; i < n; i++)
+ rxep[i] = txep[i].mbuf;
+ } else {
+ for (i = 0; i < n; i++) {
+ rxep[i] =
rte_pktmbuf_prefree_seg(txep[i].mbuf);Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
+
+ /* If Tx buffers are not the lastreference or
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
from
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ * unexpected mempool, previous
copied
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
buffers are
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
+ * considered as invalid.
+ */
+ if (unlikely((rxep[i] == NULL &&
refill_requirement) ||Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
[Konstantin]
Could you pls remind me why it is ok to have rxep[i]==NULL whenrefill_requirementis not set?Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
If
reill_requirementis not zero, it means each tx freed buffer must be valid and can be put into Rxsw_ring. Then the refill head of Rx buffer ring can be aligned with mbuf ring size. Briefly speaking the numberof Tx valid freed buffer must be equal to Rx
refill_requirement.Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
For example, i40e driver.
Quoted 7 lines
If
reill_requirementis zero, it means that the refill head of Rx buffer ring does not need to be aligned with mbuf ring size, thus if Tx have n valid freed buffers, we just need to put these n buffers into Rx
sw-ring, and not to be equal to the Rx setting rearm number. For example, mlx5 driver.
Quoted 3 lines
In conclusion, above difference is due to pmd drivers have different
strategies to update their Rx rearm(refill) head.
Quoted 3 lines
For i40e driver, if
rearm_headexceed 1024, it will be set as
0 due to theQuoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
number of each rearm is a fixed value by default.
Quoted 2 lines
For mlx5 driver. Its
rearm_headcan exceed 1024, and use mask to achievereal index. Thus its rearm number can be a different value.
Ok, but if
rte_pktmbuf_prefree_seg(txep[i].mbuf), it means that this mbuf is not free yet and can't be reused. Shouldn't we then setnb_recycle_mbufs= 0 in that casetoo?
Quoted 45 lines
Quoted 45 lines
Quoted 45 lines
Quoted 22 lines
Quoted 22 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Or probably would be enough to skip that mbuf? Might be something like that:
for (i = 0, j = 0; i < n; i++) {
rxep[j] = rte_pktmbuf_prefree_seg(txep[i].mbuf); if (rxep[j] == NULL || recycle_rxq_info->mp !=rxep[j].mbuf-
pool)) {
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
if (refill_requirement) { nb_recycle_mbufs = 0; break; } } else j++; }/* now j contains actual number of recycled mbufs */
?
Quoted 1 line
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ recycle_rxq_info-
mp !=
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
txep[i].mbuf-
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
pool))
+ nb_recycle_mbufs = 0;
+ }
+ /* If Tx buffers are not the last reference or
+ * from unexpected mempool, all recycledbuffers
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
+ * are put into mempool.
+ */
+ if (nb_recycle_mbufs == 0)
+ for (i = 0; i < n; i++) {
+ if (rxep[i] != NULL)
+rte_mempool_put(rxep[i]-
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
pool,
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
rxep[i]);
+ }
+ }
+[Konstantin] After another thought, it might be easier and cleaner
Quoted 24 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
just to:
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
if (rxep[j] == NULL ||
recycle_rxq_info->mp!= rxep[j].mbuf-pool)
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
nb_recycle_mbufs = 0;Anyway, from my understanding - if
rte_pktmbuf_prefree_seg(mbuf)returns NULL, then we can't recyclethat mbuf.
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 3 lines
[Feifei] Agree with that '
rte_pktmbuf_prefree_seg(mbuf)returns NULL, thenwe can't recycle that mbuf'.
Quoted 3 lines
Firstly, we should know for i40e driver, the number of free mbufs is fixed, it
must equal to '
tx_rs_thresh'Quoted 2 lines
This means if we start to free Tx mbufs, it cannot be interrupted until the
given amount of mbufs are freed.
Quoted 3 lines
In the meanwhile, doing prefree operation for a Tx mbuf can be looked at this mbuf is freed from this TX sw-ring if the API returns NULL. This is due
to that call '
prefree_seg' function means update the mbufrefcnt.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
So let's come back our recycle mbuf case. Here we consider that the case if we have 32 mbufs need to be freed, and
we firstly do the pre-free.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
And then first 8 mbufs is good and return value is not none. But the 9th
mbuf is bad, its refcnt is more than 1.
Quoted 2 lines
So we just update its refcnt and cannot put it into Rx sw-ring. For Tx sw-ring,
this mbuf has been freed.
Quoted 2 lines
Then we should continue to do pre-free operation for the next Tx mbufs to ensure the given amount of mbufs are
freed.
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 11 lines
Quoted 11 lines
Quoted 4 lines
Do a conclusion for this, this is because if we start to do pre-free operation, the Tx mbuf refcnt value maybe changed, so we cannot stop or
break until finish all the pre-free operation.
Quoted 4 lines
Finally, in the case that Rx
refill_requestis not zero, but the valid mbuf amount is less than this value, we must put back this Tx mbufs intomempool.
Quoted 1 line
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Above is the reason why I do not directly jump out of the loop if some mbuf
return value is NULL.
Yep, I already realized that it is a bit more complicated and we need to continue with
prefree()for all packets even when we get NULL inthe middle.
Quoted 2 lines
Quoted 2 lines
Anyway the code has to be changed, right?
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Sorry, I think for the code, it is unnecessary to be changed. For no fast free path, currently:
1. We check whether each mbuf is Ok and callpre_freefunction
----------------------------------------------------------
----
--
--
----
----------------------------------------------------------
----
2.1 For the mbuf return value is not NULL, it is put into Rx sw-ring.
Quoted 41 lines
Quoted 41 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 5 lines
2.2 For the mbuf return value is zero and refill-request, it will also firstly put into Rx sw-ring, and we set
nb_recycle=
0
----------------------------------------------------------Quoted 8 lines
----
--
--
----
----------------------------------------------------------
----
3.1 We checknb_recycle, if it is not 0, we will continue to rearm Rx descsand update its index by call
descs_refillfunction.Quoted 6 lines
3.2 if
nb_recycleis 0, we will put valid recycle mbufs back into mempool as general path. This is necessary, because we need to ensure the freed Tx number is fixed.(Some buffers return is null can be seen as freed, others need to be put into mempool)Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Or maybe I ignore something?
3 lines not shown · raw message
15 lines not shown · raw message
Quoted 6 lines
6 lines not shown · raw message
55 lines not shown · raw message
(quoted diff) +0
-0for (i = 0; i < j; i++) { if (rxep[i] != NULL) rte_mempool_put(rxep[i]->pool, rxep[i]);Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
2 lines not shown · raw message
Quoted 3 lines
1 line not shown · raw message
196 lines not shown · raw message
Parts of this message are not shown here. View the raw message.
Re: [PATCH v11 2/4] net/i40e: implement mbufs recycle mode
Quoted 529 lines
Quoted 510 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Define specific function implementation for i40e driver.
Currently, mbufs recycle mode can support 128bit
vector path and
avx2path.
Quoted 1 line
And can be enabled both in fast free and no fast free
mode.
Quoted 39 lines
Quoted 39 lines
Quoted 39 lines
Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Suggested-by: Honnappa Nagarahalli
<[email protected]>
Signed-off-by: Feifei Wang
<[email protected]>
Reviewed-by: Ruifeng Wang <[email protected]>
Reviewed-by: Honnappa NagarahalliQuoted 22 lines
Quoted 22 lines
Quoted 21 lines
---
drivers/net/i40e/i40e_ethdev.c | 1 +
drivers/net/i40e/i40e_ethdev.h | 2 +
.../net/i40e/i40e_recycle_mbufs_vec_common.c |
147
++++++++++++++++++
drivers/net/i40e/i40e_rxtx.c | 32 ++++
drivers/net/i40e/i40e_rxtx.h | 4 +
drivers/net/i40e/meson.build | 1 +
6 files changed, 187 insertions(+) create mode
100644
drivers/net/i40e/i40e_recycle_mbufs_vec_common.cdiff --git a/drivers/net/i40e/i40e_ethdev.c
b/drivers/net/i40e/i40e_ethdev.c index
8271bbb394..50ba9aac94
100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -496,6 +496,7 @@ static const struct
eth_dev_ops i40e_eth_dev_ops= {
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
.flow_ops_get = i40e_dev_flow_ops_get,
.rxq_info_get = i40e_rxq_info_get,
.txq_info_get = i40e_txq_info_get,
+ .recycle_rxq_info_get =
i40e_recycle_rxq_info_get,Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
.rx_burst_mode_get =
i40e_rx_burst_mode_get,Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
.tx_burst_mode_get =
i40e_tx_burst_mode_get,Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
.timesync_enable = i40e_timesync_enable,
diff --git a/drivers/net/i40e/i40e_ethdev.h
b/drivers/net/i40e/i40e_ethdev.h index
6f65d5e0ac..af758798e1
100644
--- a/drivers/net/i40e/i40e_ethdev.h
+++ b/drivers/net/i40e/i40e_ethdev.h
@@ -1355,6 +1355,8 @@ void
i40e_rxq_info_get(struct rte_eth_dev *dev, uint16_t
queue_id,Quoted 190 lines
Quoted 190 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
struct rte_eth_rxq_info *qinfo); void
i40e_txq_info_get(struct rte_eth_dev *dev,
uint16_t
queue_id,Quoted 186 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
struct rte_eth_txq_info *qinfo);
+void i40e_recycle_rxq_info_get(struct
+rte_eth_dev *dev, uint16_t
queue_id,Quoted 4 lines
+ struct rte_eth_recycle_rxq_info
+*recycle_rxq_info);
int i40e_rx_burst_mode_get(struct rte_eth_dev
*dev, uint16_t
queue_id,Quoted 1 line
Quoted 1 line
Quoted 1 line
struct rte_eth_burst_mode *mode);
int
Quoted 113 lines
Quoted 68 lines
Quoted 68 lines
Quoted 68 lines
Quoted 68 lines
Quoted 68 lines
Quoted 68 lines
Quoted 68 lines
i40e_tx_burst_mode_get(struct rte_eth_dev *dev,
uint16_t queue_id, diff -- git
a/drivers/net/i40e/i40e_recycle_mbufs_vec_common
.c
b/drivers/net/i40e/i40e_recycle_mbufs_vec_common
.c new file mode 100644 index
0000000000..5663ecccde
--- /dev/null
+++ b/drivers/net/i40e/i40e_recycle_mbufs_vec_co
+++ mmon
+++ .c
@@ -0,0 +1,147 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2023 Arm Limited.
+ */
+
+#include <stdint.h> #include <ethdev_driver.h>
+
+#include "base/i40e_prototype.h"
+#include "base/i40e_type.h"
+#include "i40e_ethdev.h"
+#include "i40e_rxtx.h"
+
+#pragma GCC diagnostic ignored "-Wcast-qual"
+
+void
+i40e_recycle_rx_descriptors_refill_vec(void
+*rx_queue, uint16_t
+nb_mbufs) {
+ struct i40e_rx_queue *rxq = rx_queue;
+ struct i40e_rx_entry *rxep;
+ volatile union i40e_rx_desc *rxdp;
+ uint16_t rx_id;
+ uint64_t paddr;
+ uint64_t dma_addr;
+ uint16_t i;
+
+ rxdp = rxq->rx_ring + rxq->rxrearm_start;
+ rxep = &rxq->sw_ring[rxq->rxrearm_start];
+
+ for (i = 0; i < nb_mbufs; i++) {
+ /* Initialize rxdp descs. */
+ paddr = (rxep[i].mbuf)->buf_iova +
RTE_PKTMBUF_HEADROOM;
+ dma_addr = rte_cpu_to_le_64(paddr);
+ /* flush desc with pa dma_addr */
+ rxdp[i].read.hdr_addr = 0;
+ rxdp[i].read.pkt_addr = dma_addr;
+ }
+
+ /* Update the descriptor initializer index */
+ rxq->rxrearm_start += nb_mbufs;
+ rx_id = rxq->rxrearm_start - 1;
+
+ if (unlikely(rxq->rxrearm_start >= rxq->nb_rx_desc)) {
+ rxq->rxrearm_start = 0;
+ rx_id = rxq->nb_rx_desc - 1;
+ }
+
+ rxq->rxrearm_nb -= nb_mbufs;
+
+ rte_io_wmb();
+ /* Update the tail pointer on the NIC */
+ I40E_PCI_REG_WRITE_RELAXED(rxq->qrx_tail,
+rx_id); }
+
+uint16_t
+i40e_recycle_tx_mbufs_reuse_vec(void *tx_queue,Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
+ struct rte_eth_recycle_rxq_info *recycle_rxq_info) {
+ struct i40e_tx_queue *txq = tx_queue;
+ struct i40e_tx_entry *txep;
+ struct rte_mbuf **rxep;
+ int i, n;
+ uint16_t nb_recycle_mbufs;
+ uint16_t avail = 0;
+ uint16_t mbuf_ring_size = recycle_rxq_info-
mbuf_ring_size;Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Quoted 27 lines
Quoted 3 lines
Quoted 3 lines
+ uint16_t mask = recycle_rxq_info->mbuf_ring_size - 1;
+ uint16_t refill_requirement =
+recycle_rxq_info-
refill_requirement;Quoted 4 lines
Quoted 4 lines
+ uint16_t refill_head = *recycle_rxq_info->refill_head;
+ uint16_t receive_tail =
+*recycle_rxq_info->receive_tail;
+Quoted 8 lines
Quoted 8 lines
+ /* Get available recycling Rx buffers. */
+ avail = (mbuf_ring_size - (refill_head -
+receive_tail)) & mask;
+
+ /* Check Tx free thresh and Rx available space. */
+ if (txq->nb_tx_free > txq->tx_free_thresh ||
+avail <=
+txq-
tx_rs_thresh)Quoted 10 lines
Quoted 10 lines
+ return 0;
+
+ /* check DD bits on threshold descriptor */
+ if
+((txq->tx_ring[txq->tx_next_dd].cmd_type_offset
+_bsz
+&
+
rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) !=
+Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE))
+ return 0;
+
+ n = txq->tx_rs_thresh;
+ nb_recycle_mbufs = n;
+
+ /* Mbufs recycle mode can only support no ring
+bufferwrapping
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
around.
+ * Two case for this:
+ *
+ * case 1: The refill head of Rx buffer ring
+needs to be alignedwith
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
+ * mbuf ring size. In this case, the number of
+Txfreeing buffers
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
+ * should be equal to refill_requirement.
+ *
+ * case 2: The refill head of Rx ring buffer
+does not need to bealigned
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
+ * with mbuf ring size. In this case, the
+update of refill headcan not
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
+ * exceed the Rx mbuf ring size.
+ */
+ if (refill_requirement != n ||
+ (!refill_requirement && (refill_head + n >
mbuf_ring_size)))Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
+ return 0;
+
+ /* First buffer to free from S/W ring is at index
+ * tx_next_dd - (tx_rs_thresh-1).
+ */
+ txep = &txq->sw_ring[txq->tx_next_dd - (n - 1)];
+ rxep = recycle_rxq_info->mbuf_ring;
+ rxep += refill_head;
+
+ if (txq->offloads &
RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE) {Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ /* Avoid txq contains buffers from unexpected
mempool. */
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
+ if (unlikely(recycle_rxq_info->mp
+ != txep[0].mbuf-pool))
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
+ return 0;
+
+ /* Directly put mbufs from Tx to Rx. */
+ for (i = 0; i < n; i++)
+ rxep[i] = txep[i].mbuf;
+ } else {
+ for (i = 0; i < n; i++) {
+ rxep[i] =
rte_pktmbuf_prefree_seg(txep[i].mbuf);Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
+
+ /* If Tx buffers are not the lastreference or
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
from
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ * unexpected mempool, previous
copied
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
buffers are
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
+ * considered as invalid.
+ */
+ if (unlikely((rxep[i] == NULL &&
refill_requirement) ||Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
[Konstantin]
Could you pls remind me why it is ok to have
rxep[i]==NULL when refill_requirement is not set?Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
If reill_requirement is not zero, it means each tx
freed buffer must be valid and can be put into Rx sw_ring.
Then the refill head of Rx buffer ring can be
aligned with mbuf ring size. Briefly speaking the
numberof Tx valid freed buffer must be equal to Rx
refill_requirement.Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
For example, i40e driver.
Quoted 7 lines
If reill_requirement is zero, it means that the
refill head of Rx buffer ring does not need to be
aligned with mbuf ring size, thus if Tx have n
valid freed buffers, we just need to put these n
buffers into Rx
sw-ring, and not to be equal to the Rx setting rearm number. For example, mlx5 driver.
Quoted 3 lines
In conclusion, above difference is due to pmd
drivers have differentstrategies to update their Rx rearm(refill) head.
Quoted 3 lines
For i40e driver, if rearm_head exceed 1024, it
will be set as
0 due to theQuoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
number of each rearm is a fixed value by default.
Quoted 2 lines
For mlx5 driver. Its rearm_head can exceed 1024,
and use mask to achievereal index. Thus its rearm number can be a different value.
Ok, but if
rte_pktmbuf_prefree_seg(txep[i].mbuf), it means that this mbuf is not free yet and can't be reused. Shouldn't we then setnb_recycle_mbufs= 0 in that casetoo?
Quoted 45 lines
Quoted 45 lines
Quoted 45 lines
Quoted 22 lines
Quoted 22 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Or probably would be enough to skip that mbuf? Might be something like that:
for (i = 0, j = 0; i < n; i++) {
rxep[j] = rte_pktmbuf_prefree_seg(txep[i].mbuf); if (rxep[j] == NULL || recycle_rxq_info->mp !=rxep[j].mbuf-
pool)) {
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
if (refill_requirement) { nb_recycle_mbufs = 0; break; } } else j++; }/* now j contains actual number of recycled mbufs */
?
Quoted 1 line
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ recycle_rxq_info-
mp !=
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
txep[i].mbuf-
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
pool))
+ nb_recycle_mbufs = 0;
+ }
+ /* If Tx buffers are not the last reference or
+ * from unexpected mempool, all recycledbuffers
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
+ * are put into mempool.
+ */
+ if (nb_recycle_mbufs == 0)
+ for (i = 0; i < n; i++) {
+ if (rxep[i] != NULL)
+rte_mempool_put(rxep[i]-
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
pool,
Quoted 4 lines
Quoted 4 lines
rxep[i]);
+ }
+ }
+[Konstantin] After another thought, it might be easier and cleaner
Quoted 24 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
just to:
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
if (rxep[j] == NULL ||
recycle_rxq_info->mp!= rxep[j].mbuf-pool)
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
nb_recycle_mbufs = 0;Anyway, from my understanding - if
rte_pktmbuf_prefree_seg(mbuf)returns NULL, then we can't recyclethat mbuf.
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 3 lines
[Feifei] Agree with that '
rte_pktmbuf_prefree_seg(mbuf)returns NULL, thenwe can't recycle that mbuf'.
Quoted 3 lines
Firstly, we should know for i40e driver, the number of free mbufs is fixed, it
must equal to '
tx_rs_thresh'Quoted 2 lines
This means if we start to free Tx mbufs, it cannot be interrupted until the
given amount of mbufs are freed.
Quoted 3 lines
In the meanwhile, doing prefree operation for a Tx mbuf can be looked at this mbuf is freed from this TX sw-ring if the API returns NULL. This is due
to that call '
prefree_seg' function means update the mbufrefcnt.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
So let's come back our recycle mbuf case. Here we consider that the case if we have 32 mbufs need to be freed, and
we firstly do the pre-free.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
And then first 8 mbufs is good and return value is not none. But the 9th
mbuf is bad, its refcnt is more than 1.
Quoted 2 lines
So we just update its refcnt and cannot put it into Rx sw-ring. For Tx sw-ring,
this mbuf has been freed.
Quoted 2 lines
Then we should continue to do pre-free operation for the next Tx mbufs to ensure the given amount of mbufs are
freed.
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 11 lines
Quoted 11 lines
Quoted 4 lines
Do a conclusion for this, this is because if we start to do pre-free operation, the Tx mbuf refcnt value maybe changed, so we cannot stop or
break until finish all the pre-free operation.
Quoted 4 lines
Finally, in the case that Rx
refill_requestis not zero, but the valid mbuf amount is less than this value, we must put back this Tx mbufs intomempool.
Quoted 1 line
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Above is the reason why I do not directly jump out of the loop if some mbuf
return value is NULL.
Yep, I already realized that it is a bit more complicated and we need to continue with
prefree()for all packets even when we get NULL inthe middle.
Quoted 2 lines
Quoted 2 lines
Anyway the code has to be changed, right?
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Sorry, I think for the code, it is unnecessary to be changed. For no fast free path, currently:
1. We check whether each mbuf is Ok and callpre_freefunction
----------------------------------------------------------
----
--
--
----
----------------------------------------------------------
----
2.1 For the mbuf return value is not NULL, it is put into Rx sw-ring.
Quoted 41 lines
Quoted 41 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 5 lines
2.2 For the mbuf return value is zero and refill-request, it will also firstly put into Rx sw-ring, and we set
nb_recycle=
0
----------------------------------------------------------Quoted 8 lines
----
--
--
----
----------------------------------------------------------
----
3.1 We checknb_recycle, if it is not 0, we will continue to rearm Rx descsand update its index by call
descs_refillfunction.Quoted 6 lines
3.2 if
nb_recycleis 0, we will put valid recycle mbufs back into mempool as general path. This is necessary, because we need to ensure the freed Tx number is fixed.(Some buffers return is null can be seen as freed, others need to be put into mempool)Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Or maybe I ignore something?
I am talking about the case when both
refill_requirementand mbuf return values iare zero:
if (unlikely((rxep[i] == NULL &&refill_requirement) || // ???rxep[i]
Quoted 14 lines
==
Quoted 13 lines
0
Quoted 12 lines
Quoted 7 lines
AND
refill_requirement== 0 ???
recycle_rxq_info->mp!= txep[i].mbuf->pool))nb_recycle_mbufs = 0;As I can read the code you treat such situation as valid, while I think we should reset
nb_recycle_mbufsto zero when rxep[i] == NULL, no matter what valuerefill_requirementis.So this means for maybe MLX5 driver, its
refill_request= 0. And if some mbufs return value is zero, the other mbufs can not be recycled into Rx sw-ring? Because nb_recycle=0, and they need to be put intoQuoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
mempool.
Quoted 3 lines
I think for such as MLX5 driver, we can allow recycle some valid mbufs into
Rx ring.
Quoted 1 line
Because no constraint for its refill number. Is my suggestion
reasonable?
Quoted 9 lines
Quoted 9 lines
Quoted 6 lines
Quoted 5 lines
I suppose yes: if
refill_requestis zero we potentially can skip 'bad' mbufs and continue with recycling for remaining ones.
It would probably require more changes in current code, but sounds ok to me in general.That's Ok. Thanks for your careful reviewing.
I'm very sorry not to receive your e-mail and until now I realize we need to do some code change for i40e driver. Also thanks ferruh to kindly
remind this.
No worries at all and thanks for you and Ferruh fro fast reaction.
Quoted 31 lines
Quoted 14 lines
Agree with you we need some operation for the case that (
refill_requirement== 0 && rxep[i] == 0). Thus maybe we can do a change as follows:for (i = 0; i < n; i++) { rxep[0] = rte_pktmbuf_prefree_seg(txep[i].mbuf); if (unlikely((rxep[0] == NULL && refill_requirement) || recycle_rxq_info->mp != txep[i].mbuf->pool)) nb_recycle_mbufs = 0; if (likely(rxep[0])) rxep++; }Quoted 2 lines
Is above change is Ok?
Just do a change for the above code:
----------------------------------------------------------------------
-------------------------------
int j = 0;
......for (i = 0; i < n; i++) {
rxep[j] = rte_pktmbuf_prefree_seg(txep[i].mbuf); if (unlikely(rxep[j] == NULL && !refill_requirement)) continue; if (unlikely((rxep[j] == NULL && refill_requirement) || recycle_rxq_info->mp != txep[i].mbuf->pool)) nb_recycle_mbufs = 0; j++;Quoted 7 lines
}
if (
nb_recycle_mbufs== 0)for (i = 0; i < j; i++) { if (rxep[i] != NULL) rte_mempool_put(rxep[i]->pool, rxep[i]); }I think it should work...
One more thing, shouldn't we resetnb_recycle_mbufs= j;Something like:
if (nb_recycle_mbufs== 0) {
for (i = 0; i < j; i++) {
if (rxep[i] != NULL)
rte_mempool_put(rxep[i]->pool, rxep[i]);
}
} else
nb_recycle_mbufs= j;Quoted 3 lines
?
Yes, we should reset it.
I just do a performance test with the new code and find the performance decrease with 8%, comparing with the old version.
Thus I think we should come back your previous idea:
"we should resetnb_recycle_mbufsto zero when rxep[i] == NULL, no matter what valuerefill_requirementis":for (i = 0; i < n; i++) { rxep[i] = rte_pktmbuf_prefree_seg(txep[i].mbuf); if (unlikely((rxep[i] == NULL) || recycle_rxq_info->mp != txep[i].mbuf->pool)) nb_recycle_mbufs = 0; }
Quoted 2 lines
Thus we drop the case that putting the remaining valid mbuf into Rx sw-ring when no
refill_request, but maintain good performance.
I am ok with that way too.
Again that way, it looks simpler and probaly less error-prone. Thanks
Konstantin
RE: [PATCH v11 2/4] net/i40e: implement mbufs recycle mode
In reply to Feifei WangFor Konstantin
Quoted 639 lines
-----Original Message-----
From: Feifei Wang
Sent: Saturday, September 23, 2023 1:52 PM
To: Konstantin Ananyev <[email protected]>; Konstantin Ananyev <[email protected]>
Cc: [email protected]; nd <[email protected]>; Honnappa Nagarahalli <[email protected]>; Ruifeng Wang <[email protected]>; Yuying Zhang <[email protected]>; Beilei Xing <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>
Subject: RE: [PATCH v11 2/4] net/i40e: implement mbufs recycle modeQuoted 7 lines
-----Original Message-----
From: Konstantin Ananyev <[email protected]>
Sent: Saturday, September 23, 2023 12:41 AM
To: Feifei Wang <[email protected]>; Konstantin Ananyev <[email protected]>
Cc: [email protected]; nd <[email protected]>; Honnappa Nagarahalli <[email protected]>; Ruifeng WangQuoted 3 lines
Yuying Zhang <[email protected]>; Beilei Xing <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd
<[email protected]>; nd
Quoted 38 lines
<[email protected]>
Subject: RE: [PATCH v11 2/4] net/i40e: implement mbufs recycle modeHi Feifei,
Quoted 32 lines
Quoted 32 lines
Quoted 7 lines
-----Original Message-----
From: Feifei Wang
Sent: Tuesday, September 5, 2023 11:11 AM
To: Konstantin Ananyev <[email protected]>; Konstantin Ananyev <[email protected]>
Cc: [email protected]; nd <[email protected]>; Honnappa Nagarahalli <[email protected]>; Ruifeng WangQuoted 24 lines
Yuying Zhang <[email protected]>; Beilei Xing <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>
Subject: RE: [PATCH v11 2/4] net/i40e: implement mbufs recycle modeQuoted 7 lines
-----Original Message-----
From: Konstantin Ananyev <[email protected]>
Sent: Monday, September 4, 2023 6:22 PM
To: Feifei Wang <[email protected]>; Konstantin Ananyev <[email protected]>
Cc: [email protected]; nd <[email protected]>; Honnappa Nagarahalli <[email protected]>; Ruifeng WangQuoted 8 lines
Yuying Zhang <[email protected]>; Beilei Xing <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>; nd <[email protected]>
Subject: RE: [PATCH v11 2/4] net/i40e: implement mbufs recycle modeQuoted 43 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Define specific function implementation for i40e driver.
Currently, mbufs recycle mode can support
128bit vector path and
avx2path.
Quoted 2 lines
And can be enabled both in fast free and no
fast freemode.
Quoted 35 lines
Quoted 35 lines
Quoted 35 lines
Quoted 35 lines
Quoted 35 lines
Quoted 35 lines
Quoted 35 lines
Quoted 35 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Suggested-by: Honnappa Nagarahalli
<[email protected]>
Signed-off-by: Feifei Wang
<[email protected]>
Reviewed-by: Ruifeng Wang
<[email protected]>
Reviewed-by: Honnappa NagarahalliQuoted 26 lines
Quoted 26 lines
Quoted 24 lines
---
drivers/net/i40e/i40e_ethdev.c | 1 +
drivers/net/i40e/i40e_ethdev.h | 2 +
.../net/i40e/i40e_recycle_mbufs_vec_common.c
|
147
++++++++++++++++++
drivers/net/i40e/i40e_rxtx.c | 32 ++++
drivers/net/i40e/i40e_rxtx.h | 4 +
drivers/net/i40e/meson.build | 1 +
6 files changed, 187 insertions(+) create
mode
100644
drivers/net/i40e/i40e_recycle_mbufs_vec_common
.cdiff --git a/drivers/net/i40e/i40e_ethdev.c
b/drivers/net/i40e/i40e_ethdev.c index
8271bbb394..50ba9aac94
100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -496,6 +496,7 @@ static const struct
eth_dev_ops i40e_eth_dev_ops= {
Quoted 1 line
.flow_ops_get =
i40e_dev_flow_ops_get,Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
.rxq_info_get = i40e_rxq_info_get,
.txq_info_get = i40e_txq_info_get,
+ .recycle_rxq_info_get =
i40e_recycle_rxq_info_get,Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
.rx_burst_mode_get =
i40e_rx_burst_mode_get,Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
.tx_burst_mode_get =
i40e_tx_burst_mode_get,Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
.timesync_enable =
i40e_timesync_enable,Quoted 24 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
diff --git a/drivers/net/i40e/i40e_ethdev.h
b/drivers/net/i40e/i40e_ethdev.h index
6f65d5e0ac..af758798e1
100644
--- a/drivers/net/i40e/i40e_ethdev.h
+++ b/drivers/net/i40e/i40e_ethdev.h
@@ -1355,6 +1355,8 @@ void
i40e_rxq_info_get(struct rte_eth_dev *dev,
uint16_t
queue_id,Quoted 14 lines
Quoted 14 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
struct rte_eth_rxq_info *qinfo); void
i40e_txq_info_get(struct rte_eth_dev *dev,
uint16_t
queue_id,Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
struct rte_eth_txq_info *qinfo);
+void i40e_recycle_rxq_info_get(struct
+rte_eth_dev *dev, uint16_t
queue_id,Quoted 4 lines
+ struct rte_eth_recycle_rxq_info
+*recycle_rxq_info);
int i40e_rx_burst_mode_get(struct rte_eth_dev
*dev, uint16_t
queue_id,Quoted 1 line
Quoted 1 line
Quoted 1 line
struct rte_eth_burst_mode
*mode);
Quoted 60 lines
Quoted 51 lines
Quoted 51 lines
Quoted 51 lines
int
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
i40e_tx_burst_mode_get(struct rte_eth_dev
*dev, uint16_t queue_id, diff -- git
a/drivers/net/i40e/i40e_recycle_mbufs_vec_comm
on
.c
b/drivers/net/i40e/i40e_recycle_mbufs_vec_comm
on .c new file mode 100644 index
0000000000..5663ecccde
--- /dev/null
+++ b/drivers/net/i40e/i40e_recycle_mbufs_vec_
+++ co
+++ mmon
+++ .c
@@ -0,0 +1,147 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2023 Arm Limited.
+ */
+
+#include <stdint.h> #include
+<ethdev_driver.h>
+
+#include "base/i40e_prototype.h"
+#include "base/i40e_type.h"
+#include "i40e_ethdev.h"
+#include "i40e_rxtx.h"
+
+#pragma GCC diagnostic ignored "-Wcast-qual"
+
+void
+i40e_recycle_rx_descriptors_refill_vec(void
+*rx_queue, uint16_t
+nb_mbufs) {
+ struct i40e_rx_queue *rxq = rx_queue;
+ struct i40e_rx_entry *rxep;
+ volatile union i40e_rx_desc *rxdp;
+ uint16_t rx_id;
+ uint64_t paddr;
+ uint64_t dma_addr;
+ uint16_t i;
+
+ rxdp = rxq->rx_ring + rxq->rxrearm_start;
+ rxep = &rxq->sw_ring[rxq->rxrearm_start];
+
+ for (i = 0; i < nb_mbufs; i++) {
+ /* Initialize rxdp descs. */
+ paddr = (rxep[i].mbuf)->buf_iova +
RTE_PKTMBUF_HEADROOM;
+ dma_addr = rte_cpu_to_le_64(paddr);
+ /* flush desc with pa dma_addr */
+ rxdp[i].read.hdr_addr = 0;Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
+ rxdp[i].read.pkt_addr = dma_addr;
+ }
+
+ /* Update the descriptor initializer index */
+ rxq->rxrearm_start += nb_mbufs;
+ rx_id = rxq->rxrearm_start - 1;
+
+ if (unlikely(rxq->rxrearm_start >= rxq-
nb_rx_desc)) {Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
+ rxq->rxrearm_start = 0;
+ rx_id = rxq->nb_rx_desc - 1;
+ }
+
+ rxq->rxrearm_nb -= nb_mbufs;
+Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
+ rte_io_wmb();
+ /* Update the tail pointer on the NIC */
+ I40E_PCI_REG_WRITE_RELAXED(rxq->qrx_tail,
+rx_id); }
+
+uint16_t
+i40e_recycle_tx_mbufs_reuse_vec(void *tx_queue,
+ struct rte_eth_recycle_rxq_info
*recycle_rxq_info) {Quoted 15 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
+ struct i40e_tx_queue *txq = tx_queue;
+ struct i40e_tx_entry *txep;
+ struct rte_mbuf **rxep;
+ int i, n;
+ uint16_t nb_recycle_mbufs;
+ uint16_t avail = 0;
+ uint16_t mbuf_ring_size = recycle_rxq_info-
mbuf_ring_size;Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ uint16_t mask = recycle_rxq_info-
mbuf_ring_size- 1;Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
+ uint16_t refill_requirement =
+recycle_rxq_info-
refill_requirement;Quoted 1 line
Quoted 1 line
+ uint16_t refill_head = *recycle_rxq_info-
refill_head;Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
+ uint16_t receive_tail =
+*recycle_rxq_info->receive_tail;
+
+ /* Get available recycling Rx buffers. */
+ avail = (mbuf_ring_size - (refill_head -
+receive_tail)) & mask;
+
+ /* Check Tx free thresh and Rx availablespace. */
Quoted 40 lines
Quoted 40 lines
Quoted 40 lines
Quoted 40 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 16 lines
Quoted 3 lines
Quoted 3 lines
+ if (txq->nb_tx_free > txq->tx_free_thresh ||
+avail <=
+txq-
tx_rs_thresh)Quoted 12 lines
Quoted 12 lines
+ return 0;
+
+ /* check DD bits on threshold descriptor */
+ if
+((txq->tx_ring[txq->tx_next_dd].cmd_type_offs
+et
+_bsz
+&
+
rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) !=
+Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE)
)
+ return 0;
+
+ n = txq->tx_rs_thresh;
+ nb_recycle_mbufs = n;
+
+ /* Mbufs recycle mode can only support no
+ring bufferwrapping
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
around.
+ * Two case for this:
+ *
+ * case 1: The refill head of Rx buffer ring
+needs to be alignedwith
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
+ * mbuf ring size. In this case, the number
+of Txfreeing buffers
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
+ * should be equal to refill_requirement.
+ *
+ * case 2: The refill head of Rx ring buffer
+does not need to bealigned
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
+ * with mbuf ring size. In this case, the
+update of refill headcan not
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
+ * exceed the Rx mbuf ring size.
+ */
+ if (refill_requirement != n ||
+ (!refill_requirement && (refill_head +n >
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
mbuf_ring_size)))Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
+ return 0;
+
+ /* First buffer to free from S/W ring is at index
+ * tx_next_dd - (tx_rs_thresh-1).
+ */
+ txep = &txq->sw_ring[txq->tx_next_dd - (n -1)];
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
+ rxep = recycle_rxq_info->mbuf_ring;
+ rxep += refill_head;
+
+ if (txq->offloads &
RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE) {Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
+ /* Avoid txq contains buffers from
+unexpectedmempool. */
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
+ if (unlikely(recycle_rxq_info->mp
+ !=txep[0].mbuf-
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
pool))
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
+ return 0;
+
+ /* Directly put mbufs from Tx to Rx. */
+ for (i = 0; i < n; i++)
+ rxep[i] = txep[i].mbuf;
+ } else {
+ for (i = 0; i < n; i++) {
+ rxep[i] =
rte_pktmbuf_prefree_seg(txep[i].mbuf);Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
+
+ /* If Tx buffers are not the lastreference or
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
from
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ * unexpected mempool,
previous
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
copied
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
buffers are
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
+ * considered as invalid.
+ */
+ if (unlikely((rxep[i] == NULL&&
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
refill_requirement) ||Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
[Konstantin]
Could you pls remind me why it is ok to have
rxep[i]==NULL when refill_requirement is not set?If reill_requirement is not zero, it means each
tx freed buffer must be valid and can be put into Rx
sw_ring.Quoted 29 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Then the refill head of Rx buffer ring can be
aligned with mbuf ring size. Briefly speaking
the numberof Tx valid freed buffer must be equal to Rx
refill_requirement.Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
For example, i40e driver.
Quoted 7 lines
If reill_requirement is zero, it means that the
refill head of Rx buffer ring does not need to
be aligned with mbuf ring size, thus if Tx have
n valid freed buffers, we just need to put these
n buffers into Rx
sw-ring, and not to be equal to the Rx setting rearm number. For example, mlx5 driver.
Quoted 3 lines
In conclusion, above difference is due to pmd
drivers have differentstrategies to update their Rx rearm(refill) head.
Quoted 3 lines
For i40e driver, if rearm_head exceed 1024, it
will be set as
0 due to thenumber of each rearm is a fixed value by default.
Quoted 2 lines
For mlx5 driver. Its rearm_head can exceed 1024,
and use mask to achievereal index. Thus its rearm number can be a different value.
Ok, but if
rte_pktmbuf_prefree_seg(txep[i].mbuf), it means that this mbuf is not free yet and can't bereused.
Quoted 27 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Shouldn't we then set
nb_recycle_mbufs= 0 in that casetoo?
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Or probably would be enough to skip that mbuf?
Might be something like that:for (i = 0, j = 0; i < n; i++) {
rxep[j] = rte_pktmbuf_prefree_seg(txep[i].mbuf); if (rxep[j] == NULL || recycle_rxq_info->mp !=rxep[j].mbuf-
pool)) {
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
if (refill_requirement) { nb_recycle_mbufs = 0; break; } } else j++; }/* now j contains actual number of recycled mbufs
*/?
Quoted 2 lines
+
recycle_rxq_info-
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
mp !=
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
txep[i].mbuf-
4 lines not shown · raw message
231 lines not shown · raw message
Quoted 2 lines
2 lines not shown · raw message
209 lines not shown · raw message
Part of this message is not shown here. View the raw message.
PATCH v11 3/4 net/ixgbe: implement mbufs recycle mode
In reply to Feifei WangDefine specific function implementation for ixgbe driver. Currently, recycle buffer mode can support 128bit vector path. And can be enabled both in fast free and no fast free mode.
--- drivers/net/ixgbe/ixgbe_ethdev.c | 1 + drivers/net/ixgbe/ixgbe_ethdev.h | 3 + .../ixgbe/ixgbe_recycle_mbufs_vec_common.c | 143 ++++++++++++++++++ drivers/net/ixgbe/ixgbe_rxtx.c | 37 ++++- drivers/net/ixgbe/ixgbe_rxtx.h | 4 + drivers/net/ixgbe/meson.build | 2 + 6 files changed, 188 insertions(+), 2 deletions(-) create mode 100644 drivers/net/ixgbe/ixgbe_recycle_mbufs_vec_common.c
drivers/net/ixgbe/ixgbe_ethdev.c +1 -0
@@ -543,6 +543,7 @@ static const struct eth_dev_ops ixgbe_eth_dev_ops = { .set_mc_addr_list = ixgbe_dev_set_mc_addr_list, .rxq_info_get = ixgbe_rxq_info_get, .txq_info_get = ixgbe_txq_info_get, + .recycle_rxq_info_get = ixgbe_recycle_rxq_info_get, .timesync_enable = ixgbe_timesync_enable, .timesync_disable = ixgbe_timesync_disable, .timesync_read_rx_timestamp = ixgbe_timesync_read_rx_timestamp,
drivers/net/ixgbe/ixgbe_ethdev.h +3 -0
@@ -626,6 +626,9 @@ void ixgbe_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,void ixgbe_txq_info_get (struct rte_eth_dev *dev,uint16_t queue_id,struct rte_eth_txq_info *qinfo); +void ixgbe_recycle_rxq_info_get (struct rte_eth_dev *dev,uint16_t queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info); +int ixgbevf_dev_rx_init (struct rte_eth_dev *dev);void ixgbevf_dev_tx_init (struct rte_eth_dev *dev);
drivers/net/ixgbe/ixgbe_recycle_mbufs_vec_common.c new file +143 -0
143 lines not on this page · raw message
drivers/net/ixgbe/ixgbe_rxtx.c +35 -2
@@ -2552,6 +2552,9 @@ ixgbe_set_tx_function(struct rte_eth_dev *dev, struct ixgbe_tx_queue *txq) (rte_eal_process_type() != RTE_PROC_PRIMARY || ixgbe_txq_vec_setup(txq) == 0)) {PMD_INIT_LOG (DEBUG ,"Vector tx enabled." ); +#if defined(RTE_ARCH_X86 ) || defined(RTE_ARCH_ARM ) + dev->recycle_tx_mbufs_reuse = ixgbe_recycle_tx_mbufs_reuse_vec; +#endif dev->tx_pkt_burst = ixgbe_xmit_pkts_vec; } else dev->tx_pkt_burst = ixgbe_xmit_pkts_simple;
@@ -4890,7 +4893,10 @@ ixgbe_set_rx_function(struct rte_eth_dev *dev)PMD_INIT_LOG (DEBUG ,"Using Vector Scattered Rx " "callback (port=%d)." , dev->data->port_id); - +#if defined(RTE_ARCH_X86 ) || defined(RTE_ARCH_ARM ) + dev->recycle_rx_descriptors_refill = + ixgbe_recycle_rx_descriptors_refill_vec; +#endif dev->rx_pkt_burst = ixgbe_recv_scattered_pkts_vec; }else if (adapter->rx_bulk_alloc_allowed) { PMD_INIT_LOG(DEBUG, "Using a Scattered with bulk "
@@ -4919,7 +4925,9 @@ ixgbe_set_rx_function(struct rte_eth_dev *dev)"burst size no less than %d (port=%d)." ,RTE_IXGBE_DESCS_PER_LOOP , dev->data->port_id); - +#if defined(RTE_ARCH_X86 ) || defined(RTE_ARCH_ARM ) + dev->recycle_rx_descriptors_refill = ixgbe_recycle_rx_descriptors_refill_vec; +#endif dev->rx_pkt_burst = ixgbe_recv_pkts_vec; }else if (adapter->rx_bulk_alloc_allowed) { PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are "
@@ -5691,6 +5699,31 @@ ixgbe_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, qinfo->conf.tx_deferred_start = txq->tx_deferred_start; } +void +ixgbe_recycle_rxq_info_get (struct rte_eth_dev *dev,uint16_t queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info) +{ +struct ixgbe_rx_queue *rxq; +struct ixgbe_adapter *adapter = dev->data->dev_private; + + rxq = dev->data->rx_queues[queue_id]; + + recycle_rxq_info->mbuf_ring = (void *)rxq->sw_ring; + recycle_rxq_info->mp = rxq->mb_pool; + recycle_rxq_info->mbuf_ring_size = rxq->nb_rx_desc; + recycle_rxq_info->receive_tail = &rxq->rx_tail; + +if (adapter->rx_vec_allowed) { +#if defined(RTE_ARCH_X86 ) || defined(RTE_ARCH_ARM ) + recycle_rxq_info->refill_requirement =RTE_IXGBE_RXQ_REARM_THRESH ; + recycle_rxq_info->refill_head = &rxq->rxrearm_start; +#endif + }else { + recycle_rxq_info->refill_requirement = rxq->rx_free_thresh; + recycle_rxq_info->refill_head = &rxq->rx_free_trigger; + } +} +/* * [VF] Initializes Receive Unit. */
drivers/net/ixgbe/ixgbe_rxtx.h +4 -0
@@ -295,6 +295,10 @@ int ixgbe_dev_tx_done_cleanup(void *tx_queue, uint32_t free_cnt);extern const uint32_t ptype_table[IXGBE_PACKET_TYPE_MAX ];extern const uint32_t ptype_table_tn[IXGBE_PACKET_TYPE_TN_MAX ]; +uint16_t ixgbe_recycle_tx_mbufs_reuse_vec (void *tx_queue, +struct rte_eth_recycle_rxq_info *recycle_rxq_info); +void ixgbe_recycle_rx_descriptors_refill_vec (void *rx_queue,uint16_t nb_mbufs); +uint16_t ixgbe_xmit_fixed_burst_vec (void *tx_queue,struct rte_mbuf **tx_pkts,uint16_t nb_pkts);int ixgbe_txq_vec_setup (struct ixgbe_tx_queue *txq);
drivers/net/ixgbe/meson.build +2 -0
@@ -26,11 +26,13 @@ deps += ['hash', 'security'] if arch_subdir == 'x86' sources += files('ixgbe_rxtx_vec_sse.c') + sources += files('ixgbe_recycle_mbufs_vec_common.c') if is_windows and cc.get_id() != 'clang' cflags += ['-fno-asynchronous-unwind-tables'] endif elif arch_subdir == 'arm' sources += files('ixgbe_rxtx_vec_neon.c') + sources += files('ixgbe_recycle_mbufs_vec_common.c') endif includes += include_directories('base')
Signature · 1 line
2.25.1
PATCH v11 4/4 app/testpmd: add recycle mbufs engine
In reply to Feifei WangAdd recycle mbufs engine for testpmd. This engine forward pkts with I/O forward mode. But enable mbufs recycle feature to recycle used txq mbufs for rxq mbuf ring, which can bypass mempool path and save CPU cycles.
--- app/test-pmd/meson.build | 1 + app/test-pmd/recycle_mbufs.c | 58 +++++++++++++++++++++ app/test-pmd/testpmd.c | 1 + app/test-pmd/testpmd.h | 3 ++ doc/guides/testpmd_app_ug/run_app.rst | 1 + doc/guides/testpmd_app_ug/testpmd_funcs.rst | 5 +- 6 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 app/test-pmd/recycle_mbufs.c
app/test-pmd/meson.build +1 -0
@@ -22,6 +22,7 @@ sources = files( 'macswap.c', 'noisy_vnf.c', 'parameters.c', + 'recycle_mbufs.c', 'rxonly.c', 'shared_rxq_fwd.c', 'testpmd.c',
app/test-pmd/recycle_mbufs.c new file +58 -0
58 lines not on this page · raw message
app/test-pmd/testpmd.c +1 -0
@@ -199,6 +199,7 @@ struct fwd_engine * fwd_engines[] = { &icmp_echo_engine, &noisy_vnf_engine, &five_tuple_swap_fwd_engine, + &recycle_mbufs_engine, #ifdef RTE_LIBRTE_IEEE1588 &ieee1588_fwd_engine, #endif
app/test-pmd/testpmd.h +3 -0
@@ -188,6 +188,8 @@ struct fwd_stream {struct pkt_burst_stats rx_burst_stats;struct pkt_burst_stats tx_burst_stats;struct fwd_lcore *lcore;/**< Lcore being scheduled. */ +/**< Rx queue information for recycling mbufs */ +struct rte_eth_recycle_rxq_info recycle_rxq_info; };/**
@@ -449,6 +451,7 @@ extern struct fwd_engine csum_fwd_engine;extern struct fwd_engine icmp_echo_engine;extern struct fwd_engine noisy_vnf_engine;extern struct fwd_engine five_tuple_swap_fwd_engine; +extern struct fwd_engine recycle_mbufs_engine;#ifdef RTE_LIBRTE_IEEE1588 extern struct fwd_engine ieee1588_fwd_engine;#endif
doc/guides/testpmd_app_ug/run_app.rst +1 -0
@@ -232,6 +232,7 @@ The command line options are: noisy 5tswap shared-rxq + recycle_mbufs * ``--rss-ip``
doc/guides/testpmd_app_ug/testpmd_funcs.rst +4 -1
@@ -318,7 +318,7 @@ set fwd Set the packet forwarding mode:: testpmd> set fwd (io|mac|macswap|flowgen| \ - rxonly|txonly|csum|icmpecho|noisy|5tswap|shared-rxq) (""|retry) + rxonly|txonly|csum|icmpecho|noisy|5tswap|shared-rxq|recycle_mbufs) (""|retry) ``retry`` can be specified for forwarding engines except ``rx_only``.
@@ -364,6 +364,9 @@ The available information categories are: * ``shared-rxq``: Receive only for shared Rx queue. Resolve packet source port from mbuf and update stream statistics accordingly. +* ``recycle_mbufs``: Recycle Tx queue used mbufs for Rx queue mbuf ring. + This mode uses fast path mbuf recycle feature and forwards packets in I/O mode. + Example:: testpmd> set fwd rxonly
Signature · 1 line
2.25.1
RE: [PATCH v11 0/4] Recycle mbufs from Tx queue into Rx queue
In reply to Feifei WangHi, Ferruh
Would you please give some comments on these patches?
If no comments, would mbufs recycle mode be merged in dpdk-next branch? Thanks very much.
Best Regards
Feifei
Quoted 179 lines
-----Original Message-----
From: Feifei Wang <[email protected]>
Sent: Tuesday, August 22, 2023 3:27 PM
Cc: [email protected]; nd <[email protected]>; Feifei Wang <[email protected]>
Subject: [PATCH v11 0/4] Recycle mbufs from Tx queue into Rx queueCurrently, the transmit side frees the buffers into the lcore cache and the
receive side allocates buffers from the lcore cache. The transmit side typically frees 32 buffers resulting in 32*8=256B of stores to lcore cache. The receive side allocates 32 buffers and stores them in the receive side software ring, resulting in 32*8=256B of stores and 256B of load from the lcore cache.This patch proposes a mechanism to avoid freeing to/allocating from the lcore cache. i.e. the receive side will free the buffers from transmit side directly into its software ring. This will avoid the 256B of loads and stores introduced by the lcore cache. It also frees up the cache lines used by the lcore cache. And we can call this mode as mbufs recycle mode.
In the latest version, mbufs recycle mode is packaged as a separate API. This allows for the users to change rxq/txq pairing in real time in data plane, according to the analysis of the packet flow by the application, for example:
-----------------------------------------------------------------------
Step 1: upper application analyse the flow direction Step 2:recycle_rxq_info=rte_eth_recycle_rx_queue_info_get(rx_portid, rx_queueid)Step 3:rte_eth_recycle_mbufs(rx_portid, rx_queueid, tx_portid, tx_queueid, recycle_rxq_info); Step 4:rte_eth_rx_burst(rx_portid,rx_queueid); Step 5:rte_eth_tx_burst(tx_portid,tx_queueid);
-----------------------------------------------------------------------
Above can support user to change rxq/txq pairing at run-time and user does not need to know the direction of flow in advance. This can effectively expand mbufs recycle mode's use scenarios.Furthermore, mbufs recycle mode is no longer limited to the same pmd, it can support moving mbufs between different vendor pmds, even can put the mbufs anywhere into your Rx mbuf ring as long as the address of the mbuf ring can be provided.
In the latest version, we enable mbufs recycle mode in i40e pmd and ixgbe pmd, and also try to use i40e driver in Rx, ixgbe driver in Tx, and then achieve 7-9% performance improvement by mbufs recycle mode.Difference between mbuf recycle, ZC API used in mempool and general path For general path:
Rx: 32 pkts memcpy from mempool cache torx_sw_ring
Tx: 32 pkts memcpy fromtx_sw_ringto temporary variable + 32 pkts
memcpy from temporary variable to mempool cache For ZC API used in mempool:
Rx: 32 pkts memcpy from mempool cache torx_sw_ring
Tx: 32 pkts memcpy fromtx_sw_ringto zero-copy mempool cache Refer link:
http://patches.dpdk.org/project/dpdk/patch/20230221055205.22984-2-
[email protected]/
For mbufs recycle:
Rx/Tx: 32 pkts memcpy fromtx_sw_ringtorx_sw_ringThus we can
see in the one loop, compared to general path, mbufs recycle mode reduces 32+32=64 pkts memcpy; Compared to ZC API used in mempool, we can see mbufs recycle mode reduce 32 pkts memcpy in each loop.
So, mbufs recycle has its own benefits.Testing status:
(1) dpdk l3fwd test with multiple drivers:port 0: 82599 NIC port 1: XL710 NIC-------------------------------------------------------------
Without fast free With fast free
Thunderx2: +7.53% +13.54%
-------------------------------------------------------------(2) dpdk l3fwd test with same driver:
port 0 && 1: XL710 NIC-------------------------------------------------------------
Without fast free With fast free
Ampere altra: +12.61% +11.42%
n1sdp: +8.30% +3.85%
x86-sse: +8.43% +3.72%
-------------------------------------------------------------(3) Performance comparison with
ZC_mempoolused
port 0 && 1: XL710 NIC
with fast free
-------------------------------------------------------------
With recycle buffer Withzc_mempool
Ampere altra: 11.42% 3.54%
-------------------------------------------------------------Furthermore, we add
recycle_mbufengine in testpmd. Due to XL710 NIC has I/O bottleneck in testpmd in ampere altra, we can not see throughput change compared with I/O fwd engine. However, using record cmd in testpmd:
'$set record-burst-stats on'
we can see the ratio of 'Rx/Tx burst size of 32' is reduced. This indicate mbufs recycle can save CPU cycles.V2:
1. Use data-plane API to enable direct-rearm (Konstantin, Honnappa) 2. Add 'txq_data_get' API to get txq info for Rx (Konstantin) 3. Use input parameter to enable direct rearm in l3fwd (Konstantin) 4. Add condition detection for direct rearm API (Morten, Andrew Rybchenko)V3:
1. Seperate Rx and Tx operation with two APIs in direct-rearm (Konstantin) 2. Delete L3fwd change for direct rearm (Jerin) 3. enable direct rearm in ixgbe driver in Armv4:
1. Rename direct-rearm as buffer recycle. Based on this, function name and variable name are changed to let this mode more general for all drivers. (Konstantin, Morten) 2. Add ring wrapping check (Konstantin)v5:
1. some change for ethdev API (Morten)
2. add support for avx2, sse, altivec pathv6:
1. fix ixgbe build issue in ppc
2. remove 'recycle_tx_mbufs_reuse' and 'recycle_rx_descriptors_refill' API wrapper (Tech Board meeting)
3. addrecycle_mbufsengine in testpmd (Tech Board meeting) 4. add namespace in the functions related to mbufs recycle(Ferruh)v7:
1. move 'rxq/txq data' pointers to the beginning ofeth_devstructure, in order to keep them in the same cache line as rx/tx_burst function pointers (Morten)
2. add the extra description for 'rte_eth_recycle_mbufs' to show it can support feeding 1 Rx queue from 2 Tx queues in the same thread
(Konstantin)
3. For i40e/ixgbe driver, make the previous copied buffers as invalid if there are Tx buffers refcnt > 1 or from unexpected mempool (Konstantin) 4. add check for the return value of 'rte_eth_recycle_rx_queue_info_get'
in testpmd fwd engine (Morten)v8:
1. add arm/x86 build option to fix ixgbe build issue in ppcv9:
1. delete duplicate file name for ixgbev10:
1. fix compile issue on windowsv11:
1. fix doc warningFeifei Wang (4):
ethdev: add API for mbufs recycle mode
net/i40e: implement mbufs recycle mode
net/ixgbe: implement mbufs recycle mode
app/testpmd: add recycle mbufs engineapp/test-pmd/meson.build | 1 + app/test-pmd/recycle_mbufs.c | 58 ++++++ app/test-pmd/testpmd.c | 1 + app/test-pmd/testpmd.h | 3 + doc/guides/rel_notes/release_23_11.rst | 15 ++ doc/guides/testpmd_app_ug/run_app.rst | 1 + doc/guides/testpmd_app_ug/testpmd_funcs.rst | 5 +- drivers/net/i40e/i40e_ethdev.c | 1 + drivers/net/i40e/i40e_ethdev.h | 2 + .../net/i40e/i40e_recycle_mbufs_vec_common.c | 147 ++++++++++++++ drivers/net/i40e/i40e_rxtx.c | 32 ++++ drivers/net/i40e/i40e_rxtx.h | 4 + drivers/net/i40e/meson.build | 1 + drivers/net/ixgbe/ixgbe_ethdev.c | 1 + drivers/net/ixgbe/ixgbe_ethdev.h | 3 + .../ixgbe/ixgbe_recycle_mbufs_vec_common.c | 143 ++++++++++++++ drivers/net/ixgbe/ixgbe_rxtx.c | 37 +++- drivers/net/ixgbe/ixgbe_rxtx.h | 4 + drivers/net/ixgbe/meson.build | 2 + lib/ethdev/ethdev_driver.h | 10 + lib/ethdev/ethdev_private.c | 2 + lib/ethdev/rte_ethdev.c | 31 +++ lib/ethdev/rte_ethdev.h | 181 ++++++++++++++++++ lib/ethdev/rte_ethdev_core.h | 23 ++- lib/ethdev/version.map | 3 + 25 files changed, 702 insertions(+), 9 deletions(-) create mode 100644 app/test-pmd/recycle_mbufs.c create mode 100644 drivers/net/i40e/i40e_recycle_mbufs_vec_common.c create mode 100644 drivers/net/ixgbe/ixgbe_recycle_mbufs_vec_common.c--
2.25.1
Re: [PATCH v11 0/4] Recycle mbufs from Tx queue into Rx queue
In reply to Feifei WangQuoted 7 lines · On Tue, 22 Aug 2023 15:27:06 +0800 Feifei Wang <[email protected]> wrote:
Currently, the transmit side frees the buffers into the lcore cache and
the receive side allocates buffers from the lcore cache. The transmit side typically frees 32 buffers resulting in 32*8=256B of stores to lcore cache. The receive side allocates 32 buffers and stores them in the receive side software ring, resulting in 32*8=256B of stores and 256B of load from the lcore cache.
Quoted 6 lines
This patch proposes a mechanism to avoid freeing to/allocating from the lcore cache. i.e. the receive side will free the buffers from transmit side directly into its software ring. This will avoid the 256B of loads and stores introduced by the lcore cache. It also frees up the cache lines used by the lcore cache. And we can call this mode as mbufs recycle mode.
Isn't the recycle ring just another cache? Why is the lcore cache slower? Could we fix the general case there?
RE: [PATCH v11 0/4] Recycle mbufs from Tx queue into Rx queue
Quoted 26 lines
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Tuesday, August 22, 2023 9:59 PM
To: Feifei Wang <[email protected]>
Cc: [email protected]; nd <[email protected]>
Subject: Re: [PATCH v11 0/4] Recycle mbufs from Tx queue into Rx queueQuoted 7 lines · On Tue, 22 Aug 2023 15:27:06 +0800 Feifei Wang <[email protected]> wrote:
Currently, the transmit side frees the buffers into the lcore cache
and the receive side allocates buffers from the lcore cache. The transmit side typically frees 32 buffers resulting in 32*8=256B of stores to lcore cache. The receive side allocates 32 buffers and stores them in the receive side software ring, resulting in 32*8=256B of stores and 256B of load from the lcore cache.Quoted 6 lines
This patch proposes a mechanism to avoid freeing to/allocating from the lcore cache. i.e. the receive side will free the buffers from transmit side directly into its software ring. This will avoid the 256B of loads and stores introduced by the lcore cache. It also frees up the cache lines used by the lcore cache. And we can call this mode as mbufs recycle mode.
Quoted 2 lines
Isn't the recycle ring just another cache? Why is the lcore cache slower? Could we fix the general case there?
Here lcore cache means the mempool lcore cache for each lcore: mp->local_cache[lcore_id]; For each buffer allocate from mempool and free into mempool, the thread will firstly try to do Memory copy from or into lcore cache.
We do not say lcore cache is slower, we means do memory copy from or into lcore cache will cost much CPU cycle, and mbuf recycle can bypass these memory copy.
For generic case , we try to use zero copy to optimize, but the performance is worse than mbufs recycle:
For general path:
Rx: 32 pkts memcpy from mempool cache to rx_sw_ring
Tx: 32 pkts memcpy from tx_sw_ring to temporary variable + 32 pkts memcpy from temporary variable to mempool cache
For ZC API used in mempool:
Rx: 32 pkts memcpy from mempool cache to rx_sw_ring
Tx: 32 pkts memcpy from tx_sw_ring to zero-copy mempool cache
Refer link: http://patches.dpdk.org/project/dpdk/patch/[email protected]/
For mbufs recycle:
Rx/Tx: 32 pkts memcpy from tx_sw_ring to rx_sw_ring
v12 cover Recycle mbufs from Tx queue into Rx queue
In reply to Feifei WangCurrently, the transmit side frees the buffers into the lcore cache and the receive side allocates buffers from the lcore cache. The transmit side typically frees 32 buffers resulting in 32*8=256B of stores to lcore cache. The receive side allocates 32 buffers and stores them in the receive side software ring, resulting in 32*8=256B of stores and 256B of load from the lcore cache.
This patch proposes a mechanism to avoid freeing to/allocating from the lcore cache. i.e. the receive side will free the buffers from transmit side directly into its software ring. This will avoid the 256B of loads and stores introduced by the lcore cache. It also frees up the cache lines used by the lcore cache. And we can call this mode as mbufs recycle mode.
In the latest version, mbufs recycle mode is packaged as a separate API.
This allows for the users to change rxq/txq pairing in real time in data plane, according to the analysis of the packet flow by the application, for example:
-----------------------------------------------------------------------
Step 1: upper application analyse the flow direction
Step 2: recycle_rxq_info = rte_eth_recycle_rx_queue_info_get(rx_portid, rx_queueid) Step 3: rte_eth_recycle_mbufs(rx_portid, rx_queueid, tx_portid, tx_queueid, recycle_rxq_info); Step 4: rte_eth_rx_burst(rx_portid,rx_queueid);
Step 5: rte_eth_tx_burst(tx_portid,tx_queueid);
-----------------------------------------------------------------------
Above can support user to change rxq/txq pairing at run-time and user does not need to know the direction of flow in advance. This can effectively expand mbufs recycle mode's use scenarios.
Furthermore, mbufs recycle mode is no longer limited to the same pmd,
it can support moving mbufs between different vendor pmds, even can put the mbufs anywhere into your Rx mbuf ring as long as the address of the mbuf ring can be provided. In the latest version, we enable mbufs recycle mode in i40e pmd and ixgbe pmd, and also try to use i40e driver in Rx, ixgbe driver in Tx, and then achieve 7-9% performance improvement by mbufs recycle mode.
Difference between mbuf recycle, ZC API used in mempool and general path
For general path:
Rx: 32 pkts memcpy from mempool cache to rx_sw_ring
Tx: 32 pkts memcpy from tx_sw_ring to temporary variable + 32 pkts memcpy from temporary variable to mempool cache
For ZC API used in mempool:
Rx: 32 pkts memcpy from mempool cache to rx_sw_ring
Tx: 32 pkts memcpy from tx_sw_ring to zero-copy mempool cache
Refer link: http://patches.dpdk.org/project/dpdk/patch/[email protected]/
For mbufs recycle:
Rx/Tx: 32 pkts memcpy from tx_sw_ring to rx_sw_ring
Thus we can see in the one loop, compared to general path, mbufs recycle mode reduces 32+32=64 pkts memcpy; Compared to ZC API used in mempool, we can see mbufs recycle mode reduce 32 pkts memcpy in each loop.
So, mbufs recycle has its own benefits.
Testing status:
(1) dpdk l3fwd test with multiple drivers:
port 0: 82599 NIC port 1: XL710 NIC
-------------------------------------------------------------
Without fast free With fast free
Thunderx2: +7.53% +13.54%
-------------------------------------------------------------
(2) dpdk l3fwd test with same driver:
port 0 && 1: XL710 NIC
-------------------------------------------------------------
Without fast free With fast free
Ampere altra: +12.61% +11.42%
n1sdp: +8.30% +3.85%
x86-sse: +8.43% +3.72%
-------------------------------------------------------------
(3) Performance comparison with ZC_mempool used
port 0 && 1: XL710 NIC
with fast free
-------------------------------------------------------------
With recycle buffer With zc_mempool
Ampere altra: 11.42% 3.54%
-------------------------------------------------------------
Furthermore, we add recycle_mbuf engine in testpmd. Due to XL710 NIC has I/O bottleneck in testpmd in ampere altra, we can not see throughput change compared with I/O fwd engine. However, using record cmd in testpmd:
'$set record-burst-stats on'
we can see the ratio of 'Rx/Tx burst size of 32' is reduced. This indicate mbufs recycle can save CPU cycles.
V2:
1. Use data-plane API to enable direct-rearm (Konstantin, Honnappa)
2. Add 'txq_data_get' API to get txq info for Rx (Konstantin)
3. Use input parameter to enable direct rearm in l3fwd (Konstantin)
4. Add condition detection for direct rearm API (Morten, Andrew Rybchenko)
V3:
1. Seperate Rx and Tx operation with two APIs in direct-rearm (Konstantin)
2. Delete L3fwd change for direct rearm (Jerin)
3. enable direct rearm in ixgbe driver in Arm
v4:
1. Rename direct-rearm as buffer recycle. Based on this, function name and variable name are changed to let this mode more general for all drivers. (Konstantin, Morten)
2. Add ring wrapping check (Konstantin)
v5:
1. some change for ethdev API (Morten)
2. add support for avx2, sse, altivec path
v6:
1. fix ixgbe build issue in ppc
2. remove 'recycle_tx_mbufs_reuse' and 'recycle_rx_descriptors_refill' API wrapper (Tech Board meeting)
3. add recycle_mbufs engine in testpmd (Tech Board meeting)
4. add namespace in the functions related to mbufs recycle(Ferruh)
v7:
1. move 'rxq/txq data' pointers to the beginning of eth_dev structure, in order to keep them in the same cache line as rx/tx_burst function pointers (Morten)
2. add the extra description for 'rte_eth_recycle_mbufs' to show it can support feeding 1 Rx queue from 2 Tx queues in the same thread (Konstantin)
3. For i40e/ixgbe driver, make the previous copied buffers as invalid if there are Tx buffers refcnt > 1 or from unexpected mempool (Konstantin)
4. add check for the return value of 'rte_eth_recycle_rx_queue_info_get' in testpmd fwd engine (Morten)
v8:
1. add arm/x86 build option to fix ixgbe build issue in ppc
v9:
1. delete duplicate file name for ixgbe
v10:
1. fix compile issue on windows
v11:
1. fix doc warning
v12:
1. replace rx queue check code with eth_dev_validate_rx_queue function (Stephen)
2. put port and queue check before function call (Konstantin)
Feifei Wang (4):
ethdev: add API for mbufs recycle mode
net/i40e: implement mbufs recycle mode
net/ixgbe: implement mbufs recycle mode
app/testpmd: add recycle mbufs engine
app/test-pmd/meson.build | 1 + app/test-pmd/recycle_mbufs.c | 58 ++++++ app/test-pmd/testpmd.c | 1 + app/test-pmd/testpmd.h | 3 + doc/guides/rel_notes/release_23_11.rst | 15 ++ doc/guides/testpmd_app_ug/run_app.rst | 1 + doc/guides/testpmd_app_ug/testpmd_funcs.rst | 5 +- drivers/net/i40e/i40e_ethdev.c | 1 + drivers/net/i40e/i40e_ethdev.h | 2 + .../net/i40e/i40e_recycle_mbufs_vec_common.c | 147 ++++++++++++++ drivers/net/i40e/i40e_rxtx.c | 32 ++++ drivers/net/i40e/i40e_rxtx.h | 4 + drivers/net/i40e/meson.build | 1 + drivers/net/ixgbe/ixgbe_ethdev.c | 1 + drivers/net/ixgbe/ixgbe_ethdev.h | 3 + .../ixgbe/ixgbe_recycle_mbufs_vec_common.c | 143 ++++++++++++++ drivers/net/ixgbe/ixgbe_rxtx.c | 37 +++- drivers/net/ixgbe/ixgbe_rxtx.h | 4 + drivers/net/ixgbe/meson.build | 2 + lib/ethdev/ethdev_driver.h | 10 + lib/ethdev/ethdev_private.c | 2 + lib/ethdev/rte_ethdev.c | 22 +++ lib/ethdev/rte_ethdev.h | 180 ++++++++++++++++++ lib/ethdev/rte_ethdev_core.h | 23 ++- lib/ethdev/version.map | 3 + 25 files changed, 692 insertions(+), 9 deletions(-) create mode 100644 app/test-pmd/recycle_mbufs.c create mode 100644 drivers/net/i40e/i40e_recycle_mbufs_vec_common.c create mode 100644 drivers/net/ixgbe/ixgbe_recycle_mbufs_vec_common.c
Signature · 1 line
2.25.1
PATCH v12 1/4 ethdev: add API for mbufs recycle mode
Add 'rte_eth_recycle_rx_queue_info_get' and 'rte_eth_recycle_mbufs' APIs to recycle used mbufs from a transmit queue of an Ethernet device, and move these mbufs into a mbuf ring for a receive queue of an Ethernet device. This can bypass mempool 'put/get' operations hence saving CPU cycles.
For each recycling mbufs, the rte_eth_recycle_mbufs() function performs the following operations:
- Copy used *rte_mbuf* buffer pointers from Tx mbuf ring into Rx mbuf ring.
- Replenish the Rx descriptors with the recycling *rte_mbuf* mbufs freed from the Tx mbuf ring.
--- doc/guides/rel_notes/release_23_11.rst | 15 +++ lib/ethdev/ethdev_driver.h | 10 ++ lib/ethdev/ethdev_private.c | 2 + lib/ethdev/rte_ethdev.c | 22 +++ lib/ethdev/rte_ethdev.h | 180 +++++++++++++++++++++++++ lib/ethdev/rte_ethdev_core.h | 23 +++- lib/ethdev/version.map | 3 + 7 files changed, 249 insertions(+), 6 deletions(-)
doc/guides/rel_notes/release_23_11.rst +15 -0
@@ -78,6 +78,13 @@ New Features * build: Optional libraries can now be selected with the new ``enable_libs`` build option similarly to the existing ``enable_drivers`` build option. +* **Add mbufs recycling support.** + + Added ``rte_eth_recycle_rx_queue_info_get`` and ``rte_eth_recycle_mbufs`` + APIs which allow the user to copy used mbufs from the Tx mbuf ring + into the Rx mbuf ring. This feature supports the case that the Rx Ethernet + device is different from the Tx Ethernet device with respective driver + callback functions in ``rte_eth_recycle_mbufs``. Removed Items -------------
@@ -129,6 +136,14 @@ ABI Changes Also, make sure to start the actual text at the margin. ======================================================= +* ethdev: Added ``recycle_tx_mbufs_reuse`` and ``recycle_rx_descriptors_refill`` + fields to ``rte_eth_dev`` structure. + +* ethdev: Structure ``rte_eth_fp_ops`` was affected to add + ``recycle_tx_mbufs_reuse`` and ``recycle_rx_descriptors_refill`` + fields, to move ``rxq`` and ``txq`` fields, to change the size of + ``reserved1`` and ``reserved2`` fields. + Known Issues ------------
lib/ethdev/ethdev_driver.h +10 -0
@@ -58,6 +58,10 @@ struct rte_eth_dev {eth_rx_descriptor_status_t rx_descriptor_status;/** Check the status of a Tx descriptor */ eth_tx_descriptor_status_t tx_descriptor_status; +/** Pointer to PMD transmit mbufs reuse function */ +eth_recycle_tx_mbufs_reuse_t recycle_tx_mbufs_reuse; +/** Pointer to PMD receive descriptors refill function */ +eth_recycle_rx_descriptors_refill_t recycle_rx_descriptors_refill;/** * Device data that is shared between primary and secondary processes
@@ -507,6 +511,10 @@ typedef void (*eth_rxq_info_get_t)(struct rte_eth_dev *dev,typedef void (*eth_txq_info_get_t )(struct rte_eth_dev *dev,uint16_t tx_queue_id,struct rte_eth_txq_info *qinfo); +typedef void (*eth_recycle_rxq_info_get_t )(struct rte_eth_dev *dev, +uint16_t rx_queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info); +typedef int (*eth_burst_mode_get_t )(struct rte_eth_dev *dev,uint16_t queue_id,struct rte_eth_burst_mode *mode);
@@ -1250,6 +1258,8 @@ struct eth_dev_ops {eth_rxq_info_get_t rxq_info_get;/** Retrieve Tx queue information */ eth_txq_info_get_t txq_info_get; +/** Retrieve mbufs recycle Rx queue information */ +eth_recycle_rxq_info_get_t recycle_rxq_info_get;eth_burst_mode_get_t rx_burst_mode_get;/**< Get Rx burst mode */ eth_burst_mode_get_t tx_burst_mode_get;/**< Get Tx burst mode */ eth_fw_version_get_t fw_version_get;/**< Get firmware version */
lib/ethdev/ethdev_private.c +2 -0
@@ -277,6 +277,8 @@ eth_dev_fp_ops_setup(struct rte_eth_fp_ops *fpo, fpo->rx_queue_count = dev->rx_queue_count; fpo->rx_descriptor_status = dev->rx_descriptor_status; fpo->tx_descriptor_status = dev->tx_descriptor_status; + fpo->recycle_tx_mbufs_reuse = dev->recycle_tx_mbufs_reuse; + fpo->recycle_rx_descriptors_refill = dev->recycle_rx_descriptors_refill; fpo->rxq.data = dev->data->rx_queues; fpo->rxq.clbk = (void **)(uintptr_t )dev->post_rx_burst_cbs;
lib/ethdev/rte_ethdev.c +22 -0
@@ -5876,6 +5876,28 @@ rte_eth_tx_queue_info_get(uint16_t port_id, uint16_t queue_id,return 0 ; } +int +rte_eth_recycle_rx_queue_info_get (uint16_t port_id,uint16_t queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info) +{ +struct rte_eth_dev *dev; +int ret; + +RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -ENODEV ); + dev = &rte_eth_devices[port_id]; + + ret =eth_dev_validate_rx_queue (dev, queue_id); +if (unlikely (ret !=0 )) +return ret; + +if (*dev->dev_ops->recycle_rxq_info_get ==NULL ) +return -ENOTSUP ; + + dev->dev_ops->recycle_rxq_info_get (dev, queue_id, recycle_rxq_info); + +return 0 ; +} +int rte_eth_rx_burst_mode_get (uint16_t port_id,uint16_t queue_id,struct rte_eth_burst_mode *mode)
lib/ethdev/rte_ethdev.h +180 -0
198 lines not on this page · raw message
lib/ethdev/rte_ethdev_core.h +17 -6
@@ -55,6 +55,13 @@ typedef int (*eth_rx_descriptor_status_t)(void *rxq, uint16_t offset);/** @internal Check the status of a Tx descriptor */ typedef int (*eth_tx_descriptor_status_t )(void *txq,uint16_t offset); +/** @internal Copy used mbufs from Tx mbuf ring into Rx mbuf ring */ +typedef uint16_t (*eth_recycle_tx_mbufs_reuse_t )(void *txq, +struct rte_eth_recycle_rxq_info *recycle_rxq_info); + +/** @internal Refill Rx descriptors with the recycling mbufs */ +typedef void (*eth_recycle_rx_descriptors_refill_t )(void *rxq,uint16_t nb); +/** * @internal * Structure used to hold opaque pointers to internal ethdev Rx/Tx
@@ -83,15 +90,17 @@ struct rte_eth_fp_ops {* Rx fast-path functions and related data. * 64-bit systems: occupies first 64B line */ +/** Rx queues data. */ +struct rte_ethdev_qdata rxq;/** PMD receive function. */ eth_rx_burst_t rx_pkt_burst;/** Get the number of used Rx descriptors. */ eth_rx_queue_count_t rx_queue_count;/** Check the status of a Rx descriptor. */ eth_rx_descriptor_status_t rx_descriptor_status; -/** Rx queues data. */ -struct rte_ethdev_qdata rxq; -uintptr_t reserved1[3 ]; +/** Refill Rx descriptors with the recycling mbufs. */ +eth_recycle_rx_descriptors_refill_t recycle_rx_descriptors_refill; +uintptr_t reserved1[2 ];/**@}*/ /**@{*/
@@ -99,15 +108,17 @@ struct rte_eth_fp_ops {* Tx fast-path functions and related data. * 64-bit systems: occupies second 64B line */ +/** Tx queues data. */ +struct rte_ethdev_qdata txq;/** PMD transmit function. */ eth_tx_burst_t tx_pkt_burst;/** PMD transmit prepare function. */ eth_tx_prep_t tx_pkt_prepare;/** Check the status of a Tx descriptor. */ eth_tx_descriptor_status_t tx_descriptor_status; -/** Tx queues data. */ -struct rte_ethdev_qdata txq; -uintptr_t reserved2[3 ]; +/** Copy used mbufs from Tx mbuf ring into Rx. */ +eth_recycle_tx_mbufs_reuse_t recycle_tx_mbufs_reuse; +uintptr_t reserved2[2 ];/**@}*/ } __rte_cache_aligned;
lib/ethdev/version.map +3 -0
@@ -312,6 +312,9 @@ EXPERIMENTAL { rte_flow_async_action_list_handle_query_update; rte_flow_async_actions_update; rte_flow_restore_info_dynflag; + + # added in 23.11 + rte_eth_recycle_rx_queue_info_get; }; INTERNAL {
Signature · 1 line
2.25.1
RE: [PATCH v12 1/4] ethdev: add API for mbufs recycle mode
+ping.
Have any comments about mbuf recycle mode?
Re: [PATCH v12 1/4] ethdev: add API for mbufs recycle mode
In reply to Feifei WangQuoted 13 lines · Feifei Wang
Add '
rte_eth_recycle_rx_queue_info_get' and 'rte_eth_recycle_mbufs' APIs to recycle used mbufs from a transmit queue of an Ethernet device, and move these mbufs into a mbuf ring for a receive queue of an Ethernet device. This can bypass mempool 'put/get' operations hence saving CPU cycles.For each recycling mbufs, the
rte_eth_recycle_mbufs()function performs the following operations:
- Copy used *rte_mbuf* buffer pointers from Tx mbuf ring into Rx mbuf ring.
- Replenish the Rx descriptors with the recycling *rte_mbuf* mbufs freed from the Tx mbuf ring.
Quoted 8 lines
Suggested-by Honnappa Nagarahalli <[email protected]>Suggested-by Ruifeng Wang <[email protected]>Signed-off-by Feifei Wang <[email protected]>Reviewed-by Ruifeng Wang <[email protected]>Reviewed-by Honnappa Nagarahalli <[email protected]>Acked-by Morten Brørup <[email protected]>
PATCH v12 2/4 net/i40e: implement mbufs recycle mode
In reply to Feifei WangDefine specific function implementation for i40e driver. Currently, mbufs recycle mode can support 128bit vector path and avx2 path. And can be enabled both in fast free and no fast free mode.
--- drivers/net/i40e/i40e_ethdev.c | 1 + drivers/net/i40e/i40e_ethdev.h | 2 + .../net/i40e/i40e_recycle_mbufs_vec_common.c | 147 ++++++++++++++++++ drivers/net/i40e/i40e_rxtx.c | 32 ++++ drivers/net/i40e/i40e_rxtx.h | 4 + drivers/net/i40e/meson.build | 1 + 6 files changed, 187 insertions(+) create mode 100644 drivers/net/i40e/i40e_recycle_mbufs_vec_common.c
drivers/net/i40e/i40e_ethdev.c +1 -0
@@ -496,6 +496,7 @@ static const struct eth_dev_ops i40e_eth_dev_ops = { .flow_ops_get = i40e_dev_flow_ops_get, .rxq_info_get = i40e_rxq_info_get, .txq_info_get = i40e_txq_info_get, + .recycle_rxq_info_get = i40e_recycle_rxq_info_get, .rx_burst_mode_get = i40e_rx_burst_mode_get, .tx_burst_mode_get = i40e_tx_burst_mode_get, .timesync_enable = i40e_timesync_enable,
drivers/net/i40e/i40e_ethdev.h +2 -0
@@ -1355,6 +1355,8 @@ void i40e_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, struct rte_eth_rxq_info *qinfo);void i40e_txq_info_get (struct rte_eth_dev *dev,uint16_t queue_id,struct rte_eth_txq_info *qinfo); +void i40e_recycle_rxq_info_get (struct rte_eth_dev *dev,uint16_t queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info);int i40e_rx_burst_mode_get (struct rte_eth_dev *dev,uint16_t queue_id,struct rte_eth_burst_mode *mode); int i40e_tx_burst_mode_get(struct rte_eth_dev *dev, uint16_t queue_id,
drivers/net/i40e/i40e_recycle_mbufs_vec_common.c new file +147 -0
147 lines not on this page · raw message
drivers/net/i40e/i40e_rxtx.c +32 -0
@@ -3199,6 +3199,30 @@ i40e_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, qinfo->conf.offloads = txq->offloads; } +void +i40e_recycle_rxq_info_get (struct rte_eth_dev *dev,uint16_t queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info) +{ +struct i40e_rx_queue *rxq; +struct i40e_adapter *ad = +I40E_DEV_PRIVATE_TO_ADAPTER (dev->data->dev_private); + + rxq = dev->data->rx_queues[queue_id]; + + recycle_rxq_info->mbuf_ring = (void *)rxq->sw_ring; + recycle_rxq_info->mp = rxq->mp; + recycle_rxq_info->mbuf_ring_size = rxq->nb_rx_desc; + recycle_rxq_info->receive_tail = &rxq->rx_tail; + +if (ad->rx_vec_allowed) { + recycle_rxq_info->refill_requirement =RTE_I40E_RXQ_REARM_THRESH ; + recycle_rxq_info->refill_head = &rxq->rxrearm_start; + }else { + recycle_rxq_info->refill_requirement = rxq->rx_free_thresh; + recycle_rxq_info->refill_head = &rxq->rx_free_trigger; + } +} +#ifdef RTE_ARCH_X86 static inline bool get_avx_supported (bool request_avx512)
@@ -3293,6 +3317,8 @@ i40e_set_rx_function(struct rte_eth_dev *dev) dev->rx_pkt_burst = ad->rx_use_avx2 ? i40e_recv_scattered_pkts_vec_avx2 : i40e_recv_scattered_pkts_vec; + dev->recycle_rx_descriptors_refill = + i40e_recycle_rx_descriptors_refill_vec; } }else {if (ad->rx_use_avx512) {
@@ -3311,9 +3337,12 @@ i40e_set_rx_function(struct rte_eth_dev *dev) dev->rx_pkt_burst = ad->rx_use_avx2 ? i40e_recv_pkts_vec_avx2 : i40e_recv_pkts_vec; + dev->recycle_rx_descriptors_refill = + i40e_recycle_rx_descriptors_refill_vec; } }#else /* RTE_ARCH_X86 */ + dev->recycle_rx_descriptors_refill = i40e_recycle_rx_descriptors_refill_vec;if (dev->data->scattered_rx) { PMD_INIT_LOG(DEBUG, "Using Vector Scattered Rx (port %d).",
@@ -3481,15 +3510,18 @@ i40e_set_tx_function(struct rte_eth_dev *dev) dev->tx_pkt_burst = ad->tx_use_avx2 ? i40e_xmit_pkts_vec_avx2 : i40e_xmit_pkts_vec; + dev->recycle_tx_mbufs_reuse = i40e_recycle_tx_mbufs_reuse_vec; }#else /* RTE_ARCH_X86 */ PMD_INIT_LOG (DEBUG ,"Using Vector Tx (port %d)." , dev->data->port_id); dev->tx_pkt_burst = i40e_xmit_pkts_vec; + dev->recycle_tx_mbufs_reuse = i40e_recycle_tx_mbufs_reuse_vec;#endif /* RTE_ARCH_X86 */ }else {PMD_INIT_LOG (DEBUG ,"Simple tx finally be used." ); dev->tx_pkt_burst = i40e_xmit_pkts_simple; + dev->recycle_tx_mbufs_reuse = i40e_recycle_tx_mbufs_reuse_vec; } dev->tx_pkt_prepare = i40e_simple_prep_pkts; }else {
drivers/net/i40e/i40e_rxtx.h +4 -0
@@ -236,6 +236,10 @@ uint32_t i40e_dev_rx_queue_count(void *rx_queue);int i40e_dev_rx_descriptor_status (void *rx_queue,uint16_t offset);int i40e_dev_tx_descriptor_status (void *tx_queue,uint16_t offset); +uint16_t i40e_recycle_tx_mbufs_reuse_vec (void *tx_queue, +struct rte_eth_recycle_rxq_info *recycle_rxq_info); +void i40e_recycle_rx_descriptors_refill_vec (void *rx_queue,uint16_t nb_mbufs); +uint16_t i40e_recv_pkts_vec (void *rx_queue,struct rte_mbuf **rx_pkts,uint16_t nb_pkts); uint16_t i40e_recv_scattered_pkts_vec(void *rx_queue,
drivers/net/i40e/meson.build +1 -0
@@ -34,6 +34,7 @@ sources = files( 'i40e_tm.c', 'i40e_hash.c', 'i40e_vf_representor.c', + 'i40e_recycle_mbufs_vec_common.c', 'rte_pmd_i40e.c', )
Signature · 1 line
2.25.1
PATCH v12 3/4 net/ixgbe: implement mbufs recycle mode
In reply to Feifei WangDefine specific function implementation for ixgbe driver. Currently, recycle buffer mode can support 128bit vector path. And can be enabled both in fast free and no fast free mode.
--- drivers/net/ixgbe/ixgbe_ethdev.c | 1 + drivers/net/ixgbe/ixgbe_ethdev.h | 3 + .../ixgbe/ixgbe_recycle_mbufs_vec_common.c | 143 ++++++++++++++++++ drivers/net/ixgbe/ixgbe_rxtx.c | 37 ++++- drivers/net/ixgbe/ixgbe_rxtx.h | 4 + drivers/net/ixgbe/meson.build | 2 + 6 files changed, 188 insertions(+), 2 deletions(-) create mode 100644 drivers/net/ixgbe/ixgbe_recycle_mbufs_vec_common.c
drivers/net/ixgbe/ixgbe_ethdev.c +1 -0
@@ -543,6 +543,7 @@ static const struct eth_dev_ops ixgbe_eth_dev_ops = { .set_mc_addr_list = ixgbe_dev_set_mc_addr_list, .rxq_info_get = ixgbe_rxq_info_get, .txq_info_get = ixgbe_txq_info_get, + .recycle_rxq_info_get = ixgbe_recycle_rxq_info_get, .timesync_enable = ixgbe_timesync_enable, .timesync_disable = ixgbe_timesync_disable, .timesync_read_rx_timestamp = ixgbe_timesync_read_rx_timestamp,
drivers/net/ixgbe/ixgbe_ethdev.h +3 -0
@@ -626,6 +626,9 @@ void ixgbe_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,void ixgbe_txq_info_get (struct rte_eth_dev *dev,uint16_t queue_id,struct rte_eth_txq_info *qinfo); +void ixgbe_recycle_rxq_info_get (struct rte_eth_dev *dev,uint16_t queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info); +int ixgbevf_dev_rx_init (struct rte_eth_dev *dev);void ixgbevf_dev_tx_init (struct rte_eth_dev *dev);
drivers/net/ixgbe/ixgbe_recycle_mbufs_vec_common.c new file +143 -0
143 lines not on this page · raw message
drivers/net/ixgbe/ixgbe_rxtx.c +35 -2
@@ -2552,6 +2552,9 @@ ixgbe_set_tx_function(struct rte_eth_dev *dev, struct ixgbe_tx_queue *txq) (rte_eal_process_type() != RTE_PROC_PRIMARY || ixgbe_txq_vec_setup(txq) == 0)) {PMD_INIT_LOG (DEBUG ,"Vector tx enabled." ); +#if defined(RTE_ARCH_X86 ) || defined(RTE_ARCH_ARM ) + dev->recycle_tx_mbufs_reuse = ixgbe_recycle_tx_mbufs_reuse_vec; +#endif dev->tx_pkt_burst = ixgbe_xmit_pkts_vec; } else dev->tx_pkt_burst = ixgbe_xmit_pkts_simple;
@@ -4890,7 +4893,10 @@ ixgbe_set_rx_function(struct rte_eth_dev *dev)PMD_INIT_LOG (DEBUG ,"Using Vector Scattered Rx " "callback (port=%d)." , dev->data->port_id); - +#if defined(RTE_ARCH_X86 ) || defined(RTE_ARCH_ARM ) + dev->recycle_rx_descriptors_refill = + ixgbe_recycle_rx_descriptors_refill_vec; +#endif dev->rx_pkt_burst = ixgbe_recv_scattered_pkts_vec; }else if (adapter->rx_bulk_alloc_allowed) { PMD_INIT_LOG(DEBUG, "Using a Scattered with bulk "
@@ -4919,7 +4925,9 @@ ixgbe_set_rx_function(struct rte_eth_dev *dev)"burst size no less than %d (port=%d)." ,RTE_IXGBE_DESCS_PER_LOOP , dev->data->port_id); - +#if defined(RTE_ARCH_X86 ) || defined(RTE_ARCH_ARM ) + dev->recycle_rx_descriptors_refill = ixgbe_recycle_rx_descriptors_refill_vec; +#endif dev->rx_pkt_burst = ixgbe_recv_pkts_vec; }else if (adapter->rx_bulk_alloc_allowed) { PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are "
@@ -5691,6 +5699,31 @@ ixgbe_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, qinfo->conf.tx_deferred_start = txq->tx_deferred_start; } +void +ixgbe_recycle_rxq_info_get (struct rte_eth_dev *dev,uint16_t queue_id, +struct rte_eth_recycle_rxq_info *recycle_rxq_info) +{ +struct ixgbe_rx_queue *rxq; +struct ixgbe_adapter *adapter = dev->data->dev_private; + + rxq = dev->data->rx_queues[queue_id]; + + recycle_rxq_info->mbuf_ring = (void *)rxq->sw_ring; + recycle_rxq_info->mp = rxq->mb_pool; + recycle_rxq_info->mbuf_ring_size = rxq->nb_rx_desc; + recycle_rxq_info->receive_tail = &rxq->rx_tail; + +if (adapter->rx_vec_allowed) { +#if defined(RTE_ARCH_X86 ) || defined(RTE_ARCH_ARM ) + recycle_rxq_info->refill_requirement =RTE_IXGBE_RXQ_REARM_THRESH ; + recycle_rxq_info->refill_head = &rxq->rxrearm_start; +#endif + }else { + recycle_rxq_info->refill_requirement = rxq->rx_free_thresh; + recycle_rxq_info->refill_head = &rxq->rx_free_trigger; + } +} +/* * [VF] Initializes Receive Unit. */
drivers/net/ixgbe/ixgbe_rxtx.h +4 -0
@@ -295,6 +295,10 @@ int ixgbe_dev_tx_done_cleanup(void *tx_queue, uint32_t free_cnt);extern const uint32_t ptype_table[IXGBE_PACKET_TYPE_MAX ];extern const uint32_t ptype_table_tn[IXGBE_PACKET_TYPE_TN_MAX ]; +uint16_t ixgbe_recycle_tx_mbufs_reuse_vec (void *tx_queue, +struct rte_eth_recycle_rxq_info *recycle_rxq_info); +void ixgbe_recycle_rx_descriptors_refill_vec (void *rx_queue,uint16_t nb_mbufs); +uint16_t ixgbe_xmit_fixed_burst_vec (void *tx_queue,struct rte_mbuf **tx_pkts,uint16_t nb_pkts);int ixgbe_txq_vec_setup (struct ixgbe_tx_queue *txq);
drivers/net/ixgbe/meson.build +2 -0
@@ -26,11 +26,13 @@ deps += ['hash', 'security'] if arch_subdir == 'x86' sources += files('ixgbe_rxtx_vec_sse.c') + sources += files('ixgbe_recycle_mbufs_vec_common.c') if is_windows and cc.get_id() != 'clang' cflags += ['-fno-asynchronous-unwind-tables'] endif elif arch_subdir == 'arm' sources += files('ixgbe_rxtx_vec_neon.c') + sources += files('ixgbe_recycle_mbufs_vec_common.c') endif includes += include_directories('base')
Signature · 1 line
2.25.1
PATCH v12 4/4 app/testpmd: add recycle mbufs engine
In reply to Feifei WangAdd recycle mbufs engine for testpmd. This engine forward pkts with I/O forward mode. But enable mbufs recycle feature to recycle used txq mbufs for rxq mbuf ring, which can bypass mempool path and save CPU cycles.
--- app/test-pmd/meson.build | 1 + app/test-pmd/recycle_mbufs.c | 58 +++++++++++++++++++++ app/test-pmd/testpmd.c | 1 + app/test-pmd/testpmd.h | 3 ++ doc/guides/testpmd_app_ug/run_app.rst | 1 + doc/guides/testpmd_app_ug/testpmd_funcs.rst | 5 +- 6 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 app/test-pmd/recycle_mbufs.c
app/test-pmd/meson.build +1 -0
@@ -22,6 +22,7 @@ sources = files( 'macswap.c', 'noisy_vnf.c', 'parameters.c', + 'recycle_mbufs.c', 'rxonly.c', 'shared_rxq_fwd.c', 'testpmd.c',
app/test-pmd/recycle_mbufs.c new file +58 -0
58 lines not on this page · raw message
app/test-pmd/testpmd.c +1 -0
@@ -199,6 +199,7 @@ struct fwd_engine * fwd_engines[] = { &icmp_echo_engine, &noisy_vnf_engine, &five_tuple_swap_fwd_engine, + &recycle_mbufs_engine, #ifdef RTE_LIBRTE_IEEE1588 &ieee1588_fwd_engine, #endif
app/test-pmd/testpmd.h +3 -0
@@ -188,6 +188,8 @@ struct fwd_stream {struct pkt_burst_stats rx_burst_stats;struct pkt_burst_stats tx_burst_stats;struct fwd_lcore *lcore;/**< Lcore being scheduled. */ +/**< Rx queue information for recycling mbufs */ +struct rte_eth_recycle_rxq_info recycle_rxq_info; };/**
@@ -449,6 +451,7 @@ extern struct fwd_engine csum_fwd_engine;extern struct fwd_engine icmp_echo_engine;extern struct fwd_engine noisy_vnf_engine;extern struct fwd_engine five_tuple_swap_fwd_engine; +extern struct fwd_engine recycle_mbufs_engine;#ifdef RTE_LIBRTE_IEEE1588 extern struct fwd_engine ieee1588_fwd_engine;#endif
doc/guides/testpmd_app_ug/run_app.rst +1 -0
@@ -232,6 +232,7 @@ The command line options are: noisy 5tswap shared-rxq + recycle_mbufs * ``--rss-ip``
doc/guides/testpmd_app_ug/testpmd_funcs.rst +4 -1
@@ -318,7 +318,7 @@ set fwd Set the packet forwarding mode:: testpmd> set fwd (io|mac|macswap|flowgen| \ - rxonly|txonly|csum|icmpecho|noisy|5tswap|shared-rxq) (""|retry) + rxonly|txonly|csum|icmpecho|noisy|5tswap|shared-rxq|recycle_mbufs) (""|retry) ``retry`` can be specified for forwarding engines except ``rx_only``.
@@ -364,6 +364,9 @@ The available information categories are: * ``shared-rxq``: Receive only for shared Rx queue. Resolve packet source port from mbuf and update stream statistics accordingly. +* ``recycle_mbufs``: Recycle Tx queue used mbufs for Rx queue mbuf ring. + This mode uses fast path mbuf recycle feature and forwards packets in I/O mode. + Example:: testpmd> set fwd rxonly
Signature · 1 line
2.25.1
Re: [PATCH v12 4/4] app/testpmd: add recycle mbufs engine
Quoted 7 lines · Feifei Wang
Add recycle mbufs engine for testpmd. This engine forward pkts with I/O forward mode. But enable mbufs recycle feature to recycle used txq mbufs for rxq mbuf ring, which can bypass mempool path and save CPU cycles.
Suggested-by Jerin Jacob <[email protected]>
Replacing with Jerin's primary email in .mailmap
Re: [PATCH v12 0/4] Recycle mbufs from Tx queue into Rx queue
In reply to Feifei WangQuoted 138 lines · Feifei Wang
Currently, the transmit side frees the buffers into the lcore cache and the receive side allocates buffers from the lcore cache. The transmit side typically frees 32 buffers resulting in 32*8=256B of stores to lcore cache. The receive side allocates 32 buffers and stores them in the receive side software ring, resulting in 32*8=256B of stores and 256B of load from the lcore cache.
This patch proposes a mechanism to avoid freeing to/allocating from the lcore cache. i.e. the receive side will free the buffers from transmit side directly into its software ring. This will avoid the 256B of loads and stores introduced by the lcore cache. It also frees up the cache lines used by the lcore cache. And we can call this mode as mbufs recycle mode.
In the latest version, mbufs recycle mode is packaged as a separate API.
This allows for the users to change rxq/txq pairing in real time in data plane, according to the analysis of the packet flow by the application, for example:
-----------------------------------------------------------------------
Step 1: upper application analyse the flow direction
Step 2:recycle_rxq_info=rte_eth_recycle_rx_queue_info_get(rx_portid, rx_queueid)Step 3:rte_eth_recycle_mbufs(rx_portid, rx_queueid, tx_portid, tx_queueid, recycle_rxq_info); Step 4:rte_eth_rx_burst(rx_portid,rx_queueid);
Step 5:rte_eth_tx_burst(tx_portid,tx_queueid);
-----------------------------------------------------------------------
Above can support user to change rxq/txq pairing at run-time and user does not need to know the direction of flow in advance. This can effectively expand mbufs recycle mode's use scenarios.Furthermore, mbufs recycle mode is no longer limited to the same pmd,
it can support moving mbufs between different vendor pmds, even can put the mbufs anywhere into your Rx mbuf ring as long as the address of the mbuf ring can be provided. In the latest version, we enable mbufs recycle mode in i40e pmd and ixgbe pmd, and also try to use i40e driver in Rx, ixgbe driver in Tx, and then achieve 7-9% performance improvement by mbufs recycle mode.Difference between mbuf recycle, ZC API used in mempool and general path
For general path:
Rx: 32 pkts memcpy from mempool cache torx_sw_ring
Tx: 32 pkts memcpy fromtx_sw_ringto temporary variable + 32 pkts memcpy from temporary variable to mempool cache
For ZC API used in mempool:
Rx: 32 pkts memcpy from mempool cache torx_sw_ring
Tx: 32 pkts memcpy fromtx_sw_ringto zero-copy mempool cache
Refer link: http://patches.dpdk.org/project/dpdk/patch/[email protected]/
For mbufs recycle:
Rx/Tx: 32 pkts memcpy fromtx_sw_ringtorx_sw_ring
Thus we can see in the one loop, compared to general path, mbufs recycle mode reduces 32+32=64 pkts memcpy; Compared to ZC API used in mempool, we can see mbufs recycle mode reduce 32 pkts memcpy in each loop.
So, mbufs recycle has its own benefits.Testing status:
(1) dpdk l3fwd test with multiple drivers:port 0: 82599 NIC port 1: XL710 NIC-------------------------------------------------------------
Without fast free With fast free
Thunderx2: +7.53% +13.54%
-------------------------------------------------------------(2) dpdk l3fwd test with same driver:
port 0 && 1: XL710 NIC-------------------------------------------------------------
Without fast free With fast free
Ampere altra: +12.61% +11.42%
n1sdp: +8.30% +3.85%
x86-sse: +8.43% +3.72%
-------------------------------------------------------------(3) Performance comparison with
ZC_mempoolused
port 0 && 1: XL710 NIC
with fast free
-------------------------------------------------------------
With recycle buffer Withzc_mempool
Ampere altra: 11.42% 3.54%
-------------------------------------------------------------Furthermore, we add
recycle_mbufengine in testpmd. Due to XL710 NIC has I/O bottleneck in testpmd in ampere altra, we can not see throughput change compared with I/O fwd engine. However, using record cmd in testpmd:
'$set record-burst-stats on'
we can see the ratio of 'Rx/Tx burst size of 32' is reduced. This indicate mbufs recycle can save CPU cycles.V2:
1. Use data-plane API to enable direct-rearm (Konstantin, Honnappa)
2. Add 'txq_data_get' API to get txq info for Rx (Konstantin)
3. Use input parameter to enable direct rearm in l3fwd (Konstantin)
4. Add condition detection for direct rearm API (Morten, Andrew Rybchenko)V3:
1. Seperate Rx and Tx operation with two APIs in direct-rearm (Konstantin)
2. Delete L3fwd change for direct rearm (Jerin)
3. enable direct rearm in ixgbe driver in Armv4:
1. Rename direct-rearm as buffer recycle. Based on this, function name and variable name are changed to let this mode more general for all drivers. (Konstantin, Morten)
2. Add ring wrapping check (Konstantin)v5:
1. some change for ethdev API (Morten)
2. add support for avx2, sse, altivec pathv6:
1. fix ixgbe build issue in ppc
2. remove 'recycle_tx_mbufs_reuse' and 'recycle_rx_descriptors_refill' API wrapper (Tech Board meeting)
3. addrecycle_mbufsengine in testpmd (Tech Board meeting)
4. add namespace in the functions related to mbufs recycle(Ferruh)v7:
1. move 'rxq/txq data' pointers to the beginning ofeth_devstructure, in order to keep them in the same cache line as rx/tx_burst function pointers (Morten)
2. add the extra description for 'rte_eth_recycle_mbufs' to show it can support feeding 1 Rx queue from 2 Tx queues in the same thread (Konstantin)
3. For i40e/ixgbe driver, make the previous copied buffers as invalid if there are Tx buffers refcnt > 1 or from unexpected mempool (Konstantin)
4. add check for the return value of 'rte_eth_recycle_rx_queue_info_get' in testpmd fwd engine (Morten)v8:
1. add arm/x86 build option to fix ixgbe build issue in ppcv9:
1. delete duplicate file name for ixgbev10:
1. fix compile issue on windowsv11:
1. fix doc warningv12:
1. replace rx queue check code witheth_dev_validate_rx_queuefunction (Stephen)
2. put port and queue check before function call (Konstantin)
Quoted 6 lines
Feifei Wang (4):
ethdev: add API for mbufs recycle mode
net/i40e: implement mbufs recycle mode
net/ixgbe: implement mbufs recycle mode
app/testpmd: add recycle mbufs engine
Thanks for dedication to improve the patchset and finding better solution, it is appreciated.
Series applied to dpdk-next-net/main, thanks.
Re: [PATCH v12 0/4] Recycle mbufs from Tx queue into Rx queue
Quoted 146 lines · Ferruh Yigit
Quoted 138 lines · Feifei Wang
Currently, the transmit side frees the buffers into the lcore cache and the receive side allocates buffers from the lcore cache. The transmit side typically frees 32 buffers resulting in 32*8=256B of stores to lcore cache. The receive side allocates 32 buffers and stores them in the receive side software ring, resulting in 32*8=256B of stores and 256B of load from the lcore cache.
This patch proposes a mechanism to avoid freeing to/allocating from the lcore cache. i.e. the receive side will free the buffers from transmit side directly into its software ring. This will avoid the 256B of loads and stores introduced by the lcore cache. It also frees up the cache lines used by the lcore cache. And we can call this mode as mbufs recycle mode.
In the latest version, mbufs recycle mode is packaged as a separate API.
This allows for the users to change rxq/txq pairing in real time in data plane, according to the analysis of the packet flow by the application, for example:
-----------------------------------------------------------------------
Step 1: upper application analyse the flow direction
Step 2:recycle_rxq_info=rte_eth_recycle_rx_queue_info_get(rx_portid, rx_queueid)Step 3:rte_eth_recycle_mbufs(rx_portid, rx_queueid, tx_portid, tx_queueid, recycle_rxq_info); Step 4:rte_eth_rx_burst(rx_portid,rx_queueid);
Step 5:rte_eth_tx_burst(tx_portid,tx_queueid);
-----------------------------------------------------------------------
Above can support user to change rxq/txq pairing at run-time and user does not need to know the direction of flow in advance. This can effectively expand mbufs recycle mode's use scenarios.Furthermore, mbufs recycle mode is no longer limited to the same pmd,
it can support moving mbufs between different vendor pmds, even can put the mbufs anywhere into your Rx mbuf ring as long as the address of the mbuf ring can be provided. In the latest version, we enable mbufs recycle mode in i40e pmd and ixgbe pmd, and also try to use i40e driver in Rx, ixgbe driver in Tx, and then achieve 7-9% performance improvement by mbufs recycle mode.Difference between mbuf recycle, ZC API used in mempool and general path
For general path:
Rx: 32 pkts memcpy from mempool cache torx_sw_ring
Tx: 32 pkts memcpy fromtx_sw_ringto temporary variable + 32 pkts memcpy from temporary variable to mempool cache
For ZC API used in mempool:
Rx: 32 pkts memcpy from mempool cache torx_sw_ring
Tx: 32 pkts memcpy fromtx_sw_ringto zero-copy mempool cache
Refer link: http://patches.dpdk.org/project/dpdk/patch/[email protected]/
For mbufs recycle:
Rx/Tx: 32 pkts memcpy fromtx_sw_ringtorx_sw_ring
Thus we can see in the one loop, compared to general path, mbufs recycle mode reduces 32+32=64 pkts memcpy; Compared to ZC API used in mempool, we can see mbufs recycle mode reduce 32 pkts memcpy in each loop.
So, mbufs recycle has its own benefits.Testing status:
(1) dpdk l3fwd test with multiple drivers:port 0: 82599 NIC port 1: XL710 NIC-------------------------------------------------------------
Without fast free With fast free
Thunderx2: +7.53% +13.54%
-------------------------------------------------------------(2) dpdk l3fwd test with same driver:
port 0 && 1: XL710 NIC-------------------------------------------------------------
Without fast free With fast free
Ampere altra: +12.61% +11.42%
n1sdp: +8.30% +3.85%
x86-sse: +8.43% +3.72%
-------------------------------------------------------------(3) Performance comparison with
ZC_mempoolused
port 0 && 1: XL710 NIC
with fast free
-------------------------------------------------------------
With recycle buffer Withzc_mempool
Ampere altra: 11.42% 3.54%
-------------------------------------------------------------Furthermore, we add
recycle_mbufengine in testpmd. Due to XL710 NIC has I/O bottleneck in testpmd in ampere altra, we can not see throughput change compared with I/O fwd engine. However, using record cmd in testpmd:
'$set record-burst-stats on'
we can see the ratio of 'Rx/Tx burst size of 32' is reduced. This indicate mbufs recycle can save CPU cycles.V2:
1. Use data-plane API to enable direct-rearm (Konstantin, Honnappa)
2. Add 'txq_data_get' API to get txq info for Rx (Konstantin)
3. Use input parameter to enable direct rearm in l3fwd (Konstantin)
4. Add condition detection for direct rearm API (Morten, Andrew Rybchenko)V3:
1. Seperate Rx and Tx operation with two APIs in direct-rearm (Konstantin)
2. Delete L3fwd change for direct rearm (Jerin)
3. enable direct rearm in ixgbe driver in Armv4:
1. Rename direct-rearm as buffer recycle. Based on this, function name and variable name are changed to let this mode more general for all drivers. (Konstantin, Morten)
2. Add ring wrapping check (Konstantin)v5:
1. some change for ethdev API (Morten)
2. add support for avx2, sse, altivec pathv6:
1. fix ixgbe build issue in ppc
2. remove 'recycle_tx_mbufs_reuse' and 'recycle_rx_descriptors_refill' API wrapper (Tech Board meeting)
3. addrecycle_mbufsengine in testpmd (Tech Board meeting)
4. add namespace in the functions related to mbufs recycle(Ferruh)v7:
1. move 'rxq/txq data' pointers to the beginning ofeth_devstructure, in order to keep them in the same cache line as rx/tx_burst function pointers (Morten)
2. add the extra description for 'rte_eth_recycle_mbufs' to show it can support feeding 1 Rx queue from 2 Tx queues in the same thread (Konstantin)
3. For i40e/ixgbe driver, make the previous copied buffers as invalid if there are Tx buffers refcnt > 1 or from unexpected mempool (Konstantin)
4. add check for the return value of 'rte_eth_recycle_rx_queue_info_get' in testpmd fwd engine (Morten)v8:
1. add arm/x86 build option to fix ixgbe build issue in ppcv9:
1. delete duplicate file name for ixgbev10:
1. fix compile issue on windowsv11:
1. fix doc warningv12:
1. replace rx queue check code witheth_dev_validate_rx_queuefunction (Stephen)
2. put port and queue check before function call (Konstantin)Quoted 6 lines
Feifei Wang (4):
ethdev: add API for mbufs recycle mode
net/i40e: implement mbufs recycle mode
net/ixgbe: implement mbufs recycle mode
app/testpmd: add recycle mbufs engine
Quoted 5 lines
Thanks for dedication to improve the patchset and finding better solution, it is appreciated.
Series applied to dpdk-next-net/main, thanks.
Konstantin highlighted that there is an outstanding discussion:
http://patchwork.dpdk.org/project/dpdk/patch/[email protected]/
Dropping the patchset from next-net, and updating its status in the patchwork as "Changes Requested".