diff mbox

[v3,5/5] performance: odp_pktio_perf: fix potential overflow for burst_gap

Message ID 1442478691-30098-6-git-send-email-ivan.khoronzhuk@linaro.org
State Accepted
Commit d79849da2e1588f9cdd86460f80da1a50c60bf0d
Headers show

Commit Message

Ivan Khoronzhuk Sept. 17, 2015, 8:31 a.m. UTC
The direct comparing of "cur_cycles" and "next_tx_cycles" is not
valid, as "next_tx_cycles" can be overflowed and comparison will
give wrong result. So use odp_time_diff_cycles() for that, as it
takes into account ticks overflow.

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

Patch

diff --git a/test/performance/odp_pktio_perf.c b/test/performance/odp_pktio_perf.c
index 61ff312..4dfeb6a 100644
--- a/test/performance/odp_pktio_perf.c
+++ b/test/performance/odp_pktio_perf.c
@@ -305,7 +305,7 @@  static void *run_thread_tx(void *arg)
 	int thr_id;
 	odp_queue_t outq;
 	pkt_tx_stats_t *stats;
-	uint64_t next_tx_cycles, start_cycles, cur_cycles, send_duration;
+	uint64_t burst_start_cycles, start_cycles, cur_cycles, send_duration;
 	uint64_t burst_gap_cycles;
 	uint32_t batch_len;
 	int unsent_pkts = 0;
@@ -336,11 +336,12 @@  static void *run_thread_tx(void *arg)
 
 	cur_cycles     = odp_time_cycles();
 	start_cycles   = cur_cycles;
-	next_tx_cycles = cur_cycles;
+	burst_start_cycles = odp_time_diff_cycles(burst_gap_cycles, cur_cycles);
 	while (odp_time_diff_cycles(start_cycles, cur_cycles) < send_duration) {
 		unsigned alloc_cnt = 0, tx_cnt;
 
-		if (cur_cycles < next_tx_cycles) {
+		if (odp_time_diff_cycles(burst_start_cycles, cur_cycles)
+							< burst_gap_cycles) {
 			cur_cycles = odp_time_cycles();
 			if (idle_start == 0)
 				idle_start = cur_cycles;
@@ -353,7 +354,7 @@  static void *run_thread_tx(void *arg)
 			idle_start = 0;
 		}
 
-		next_tx_cycles += burst_gap_cycles;
+		burst_start_cycles += burst_gap_cycles;
 
 		alloc_cnt = alloc_packets(tx_event, batch_len - unsent_pkts);
 		if (alloc_cnt != batch_len)