aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/qemu/throttle.h4
-rw-r--r--tests/test-throttle.c3
-rw-r--r--util/throttle.c7
3 files changed, 7 insertions, 7 deletions
diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h
index 66a8ac10a4..6e31155fd4 100644
--- a/include/qemu/throttle.h
+++ b/include/qemu/throttle.h
@@ -77,8 +77,8 @@ typedef enum {
*/
typedef struct LeakyBucket {
- double avg; /* average goal in units per second */
- double max; /* leaky bucket max burst in units */
+ uint64_t avg; /* average goal in units per second */
+ uint64_t max; /* leaky bucket max burst in units */
double level; /* bucket level in units */
double burst_level; /* bucket level in units (for computing bursts) */
unsigned burst_length; /* max length of the burst period, in seconds */
diff --git a/tests/test-throttle.c b/tests/test-throttle.c
index 768f11dfed..41c0dd2529 100644
--- a/tests/test-throttle.c
+++ b/tests/test-throttle.c
@@ -284,13 +284,14 @@ static void test_enabled(void)
for (i = 0; i < BUCKETS_COUNT; i++) {
throttle_config_init(&cfg);
set_cfg_value(false, i, 150);
+ g_assert(throttle_is_valid(&cfg, NULL));
g_assert(throttle_enabled(&cfg));
}
for (i = 0; i < BUCKETS_COUNT; i++) {
throttle_config_init(&cfg);
set_cfg_value(false, i, -150);
- g_assert(!throttle_enabled(&cfg));
+ g_assert(!throttle_is_valid(&cfg, NULL));
}
}
diff --git a/util/throttle.c b/util/throttle.c
index 4e80a7ea54..80660ffd2c 100644
--- a/util/throttle.c
+++ b/util/throttle.c
@@ -106,13 +106,13 @@ int64_t throttle_compute_wait(LeakyBucket *bkt)
/* If bkt->max is 0 we still want to allow short bursts of I/O
* from the guest, otherwise every other request will be throttled
* and performance will suffer considerably. */
- bucket_size = bkt->avg / 10;
+ bucket_size = (double) bkt->avg / 10;
burst_bucket_size = 0;
} else {
/* If we have a burst limit then we have to wait until all I/O
* at burst rate has finished before throttling to bkt->avg */
bucket_size = bkt->max * bkt->burst_length;
- burst_bucket_size = bkt->max / 10;
+ burst_bucket_size = (double) bkt->max / 10;
}
/* If the main bucket is full then we have to wait */
@@ -338,8 +338,7 @@ bool throttle_is_valid(ThrottleConfig *cfg, Error **errp)
for (i = 0; i < BUCKETS_COUNT; i++) {
LeakyBucket *bkt = &cfg->buckets[i];
- if (bkt->avg < 0 || bkt->max < 0 ||
- bkt->avg > THROTTLE_VALUE_MAX || bkt->max > THROTTLE_VALUE_MAX) {
+ if (bkt->avg > THROTTLE_VALUE_MAX || bkt->max > THROTTLE_VALUE_MAX) {
error_setg(errp, "bps/iops/max values must be within [0, %lld]",
THROTTLE_VALUE_MAX);
return false;