All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 02/21] block: add clock_type field to ThrottleGroup
Date: Tue, 18 Jul 2017 16:17:47 +0200	[thread overview]
Message-ID: <1500387486-5469-3-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1500387486-5469-1-git-send-email-kwolf@redhat.com>

From: Manos Pitsidianakis <el13635@mail.ntua.gr>

Clock type in throttling is currently inferred by the ThrottleTimer's
clock type even though it is a per-ThrottleGroup property; it doesn't
make sense to have different clock types in the same group. Moving this
to a field in ThrottleGroup can simplify some of the throttle functions.

Signed-off-by: Manos Pitsidianakis <el13635@mail.ntua.gr>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/throttle-groups.c     | 20 ++++++++++----------
 fsdev/qemu-fsdev-throttle.c |  2 +-
 include/qemu/throttle.h     |  1 +
 tests/test-throttle.c       |  4 ++--
 util/throttle.c             |  4 +++-
 5 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/block/throttle-groups.c b/block/throttle-groups.c
index da2b490..71af3f7 100644
--- a/block/throttle-groups.c
+++ b/block/throttle-groups.c
@@ -61,6 +61,7 @@ typedef struct ThrottleGroup {
     QLIST_HEAD(, BlockBackendPublic) head;
     BlockBackend *tokens[2];
     bool any_timer_armed[2];
+    QEMUClockType clock_type;
 
     /* These two are protected by the global throttle_groups_lock */
     unsigned refcount;
@@ -98,6 +99,12 @@ ThrottleState *throttle_group_incref(const char *name)
     if (!tg) {
         tg = g_new0(ThrottleGroup, 1);
         tg->name = g_strdup(name);
+        tg->clock_type = QEMU_CLOCK_REALTIME;
+
+        if (qtest_enabled()) {
+            /* For testing block IO throttling only */
+            tg->clock_type = QEMU_CLOCK_VIRTUAL;
+        }
         qemu_mutex_init(&tg->lock);
         throttle_init(&tg->ts);
         QLIST_INIT(&tg->head);
@@ -310,7 +317,7 @@ static void schedule_next_request(BlockBackend *blk, bool is_write)
             token = blk;
         } else {
             ThrottleTimers *tt = &blk_get_public(token)->throttle_timers;
-            int64_t now = qemu_clock_get_ns(tt->clock_type);
+            int64_t now = qemu_clock_get_ns(tg->clock_type);
             timer_mod(tt->timers[is_write], now);
             tg->any_timer_armed[is_write] = true;
         }
@@ -430,7 +437,7 @@ void throttle_group_config(BlockBackend *blk, ThrottleConfig *cfg)
     if (timer_pending(tt->timers[1])) {
         tg->any_timer_armed[1] = false;
     }
-    throttle_config(ts, tt, cfg);
+    throttle_config(ts, tg->clock_type, tt, cfg);
     qemu_mutex_unlock(&tg->lock);
 
     throttle_group_restart_blk(blk);
@@ -497,13 +504,6 @@ void throttle_group_register_blk(BlockBackend *blk, const char *groupname)
     BlockBackendPublic *blkp = blk_get_public(blk);
     ThrottleState *ts = throttle_group_incref(groupname);
     ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts);
-    int clock_type = QEMU_CLOCK_REALTIME;
-
-    if (qtest_enabled()) {
-        /* For testing block IO throttling only */
-        clock_type = QEMU_CLOCK_VIRTUAL;
-    }
-
     blkp->throttle_state = ts;
 
     qemu_mutex_lock(&tg->lock);
@@ -518,7 +518,7 @@ void throttle_group_register_blk(BlockBackend *blk, const char *groupname)
 
     throttle_timers_init(&blkp->throttle_timers,
                          blk_get_aio_context(blk),
-                         clock_type,
+                         tg->clock_type,
                          read_timer_cb,
                          write_timer_cb,
                          blk);
diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c
index 7ae4e86..453fb1e 100644
--- a/fsdev/qemu-fsdev-throttle.c
+++ b/fsdev/qemu-fsdev-throttle.c
@@ -86,7 +86,7 @@ void fsdev_throttle_init(FsThrottle *fst)
                              fsdev_throttle_read_timer_cb,
                              fsdev_throttle_write_timer_cb,
                              fst);
-        throttle_config(&fst->ts, &fst->tt, &fst->cfg);
+        throttle_config(&fst->ts, QEMU_CLOCK_REALTIME, &fst->tt, &fst->cfg);
         qemu_co_queue_init(&fst->throttled_reqs[0]);
         qemu_co_queue_init(&fst->throttled_reqs[1]);
     }
diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h
index 9109657..8d2fd77 100644
--- a/include/qemu/throttle.h
+++ b/include/qemu/throttle.h
@@ -139,6 +139,7 @@ bool throttle_enabled(ThrottleConfig *cfg);
 bool throttle_is_valid(ThrottleConfig *cfg, Error **errp);
 
 void throttle_config(ThrottleState *ts,
+                     QEMUClockType clock_type,
                      ThrottleTimers *tt,
                      ThrottleConfig *cfg);
 
diff --git a/tests/test-throttle.c b/tests/test-throttle.c
index a9201b1..2d9cd46 100644
--- a/tests/test-throttle.c
+++ b/tests/test-throttle.c
@@ -228,7 +228,7 @@ static void test_config_functions(void)
                          read_timer_cb, write_timer_cb, &ts);
     /* structure reset by throttle_init previous_leak should be null */
     g_assert(!ts.previous_leak);
-    throttle_config(&ts, &tt, &orig_cfg);
+    throttle_config(&ts, QEMU_CLOCK_VIRTUAL, &tt, &orig_cfg);
 
     /* has previous leak been initialized by throttle_config ? */
     g_assert(ts.previous_leak);
@@ -486,7 +486,7 @@ static bool do_test_accounting(bool is_ops, /* are we testing bps or ops */
     throttle_init(&ts);
     throttle_timers_init(&tt, ctx, QEMU_CLOCK_VIRTUAL,
                          read_timer_cb, write_timer_cb, &ts);
-    throttle_config(&ts, &tt, &cfg);
+    throttle_config(&ts, QEMU_CLOCK_VIRTUAL, &tt, &cfg);
 
     /* account a read */
     throttle_account(&ts, false, size);
diff --git a/util/throttle.c b/util/throttle.c
index 3570ed2..3e94807 100644
--- a/util/throttle.c
+++ b/util/throttle.c
@@ -399,10 +399,12 @@ static void throttle_cancel_timer(QEMUTimer *timer)
 /* Used to configure the throttle
  *
  * @ts: the throttle state we are working on
+ * @clock_type: the group's clock_type
  * @tt: the throttle timers we use in this aio context
  * @cfg: the config to set
  */
 void throttle_config(ThrottleState *ts,
+                     QEMUClockType clock_type,
                      ThrottleTimers *tt,
                      ThrottleConfig *cfg)
 {
@@ -414,7 +416,7 @@ void throttle_config(ThrottleState *ts,
         throttle_fix_bucket(&ts->cfg.buckets[i]);
     }
 
-    ts->previous_leak = qemu_clock_get_ns(tt->clock_type);
+    ts->previous_leak = qemu_clock_get_ns(clock_type);
 
     for (i = 0; i < 2; i++) {
         throttle_cancel_timer(tt->timers[i]);
-- 
1.8.3.1

  parent reply	other threads:[~2017-07-18 14:18 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-18 14:17 [Qemu-devel] [PULL 00/21] Block layer patches Kevin Wolf
2017-07-18 14:17 ` [Qemu-devel] [PULL 01/21] commit: Add NULL check for overlay_bs Kevin Wolf
2017-07-18 14:17 ` Kevin Wolf [this message]
2017-07-18 14:17 ` [Qemu-devel] [PULL 03/21] block: remove timer canceling in throttle_config() Kevin Wolf
2017-07-18 14:17 ` [Qemu-devel] [PULL 04/21] block/vmdk: Report failures in vmdk_read_cid() Kevin Wolf
2017-07-18 14:17 ` [Qemu-devel] [PULL 05/21] block/vpc.c: Handle write failures in get_image_offset() Kevin Wolf
2017-07-18 14:17 ` [Qemu-devel] [PULL 06/21] block: Make blk_get_attached_dev_id() public Kevin Wolf
2017-07-18 14:17 ` [Qemu-devel] [PULL 07/21] block/qapi: Add qdev device name to query-block Kevin Wolf
2017-07-18 14:17 ` [Qemu-devel] [PULL 08/21] block: Make blk_all_next() public Kevin Wolf
2017-07-18 14:17 ` [Qemu-devel] [PULL 09/21] block/qapi: Use blk_all_next() for query-block Kevin Wolf
2017-07-18 14:17 ` [Qemu-devel] [PULL 10/21] block: List anonymous device BBs in query-block Kevin Wolf
2017-07-18 14:17 ` [Qemu-devel] [PULL 11/21] ide: bdrv_attach_dev() for empty CD-ROM Kevin Wolf
2017-07-18 14:17 ` [Qemu-devel] [PULL 12/21] scsi-disk: " Kevin Wolf
2017-07-18 14:17 ` [Qemu-devel] [PULL 13/21] qemu-iotests: Test 'info block' Kevin Wolf
2017-07-18 14:17 ` [Qemu-devel] [PULL 14/21] qemu-iotests: Test unplug of -device without drive Kevin Wolf
2017-07-18 14:18 ` [Qemu-devel] [PULL 15/21] vvfat: add constants for special values of name[0] Kevin Wolf
2017-07-18 14:18 ` [Qemu-devel] [PULL 16/21] vvfat: add a constant for bootsector name Kevin Wolf
2017-07-18 14:18 ` [Qemu-devel] [PULL 17/21] vvfat: correctly parse non-ASCII short and long file names Kevin Wolf
2017-07-18 14:18 ` [Qemu-devel] [PULL 18/21] vvfat: initialize memory after allocating it Kevin Wolf
2017-07-18 14:18 ` [Qemu-devel] [PULL 19/21] block/vvfat: Fix compiler warning with gcc 7 Kevin Wolf
2017-07-18 14:18 ` [Qemu-devel] [PULL 20/21] blockdev: move BDRV_O_NO_BACKING option forward Kevin Wolf
2017-07-18 14:18 ` [Qemu-devel] [PULL 21/21] qemu-img: Check for backing image if specified during create Kevin Wolf
2017-07-18 18:57 ` [Qemu-devel] [PULL 00/21] Block layer patches no-reply
2017-07-19  6:11   ` Kevin Wolf
2017-07-18 21:23 ` no-reply
2017-07-19 11:28 ` Peter Maydell

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=1500387486-5469-3-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.