From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52276) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XbUnT-0004Ei-42 for qemu-devel@nongnu.org; Tue, 07 Oct 2014 09:27:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XbUnG-0007iF-3S for qemu-devel@nongnu.org; Tue, 07 Oct 2014 09:27:23 -0400 Received: from lputeaux-656-01-25-125.w80-12.abo.wanadoo.fr ([80.12.84.125]:60875 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XbUnF-0007hj-Tu for qemu-devel@nongnu.org; Tue, 07 Oct 2014 09:27:10 -0400 From: =?UTF-8?q?Beno=C3=AEt=20Canet?= Date: Tue, 7 Oct 2014 15:24:35 +0200 Message-Id: <1412688279-8312-5-git-send-email-benoit.canet@nodalink.com> In-Reply-To: <1412688279-8312-1-git-send-email-benoit.canet@nodalink.com> References: <1412688279-8312-1-git-send-email-benoit.canet@nodalink.com> Subject: [Qemu-devel] [PATCH v1 4/8] throttle: Prepare to have multiple timers for one ThrottleState List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, famz@redhat.com, =?UTF-8?q?Beno=C3=AEt=20Canet?= , stefanha@redhat.com 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 --- 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 f209f55..079b0dc 100644 --- a/block.c +++ b/block.c @@ -168,12 +168,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.1