[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 1/3] throttle: Make NANOSECONDS_PER_SECOND an int
From: |
Benoît Canet |
Subject: |
[Qemu-devel] [PATCH v2 1/3] throttle: Make NANOSECONDS_PER_SECOND an integer |
Date: |
Mon, 8 Sep 2014 14:18:11 +0200 |
We will want to reuse this define in the future by making it common to multiples
QEMU modules.
It would be safer that this define be an integer so we avoid stranges float
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
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;
/* 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;
wait /= limit;
return wait;
}
--
2.1.0
- Re: [Qemu-devel] [PATCH v2 2/3] timers: Move NANOSECONDS_PER_SECONDS to timer.h for future reuse, (continued)
- [Qemu-devel] [PATCH v2 3/3] util: Add an utility infrastructure used to compute an average on a time slice, Benoît Canet, 2014/09/08
- Re: [Qemu-devel] [PATCH v2 3/3] util: Add an utility infrastructure used to compute an average on a time slice, Paolo Bonzini, 2014/09/08
- Re: [Qemu-devel] [PATCH v2 3/3] util: Add an utility infrastructure used to compute an average on a time slice, Benoît Canet, 2014/09/08
- Re: [Qemu-devel] [PATCH v2 3/3] util: Add an utility infrastructure used to compute an average on a time slice, Paolo Bonzini, 2014/09/08
- Re: [Qemu-devel] [PATCH v2 3/3] util: Add an utility infrastructure used to compute an average on a time slice, Benoît Canet, 2014/09/08
- Re: [Qemu-devel] [PATCH v2 3/3] util: Add an utility infrastructure used to compute an average on a time slice, Markus Armbruster, 2014/09/15
- Re: [Qemu-devel] [PATCH v2 3/3] util: Add an utility infrastructure used to compute an average on a time slice, Benoît Canet, 2014/09/15
- Re: [Qemu-devel] [PATCH v2 3/3] util: Add an utility infrastructure used to compute an average on a time slice, Benoît Canet, 2014/09/15
Re: [Qemu-devel] [PATCH v2 3/3] util: Add an utility infrastructure used to compute an average on a time slice, Markus Armbruster, 2014/09/15
[Qemu-devel] [PATCH v2 1/3] throttle: Make NANOSECONDS_PER_SECOND an integer,
Benoît Canet <=