Skip to contentSkip to conversation

block: Switch to host monotonic clock for IO throttling

PATCH Superseded Fam Zheng 2 participants 3 messages Mar 25, 2015

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

PATCH v3 1/1 block: Switch to host monotonic clock for IO throttling

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.

Block jobs are confusingly inconsistent between with and without
throttling: if user sets a bps limit, starts a block job, then stops vm, the block job will not make any progress; in contrary, if user unsets the bps limit, the block job will run normally.

After this patch, with the host clock, even if the VCPUs are stopped, the throttle queues will be processed.

This patch also enables potential to add throttle to bdrv_drain_all. Currently all requests are drained immediately. In other words whenever it is called, IO throttling goes ineffective (examples: system reset, migration and many block job operations.). This is a loophole that guest could exploit. If we use the host clock, we can later just trust the nested poll. This could be done on top.

Note that for qemu-iotests case 093, which uses qtest, we still keep vm clock so the script can control the clock stepping in order to be deterministic.

---
v3: More justification in commit message. [Stefan]
Add Paolo's and Alberto's rev-bys.
v2: Don't break qemu-iotests 093.

---
 block.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
block.c +8 -1
index 0fe97de..89a1d5b 100644
@@ -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);
Signature · 1 line
1.9.3
#1 lore raw
Quoted 4 lines · Fam Zheng

Block jobs are confusingly inconsistent between with and without
throttling: if user sets a bps limit, starts a block job, then stops vm, the block job will not make any progress; in contrary, if user unsets the bps limit, the block job will run normally.

Wait, that's not what happens:

a) If you start a job then stop the vm then the job will be completed immediately.
b) If you stop the vm then start the job then it won't make any progress.

This patch fixes b), but a) still happens.

Berto

author
#2 lore raw
Quoted 7 lines · Alberto Garcia
Quoted 4 lines · Fam Zheng

Block jobs are confusingly inconsistent between with and without
throttling: if user sets a bps limit, starts a block job, then stops vm, the block job will not make any progress; in contrary, if user unsets the bps limit, the block job will run normally.

Quoted 9 lines

Wait, that's not what happens:

a) If you start a job then stop the vm then the job will be completed immediately.
b) If you stop the vm then start the job then it won't make any progress.

This patch fixes b), but a) still happens.

Ah you're right, I put the order wrong. I'v just started looking at issue a).

I'll fix the text.

Fam