summary refs log tree commit diff stats
path: root/include/qemu/ratelimit.h
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2018-02-15 15:45:33 +0000
committerPeter Maydell <peter.maydell@linaro.org>2018-02-15 15:45:33 +0000
commitf003d07337a6d4d02c43429b26a4270459afb51a (patch)
tree6caf67e3cd097fabea32e1a66c635d9df2040e11 /include/qemu/ratelimit.h
parent8c5e7bddc22dac9d4dc3526996babce4c7242d9d (diff)
parentd2f668b74907cbd96d9df0774971768ed06de2f0 (diff)
downloadfocaccia-qemu-f003d07337a6d4d02c43429b26a4270459afb51a.tar.gz
focaccia-qemu-f003d07337a6d4d02c43429b26a4270459afb51a.zip
Merge remote-tracking branch 'remotes/stefanha/tags/block-pull-request' into staging
Pull request

v2:
 * Dropped Fam's git-publish series because there is still ongoing discussion

# gpg: Signature made Thu 15 Feb 2018 09:42:03 GMT
# gpg:                using RSA key 9CA4ABB381AB73C8
# gpg: Good signature from "Stefan Hajnoczi <stefanha@redhat.com>"
# gpg:                 aka "Stefan Hajnoczi <stefanha@gmail.com>"
# Primary key fingerprint: 8695 A8BF D3F9 7CDA AC35  775A 9CA4 ABB3 81AB 73C8

* remotes/stefanha/tags/block-pull-request:
  misc: fix spelling
  ratelimit: don't align wait time with slices
  vl: pause vcpus before stopping iothreads

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'include/qemu/ratelimit.h')
-rw-r--r--include/qemu/ratelimit.h11
1 files changed, 5 insertions, 6 deletions
diff --git a/include/qemu/ratelimit.h b/include/qemu/ratelimit.h
index 8dece483f5..1b38291823 100644
--- a/include/qemu/ratelimit.h
+++ b/include/qemu/ratelimit.h
@@ -36,7 +36,7 @@ typedef struct {
 static inline int64_t ratelimit_calculate_delay(RateLimit *limit, uint64_t n)
 {
     int64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
-    uint64_t delay_slices;
+    double delay_slices;
 
     assert(limit->slice_quota && limit->slice_ns);
 
@@ -55,12 +55,11 @@ static inline int64_t ratelimit_calculate_delay(RateLimit *limit, uint64_t n)
         return 0;
     }
 
-    /* Quota exceeded. Calculate the next time slice we may start
-     * sending data again. */
-    delay_slices = (limit->dispatched + limit->slice_quota - 1) /
-        limit->slice_quota;
+    /* Quota exceeded. Wait based on the excess amount and then start a new
+     * slice. */
+    delay_slices = (double)limit->dispatched / limit->slice_quota;
     limit->slice_end_time = limit->slice_start_time +
-        delay_slices * limit->slice_ns;
+        (uint64_t)(delay_slices * limit->slice_ns);
     return limit->slice_end_time - now;
 }