qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Fam Zheng <famz@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	pbonzini@redhat.com, berto@igalia.com,
	Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PATCH v2] block: Switch to host monotonic clock for IO throttling
Date: Mon, 23 Mar 2015 13:24:15 +0800	[thread overview]
Message-ID: <1427088255-29885-1-git-send-email-famz@redhat.com> (raw)

Currently, throttle timers won't make any progress when VCPU is not
running, which would stall the request queue in utils, qtest, vm
suspending, and live migration without special handling.

For example in bdrv_drain_all, all requests are resumed immediately
without taking throttling limit into account. This means whenever it is
called, IO throttling goes ineffective (examples: system reset,
migration and many block job operations.).

This might be some loophole that guest could exploit.

If we use the host clock, we can later just trust the nested poll when
waiting for requests.

Note that for qemu-iotests case 093, which sets up qtest when running
QEMU, we still use vm clock so the script can control the clock stepping
in order to be deterministic.

Signed-off-by: Fam Zheng <famz@redhat.com>

---
v2: Don't break qemu-iotests 093.
---
 block.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/block.c b/block.c
index 0fe97de..89a1d5b 100644
--- a/block.c
+++ b/block.c
@@ -30,6 +30,7 @@
 #include "qapi/qmp/qjson.h"
 #include "sysemu/block-backend.h"
 #include "sysemu/sysemu.h"
+#include "sysemu/qtest.h"
 #include "qemu/notify.h"
 #include "block/coroutine.h"
 #include "block/qapi.h"
@@ -181,10 +182,16 @@ static void bdrv_throttle_write_timer_cb(void *opaque)
 /* should be called before bdrv_set_io_limits if a limit is set */
 void bdrv_io_limits_enable(BlockDriverState *bs)
 {
+    int clock_type = QEMU_CLOCK_REALTIME;
+
+    if (qtest_enabled()) {
+        /* For testing block IO throttling only */
+        clock_type = QEMU_CLOCK_VIRTUAL;
+    }
     assert(!bs->io_limits_enabled);
     throttle_init(&bs->throttle_state,
                   bdrv_get_aio_context(bs),
-                  QEMU_CLOCK_VIRTUAL,
+                  clock_type,
                   bdrv_throttle_read_timer_cb,
                   bdrv_throttle_write_timer_cb,
                   bs);
-- 
1.9.3

             reply	other threads:[~2015-03-23  5:25 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-23  5:24 Fam Zheng [this message]
2015-03-23  8:10 ` [Qemu-devel] [PATCH v2] block: Switch to host monotonic clock for IO throttling Paolo Bonzini
2015-03-23  8:56 ` Alberto Garcia
2015-03-23 13:56 ` Stefan Hajnoczi
2015-03-23 13:58   ` Paolo Bonzini
2015-03-23 14:28     ` Stefan Hajnoczi
2015-03-23 14:49       ` Paolo Bonzini
2015-03-23 15:00         ` Stefan Hajnoczi
2015-03-23 15:02           ` Paolo Bonzini
2015-03-24  1:17       ` Fam Zheng
2015-03-24 13:29         ` 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=1427088255-29885-1-git-send-email-famz@redhat.com \
    --to=famz@redhat.com \
    --cc=berto@igalia.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@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).