From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 47BB4A034F;
	Tue, 23 Feb 2021 19:26:24 +0100 (CET)
Received: from [217.70.189.124] (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id B842A4068C;
	Tue, 23 Feb 2021 19:26:23 +0100 (CET)
Received: from foss.arm.com (foss.arm.com [217.140.110.172])
 by mails.dpdk.org (Postfix) with ESMTP id 04AC14068B
 for <dev@dpdk.org>; Tue, 23 Feb 2021 19:26:21 +0100 (CET)
Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14])
 by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 22C5431B;
 Tue, 23 Feb 2021 10:26:21 -0800 (PST)
Received: from n1sdp-2.usa.Arm.com (n1sdp-2.usa.arm.com [10.118.91.151])
 by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0AD213F73B;
 Tue, 23 Feb 2021 10:26:21 -0800 (PST)
From: Kathleen Capella <kathleen.capella@arm.com>
To: dev@dpdk.org
Cc: nd@arm.com,
	honnappa.nagarahalli@arm.com,
	kathleen.capella@arm.com
Date: Tue, 23 Feb 2021 18:23:00 +0000
Message-Id: <20210223182300.29817-1-kathleen.capella@arm.com>
X-Mailer: git-send-email 2.17.1
Subject: [dpdk-dev] [PATCH] examples/l3fwd: fix TX burst queue drain edge
 case
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org
Sender: "dev" <dev-bounces@dpdk.org>

Initialize prev_tsc to cur_tsc. This avoids running the TX queue drain
in the first iteration of the packet processing loop.

Fixes: af75078fece3 ("first public release")

Signed-off-by: Kathleen Capella <kathleen.capella@arm.com>
Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
---
 examples/l3fwd/l3fwd_em.c  | 9 +++++----
 examples/l3fwd/l3fwd_lpm.c | 9 +++++----
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/examples/l3fwd/l3fwd_em.c b/examples/l3fwd/l3fwd_em.c
index 9996bfba3..01f8dff48 100644
--- a/examples/l3fwd/l3fwd_em.c
+++ b/examples/l3fwd/l3fwd_em.c
@@ -629,8 +629,6 @@ em_main_loop(__rte_unused void *dummy)
 	const uint64_t drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1) /
 		US_PER_S * BURST_TX_DRAIN_US;
 
-	prev_tsc = 0;
-
 	lcore_id = rte_lcore_id();
 	qconf = &lcore_conf[lcore_id];
 
@@ -650,9 +648,10 @@ em_main_loop(__rte_unused void *dummy)
 			lcore_id, portid, queueid);
 	}
 
-	while (!force_quit) {
+	cur_tsc = rte_rdtsc();
+	prev_tsc = cur_tsc;
 
-		cur_tsc = rte_rdtsc();
+	while (!force_quit) {
 
 		/*
 		 * TX burst queue drain
@@ -692,6 +691,8 @@ em_main_loop(__rte_unused void *dummy)
 							portid, qconf);
 #endif
 		}
+
+		cur_tsc = rte_rdtsc();
 	}
 
 	return 0;
diff --git a/examples/l3fwd/l3fwd_lpm.c b/examples/l3fwd/l3fwd_lpm.c
index 3dcf1fef1..375746fef 100644
--- a/examples/l3fwd/l3fwd_lpm.c
+++ b/examples/l3fwd/l3fwd_lpm.c
@@ -185,8 +185,6 @@ lpm_main_loop(__rte_unused void *dummy)
 	const uint64_t drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1) /
 		US_PER_S * BURST_TX_DRAIN_US;
 
-	prev_tsc = 0;
-
 	lcore_id = rte_lcore_id();
 	qconf = &lcore_conf[lcore_id];
 
@@ -206,9 +204,10 @@ lpm_main_loop(__rte_unused void *dummy)
 			lcore_id, portid, queueid);
 	}
 
-	while (!force_quit) {
+	cur_tsc = rte_rdtsc();
+	prev_tsc = cur_tsc;
 
-		cur_tsc = rte_rdtsc();
+	while (!force_quit) {
 
 		/*
 		 * TX burst queue drain
@@ -249,6 +248,8 @@ lpm_main_loop(__rte_unused void *dummy)
 							portid, qconf);
 #endif /* X86 */
 		}
+
+		cur_tsc = rte_rdtsc();
 	}
 
 	return 0;
-- 
2.17.1