diff mbox

[API-NEXT,v6,2/6] example: generator: compare ticks instead of ns in loop

Message ID 1446721478-30656-3-git-send-email-ivan.khoronzhuk@linaro.org
State Superseded
Headers show

Commit Message

Ivan Khoronzhuk Nov. 5, 2015, 11:04 a.m. UTC
It's more accurate to compare ticks instead of ns in each
iteration, so calculate wait range before entering the loop.

Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
---
 example/generator/odp_generator.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
diff mbox

Patch

diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c
index 60e015b..dd30403 100644
--- a/example/generator/odp_generator.c
+++ b/example/generator/odp_generator.c
@@ -586,7 +586,7 @@  static void *gen_recv_thread(void *arg)
  */
 static void print_global_stats(int num_workers)
 {
-	uint64_t start, now, diff;
+	uint64_t start, wait, diff;
 	uint64_t pkts, pkts_prev = 0, pps, maximum_pps = 0;
 	int verbose_interval = 20;
 	odp_thrmask_t thrd_mask;
@@ -594,6 +594,7 @@  static void print_global_stats(int num_workers)
 	while (odp_thrmask_worker(&thrd_mask) < num_workers)
 		continue;
 
+	wait = odp_time_ns_to_cycles(verbose_interval * ODP_TIME_SEC);
 	start = odp_time_cycles();
 
 	while (odp_thrmask_worker(&thrd_mask) == num_workers) {
@@ -603,12 +604,9 @@  static void print_global_stats(int num_workers)
 			break;
 		}
 
-		now = odp_time_cycles();
-		diff = odp_time_diff_cycles(start, now);
-		if (odp_time_cycles_to_ns(diff) <
-		    verbose_interval * ODP_TIME_SEC) {
+		diff = odp_time_diff_cycles(start, odp_time_cycles());
+		if (diff < wait)
 			continue;
-		}
 
 		start = odp_time_cycles();