From: "Benoît Canet" <benoit.canet@irqsave.net>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, "Benoît Canet" <benoit.canet@irqsave.net>,
"Benoit Canet" <benoit@irqsave.net>,
stefanha@redhat.com
Subject: [Qemu-devel] [RFC 4/5] throttle: Prepare to have multiple timers for one ThrottleState
Date: Tue, 12 Aug 2014 15:42:26 +0200 [thread overview]
Message-ID: <1407850947-17625-5-git-send-email-benoit.canet@irqsave.net> (raw)
In-Reply-To: <1407850947-17625-1-git-send-email-benoit.canet@irqsave.net>
This patch transform the timer_pending call into two boolean values in the
ThrottleState structure.
This way we are sure that when multiple timers will be used only
one can be armed at a time.
Signed-off-by: Benoit Canet <benoit@irqsave.net>
---
block.c | 2 ++
include/qemu/throttle.h | 3 +++
util/throttle.c | 17 ++++++++++++++---
3 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/block.c b/block.c
index d2ca851..5edb3c3 100644
--- a/block.c
+++ b/block.c
@@ -165,12 +165,14 @@ void bdrv_io_limits_disable(BlockDriverState *bs)
static void bdrv_throttle_read_timer_cb(void *opaque)
{
BlockDriverState *bs = opaque;
+ throttle_timer_fired(&bs->throttle_state, false);
qemu_co_enter_next(&bs->throttled_reqs[0]);
}
static void bdrv_throttle_write_timer_cb(void *opaque)
{
BlockDriverState *bs = opaque;
+ throttle_timer_fired(&bs->throttle_state, true);
qemu_co_enter_next(&bs->throttled_reqs[1]);
}
diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h
index b89d4d8..3aece3a 100644
--- a/include/qemu/throttle.h
+++ b/include/qemu/throttle.h
@@ -65,6 +65,7 @@ typedef struct ThrottleConfig {
typedef struct ThrottleState {
ThrottleConfig cfg; /* configuration */
int64_t previous_leak; /* timestamp of the last leak done */
+ bool any_timer_armed[2]; /* is any timer armed for this throttle state */
} ThrottleState;
typedef struct ThrottleTimers {
@@ -125,6 +126,8 @@ bool throttle_schedule_timer(ThrottleState *ts,
ThrottleTimers *tt,
bool is_write);
+void throttle_timer_fired(ThrottleState *ts, bool is_write);
+
void throttle_account(ThrottleState *ts, bool is_write, uint64_t size);
#endif
diff --git a/util/throttle.c b/util/throttle.c
index 4d7c8d4..0e305e3 100644
--- a/util/throttle.c
+++ b/util/throttle.c
@@ -172,6 +172,7 @@ void throttle_timers_attach_aio_context(ThrottleTimers *tt,
void throttle_init(ThrottleState *ts)
{
memset(ts, 0, sizeof(ThrottleState));
+ ts->any_timer_armed[0] = ts->any_timer_armed[1] = false;
}
/* To be called first on the ThrottleTimers */
@@ -390,16 +391,26 @@ bool throttle_schedule_timer(ThrottleState *ts,
return false;
}
- /* request throttled and timer pending -> do nothing */
- if (timer_pending(tt->timers[is_write])) {
+ /* request throttled and any timer pending -> do nothing */
+ if (ts->any_timer_armed[is_write]) {
return true;
}
- /* request throttled and timer not pending -> arm timer */
+ ts->any_timer_armed[is_write] = true;
timer_mod(tt->timers[is_write], next_timestamp);
return true;
}
+/* Remember that now timers are currently armed
+ *
+ * @ts: the throttle state we are working on
+ * @is_write: the type of operation (read/write)
+ */
+void throttle_timer_fired(ThrottleState *ts, bool is_write)
+{
+ ts->any_timer_armed[is_write] = false;
+}
+
/* do the accounting for this operation
*
* @is_write: the type of operation (read/write)
--
2.1.0.rc1
next prev parent reply other threads:[~2014-08-12 13:43 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-12 13:42 [Qemu-devel] [RFC 0/5] Throttle group cooperative round robin scheduling Benoît Canet
2014-08-12 13:42 ` [Qemu-devel] [RFC 1/5] throttle: Extract timers from ThrottleState into a separate ThrottleTimers structure Benoît Canet
2014-08-12 13:42 ` [Qemu-devel] [RFC 2/5] throttle: Add throttle group infrastructure Benoît Canet
2014-08-12 13:42 ` [Qemu-devel] [RFC 3/5] throttle: Add throttle group infrastructure tests Benoît Canet
2014-08-12 13:42 ` Benoît Canet [this message]
2014-08-12 13:42 ` [Qemu-devel] [RFC 5/5] throttle: Add throttle group support Benoît Canet
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=1407850947-17625-5-git-send-email-benoit.canet@irqsave.net \
--to=benoit.canet@irqsave.net \
--cc=benoit@irqsave.net \
--cc=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.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).