diff mbox

[API-NEXT,v7,9/9] test/example: use local time API as wall time

Message ID 1449251494-23210-10-git-send-email-ivan.khoronzhuk@linaro.org
State Accepted
Commit 5aa71441a799d68aee62c3ad71e728bbd172869a
Headers show

Commit Message

Ivan Khoronzhuk Dec. 4, 2015, 5:51 p.m. UTC
The local time API is supposed to behave like wall time now,
so correct it in examples and tests.

Reviewed-by: Petri Savolainen <petri.savolainen@nokia.com>
Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
---
 example/generator/odp_generator.c | 10 +++++-----
 test/performance/odp_pktio_perf.c | 27 ++++++++++++---------------
 test/validation/pktio/pktio.c     | 21 ++++++++-------------
 3 files changed, 25 insertions(+), 33 deletions(-)
diff mbox

Patch

diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c
index 9d79f89..2de530d 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)
 {
-	odp_time_t start, wait, diff;
+	odp_time_t cur, wait, next;
 	uint64_t pkts, pkts_prev = 0, pps, maximum_pps = 0;
 	int verbose_interval = 20;
 	odp_thrmask_t thrd_mask;
@@ -595,7 +595,7 @@  static void print_global_stats(int num_workers)
 		continue;
 
 	wait = odp_time_local_from_ns(verbose_interval * ODP_TIME_SEC_IN_NS);
-	start = odp_time_local();
+	next = odp_time_sum(odp_time_local(), wait);
 
 	while (odp_thrmask_worker(&thrd_mask) == num_workers) {
 		if (args->appl.number != -1 &&
@@ -604,11 +604,11 @@  static void print_global_stats(int num_workers)
 			break;
 		}
 
-		diff = odp_time_diff(odp_time_local(), start);
-		if (odp_time_cmp(wait, diff) > 0)
+		cur = odp_time_local();
+		if (odp_time_cmp(next, cur) > 0)
 			continue;
 
-		start = odp_time_local();
+		next = odp_time_sum(cur, wait);
 
 		if (args->appl.mode == APPL_MODE_RCV) {
 			pkts = odp_atomic_load_u64(&counters.udp);
diff --git a/test/performance/odp_pktio_perf.c b/test/performance/odp_pktio_perf.c
index ec67d55..8737bc8 100644
--- a/test/performance/odp_pktio_perf.c
+++ b/test/performance/odp_pktio_perf.c
@@ -305,8 +305,8 @@  static void *run_thread_tx(void *arg)
 	int thr_id;
 	odp_queue_t outq;
 	pkt_tx_stats_t *stats;
-	odp_time_t start_time, cur_time, send_duration;
-	odp_time_t burst_start_time, burst_gap;
+	odp_time_t cur_time, send_time_end, send_duration;
+	odp_time_t burst_gap_end, burst_gap;
 	uint32_t batch_len;
 	int unsent_pkts = 0;
 	odp_event_t  tx_event[BATCH_LEN_MAX];
@@ -336,22 +336,19 @@  static void *run_thread_tx(void *arg)
 	odp_barrier_wait(&globals->tx_barrier);
 
 	cur_time     = odp_time_local();
-	start_time   = cur_time;
-	burst_start_time = odp_time_diff(cur_time, burst_gap);
-	while (odp_time_cmp(send_duration,
-			    odp_time_diff(cur_time, start_time)) > 0) {
+	send_time_end = odp_time_sum(cur_time, send_duration);
+	burst_gap_end = cur_time;
+	while (odp_time_cmp(send_time_end, cur_time) > 0) {
 		unsigned alloc_cnt = 0, tx_cnt;
 
-		if (odp_time_cmp(burst_gap,
-				 odp_time_diff(cur_time, burst_start_time))
-				 > 0) {
+		if (odp_time_cmp(burst_gap_end, cur_time) > 0) {
 			cur_time = odp_time_local();
 			if (!odp_time_cmp(idle_start, ODP_TIME_NULL))
 				idle_start = cur_time;
 			continue;
 		}
 
-		if (odp_time_cmp(idle_start, ODP_TIME_NULL)) {
+		if (odp_time_cmp(idle_start, ODP_TIME_NULL) > 0) {
 			odp_time_t diff = odp_time_diff(cur_time, idle_start);
 
 			stats->s.idle_ticks =
@@ -360,7 +357,7 @@  static void *run_thread_tx(void *arg)
 			idle_start = ODP_TIME_NULL;
 		}
 
-		burst_start_time = odp_time_sum(burst_start_time, burst_gap);
+		burst_gap_end = odp_time_sum(burst_gap_end, burst_gap);
 
 		alloc_cnt = alloc_packets(tx_event, batch_len - unsent_pkts);
 		if (alloc_cnt != batch_len)
@@ -598,13 +595,13 @@  static int setup_txrx_masks(odp_cpumask_t *thd_mask_tx,
  */
 static void busy_loop_ns(uint64_t wait_ns)
 {
-	odp_time_t diff;
-	odp_time_t start_time = odp_time_local();
 	odp_time_t wait = odp_time_local_from_ns(wait_ns);
+	odp_time_t cur = odp_time_local();
+	odp_time_t end_time = odp_time_sum(cur, wait);
 
 	do {
-		diff = odp_time_diff(odp_time_local(), start_time);
-	} while (odp_time_cmp(wait, diff) > 0);
+		cur = odp_time_local();
+	} while (odp_time_cmp(end_time, cur) > 0);
 }
 
 /*
diff --git a/test/validation/pktio/pktio.c b/test/validation/pktio/pktio.c
index 0a6592c..002c26b 100644
--- a/test/validation/pktio/pktio.c
+++ b/test/validation/pktio/pktio.c
@@ -336,18 +336,16 @@  static int destroy_inq(odp_pktio_t pktio)
 
 static odp_event_t queue_deq_wait_time(odp_queue_t queue, uint64_t ns)
 {
-	odp_time_t start, now, diff;
+	odp_time_t wait, end;
 	odp_event_t ev;
 
-	start = odp_time_local();
-
+	wait = odp_time_local_from_ns(ns);
+	end = odp_time_sum(odp_time_local(), wait);
 	do {
 		ev = odp_queue_deq(queue);
 		if (ev != ODP_EVENT_INVALID)
 			return ev;
-		now = odp_time_local();
-		diff = odp_time_diff(now, start);
-	} while (odp_time_to_ns(diff) < ns);
+	} while (odp_time_cmp(end, odp_time_local()) > 0);
 
 	return ODP_EVENT_INVALID;
 }
@@ -355,14 +353,14 @@  static odp_event_t queue_deq_wait_time(odp_queue_t queue, uint64_t ns)
 static odp_packet_t wait_for_packet(pktio_info_t *pktio_rx,
 				    uint32_t seq, uint64_t ns)
 {
-	odp_time_t start, now, diff;
+	odp_time_t wait_time, end;
 	odp_event_t ev;
 	odp_packet_t pkt;
 	uint64_t wait;
 
-	start = odp_time_local();
 	wait = odp_schedule_wait_time(ns);
-
+	wait_time = odp_time_local_from_ns(ns);
+	end = odp_time_sum(odp_time_local(), wait_time);
 	do {
 		pkt = ODP_PACKET_INVALID;
 
@@ -388,10 +386,7 @@  static odp_packet_t wait_for_packet(pktio_info_t *pktio_rx,
 
 			odp_packet_free(pkt);
 		}
-
-		now = odp_time_local();
-		diff = odp_time_diff(now, start);
-	} while (odp_time_to_ns(diff) < ns);
+	} while (odp_time_cmp(end, odp_time_local()) > 0);
 
 	CU_FAIL("failed to receive transmitted packet");