diff mbox

[v2,4/5] performance: odp_pktio_perf: fix potential overflow for send_duration

Message ID 1441965889-15727-5-git-send-email-ivan.khoronzhuk@linaro.org
State Superseded
Headers show

Commit Message

Ivan Khoronzhuk Sept. 11, 2015, 10:04 a.m. UTC
The direct comparing of "cur_cycles" and "end_cycles" is not valid,
as "end_cycles" can be overflowed and comparison will give wrong
result. So use odp_time_diff_cycles() for that, as it takes in
account cycles overflow.

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

Comments

Ivan Khoronzhuk Sept. 15, 2015, 2:56 p.m. UTC | #1
Stuart,

Could you please review this patch.
It uses start_cycles as it was proposed.

On 11.09.15 13:04, Ivan Khoronzhuk wrote:
> The direct comparing of "cur_cycles" and "end_cycles" is not valid,
> as "end_cycles" can be overflowed and comparison will give wrong
> result. So use odp_time_diff_cycles() for that, as it takes in
> account cycles overflow.
>
> Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
> ---
>   test/performance/odp_pktio_perf.c | 9 ++++-----
>   1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/test/performance/odp_pktio_perf.c b/test/performance/odp_pktio_perf.c
> index 709becf..ac32b15 100644
> --- a/test/performance/odp_pktio_perf.c
> +++ b/test/performance/odp_pktio_perf.c
> @@ -303,7 +303,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, end_cycles, cur_cycles;
> +	uint64_t next_tx_cycles, start_cycles, cur_cycles, send_duration;
>   	uint64_t burst_gap_cycles;
>   	uint32_t batch_len;
>   	int unsent_pkts = 0;
> @@ -328,15 +328,14 @@ static void *run_thread_tx(void *arg)
>
>   	burst_gap_cycles = odp_time_ns_to_cycles(
>   				ODP_TIME_SEC / (targs->pps / targs->batch_len));
> +	send_duration = odp_time_ns_to_cycles(targs->duration * ODP_TIME_SEC);
>
>   	odp_barrier_wait(&globals->tx_barrier);
>
>   	cur_cycles     = odp_time_cycles();
> +	start_cycles   = cur_cycles;
>   	next_tx_cycles = cur_cycles;
> -	end_cycles     = cur_cycles +
> -			 odp_time_ns_to_cycles(targs->duration * ODP_TIME_SEC);
> -
> -	while (cur_cycles < end_cycles) {
> +	while (odp_time_diff_cycles(start_cycles, cur_cycles) < send_duration) {
>   		unsigned alloc_cnt = 0, tx_cnt;
>
>   		if (cur_cycles < next_tx_cycles) {
>
Stuart Haslam Sept. 15, 2015, 5:30 p.m. UTC | #2
On Fri, Sep 11, 2015 at 01:04:48PM +0300, Ivan Khoronzhuk wrote:
> The direct comparing of "cur_cycles" and "end_cycles" is not valid,
> as "end_cycles" can be overflowed and comparison will give wrong
> result. So use odp_time_diff_cycles() for that, as it takes in
> account cycles overflow.
> 
> Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>

Reviewed-by: Stuart Haslam <stuart.haslam@linaro.org>

> ---
>  test/performance/odp_pktio_perf.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/test/performance/odp_pktio_perf.c b/test/performance/odp_pktio_perf.c
> index 709becf..ac32b15 100644
> --- a/test/performance/odp_pktio_perf.c
> +++ b/test/performance/odp_pktio_perf.c
> @@ -303,7 +303,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, end_cycles, cur_cycles;
> +	uint64_t next_tx_cycles, start_cycles, cur_cycles, send_duration;
>  	uint64_t burst_gap_cycles;
>  	uint32_t batch_len;
>  	int unsent_pkts = 0;
> @@ -328,15 +328,14 @@ static void *run_thread_tx(void *arg)
>  
>  	burst_gap_cycles = odp_time_ns_to_cycles(
>  				ODP_TIME_SEC / (targs->pps / targs->batch_len));
> +	send_duration = odp_time_ns_to_cycles(targs->duration * ODP_TIME_SEC);
>  
>  	odp_barrier_wait(&globals->tx_barrier);
>  
>  	cur_cycles     = odp_time_cycles();
> +	start_cycles   = cur_cycles;
>  	next_tx_cycles = cur_cycles;
> -	end_cycles     = cur_cycles +
> -			 odp_time_ns_to_cycles(targs->duration * ODP_TIME_SEC);
> -
> -	while (cur_cycles < end_cycles) {
> +	while (odp_time_diff_cycles(start_cycles, cur_cycles) < send_duration) {
>  		unsigned alloc_cnt = 0, tx_cnt;
>  
>  		if (cur_cycles < next_tx_cycles) {
> -- 
> 1.9.1
> 
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> https://lists.linaro.org/mailman/listinfo/lng-odp
diff mbox

Patch

diff --git a/test/performance/odp_pktio_perf.c b/test/performance/odp_pktio_perf.c
index 709becf..ac32b15 100644
--- a/test/performance/odp_pktio_perf.c
+++ b/test/performance/odp_pktio_perf.c
@@ -303,7 +303,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, end_cycles, cur_cycles;
+	uint64_t next_tx_cycles, start_cycles, cur_cycles, send_duration;
 	uint64_t burst_gap_cycles;
 	uint32_t batch_len;
 	int unsent_pkts = 0;
@@ -328,15 +328,14 @@  static void *run_thread_tx(void *arg)
 
 	burst_gap_cycles = odp_time_ns_to_cycles(
 				ODP_TIME_SEC / (targs->pps / targs->batch_len));
+	send_duration = odp_time_ns_to_cycles(targs->duration * ODP_TIME_SEC);
 
 	odp_barrier_wait(&globals->tx_barrier);
 
 	cur_cycles     = odp_time_cycles();
+	start_cycles   = cur_cycles;
 	next_tx_cycles = cur_cycles;
-	end_cycles     = cur_cycles +
-			 odp_time_ns_to_cycles(targs->duration * ODP_TIME_SEC);
-
-	while (cur_cycles < end_cycles) {
+	while (odp_time_diff_cycles(start_cycles, cur_cycles) < send_duration) {
 		unsigned alloc_cnt = 0, tx_cnt;
 
 		if (cur_cycles < next_tx_cycles) {