[v2,06/12] examples/l2fwd: move drain buffers to new function

Message ID 1531289248-20025-7-git-send-email-anoob.joseph@caviumnetworks.com
State Rejected, archived
Delegated to: Thomas Monjalon
Headers show
Series
  • preparing l2fwd for eventmode additions
Related show

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Anoob Joseph July 11, 2018, 6:07 a.m.
Signed-off-by: Anoob Joseph <anoob.joseph@caviumnetworks.com>
---
v2:
* No change

v1:
* Replaced 'unsigned' with 'unsigned int'

 examples/l2fwd/l2fwd_worker.c | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

Patch

diff --git a/examples/l2fwd/l2fwd_worker.c b/examples/l2fwd/l2fwd_worker.c
index ad5468a..dfa78ed 100644
--- a/examples/l2fwd/l2fwd_worker.c
+++ b/examples/l2fwd/l2fwd_worker.c
@@ -76,6 +76,24 @@  print_stats(void)
 	printf("\n====================================================\n");
 }
 
+static inline void
+l2fwd_drain_buffers(struct lcore_queue_conf *qconf)
+{
+	unsigned int i, sent;
+	unsigned int portid;
+	struct rte_eth_dev_tx_buffer *buffer;
+
+	for (i = 0; i < qconf->n_rx_port; i++) {
+
+		portid = l2fwd_dst_ports[qconf->rx_port_list[i]];
+		buffer = tx_buffer[portid];
+
+		sent = rte_eth_tx_buffer_flush(portid, 0, buffer);
+		if (sent)
+			port_statistics[portid].tx += sent;
+	}
+}
+
 static void
 l2fwd_mac_updating(struct rte_mbuf *m, unsigned int dest_portid)
 {
@@ -116,7 +134,6 @@  l2fwd_main_loop(void)
 {
 	struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
 	struct rte_mbuf *m;
-	int sent;
 	unsigned int lcore_id;
 	unsigned int master_core_id;
 	uint64_t prev_tsc, diff_tsc, cur_tsc, timer_tsc;
@@ -124,7 +141,6 @@  l2fwd_main_loop(void)
 	struct lcore_queue_conf *qconf;
 	const uint64_t drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1)
 			/ US_PER_S * BURST_TX_DRAIN_US;
-	struct rte_eth_dev_tx_buffer *buffer;
 
 	prev_tsc = 0;
 	timer_tsc = 0;
@@ -159,18 +175,8 @@  l2fwd_main_loop(void)
 		diff_tsc = cur_tsc - prev_tsc;
 		if (unlikely(diff_tsc > drain_tsc)) {
 
-			for (i = 0; i < qconf->n_rx_port; i++) {
-
-				portid =
-					l2fwd_dst_ports[qconf->rx_port_list[i]];
-				buffer = tx_buffer[portid];
-
-				sent = rte_eth_tx_buffer_flush(portid, 0,
-						buffer);
-				if (sent)
-					port_statistics[portid].tx += sent;
-
-			}
+			/* Drain buffers */
+			l2fwd_drain_buffers(qconf);
 
 			/* if timer is enabled */
 			if (timer_period > 0) {