qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 4/9] throttle: Prepare to have multiple timers for o


From: Alberto Garcia
Subject: [Qemu-devel] [PATCH 4/9] throttle: Prepare to have multiple timers for one ThrottleState
Date: Fri, 13 Feb 2015 18:06:12 +0200

From: Benoît Canet <address@hidden>

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 <address@hidden>
Signed-off-by: Alberto Garcia <address@hidden>
---
 block.c                 |  2 ++
 include/qemu/throttle.h |  3 +++
 util/throttle.c         | 16 +++++++++++++---
 3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/block.c b/block.c
index b7469a7..fb45c6e 100644
--- a/block.c
+++ b/block.c
@@ -169,12 +169,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 2c560db..546ba12 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 d76a48e..71770d3 100644
--- a/util/throttle.c
+++ b/util/throttle.c
@@ -390,16 +390,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.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]