qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v2 1/3] throttle: Make NANOSECONDS_PER_SECOND an


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH v2 1/3] throttle: Make NANOSECONDS_PER_SECOND an integer
Date: Mon, 08 Sep 2014 08:46:05 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.7.0

On 09/08/2014 06:18 AM, Benoît Canet wrote:
> We will want to reuse this define in the future by making it common to 
> multiples

s/multiples/multiple/

> QEMU modules.
> It would be safer that this define be an integer so we avoid stranges float

s/stranges/strange/

> rounding errors.
> Do this conversion.
> 
> Signed-off-by: Benoît Canet <address@hidden>
> ---
>  include/qemu/throttle.h | 2 +-
>  util/throttle.c         | 4 ++--
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h
> index b890613..8f9e611 100644
> --- a/include/qemu/throttle.h
> +++ b/include/qemu/throttle.h
> @@ -27,7 +27,7 @@
>  #include "qemu-common.h"
>  #include "qemu/timer.h"
>  
> -#define NANOSECONDS_PER_SECOND  1000000000.0
> +#define NANOSECONDS_PER_SECOND  1000000000

This hunk is good.

>  
>  typedef enum {
>      THROTTLE_BPS_TOTAL,
> diff --git a/util/throttle.c b/util/throttle.c
> index f976ac7..af8445a 100644
> --- a/util/throttle.c
> +++ b/util/throttle.c
> @@ -34,7 +34,7 @@ void throttle_leak_bucket(LeakyBucket *bkt, int64_t 
> delta_ns)
>      double leak;
>  
>      /* compute how much to leak */
> -    leak = (bkt->avg * (double) delta_ns) / NANOSECONDS_PER_SECOND;
> +    leak = (bkt->avg * (double) delta_ns) / (double) NANOSECONDS_PER_SECOND;

This hunk is spurious.  With just your first hunk, it evaluates to the
following types via promotion rules:

(double * double) / int
double / int
double / double
double

so the explicit cast isn't changing anything.

>  
>      /* make the bucket leak */
>      bkt->level = MAX(bkt->level - leak, 0);
> @@ -70,7 +70,7 @@ static void throttle_do_leak(ThrottleState *ts, int64_t now)
>   */
>  static int64_t throttle_do_compute_wait(double limit, double extra)
>  {
> -    double wait = extra * NANOSECONDS_PER_SECOND;
> +    double wait = extra * (double) NANOSECONDS_PER_SECOND;

This hunk is also spurious.  Again, with just your first hunk, it
evaluates through the following promotion rules:

double * int
double * double
double

and the cast isn't changing anything.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]