xref: /dpdk/app/test-pmd/recycle_mbufs.c (revision 5fe42bc6425fa7ebdfa2e6257a70563f8557f959)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2023 Arm Limited.
3  */
4 
5 #include "testpmd.h"
6 
7 /*
8  * Forwarding of packets in I/O mode.
9  * Enable mbufs recycle mode to recycle txq used mbufs
10  * for rxq mbuf ring. This can bypass mempool path and
11  * save CPU cycles.
12  */
13 static bool
pkt_burst_recycle_mbufs(struct fwd_stream * fs)14 pkt_burst_recycle_mbufs(struct fwd_stream *fs)
15 {
16 	struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
17 	uint16_t nb_rx;
18 
19 	/* Recycle used mbufs from the txq, and move these mbufs into
20 	 * the rxq mbuf ring.
21 	 */
22 	rte_eth_recycle_mbufs(fs->rx_port, fs->rx_queue,
23 			fs->tx_port, fs->tx_queue, &(fs->recycle_rxq_info));
24 
25 	/*
26 	 * Receive a burst of packets and forward them.
27 	 */
28 	nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst);
29 	if (unlikely(nb_rx == 0))
30 		return false;
31 
32 	common_fwd_stream_transmit(fs, pkts_burst, nb_rx);
33 
34 	return true;
35 }
36 
37 static void
recycle_mbufs_stream_init(struct fwd_stream * fs)38 recycle_mbufs_stream_init(struct fwd_stream *fs)
39 {
40 	int rc;
41 
42 	/* Retrieve information about given ports's Rx queue
43 	 * for recycling mbufs.
44 	 */
45 	rc = rte_eth_recycle_rx_queue_info_get(fs->rx_port,
46 			fs->rx_queue, &(fs->recycle_rxq_info));
47 	if (rc != 0)
48 		TESTPMD_LOG(WARNING,
49 			"Failed to get rx queue mbufs recycle info\n");
50 
51 	common_fwd_stream_init(fs);
52 }
53 
54 struct fwd_engine recycle_mbufs_engine = {
55 	.fwd_mode_name  = "recycle_mbufs",
56 	.stream_init    = recycle_mbufs_stream_init,
57 	.packet_fwd     = pkt_burst_recycle_mbufs,
58 };
59