From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Peter Maydell <peter.maydell@linaro.org>,
Kevin Wolf <kwolf@redhat.com>,
Wolfgang Bumiller <w.bumiller@proxmox.com>
Subject: [Qemu-devel] [PATCH 4/5] ratelimit: don't align wait time with slices
Date: Tue, 13 Feb 2018 17:34:28 +0000 [thread overview]
Message-ID: <20180213173429.19501-5-stefanha@redhat.com> (raw)
In-Reply-To: <20180213173429.19501-1-stefanha@redhat.com>
From: Wolfgang Bumiller <w.bumiller@proxmox.com>
It is possible for rate limited writes to keep overshooting a slice's
quota by a tiny amount causing the slice-aligned waiting period to
effectively halve the rate.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Reviewed-by: Alberto Garcia <berto@igalia.com>
Message-id: 20180207071758.6818-1-w.bumiller@proxmox.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
include/qemu/ratelimit.h | 11 +++++------
1 file 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;
}
--
2.14.3
next prev parent reply other threads:[~2018-02-13 17:34 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-13 17:34 [Qemu-devel] [PATCH 0/5] Block patches Stefan Hajnoczi
2018-02-13 17:34 ` [Qemu-devel] [PATCH 1/5] Add a git-publish configuration file Stefan Hajnoczi
2018-02-13 18:09 ` Daniel P. Berrangé
2018-02-14 1:01 ` Fam Zheng
2018-02-14 13:34 ` Stefan Hajnoczi
2018-02-14 13:45 ` Fam Zheng
2018-02-14 15:21 ` Eric Blake
2018-02-14 14:08 ` Paolo Bonzini
2018-02-14 14:27 ` Paolo Bonzini
2018-02-25 6:04 ` Fam Zheng
2018-02-14 17:37 ` Philippe Mathieu-Daudé
2018-02-25 6:05 ` Fam Zheng
2018-02-13 17:34 ` [Qemu-devel] [PATCH 2/5] README: Document 'git-publish' workflow Stefan Hajnoczi
2018-02-13 17:34 ` [Qemu-devel] [PATCH 3/5] vl: pause vcpus before stopping iothreads Stefan Hajnoczi
2018-02-13 17:34 ` Stefan Hajnoczi [this message]
2018-02-13 17:34 ` [Qemu-devel] [PATCH 5/5] misc: fix spelling Stefan Hajnoczi
2018-02-14 0:48 ` [Qemu-devel] [PATCH 0/5] Block patches Fam Zheng
2018-02-14 13:25 ` Stefan Hajnoczi
2018-02-14 13:58 ` Fam Zheng
2018-02-15 9:39 ` Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180213173429.19501-5-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=w.bumiller@proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).