DPDK patches and discussions
 help / color / mirror / Atom feed
From: Anoob Joseph <anoob.joseph@caviumnetworks.com>
To: Bruce Richardson <bruce.richardson@intel.com>,
	Pablo de Lara <pablo.de.lara.guarch@intel.com>
Cc: Anoob Joseph <anoob.joseph@caviumnetworks.com>,
	Jerin Jacob <jerin.jacob@caviumnetworks.com>,
	Narayana Prasad <narayanaprasad.athreya@caviumnetworks.com>,
	dev@dpdk.org
Subject: [dpdk-dev] [PATCH v2 08/12] examples/l2fwd: move periodic tasks to new function
Date: Wed, 11 Jul 2018 11:37:24 +0530	[thread overview]
Message-ID: <1531289248-20025-9-git-send-email-anoob.joseph@caviumnetworks.com> (raw)
In-Reply-To: <1531289248-20025-1-git-send-email-anoob.joseph@caviumnetworks.com>

Move the periodic operations (stats flush and drain buffers) to a new
function.

Signed-off-by: Anoob Joseph <anoob.joseph@caviumnetworks.com>
---
v2:
* No change

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

 examples/l2fwd/l2fwd_worker.c | 83 ++++++++++++++++++++++++-------------------
 examples/l2fwd/l2fwd_worker.h |  6 ++++
 2 files changed, 52 insertions(+), 37 deletions(-)

diff --git a/examples/l2fwd/l2fwd_worker.c b/examples/l2fwd/l2fwd_worker.c
index f847832..868d0c6 100644
--- a/examples/l2fwd/l2fwd_worker.c
+++ b/examples/l2fwd/l2fwd_worker.c
@@ -94,6 +94,45 @@ l2fwd_drain_buffers(struct lcore_queue_conf *qconf)
 	}
 }
 
+static inline void
+l2fwd_periodic_drain_stats_monitor(struct lcore_queue_conf *qconf,
+		struct tsc_tracker *t, int is_master_core)
+{
+	uint64_t diff_tsc, cur_tsc;
+
+	cur_tsc = rte_rdtsc();
+
+	/*
+	 * TX burst queue drain
+	 */
+	diff_tsc = cur_tsc - t->prev_tsc;
+	if (unlikely(diff_tsc > t->drain_tsc)) {
+
+		/* Drain buffers */
+		l2fwd_drain_buffers(qconf);
+
+		/* if timer is enabled */
+		if (timer_period > 0) {
+
+			/* advance the timer */
+			t->timer_tsc += diff_tsc;
+
+			/* if timer has reached its timeout */
+			if (unlikely(t->timer_tsc >= timer_period)) {
+
+				/* do this only on master core */
+				if (is_master_core) {
+					print_stats();
+					/* reset the timer */
+					t->timer_tsc = 0;
+				}
+			}
+		}
+
+		t->prev_tsc = cur_tsc;
+	}
+}
+
 static void
 l2fwd_mac_updating(struct rte_mbuf *m, unsigned int dest_portid)
 {
@@ -135,19 +174,18 @@ l2fwd_main_loop(void)
 	struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
 	struct rte_mbuf *m;
 	unsigned int lcore_id;
-	uint64_t prev_tsc, diff_tsc, cur_tsc, timer_tsc;
 	unsigned int i, j, portid, nb_rx;
 	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;
 	int is_master_core;
-
-	prev_tsc = 0;
-	timer_tsc = 0;
+	struct tsc_tracker tsc = {0};
 
 	lcore_id = rte_lcore_id();
 	qconf = &lcore_queue_conf[lcore_id];
 
+	/* Set drain tsc */
+	tsc.drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1) /
+			US_PER_S * BURST_TX_DRAIN_US;
+
 	if (qconf->n_rx_port == 0) {
 		RTE_LOG(INFO, L2FWD, "lcore %u has nothing to do\n", lcore_id);
 		return;
@@ -167,37 +205,8 @@ l2fwd_main_loop(void)
 
 	while (!force_quit) {
 
-		cur_tsc = rte_rdtsc();
-
-		/*
-		 * TX burst queue drain
-		 */
-		diff_tsc = cur_tsc - prev_tsc;
-		if (unlikely(diff_tsc > drain_tsc)) {
-
-			/* Drain buffers */
-			l2fwd_drain_buffers(qconf);
-
-			/* if timer is enabled */
-			if (timer_period > 0) {
-
-				/* advance the timer */
-				timer_tsc += diff_tsc;
-
-				/* if timer has reached its timeout */
-				if (unlikely(timer_tsc >= timer_period)) {
-
-					/* do this only on master core */
-					if (is_master_core) {
-						print_stats();
-						/* reset the timer */
-						timer_tsc = 0;
-					}
-				}
-			}
-
-			prev_tsc = cur_tsc;
-		}
+		/* Do periodic operations (buffer drain & stats monitor) */
+		l2fwd_periodic_drain_stats_monitor(qconf, &tsc, is_master_core);
 
 		/*
 		 * Read packet from RX queues
diff --git a/examples/l2fwd/l2fwd_worker.h b/examples/l2fwd/l2fwd_worker.h
index 8971a6a..65650aa 100644
--- a/examples/l2fwd/l2fwd_worker.h
+++ b/examples/l2fwd/l2fwd_worker.h
@@ -4,6 +4,12 @@
 #ifndef _L2FWD_WORKER_H_
 #define _L2FWD_WORKER_H_
 
+struct tsc_tracker {
+	uint64_t prev_tsc;
+	uint64_t timer_tsc;
+	uint64_t drain_tsc;
+};
+
 int
 l2fwd_launch_one_lcore(__attribute__((unused)) void *dummy);
 
-- 
2.7.4

  parent reply	other threads:[~2018-07-11  6:08 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-08 17:09 [dpdk-dev] [PATCH 00/15] preparing l2fwd for eventmode additions Anoob Joseph
2018-06-08 17:09 ` [dpdk-dev] [PATCH 01/15] examples/l2fwd: add new header to move common code Anoob Joseph
2018-06-08 17:09 ` [dpdk-dev] [PATCH 02/15] examples/l2fwd: move macro definitions to common header Anoob Joseph
2018-06-08 17:09 ` [dpdk-dev] [PATCH 03/15] examples/l2fwd: move structure " Anoob Joseph
2018-06-08 17:09 ` [dpdk-dev] [PATCH 04/15] examples/l2fwd: move globally accessed vars " Anoob Joseph
2018-06-08 17:09 ` [dpdk-dev] [PATCH 05/15] examples/l2fwd: add missing space Anoob Joseph
2018-06-08 17:09 ` [dpdk-dev] [PATCH 06/15] examples/l2fwd: fix lines exceeding 80 char limit Anoob Joseph
2018-06-08 17:09 ` [dpdk-dev] [PATCH 07/15] examples/l2fwd: move dataplane code to new file Anoob Joseph
2018-06-08 17:09 ` [dpdk-dev] [PATCH 08/15] examples/l2fwd: remove unused header includes Anoob Joseph
2018-06-08 17:09 ` [dpdk-dev] [PATCH 09/15] examples/l2fwd: move drain buffers to new function Anoob Joseph
2018-06-08 17:09 ` [dpdk-dev] [PATCH 10/15] examples/l2fwd: optimize check for master core Anoob Joseph
2018-06-08 17:09 ` [dpdk-dev] [PATCH 11/15] examples/l2fwd: move periodic tasks to new function Anoob Joseph
2018-06-08 17:09 ` [dpdk-dev] [PATCH 12/15] examples/l2fwd: skip timer updates for non master cores Anoob Joseph
2018-06-08 17:09 ` [dpdk-dev] [PATCH 13/15] examples/l2fwd: move pkt send code to a new function Anoob Joseph
2018-06-08 17:09 ` [dpdk-dev] [PATCH 14/15] examples/l2fwd: use fprint instead of printf for usage print Anoob Joseph
2018-06-08 17:09 ` [dpdk-dev] [PATCH 15/15] examples/l2fwd: improvements to the " Anoob Joseph
2018-06-14 10:17 ` [dpdk-dev] [PATCH v1 00/15] preparing l2fwd for eventmode additions Anoob Joseph
2018-06-14 10:17   ` [dpdk-dev] [PATCH v1 01/15] examples/l2fwd: add new header to move common code Anoob Joseph
2018-07-09 22:46     ` De Lara Guarch, Pablo
2018-07-10  3:16       ` Anoob Joseph
2018-07-10 10:20         ` De Lara Guarch, Pablo
2018-06-14 10:17   ` [dpdk-dev] [PATCH v1 02/15] examples/l2fwd: move macro definitions to common header Anoob Joseph
2018-06-14 10:17   ` [dpdk-dev] [PATCH v1 03/15] examples/l2fwd: move structure " Anoob Joseph
2018-06-14 10:17   ` [dpdk-dev] [PATCH v1 04/15] examples/l2fwd: move globally accessed vars " Anoob Joseph
2018-06-14 10:17   ` [dpdk-dev] [PATCH v1 05/15] examples/l2fwd: add missing space Anoob Joseph
2018-06-14 10:17   ` [dpdk-dev] [PATCH v1 06/15] examples/l2fwd: fix lines exceeding 80 char limit Anoob Joseph
2018-07-09 22:48     ` De Lara Guarch, Pablo
2018-06-14 10:17   ` [dpdk-dev] [PATCH v1 07/15] examples/l2fwd: move dataplane code to new file Anoob Joseph
2018-06-14 10:17   ` [dpdk-dev] [PATCH v1 08/15] examples/l2fwd: remove unused header includes Anoob Joseph
2018-06-14 10:17   ` [dpdk-dev] [PATCH v1 09/15] examples/l2fwd: move drain buffers to new function Anoob Joseph
2018-07-09 22:49     ` De Lara Guarch, Pablo
2018-07-10  3:17       ` Anoob Joseph
2018-06-14 10:17   ` [dpdk-dev] [PATCH v1 10/15] examples/l2fwd: optimize check for master core Anoob Joseph
2018-06-14 10:17   ` [dpdk-dev] [PATCH v1 11/15] examples/l2fwd: move periodic tasks to new function Anoob Joseph
2018-06-14 10:17   ` [dpdk-dev] [PATCH v1 12/15] examples/l2fwd: skip timer updates for non master cores Anoob Joseph
2018-06-14 10:17   ` [dpdk-dev] [PATCH v1 13/15] examples/l2fwd: move pkt send code to a new function Anoob Joseph
2018-06-14 10:17   ` [dpdk-dev] [PATCH v1 14/15] examples/l2fwd: use fprint instead of printf for usage print Anoob Joseph
2018-06-14 10:17   ` [dpdk-dev] [PATCH v1 15/15] examples/l2fwd: improvements to the " Anoob Joseph
2018-06-14 11:48 ` [dpdk-dev] [PATCH v1 00/15] preparing l2fwd for eventmode additions Anoob Joseph
2018-06-14 11:48   ` [dpdk-dev] [PATCH v1 01/15] examples/l2fwd: add new header to move common code Anoob Joseph
2018-06-14 11:48   ` [dpdk-dev] [PATCH v1 02/15] examples/l2fwd: move macro definitions to common header Anoob Joseph
2018-06-14 11:48   ` [dpdk-dev] [PATCH v1 03/15] examples/l2fwd: move structure " Anoob Joseph
2018-06-14 11:48   ` [dpdk-dev] [PATCH v1 04/15] examples/l2fwd: move globally accessed vars " Anoob Joseph
2018-06-14 11:48   ` [dpdk-dev] [PATCH v1 05/15] examples/l2fwd: add missing space Anoob Joseph
2018-07-09 22:51     ` De Lara Guarch, Pablo
2018-07-10  3:23       ` Anoob Joseph
2018-06-14 11:48   ` [dpdk-dev] [PATCH v1 06/15] examples/l2fwd: fix lines exceeding 80 char limit Anoob Joseph
2018-06-14 11:48   ` [dpdk-dev] [PATCH v1 07/15] examples/l2fwd: move dataplane code to new file Anoob Joseph
2018-06-14 11:48   ` [dpdk-dev] [PATCH v1 08/15] examples/l2fwd: remove unused header includes Anoob Joseph
2018-06-14 11:49   ` [dpdk-dev] [PATCH v1 09/15] examples/l2fwd: move drain buffers to new function Anoob Joseph
2018-06-14 11:49   ` [dpdk-dev] [PATCH v1 10/15] examples/l2fwd: optimize check for master core Anoob Joseph
2018-06-14 11:49   ` [dpdk-dev] [PATCH v1 11/15] examples/l2fwd: move periodic tasks to new function Anoob Joseph
2018-06-14 11:49   ` [dpdk-dev] [PATCH v1 12/15] examples/l2fwd: skip timer updates for non master cores Anoob Joseph
2018-06-14 11:49   ` [dpdk-dev] [PATCH v1 13/15] examples/l2fwd: move pkt send code to a new function Anoob Joseph
2018-06-14 11:49   ` [dpdk-dev] [PATCH v1 14/15] examples/l2fwd: use fprint instead of printf for usage print Anoob Joseph
2018-06-14 11:49   ` [dpdk-dev] [PATCH v1 15/15] examples/l2fwd: improvements to the " Anoob Joseph
2018-06-19 10:04   ` [dpdk-dev] [PATCH v1 00/15] preparing l2fwd for eventmode additions Anoob Joseph
2018-06-19 10:09     ` Bruce Richardson
2018-06-19 14:07       ` Anoob Joseph
2018-07-03 13:16         ` Joseph, Anoob
2018-07-11  6:07   ` [dpdk-dev] [PATCH v2 00/12] " Anoob Joseph
2018-07-11  6:07     ` [dpdk-dev] [PATCH v2 01/12] examples/l2fwd: move macro definitions to common header Anoob Joseph
2018-07-11  6:07     ` [dpdk-dev] [PATCH v2 03/12] examples/l2fwd: move globally accessed vars " Anoob Joseph
2018-07-11  6:07     ` [dpdk-dev] [PATCH v2 04/12] examples/l2fwd: move dataplane code to new file Anoob Joseph
2018-07-11  6:07     ` [dpdk-dev] [PATCH v2 05/12] examples/l2fwd: remove unused header includes Anoob Joseph
2018-07-11  6:07     ` [dpdk-dev] [PATCH v2 06/12] examples/l2fwd: move drain buffers to new function Anoob Joseph
2018-07-11  6:07     ` [dpdk-dev] [PATCH v2 07/12] examples/l2fwd: optimize check for master core Anoob Joseph
2018-07-11  6:07     ` Anoob Joseph [this message]
2018-07-11  6:07     ` [dpdk-dev] [PATCH v2 09/12] examples/l2fwd: skip timer updates for non master cores Anoob Joseph
2018-07-11  6:07     ` [dpdk-dev] [PATCH v2 10/12] examples/l2fwd: move pkt send code to a new function Anoob Joseph
2018-07-11  6:07     ` [dpdk-dev] [PATCH v2 11/12] examples/l2fwd: use fprint instead of printf for usage print Anoob Joseph
2018-07-11  6:07     ` [dpdk-dev] [PATCH v2 12/12] examples/l2fwd: improvements to the " Anoob Joseph
2018-07-26 16:57     ` [dpdk-dev] [PATCH v2 00/12] preparing l2fwd for eventmode additions Thomas Monjalon
2018-08-01  6:59       ` Joseph, Anoob
2018-08-01 16:54         ` Stephen Hemminger
2018-08-01 17:26           ` Jerin Jacob
2018-08-02  8:19             ` Ananyev, Konstantin
2018-08-13  7:22               ` Joseph, Anoob
2018-08-13  9:27                 ` Bruce Richardson
2018-08-13 15:59                   ` Joseph, Anoob
2018-08-14 10:33                     ` Bruce Richardson
2018-08-18  9:58                       ` Joseph, Anoob
2018-10-29  2:22                         ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1531289248-20025-9-git-send-email-anoob.joseph@caviumnetworks.com \
    --to=anoob.joseph@caviumnetworks.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=jerin.jacob@caviumnetworks.com \
    --cc=narayanaprasad.athreya@caviumnetworks.com \
    --cc=pablo.de.lara.guarch@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).