diff mbox

Time should be cast to double when calculate rtt

Message ID 1408957576-28208-1-git-send-email-weilong.chen@linaro.org
State New
Headers show

Commit Message

Weilong Chen Aug. 25, 2014, 9:06 a.m. UTC
This patch fix two point:
1.Time should be cast to double when calculate rtt.
2.Don't display receive message in flood mode.

Signed-off-by: Weilong Chen <weilong.chen@linaro.org>
---
 example/generator/odp_generator.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Ola Liljedahl Aug. 25, 2014, 9:13 a.m. UTC | #1
Or perhaps use 64-bit (integer) arithmetic (e.g. uint64_t) to avoid using
floating point?



On 25 August 2014 11:06, Weilong Chen <weilong.chen@linaro.org> wrote:

> This patch fix two point:
> 1.Time should be cast to double when calculate rtt.
> 2.Don't display receive message in flood mode.
>
> Signed-off-by: Weilong Chen <weilong.chen@linaro.org>
> ---
>  example/generator/odp_generator.c |    8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/example/generator/odp_generator.c
> b/example/generator/odp_generator.c
> index 9fa9b37..c141bc5 100644
> --- a/example/generator/odp_generator.c
> +++ b/example/generator/odp_generator.c
> @@ -427,9 +427,10 @@ static void print_pkts(int thr, odp_packet_t
> pkt_tbl[], unsigned len)
>                                  * ODP timer API once one exists. */
>                                 gettimeofday(&tvrecv, NULL);
>                                 tv_sub(&tvrecv, &tvsend);
> -                               rtt = tvrecv.tv_sec*1000 +
> tvrecv.tv_usec/1000;
> +                               rtt = tvrecv.tv_sec*1000 +
> +                                     (double)tvrecv.tv_usec/1000;
>                                 rlen += sprintf(msg + rlen,
> -                                       "ICMP Echo Reply seq %d time %.1f
> ",
> +                                       "ICMP Echo Reply seq %d time %.3f
> ms",
>
> odp_be_to_cpu_16(icmp->un.echo.sequence)
>                                         , rtt);
>                         } else if (icmp->type == ICMP_ECHO) {
> @@ -439,7 +440,8 @@ static void print_pkts(int thr, odp_packet_t
> pkt_tbl[], unsigned len)
>                 }
>
>                 msg[rlen] = '\0';
> -               printf("  [%02i] %s\n", thr, msg);
> +               if (args->appl.interval != 0)
> +                       printf("  [%02i] %s\n", thr, msg);
>         }
>  }
>
> --
> 1.7.9.5
>
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> http://lists.linaro.org/mailman/listinfo/lng-odp
>
Bill Fischofer Aug. 25, 2014, 11:49 a.m. UTC | #2
Agreed.  In general you want to avoid the use of floating point in the data
plane if possible.


On Mon, Aug 25, 2014 at 4:13 AM, Ola Liljedahl <ola.liljedahl@linaro.org>
wrote:

> Or perhaps use 64-bit (integer) arithmetic (e.g. uint64_t) to avoid using
> floating point?
>
>
>
> On 25 August 2014 11:06, Weilong Chen <weilong.chen@linaro.org> wrote:
>
>> This patch fix two point:
>> 1.Time should be cast to double when calculate rtt.
>> 2.Don't display receive message in flood mode.
>>
>> Signed-off-by: Weilong Chen <weilong.chen@linaro.org>
>> ---
>>  example/generator/odp_generator.c |    8 +++++---
>>  1 file changed, 5 insertions(+), 3 deletions(-)
>>
>> diff --git a/example/generator/odp_generator.c
>> b/example/generator/odp_generator.c
>> index 9fa9b37..c141bc5 100644
>> --- a/example/generator/odp_generator.c
>> +++ b/example/generator/odp_generator.c
>> @@ -427,9 +427,10 @@ static void print_pkts(int thr, odp_packet_t
>> pkt_tbl[], unsigned len)
>>                                  * ODP timer API once one exists. */
>>                                 gettimeofday(&tvrecv, NULL);
>>                                 tv_sub(&tvrecv, &tvsend);
>> -                               rtt = tvrecv.tv_sec*1000 +
>> tvrecv.tv_usec/1000;
>> +                               rtt = tvrecv.tv_sec*1000 +
>> +                                     (double)tvrecv.tv_usec/1000;
>>                                 rlen += sprintf(msg + rlen,
>> -                                       "ICMP Echo Reply seq %d time %.1f
>> ",
>> +                                       "ICMP Echo Reply seq %d time %.3f
>> ms",
>>
>> odp_be_to_cpu_16(icmp->un.echo.sequence)
>>                                         , rtt);
>>                         } else if (icmp->type == ICMP_ECHO) {
>> @@ -439,7 +440,8 @@ static void print_pkts(int thr, odp_packet_t
>> pkt_tbl[], unsigned len)
>>                 }
>>
>>                 msg[rlen] = '\0';
>> -               printf("  [%02i] %s\n", thr, msg);
>> +               if (args->appl.interval != 0)
>> +                       printf("  [%02i] %s\n", thr, msg);
>>         }
>>  }
>>
>> --
>> 1.7.9.5
>>
>>
>> _______________________________________________
>> lng-odp mailing list
>> lng-odp@lists.linaro.org
>> http://lists.linaro.org/mailman/listinfo/lng-odp
>>
>
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> http://lists.linaro.org/mailman/listinfo/lng-odp
>
>
Weilong Chen Aug. 26, 2014, 7:27 a.m. UTC | #3
Thanks for review.
I'll send v2.


On 25 August 2014 19:49, Bill Fischofer <bill.fischofer@linaro.org> wrote:

> Agreed.  In general you want to avoid the use of floating point in the
> data plane if possible.
>
>
> On Mon, Aug 25, 2014 at 4:13 AM, Ola Liljedahl <ola.liljedahl@linaro.org>
> wrote:
>
>> Or perhaps use 64-bit (integer) arithmetic (e.g. uint64_t) to avoid using
>> floating point?
>>
>>
>>
>> On 25 August 2014 11:06, Weilong Chen <weilong.chen@linaro.org> wrote:
>>
>>> This patch fix two point:
>>> 1.Time should be cast to double when calculate rtt.
>>> 2.Don't display receive message in flood mode.
>>>
>>> Signed-off-by: Weilong Chen <weilong.chen@linaro.org>
>>> ---
>>>  example/generator/odp_generator.c |    8 +++++---
>>>  1 file changed, 5 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/example/generator/odp_generator.c
>>> b/example/generator/odp_generator.c
>>> index 9fa9b37..c141bc5 100644
>>> --- a/example/generator/odp_generator.c
>>> +++ b/example/generator/odp_generator.c
>>> @@ -427,9 +427,10 @@ static void print_pkts(int thr, odp_packet_t
>>> pkt_tbl[], unsigned len)
>>>                                  * ODP timer API once one exists. */
>>>                                 gettimeofday(&tvrecv, NULL);
>>>                                 tv_sub(&tvrecv, &tvsend);
>>> -                               rtt = tvrecv.tv_sec*1000 +
>>> tvrecv.tv_usec/1000;
>>> +                               rtt = tvrecv.tv_sec*1000 +
>>> +                                     (double)tvrecv.tv_usec/1000;
>>>                                 rlen += sprintf(msg + rlen,
>>> -                                       "ICMP Echo Reply seq %d time
>>> %.1f ",
>>> +                                       "ICMP Echo Reply seq %d time
>>> %.3f ms",
>>>
>>> odp_be_to_cpu_16(icmp->un.echo.sequence)
>>>                                         , rtt);
>>>                         } else if (icmp->type == ICMP_ECHO) {
>>> @@ -439,7 +440,8 @@ static void print_pkts(int thr, odp_packet_t
>>> pkt_tbl[], unsigned len)
>>>                 }
>>>
>>>                 msg[rlen] = '\0';
>>> -               printf("  [%02i] %s\n", thr, msg);
>>> +               if (args->appl.interval != 0)
>>> +                       printf("  [%02i] %s\n", thr, msg);
>>>         }
>>>  }
>>>
>>> --
>>> 1.7.9.5
>>>
>>>
>>> _______________________________________________
>>> lng-odp mailing list
>>> lng-odp@lists.linaro.org
>>> http://lists.linaro.org/mailman/listinfo/lng-odp
>>>
>>
>>
>> _______________________________________________
>> lng-odp mailing list
>> lng-odp@lists.linaro.org
>> http://lists.linaro.org/mailman/listinfo/lng-odp
>>
>>
>
diff mbox

Patch

diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c
index 9fa9b37..c141bc5 100644
--- a/example/generator/odp_generator.c
+++ b/example/generator/odp_generator.c
@@ -427,9 +427,10 @@  static void print_pkts(int thr, odp_packet_t pkt_tbl[], unsigned len)
 				 * ODP timer API once one exists. */
 				gettimeofday(&tvrecv, NULL);
 				tv_sub(&tvrecv, &tvsend);
-				rtt = tvrecv.tv_sec*1000 + tvrecv.tv_usec/1000;
+				rtt = tvrecv.tv_sec*1000 +
+				      (double)tvrecv.tv_usec/1000;
 				rlen += sprintf(msg + rlen,
-					"ICMP Echo Reply seq %d time %.1f ",
+					"ICMP Echo Reply seq %d time %.3f ms",
 					odp_be_to_cpu_16(icmp->un.echo.sequence)
 					, rtt);
 			} else if (icmp->type == ICMP_ECHO) {
@@ -439,7 +440,8 @@  static void print_pkts(int thr, odp_packet_t pkt_tbl[], unsigned len)
 		}
 
 		msg[rlen] = '\0';
-		printf("  [%02i] %s\n", thr, msg);
+		if (args->appl.interval != 0)
+			printf("  [%02i] %s\n", thr, msg);
 	}
 }