From faa8215c1778159803d6af9368b922d8ef61aee2 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Date: Thu, 24 Aug 2017 16:24:43 +0300 Subject: throttle: Fix wrong variable name in the header documentation The level of the burst bucket is stored in bkt.burst_level, not bkt.burst_length. Signed-off-by: Alberto Garcia Reviewed-by: Manos Pitsidianakis Message-id: 49aab2711d02f285567f3b3b13a113847af33812.1503580370.git.berto@igalia.com Signed-off-by: Stefan Hajnoczi --- include/qemu/throttle.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h index d056008c18..66a8ac10a4 100644 --- a/include/qemu/throttle.h +++ b/include/qemu/throttle.h @@ -63,7 +63,7 @@ typedef enum { * - The bkt.avg rate does not apply until the bucket is full, * allowing the user to do bursts until then. The I/O limit during * bursts is bkt.max. To enforce this limit we keep an additional - * bucket in bkt.burst_length that leaks at a rate of bkt.max units + * bucket in bkt.burst_level that leaks at a rate of bkt.max units * per second. * * - Because of all of the above, the user can perform I/O at a -- cgit v1.2.3 From d00e6923b1e2c1bec7840b0a0706764493648527 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Date: Thu, 24 Aug 2017 16:24:47 +0300 Subject: throttle: Make LeakyBucket.avg and LeakyBucket.max integer types Both the throttling limits set with the throttling.iops-* and throttling.bps-* options and their QMP equivalents defined in the BlockIOThrottle struct are integer values. Those limits are also reported in the BlockDeviceInfo struct and they are integers there as well. Therefore there's no reason to store them internally as double and do the conversion everytime we're setting or querying them, so this patch uses uint64_t for those types. Let's also use an unsigned type because we don't allow negative values anyway. LeakyBucket.level and LeakyBucket.burst_level do however remain double because their value changes depending on the fraction of time elapsed since the previous I/O operation. Signed-off-by: Alberto Garcia Message-id: f29b840422767b5be2c41c2dfdbbbf6c5f8fedf8.1503580370.git.berto@igalia.com Signed-off-by: Stefan Hajnoczi --- include/qemu/throttle.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') 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 */ -- cgit v1.2.3 From 67335a4558d3cad2173aac0ce13b6c096b077c41 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Date: Thu, 24 Aug 2017 16:24:48 +0300 Subject: throttle: Make burst_length 64bit and add range checks LeakyBucket.burst_length is defined as an unsigned integer but the code never checks for overflows and it only makes sure that the value is not 0. In practice this means that the user can set something like throttling.iops-total-max-length=4294967300 despite being larger than UINT_MAX and the final value after casting to unsigned int will be 4. This patch changes the data type to uint64_t. This does not increase the storage size of LeakyBucket, and allows us to assign the value directly from qemu_opt_get_number() or BlockIOThrottle and then do the checks directly in throttle_is_valid(). The value of burst_length does not have a specific upper limit, but since the bucket size is defined by max * burst_length we have to prevent overflows. Instead of going for UINT64_MAX or something similar this patch reuses THROTTLE_VALUE_MAX, which allows I/O bursts of 1 GiB/s for 10 days in a row. Signed-off-by: Alberto Garcia Message-id: 1b2e3049803f71cafb2e1fa1be4fb47147a0d398.1503580370.git.berto@igalia.com Signed-off-by: Stefan Hajnoczi --- include/qemu/throttle.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h index 6e31155fd4..8e01885d29 100644 --- a/include/qemu/throttle.h +++ b/include/qemu/throttle.h @@ -81,7 +81,7 @@ typedef struct LeakyBucket { 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 */ + uint64_t burst_length; /* max length of the burst period, in seconds */ } LeakyBucket; /* The following structure is used to configure a ThrottleState -- cgit v1.2.3