[v7,1/1] odp-generator: Use clock related functions less when printing

Message ID 1504530006-8429-2-git-send-email-odpbot@yandex.ru
State New
Headers show
Series
  • [v7,1/1] odp-generator: Use clock related functions less when printing
Related show

Commit Message

Github ODP bot Sept. 4, 2017, 1 p.m.
From: Ilias Apalodimas <ilias.apalodimas@linaro.org>


Using odp_time_local() on each iteration consumes too much cpu for
no reason. Netmap pktio reported a boost from ~550kpps to ~1.2Mpps
when odp_generator was used as a receiver on 1Gbit links.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

---
/** Email created from pull request 157 (apalos:gen_cpu_fix)
 ** https://github.com/Linaro/odp/pull/157
 ** Patch: https://github.com/Linaro/odp/pull/157.patch
 ** Base sha: 7508c5ac906bb7cb1d339b4c5e924f3a18e504ca
 ** Merge commit sha: 2679354c415eb41ed8f4272740f17284fe165de3
 **/
 example/generator/odp_generator.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Patch

diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c
index f3ec43be..1cddc92c 100644
--- a/example/generator/odp_generator.c
+++ b/example/generator/odp_generator.c
@@ -765,11 +765,12 @@  static int gen_recv_thread(void *arg)
  */
 static void print_global_stats(int num_workers)
 {
-	odp_time_t cur, wait, next;
+	odp_time_t cur, wait, next, left;
 	uint64_t pkts_snd = 0, pkts_snd_prev = 0;
 	uint64_t pps_snd = 0, maximum_pps_snd = 0;
 	uint64_t pkts_rcv = 0, pkts_rcv_prev = 0;
 	uint64_t pps_rcv = 0, maximum_pps_rcv = 0;
+	uint64_t stall;
 	int verbose_interval = 20;
 	odp_thrmask_t thrd_mask;
 
@@ -786,8 +787,15 @@  static void print_global_stats(int num_workers)
 		}
 
 		cur = odp_time_local();
-		if (odp_time_cmp(next, cur) > 0)
+		if (odp_time_cmp(next, cur) > 0) {
+			left = odp_time_diff(next, cur);
+			stall = odp_time_to_ns(left);
+			if (stall / ODP_TIME_SEC_IN_NS)
+				sleep(1);
+			else
+				usleep(stall / ODP_TIME_USEC_IN_NS);
 			continue;
+		}
 
 		next = odp_time_sum(cur, wait);
 		switch (args->appl.mode) {