<div> </div><div> </div><div> </div><blockquote><p>Add recycle mbufs engine for testpmd. This engine forward pkts with<br />I/O forward mode. But enable mbufs recycle feature to recycle used<br />txq mbufs for rxq mbuf ring, which can bypass mempool path and save<br />CPU cycles.<br /><br />Suggested-by: Jerin Jacob <<a href="mailto:jerinjacobk@gmail.com" rel="noopener noreferrer">jerinjacobk@gmail.com</a>><br />Signed-off-by: Feifei Wang <<a href="mailto:feifei.wang2@arm.com" rel="noopener noreferrer">feifei.wang2@arm.com</a>><br />Reviewed-by: Ruifeng Wang <<a href="mailto:ruifeng.wang@arm.com" rel="noopener noreferrer">ruifeng.wang@arm.com</a>><br />---<br /> app/test-pmd/meson.build | 1 +<br /> app/test-pmd/recycle_mbufs.c | 79 +++++++++++++++++++++<br /> app/test-pmd/testpmd.c | 1 +<br /> app/test-pmd/testpmd.h | 3 +<br /> doc/guides/testpmd_app_ug/run_app.rst | 1 +<br /> doc/guides/testpmd_app_ug/testpmd_funcs.rst | 5 +-<br /> 6 files changed, 89 insertions(+), 1 deletion(-)<br /> create mode 100644 app/test-pmd/recycle_mbufs.c<br /><br />diff --git a/app/test-pmd/meson.build b/app/test-pmd/meson.build<br />index d2e3f60892..6e5f067274 100644<br />--- a/app/test-pmd/meson.build<br />+++ b/app/test-pmd/meson.build<br />@@ -22,6 +22,7 @@ sources = files(<br />         'macswap.c',<br />         'noisy_vnf.c',<br />         'parameters.c',<br />+ 'recycle_mbufs.c',<br />         'rxonly.c',<br />         'shared_rxq_fwd.c',<br />         'testpmd.c',<br />diff --git a/app/test-pmd/recycle_mbufs.c b/app/test-pmd/recycle_mbufs.c<br />new file mode 100644<br />index 0000000000..0c603c3ec2<br />--- /dev/null<br />+++ b/app/test-pmd/recycle_mbufs.c<br />@@ -0,0 +1,79 @@<br />+/* SPDX-License-Identifier: BSD-3-Clause<br />+ * Copyright (c) 2023 Arm Limited.<br />+ */<br />+<br />+#include <stdarg.h><br />+#include <stdio.h><br />+#include <string.h><br />+#include <errno.h><br />+#include <stdint.h><br />+#include <unistd.h><br />+#include <inttypes.h><br />+<br />+#include <sys/queue.h><br />+#include <sys/stat.h><br />+<br />+#include <rte_common.h><br />+#include <rte_log.h><br />+#include <rte_debug.h><br />+#include <rte_cycles.h><br />+#include <rte_memory.h><br />+#include <rte_launch.h><br />+#include <rte_eal.h><br />+#include <rte_per_lcore.h><br />+#include <rte_lcore.h><br />+#include <rte_branch_prediction.h><br />+#include <rte_mbuf.h><br />+#include <rte_interrupts.h><br />+#include <rte_ether.h><br />+#include <rte_ethdev.h><br />+<br />+#include "testpmd.h"<br />+<br />+/*<br />+ * Forwarding of packets in I/O mode.<br />+ * Enable mbufs recycle mode to recycle txq used mbufs<br />+ * for rxq mbuf ring. This can bypass mempool path and<br />+ * save CPU cycles.<br />+ */<br />+static bool<br />+pkt_burst_recycle_mbufs(struct fwd_stream *fs)<br />+{<!-- --><br />+ struct rte_mbuf *pkts_burst[MAX_PKT_BURST];<br />+ uint16_t nb_rx;<br />+<br />+ /* Recycle used mbufs from the txq, and move these mbufs into<br />+ * the rxq mbuf ring.<br />+ */<br />+ rte_eth_recycle_mbufs(fs->rx_port, fs->rx_queue,<br />+ fs->tx_port, fs->tx_queue, &(fs->recycle_rxq_info));<br />+<br />+ /*<br />+ * Receive a burst of packets and forward them.<br />+ */<br />+ nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst);<br />+ if (unlikely(nb_rx == 0))<br />+ return false;<br />+<br />+ common_fwd_stream_transmit(fs, pkts_burst, nb_rx);<br />+<br />+ return true;<br />+}<br />+<br />+static void<br />+recycle_mbufs_stream_init(struct fwd_stream *fs)<br />+{<!-- --><br />+ /* Retrieve information about given ports's Rx queue<br />+ * for recycling mbufs.<br />+ */<br />+ rte_eth_recycle_rx_queue_info_get(fs->rx_port, fs->rx_queue,<br />+ &(fs->recycle_rxq_info));</p></blockquote><div> </div><div>We probably should check the return status and complain about failure.</div><div> </div><blockquote><p>+<br />+ common_fwd_stream_init(fs);<br />+}<br />+<br />+struct fwd_engine recycle_mbufs_engine = {<!-- --><br />+ .fwd_mode_name = "recycle_mbufs",<br />+ .stream_init = recycle_mbufs_stream_init,<br />+ .packet_fwd = pkt_burst_recycle_mbufs,<br />+};<br />diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c<br />index 5cb6f92523..050e48d79a 100644<br />--- a/app/test-pmd/testpmd.c<br />+++ b/app/test-pmd/testpmd.c<br />@@ -199,6 +199,7 @@ struct fwd_engine * fwd_engines[] = {<!-- --><br />         &icmp_echo_engine,<br />         &noisy_vnf_engine,<br />         &five_tuple_swap_fwd_engine,<br />+ &recycle_mbufs_engine,<br /> #ifdef RTE_LIBRTE_IEEE1588<br />         &ieee1588_fwd_engine,<br /> #endif<br />diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h<br />index bdfbfd36d3..34e72fd7d5 100644<br />--- a/app/test-pmd/testpmd.h<br />+++ b/app/test-pmd/testpmd.h<br />@@ -179,6 +179,8 @@ struct fwd_stream {<!-- --><br />         struct pkt_burst_stats rx_burst_stats;<br />         struct pkt_burst_stats tx_burst_stats;<br />         struct fwd_lcore *lcore; /**< Lcore being scheduled. */<br />+ /**< Rx queue information for recycling mbufs */<br />+ struct rte_eth_recycle_rxq_info recycle_rxq_info;<br /> };<br /> <br /> /**<br />@@ -432,6 +434,7 @@ extern struct fwd_engine csum_fwd_engine;<br /> extern struct fwd_engine icmp_echo_engine;<br /> extern struct fwd_engine noisy_vnf_engine;<br /> extern struct fwd_engine five_tuple_swap_fwd_engine;<br />+extern struct fwd_engine recycle_mbufs_engine;<br /> #ifdef RTE_LIBRTE_IEEE1588<br /> extern struct fwd_engine ieee1588_fwd_engine;<br /> #endif<br />diff --git a/doc/guides/testpmd_app_ug/run_app.rst b/doc/guides/testpmd_app_ug/run_app.rst<br />index 57b23241cf..cbc68acc36 100644<br />--- a/doc/guides/testpmd_app_ug/run_app.rst<br />+++ b/doc/guides/testpmd_app_ug/run_app.rst<br />@@ -232,6 +232,7 @@ The command line options are:<br />        noisy<br />        5tswap<br />        shared-rxq<br />+ recycle_mbufs<br /> <br /> * ``--rss-ip``<br /> <br />diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst<br />index 8f23847859..482e583263 100644<br />--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst<br />+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst<br />@@ -318,7 +318,7 @@ set fwd<br /> Set the packet forwarding mode::<br /> <br />    testpmd> set fwd (io|mac|macswap|flowgen| \<br />- rxonly|txonly|csum|icmpecho|noisy|5tswap|shared-rxq) (""|retry)<br />+ rxonly|txonly|csum|icmpecho|noisy|5tswap|shared-rxq|recycle_mbufs) (""|retry)<br /> <br /> ``retry`` can be specified for forwarding engines except ``rx_only``.<br /> <br />@@ -364,6 +364,9 @@ The available information categories are:<br /> * ``shared-rxq``: Receive only for shared Rx queue.<br />   Resolve packet source port from mbuf and update stream statistics accordingly.<br /> <br />+* ``recycle_mbufs``: Recycle Tx queue used mbufs for Rx queue mbuf ring.<br />+ This mode uses fast path mbuf recycle feature and forwards packets in I/O mode.<br />+<br /> Example::<br /> <br />    testpmd> set fwd rxonly</p>--<br />2.25.1<br /> </blockquote>