diff mbox

[API-NEXT,v6,1/6] performance: odp_pktio_perf: fix potential overflow in wait loop

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

Commit Message

Ivan Khoronzhuk Nov. 5, 2015, 11:04 a.m. UTC
There cannot be used direct comparison of timestamps of counter
that can overflow, better to compare ranges.

Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
---
 test/performance/odp_pktio_perf.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/test/performance/odp_pktio_perf.c b/test/performance/odp_pktio_perf.c
index efd26dc..ae5b4c0 100644
--- a/test/performance/odp_pktio_perf.c
+++ b/test/performance/odp_pktio_perf.c
@@ -591,9 +591,13 @@  static int setup_txrx_masks(odp_cpumask_t *thd_mask_tx,
  */
 static void busy_loop_ns(uint64_t wait_ns)
 {
-	uint64_t end = odp_time_cycles() + odp_time_ns_to_cycles(wait_ns);
-	while (odp_time_cycles() < end)
-		;
+	uint64_t diff;
+	uint64_t start_time = odp_time_cycles();
+	uint64_t wait = odp_time_ns_to_cycles(wait_ns);
+
+	do {
+		diff = odp_time_diff_cycles(start_time, odp_time_cycles());
+	} while (diff < wait);
 }
 
 /*