diff options
author | Stefan Hajnoczi <stefanha@redhat.com> | 2017-03-01 11:50:26 +0000 |
---|---|---|
committer | Stefan Hajnoczi <stefanha@redhat.com> | 2017-04-21 10:36:12 +0100 |
commit | d72915c60bff51495529449750e051d01b03c62f (patch) | |
tree | c88c623920e0b81b24afd435adad57c4e65c39d2 /util/throttle.c | |
parent | ab08aec45f67a776ea37cee0bf94a34abb84ad97 (diff) | |
download | qemu-d72915c60bff51495529449750e051d01b03c62f.zip qemu-d72915c60bff51495529449750e051d01b03c62f.tar.gz qemu-d72915c60bff51495529449750e051d01b03c62f.tar.bz2 |
throttle: make throttle_config(throttle_get_config()) symmetric
Throttling has a weird property that throttle_get_config() does not
always return the same throttling settings that were given with
throttle_config(). In other words, the set and get functions aren't
symmetric.
If .max is 0 then the throttling code assigns a default value of .avg /
10 in throttle_config(). This is an implementation detail of the
throttling algorithm. When throttle_get_config() is called the .max
value returned should still be 0.
Users are exposed to this quirk via "info block" or "query-block"
monitor commands. This has caused confusion because it looks like a bug
when an unexpected value is reported.
This patch hides the .max value adjustment in throttle_get_config() and
updates test-throttle.c appropriately.
Reported-by: Nini Gu <ngu@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Alberto Garcia <berto@igalia.com>
Message-id: 20170301115026.22621-4-stefanha@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'util/throttle.c')
-rw-r--r-- | util/throttle.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/util/throttle.c b/util/throttle.c index 3817d9b..3570ed2 100644 --- a/util/throttle.c +++ b/util/throttle.c @@ -380,6 +380,14 @@ static void throttle_fix_bucket(LeakyBucket *bkt) } } +/* undo internal bucket parameter changes (see throttle_fix_bucket()) */ +static void throttle_unfix_bucket(LeakyBucket *bkt) +{ + if (bkt->max < bkt->avg) { + bkt->max = 0; + } +} + /* take care of canceling a timer */ static void throttle_cancel_timer(QEMUTimer *timer) { @@ -420,7 +428,13 @@ void throttle_config(ThrottleState *ts, */ void throttle_get_config(ThrottleState *ts, ThrottleConfig *cfg) { + int i; + *cfg = ts->cfg; + + for (i = 0; i < BUCKETS_COUNT; i++) { + throttle_unfix_bucket(&cfg->buckets[i]); + } } |