diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2016-02-22 16:55:41 +0000 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2016-02-22 16:55:41 +0000 |
commit | 8eb779e4223a18db9838a49ece1bc72cfdfb7761 (patch) | |
tree | 8b3bac97d620379d579e02cff3bb845f79ccdda3 /include | |
parent | a02dabe10adc4ae3be54f7413f60dcaa67028389 (diff) | |
parent | fe243e4881bc9e09767dba05f15acb016cfa7a52 (diff) |
Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging
Block layer patches
# gpg: Signature made Mon 22 Feb 2016 15:59:25 GMT using RSA key ID C88F2FD6
# gpg: Good signature from "Kevin Wolf <kwolf@redhat.com>"
* remotes/kevin/tags/for-upstream: (34 commits)
qemu-iotests: 140: make description slightly more verbose
qemu-iotests: 140: don't use IDE device
qemu-iotests: 067: ignore QMP events
blockdev: unset inappropriate flags when changing medium
MAINTAINERS: Add myself as maintainer of the throttling code
docs: Document the throttling infrastructure
qapi: Correct the name of the iops_rd parameter
qemu-iotests: Extend iotest 093 to test bursts
throttle: Test throttle_compute_wait() during bursts
throttle: Check that burst_level leaks correctly
qapi: Add burst length fields to BlockDeviceInfo
qapi: Add burst length parameters to block_set_io_throttle
throttle: Add command-line settings to define the burst periods
throttle: Add support for burst periods
throttle: Use throttle_config_init() to initialize ThrottleConfig
throttle: Merge all functions that check the configuration into one
throttle: Set always an average value when setting a maximum value
throttle: Make throttle_is_valid() set errp
throttle: Make throttle_max_is_missing_limit() set errp
throttle: Make throttle_conflicting() set errp
...
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/qemu/throttle.h | 55 |
1 files changed, 39 insertions, 16 deletions
diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h index d0c98ed25b..63df69070a 100644 --- a/include/qemu/throttle.h +++ b/include/qemu/throttle.h @@ -2,7 +2,7 @@ * QEMU throttling infrastructure * * Copyright (C) Nodalink, EURL. 2013-2014 - * Copyright (C) Igalia, S.L. 2015 + * Copyright (C) Igalia, S.L. 2015-2016 * * Authors: * BenoƮt Canet <benoit.canet@nodalink.com> @@ -42,16 +42,47 @@ typedef enum { } BucketType; /* - * The max parameter of the leaky bucket throttling algorithm can be used to - * allow the guest to do bursts. - * The max value is a pool of I/O that the guest can use without being throttled - * at all. Throttling is triggered once this pool is empty. + * This module implements I/O limits using the leaky bucket + * algorithm. The code is independent of the I/O units, but it is + * currently used for bytes per second and operations per second. + * + * Three parameters can be set by the user: + * + * - avg: the desired I/O limits in units per second. + * - max: the limit during bursts, also in units per second. + * - burst_length: the maximum length of the burst period, in seconds. + * + * Here's how it works: + * + * - The bucket level (number of performed I/O units) is kept in + * bkt.level and leaks at a rate of bkt.avg units per second. + * + * - The size of the bucket is bkt.max * bkt.burst_length. Once the + * bucket is full no more I/O is performed until the bucket leaks + * again. This is what makes the I/O rate bkt.avg. + * + * - 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 + * per second. + * + * - Because of all of the above, the user can perform I/O at a + * maximum of bkt.max units per second for at most bkt.burst_length + * seconds in a row. After that the bucket will be full and the I/O + * rate will go down to bkt.avg. + * + * - Since the bucket always leaks at a rate of bkt.avg, this also + * determines how much the user needs to wait before being able to + * do bursts again. */ typedef struct LeakyBucket { double avg; /* average goal in units per second */ double 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 */ } LeakyBucket; /* The following structure is used to configure a ThrottleState @@ -84,12 +115,6 @@ void throttle_leak_bucket(LeakyBucket *bkt, int64_t delta); int64_t throttle_compute_wait(LeakyBucket *bkt); -/* expose timer computation function for unit tests */ -bool throttle_compute_timer(ThrottleState *ts, - bool is_write, - int64_t now, - int64_t *next_timestamp); - /* init/destroy cycle */ void throttle_init(ThrottleState *ts); @@ -112,11 +137,7 @@ bool throttle_timers_are_initialized(ThrottleTimers *tt); /* configuration */ bool throttle_enabled(ThrottleConfig *cfg); -bool throttle_conflicting(ThrottleConfig *cfg); - -bool throttle_is_valid(ThrottleConfig *cfg); - -bool throttle_max_is_missing_limit(ThrottleConfig *cfg); +bool throttle_is_valid(ThrottleConfig *cfg, Error **errp); void throttle_config(ThrottleState *ts, ThrottleTimers *tt, @@ -124,6 +145,8 @@ void throttle_config(ThrottleState *ts, void throttle_get_config(ThrottleState *ts, ThrottleConfig *cfg); +void throttle_config_init(ThrottleConfig *cfg); + /* usage */ bool throttle_schedule_timer(ThrottleState *ts, ThrottleTimers *tt, |