Skip to contentSkip to conversation

qemu-iotests: Test case for IO throttling

PATCH Superseded Fam Zheng 5 participants 20 messages Jan 29, 2014 – Feb 7, 2014

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

cover qemu-iotests: Test case for IO throttling

This series adds iotest case for IO throttling.

There is a new option "-a" for qemu-io sub-commands "aio_read" and "aio_write", which makes the aio requests accounted and the statistics reflected in blockstats.

Note that IO throttling implementation allows overcommiting of requests, so the actual IO happened in a time unit may be a bit larger than given limits. In the test case, the stats numbers are compared against 11%, to make room for such flexibility in order to improve determinism.

Fam Zheng (4):
qemu-io: New option "-a" to aio_read and aio_write
qemu-iotests: Add VM method qtest_cmd() to iotests.py
qemu-iotests: Allow caller to disable underscore convertion for qmp
qemu-iotests: Add 080 for IO throttling

 qemu-io-cmds.c                |  35 +++++++--
 tests/qemu-iotests/080        | 164 ++++++++++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/080.out    |   5 ++
 tests/qemu-iotests/group      |   1 +
 tests/qemu-iotests/iotests.py |  14 ++--
 5 files changed, 211 insertions(+), 8 deletions(-)
 create mode 100755 tests/qemu-iotests/080
 create mode 100644 tests/qemu-iotests/080.out
Signature · 1 line
1.8.5.3
author
#1 lore raw

PATCH 1/4 qemu-io: New option "-a" to aio_read and aio_write

This option will enable accounting of aio requests.

---
 qemu-io-cmds.c | 35 +++++++++++++++++++++++++++++++----
 1 file changed, 31 insertions(+), 4 deletions(-)
qemu-io-cmds.c +31 -4
index f1de24c..d6e20e6 100644
@@ -1346,6 +1346,7 @@ out:
 }
 
 struct aio_ctx {
+    BlockDriverState *bs;
     QEMUIOVector qiov;
     int64_t offset;
     char *buf;
@@ -1353,6 +1354,8 @@ struct aio_ctx {
     int vflag;
     int Cflag;
     int Pflag;
+    int aflag;
+    BlockAcctCookie acct;
     int pattern;
     struct timeval t1;
 };
@@ -1370,6 +1373,10 @@ static void aio_write_done(void *opaque, int ret)
         goto out;
     }
 
+    if (ctx->aflag) {
+        bdrv_acct_done(ctx->bs, &ctx->acct);
+    }
+
     if (ctx->qflag) {
         goto out;
     }
@@ -1407,6 +1414,10 @@ static void aio_read_done(void *opaque, int ret)
         g_free(cmp_buf);
     }
 
+    if (ctx->aflag) {
+        bdrv_acct_done(ctx->bs, &ctx->acct);
+    }
+
     if (ctx->qflag) {
         goto out;
     }
@@ -1442,6 +1453,7 @@ static void aio_read_help(void)
 " -P, -- use a pattern to verify read data\n"
 " -v, -- dump buffer to standard output\n"
 " -q, -- quiet mode, do not show I/O statistics\n"
+" -a, -- account IO\n"
 "\n");
 }
 
@@ -1452,7 +1464,7 @@ static const cmdinfo_t aio_read_cmd = {
     .cfunc      = aio_read_f,
     .argmin     = 2,
     .argmax     = -1,
-    .args       = "[-Cqv] [-P pattern ] off len [len..]",
+    .args       = "[-Cqva] [-P pattern ] off len [len..]",
     .oneline    = "asynchronously reads a number of bytes",
     .help       = aio_read_help,
 };
@@ -1462,7 +1474,8 @@ static int aio_read_f(BlockDriverState *bs, int argc, char **argv)
     int nr_iov, c;
     struct aio_ctx *ctx = g_new0(struct aio_ctx, 1);
 
-    while ((c = getopt(argc, argv, "CP:qv")) != EOF) {
+    ctx->bs = bs;
+    while ((c = getopt(argc, argv, "CP:qva")) != EOF) {
         switch (c) {
         case 'C':
             ctx->Cflag = 1;
@@ -1481,6 +1494,9 @@ static int aio_read_f(BlockDriverState *bs, int argc, char **argv)
         case 'v':
             ctx->vflag = 1;
             break;
+        case 'a':
+            ctx->aflag = 1;
+            break;
         default:
             g_free(ctx);
             return qemuio_command_usage(&aio_read_cmd);
@@ -1515,6 +1531,9 @@ static int aio_read_f(BlockDriverState *bs, int argc, char **argv)
     }
 
     gettimeofday(&ctx->t1, NULL);
+    if (ctx->aflag) {
+        bdrv_acct_start(bs, &ctx->acct, ctx->qiov.size, BDRV_ACCT_READ);
+    }
     bdrv_aio_readv(bs, ctx->offset >> 9, &ctx->qiov,
                    ctx->qiov.size >> 9, aio_read_done, ctx);
     return 0;
@@ -1537,6 +1556,7 @@ static void aio_write_help(void)
 " -P, -- use different pattern to fill file\n"
 " -C, -- report statistics in a machine parsable format\n"
 " -q, -- quiet mode, do not show I/O statistics\n"
+" -a, -- account IO\n"
 "\n");
 }
 
@@ -1547,7 +1567,7 @@ static const cmdinfo_t aio_write_cmd = {
     .cfunc      = aio_write_f,
     .argmin     = 2,
     .argmax     = -1,
-    .args       = "[-Cq] [-P pattern ] off len [len..]",
+    .args       = "[-Cqa] [-P pattern ] off len [len..]",
     .oneline    = "asynchronously writes a number of bytes",
     .help       = aio_write_help,
 };
@@ -1558,7 +1578,8 @@ static int aio_write_f(BlockDriverState *bs, int argc, char **argv)
     int pattern = 0xcd;
     struct aio_ctx *ctx = g_new0(struct aio_ctx, 1);
 
-    while ((c = getopt(argc, argv, "CqP:")) != EOF) {
+    ctx->bs = bs;
+    while ((c = getopt(argc, argv, "CqP:a")) != EOF) {
         switch (c) {
         case 'C':
             ctx->Cflag = 1;
@@ -1573,6 +1594,9 @@ static int aio_write_f(BlockDriverState *bs, int argc, char **argv)
                 return 0;
             }
             break;
+        case 'a':
+            ctx->aflag = 1;
+            break;
         default:
             g_free(ctx);
             return qemuio_command_usage(&aio_write_cmd);
@@ -1607,6 +1631,9 @@ static int aio_write_f(BlockDriverState *bs, int argc, char **argv)
     }
 
     gettimeofday(&ctx->t1, NULL);
+    if (ctx->aflag) {
+        bdrv_acct_start(bs, &ctx->acct, ctx->qiov.size, BDRV_ACCT_WRITE);
+    }
     bdrv_aio_writev(bs, ctx->offset >> 9, &ctx->qiov,
                     ctx->qiov.size >> 9, aio_write_done, ctx);
     return 0;
Signature · 1 line
1.8.5.3
#2 lore raw

Re: [Qemu-devel] [PATCH 1/4] qemu-io: New option "-a" to aio_read and aio_write

qemu-io-cmds.c static void aio_read_help(void) · line 1458

Quoted 7 lines · Fam Zheng
qemu-io-cmds.c +1 -0
@@ -1442,6 +1453,7 @@ static void aio_read_help(void)
 " -P, -- use a pattern to verify read data\n"
 " -v, -- dump buffer to standard output\n"
 " -q, -- quiet mode, do not show I/O statistics\n"
+" -a, -- account IO\n"
 "\n");
 }

This is too brief and probably won't help users. Maybe "use BlockStats I/O accounting"?

(I can fix this up when merging if you do not want to respin.)

Reviewed-by Benoit Canet on v1 1/4
#3 lore raw

Re: [Qemu-devel] [PATCH 1/4] qemu-io: New option "-a" to aio_read and aio_write

In reply to Fam Zheng
Quoted 148 lines · Fam Zheng

This option will enable accounting of aio requests.

---
 qemu-io-cmds.c | 35 +++++++++++++++++++++++++++++++----
 1 file changed, 31 insertions(+), 4 deletions(-)
qemu-io-cmds.c +31 -4
index f1de24c..d6e20e6 100644
@@ -1346,6 +1346,7 @@ out:
 }
 
 struct aio_ctx {
+    BlockDriverState *bs;
     QEMUIOVector qiov;
     int64_t offset;
     char *buf;
@@ -1353,6 +1354,8 @@ struct aio_ctx {
     int vflag;
     int Cflag;
     int Pflag;
+    int aflag;
+    BlockAcctCookie acct;
     int pattern;
     struct timeval t1;
 };
@@ -1370,6 +1373,10 @@ static void aio_write_done(void *opaque, int ret)
         goto out;
     }
 
+    if (ctx->aflag) {
+        bdrv_acct_done(ctx->bs, &ctx->acct);
+    }
+
     if (ctx->qflag) {
         goto out;
     }
@@ -1407,6 +1414,10 @@ static void aio_read_done(void *opaque, int ret)
         g_free(cmp_buf);
     }
 
+    if (ctx->aflag) {
+        bdrv_acct_done(ctx->bs, &ctx->acct);
+    }
+
     if (ctx->qflag) {
         goto out;
     }
@@ -1442,6 +1453,7 @@ static void aio_read_help(void)
 " -P, -- use a pattern to verify read data\n"
 " -v, -- dump buffer to standard output\n"
 " -q, -- quiet mode, do not show I/O statistics\n"
+" -a, -- account IO\n"
 "\n");
 }
 
@@ -1452,7 +1464,7 @@ static const cmdinfo_t aio_read_cmd = {
     .cfunc      = aio_read_f,
     .argmin     = 2,
     .argmax     = -1,
-    .args       = "[-Cqv] [-P pattern ] off len [len..]",
+    .args       = "[-Cqva] [-P pattern ] off len [len..]",
     .oneline    = "asynchronously reads a number of bytes",
     .help       = aio_read_help,
 };
@@ -1462,7 +1474,8 @@ static int aio_read_f(BlockDriverState *bs, int argc, char **argv)
     int nr_iov, c;
     struct aio_ctx *ctx = g_new0(struct aio_ctx, 1);
 
-    while ((c = getopt(argc, argv, "CP:qv")) != EOF) {
+    ctx->bs = bs;
+    while ((c = getopt(argc, argv, "CP:qva")) != EOF) {
         switch (c) {
         case 'C':
             ctx->Cflag = 1;
@@ -1481,6 +1494,9 @@ static int aio_read_f(BlockDriverState *bs, int argc, char **argv)
         case 'v':
             ctx->vflag = 1;
             break;
+        case 'a':
+            ctx->aflag = 1;
+            break;
         default:
             g_free(ctx);
             return qemuio_command_usage(&aio_read_cmd);
@@ -1515,6 +1531,9 @@ static int aio_read_f(BlockDriverState *bs, int argc, char **argv)
     }
 
     gettimeofday(&ctx->t1, NULL);
+    if (ctx->aflag) {
+        bdrv_acct_start(bs, &ctx->acct, ctx->qiov.size, BDRV_ACCT_READ);
+    }
     bdrv_aio_readv(bs, ctx->offset >> 9, &ctx->qiov,
                    ctx->qiov.size >> 9, aio_read_done, ctx);
     return 0;
@@ -1537,6 +1556,7 @@ static void aio_write_help(void)
 " -P, -- use different pattern to fill file\n"
 " -C, -- report statistics in a machine parsable format\n"
 " -q, -- quiet mode, do not show I/O statistics\n"
+" -a, -- account IO\n"
 "\n");
 }
 
@@ -1547,7 +1567,7 @@ static const cmdinfo_t aio_write_cmd = {
     .cfunc      = aio_write_f,
     .argmin     = 2,
     .argmax     = -1,
-    .args       = "[-Cq] [-P pattern ] off len [len..]",
+    .args       = "[-Cqa] [-P pattern ] off len [len..]",
     .oneline    = "asynchronously writes a number of bytes",
     .help       = aio_write_help,
 };
@@ -1558,7 +1578,8 @@ static int aio_write_f(BlockDriverState *bs, int argc, char **argv)
     int pattern = 0xcd;
     struct aio_ctx *ctx = g_new0(struct aio_ctx, 1);
 
-    while ((c = getopt(argc, argv, "CqP:")) != EOF) {
+    ctx->bs = bs;
+    while ((c = getopt(argc, argv, "CqP:a")) != EOF) {
         switch (c) {
         case 'C':
             ctx->Cflag = 1;
@@ -1573,6 +1594,9 @@ static int aio_write_f(BlockDriverState *bs, int argc, char **argv)
                 return 0;
             }
             break;
+        case 'a':
+            ctx->aflag = 1;
+            break;
         default:
             g_free(ctx);
             return qemuio_command_usage(&aio_write_cmd);
@@ -1607,6 +1631,9 @@ static int aio_write_f(BlockDriverState *bs, int argc, char **argv)
     }
 
     gettimeofday(&ctx->t1, NULL);
+    if (ctx->aflag) {
+        bdrv_acct_start(bs, &ctx->acct, ctx->qiov.size, BDRV_ACCT_WRITE);
+    }
     bdrv_aio_writev(bs, ctx->offset >> 9, &ctx->qiov,
                     ctx->qiov.size >> 9, aio_write_done, ctx);
     return 0;
Signature · 1 line
1.8.5.3
#4 lore raw

Re: [Qemu-devel] [PATCH 1/4] qemu-io: New option "-a" to aio_read and aio_write

In reply to Fam Zheng

Il 29/01/2014 09:40, Fam Zheng ha scritto:

Quoted 136 lines

This option will enable accounting of aio requests.

---
 qemu-io-cmds.c | 35 +++++++++++++++++++++++++++++++----
 1 file changed, 31 insertions(+), 4 deletions(-)
qemu-io-cmds.c +28 -4
index f1de24c..d6e20e6 100644
@@ -1346,6 +1346,7 @@ out:
 }
 
 struct aio_ctx {
+    BlockDriverState *bs;
     QEMUIOVector qiov;
     int64_t offset;
     char *buf;
@@ -1353,6 +1354,8 @@ struct aio_ctx {
     int vflag;
     int Cflag;
     int Pflag;
+    int aflag;
+    BlockAcctCookie acct;
     int pattern;
     struct timeval t1;
 };
@@ -1370,6 +1373,10 @@ static void aio_write_done(void *opaque, int ret)
         goto out;
     }
 
+    if (ctx->aflag) {
+        bdrv_acct_done(ctx->bs, &ctx->acct);
+    }
+
     if (ctx->qflag) {
         goto out;
     }
@@ -1407,6 +1414,10 @@ static void aio_read_done(void *opaque, int ret)
         g_free(cmp_buf);
     }
 
+    if (ctx->aflag) {
+        bdrv_acct_done(ctx->bs, &ctx->acct);
+    }
+
     if (ctx->qflag) {
         goto out;
     }
@@ -1442,6 +1453,7 @@ static void aio_read_help(void)
 " -P, -- use a pattern to verify read data\n"
 " -v, -- dump buffer to standard output\n"
 " -q, -- quiet mode, do not show I/O statistics\n"
+" -a, -- account IO\n"
 "\n");
 }
 
@@ -1452,7 +1464,7 @@ static const cmdinfo_t aio_read_cmd = {
     .cfunc      = aio_read_f,
     .argmin     = 2,
     .argmax     = -1,
-    .args       = "[-Cqv] [-P pattern ] off len [len..]",
+    .args       = "[-Cqva] [-P pattern ] off len [len..]",
     .oneline    = "asynchronously reads a number of bytes",
     .help       = aio_read_help,
 };
@@ -1462,7 +1474,8 @@ static int aio_read_f(BlockDriverState *bs, int argc, char **argv)
     int nr_iov, c;
     struct aio_ctx *ctx = g_new0(struct aio_ctx, 1);
 
-    while ((c = getopt(argc, argv, "CP:qv")) != EOF) {
+    ctx->bs = bs;
+    while ((c = getopt(argc, argv, "CP:qva")) != EOF) {
         switch (c) {
         case 'C':
             ctx->Cflag = 1;
@@ -1481,6 +1494,9 @@ static int aio_read_f(BlockDriverState *bs, int argc, char **argv)
         case 'v':
             ctx->vflag = 1;
             break;
+        case 'a':
+            ctx->aflag = 1;
+            break;
         default:
             g_free(ctx);
             return qemuio_command_usage(&aio_read_cmd);
@@ -1515,6 +1531,9 @@ static int aio_read_f(BlockDriverState *bs, int argc, char **argv)
     }
 
     gettimeofday(&ctx->t1, NULL);
+    if (ctx->aflag) {
+        bdrv_acct_start(bs, &ctx->acct, ctx->qiov.size, BDRV_ACCT_READ);
+    }
     bdrv_aio_readv(bs, ctx->offset >> 9, &ctx->qiov,
                    ctx->qiov.size >> 9, aio_read_done, ctx);
     return 0;
@@ -1537,6 +1556,7 @@ static void aio_write_help(void)
 " -P, -- use different pattern to fill file\n"
 " -C, -- report statistics in a machine parsable format\n"
 " -q, -- quiet mode, do not show I/O statistics\n"
+" -a, -- account IO\n"
 "\n");
 }
 
@@ -1547,7 +1567,7 @@ static const cmdinfo_t aio_write_cmd = {
     .cfunc      = aio_write_f,
     .argmin     = 2,
     .argmax     = -1,
-    .args       = "[-Cq] [-P pattern ] off len [len..]",
+    .args       = "[-Cqa] [-P pattern ] off len [len..]",
     .oneline    = "asynchronously writes a number of bytes",
     .help       = aio_write_help,
 };
@@ -1558,7 +1578,8 @@ static int aio_write_f(BlockDriverState *bs, int argc, char **argv)
     int pattern = 0xcd;
     struct aio_ctx *ctx = g_new0(struct aio_ctx, 1);
 
-    while ((c = getopt(argc, argv, "CqP:")) != EOF) {
+    ctx->bs = bs;
+    while ((c = getopt(argc, argv, "CqP:a")) != EOF) {
         switch (c) {
         case 'C':
             ctx->Cflag = 1;
@@ -1573,6 +1594,9 @@ static int aio_write_f(BlockDriverState *bs, int argc, char **argv)
                 return 0;
             }
             break;
+        case 'a':
+            ctx->aflag = 1;
+            break;
         default:
             g_free(ctx);
             return qemuio_command_usage(&aio_write_cmd);

qemu-io-cmds.c static int aio_write_f(BlockDriverState *bs, int argc, char **argv) · line 1639

Quoted 9 lines
qemu-io-cmds.c +3 -0
@@ -1607,6 +1631,9 @@ static int aio_write_f(BlockDriverState *bs, int argc, char **argv)
     }
 
     gettimeofday(&ctx->t1, NULL);
+    if (ctx->aflag) {
+        bdrv_acct_start(bs, &ctx->acct, ctx->qiov.size, BDRV_ACCT_WRITE);
+    }
     bdrv_aio_writev(bs, ctx->offset >> 9, &ctx->qiov,
                     ctx->qiov.size >> 9, aio_write_done, ctx);
     return 0;

Why can't it be enabled unconditionally?

Paolo

author
#5 lore raw

Re: [Qemu-devel] [PATCH 1/4] qemu-io: New option "-a" to aio_read and aio_write

Quoted 138 lines · Paolo Bonzini

Il 29/01/2014 09:40, Fam Zheng ha scritto:

Quoted 137 lines

This option will enable accounting of aio requests.

---
qemu-io-cmds.c | 35 +++++++++++++++++++++++++++++++----

1 file changed, 31 insertions(+), 4 deletions(-)
qemu-io-cmds.c +11 -0
index f1de24c..d6e20e6 100644
@@ -1346,6 +1346,7 @@ out:
 }
 
 struct aio_ctx {
+    BlockDriverState *bs;
    QEMUIOVector qiov;
    int64_t offset;
    char *buf;
@@ -1353,6 +1354,8 @@ struct aio_ctx {
    int vflag;
    int Cflag;
    int Pflag;
+    int aflag;
+    BlockAcctCookie acct;
    int pattern;
    struct timeval t1;
 };
@@ -1370,6 +1373,10 @@ static void aio_write_done(void *opaque, int ret)
        goto out;
    }
 
+    if (ctx->aflag) {
+        bdrv_acct_done(ctx->bs, &ctx->acct);
+    }
+
    if (ctx->qflag) {
        goto out;
    }
@@ -1407,6 +1414,10 @@ static void aio_read_done(void *opaque, int ret)
        g_free(cmp_buf);
    }
 
+    if (ctx->aflag) {
+        bdrv_acct_done(ctx->bs, &ctx->acct);
+    }
+
    if (ctx->qflag) {
        goto out;
    }
@@ -1442,6 +1453,7 @@ static void aio_read_help(void)

" -P, -- use a pattern to verify read data\n" " -v, -- dump buffer to standard output\n" " -q, -- quiet mode, do not show I/O statistics\n" +" -a, -- account IO\n"
"\n");
}

qemu-io-cmds.c +9 -2
@@ -1452,7 +1464,7 @@ static const cmdinfo_t aio_read_cmd = {
    .cfunc      = aio_read_f,
    .argmin     = 2,
    .argmax     = -1,
-    .args       = "[-Cqv] [-P pattern ] off len [len..]",
+    .args       = "[-Cqva] [-P pattern ] off len [len..]",
    .oneline    = "asynchronously reads a number of bytes",
    .help       = aio_read_help,
 };
@@ -1462,7 +1474,8 @@ static int aio_read_f(BlockDriverState *bs, int argc, char **argv)
    int nr_iov, c;
    struct aio_ctx *ctx = g_new0(struct aio_ctx, 1);
 
-    while ((c = getopt(argc, argv, "CP:qv")) != EOF) {
+    ctx->bs = bs;
+    while ((c = getopt(argc, argv, "CP:qva")) != EOF) {
        switch (c) {
        case 'C':
            ctx->Cflag = 1;
@@ -1481,6 +1494,9 @@ static int aio_read_f(BlockDriverState *bs, int argc, char **argv)
        case 'v':
            ctx->vflag = 1;
            break;
+        case 'a':
+            ctx->aflag = 1;
+            break;
        default:
            g_free(ctx);
            return qemuio_command_usage(&aio_read_cmd);
@@ -1515,6 +1531,9 @@ static int aio_read_f(BlockDriverState *bs, int argc, char **argv)
    }
 
    gettimeofday(&ctx->t1, NULL);
+    if (ctx->aflag) {
+        bdrv_acct_start(bs, &ctx->acct, ctx->qiov.size, BDRV_ACCT_READ);
+    }
    bdrv_aio_readv(bs, ctx->offset >> 9, &ctx->qiov,
                   ctx->qiov.size >> 9, aio_read_done, ctx);
    return 0;
@@ -1537,6 +1556,7 @@ static void aio_write_help(void)

" -P, -- use different pattern to fill file\n"
" -C, -- report statistics in a machine parsable format\n" " -q, -- quiet mode, do not show I/O statistics\n" +" -a, -- account IO\n"
"\n");
}

qemu-io-cmds.c +6 -2
@@ -1547,7 +1567,7 @@ static const cmdinfo_t aio_write_cmd = {
    .cfunc      = aio_write_f,
    .argmin     = 2,
    .argmax     = -1,
-    .args       = "[-Cq] [-P pattern ] off len [len..]",
+    .args       = "[-Cqa] [-P pattern ] off len [len..]",
    .oneline    = "asynchronously writes a number of bytes",
    .help       = aio_write_help,
 };
@@ -1558,7 +1578,8 @@ static int aio_write_f(BlockDriverState *bs, int argc, char **argv)
    int pattern = 0xcd;
    struct aio_ctx *ctx = g_new0(struct aio_ctx, 1);
 
-    while ((c = getopt(argc, argv, "CqP:")) != EOF) {
+    ctx->bs = bs;
+    while ((c = getopt(argc, argv, "CqP:a")) != EOF) {
        switch (c) {
        case 'C':
            ctx->Cflag = 1;
@@ -1573,6 +1594,9 @@ static int aio_write_f(BlockDriverState *bs, int argc, char **argv)
                return 0;
            }
            break;
+        case 'a':
+            ctx->aflag = 1;
+            break;
        default:
            g_free(ctx);
            return qemuio_command_usage(&aio_write_cmd);
@@ -1607,6 +1631,9 @@ static int aio_write_f(BlockDriverState *bs, int argc, char **argv)
    }
 
Quoted 11 lines

qemu-io-cmds.c static int aio_write_f(BlockDriverState *bs, int argc, char **argv) · line 1639

Quoted 8 lines
qemu-io-cmds.c +3 -0
    gettimeofday(&ctx->t1, NULL);
+    if (ctx->aflag) {
+        bdrv_acct_start(bs, &ctx->acct, ctx->qiov.size, BDRV_ACCT_WRITE);
+    }
    bdrv_aio_writev(bs, ctx->offset >> 9, &ctx->qiov,
                    ctx->qiov.size >> 9, aio_write_done, ctx);
    return 0;

Why can't it be enabled unconditionally?

So the default behavior is unchanged.

Fam

#6 lore raw

Re: [Qemu-devel] [PATCH 1/4] qemu-io: New option "-a" to aio_read and aio_write

Il 01/02/2014 15:31, Fam Zheng ha scritto:

Quoted 4 lines
Quoted 2 lines

Why can't it be enabled unconditionally?

So the default behavior is unchanged.

For the stand-alone executable there is no difference, is there anything that breaks for the monitor if you always do the accounting?

Paolo

author
#7 lore raw

Re: [Qemu-devel] [PATCH 1/4] qemu-io: New option "-a" to aio_read and aio_write

Quoted 9 lines · Paolo Bonzini

Il 01/02/2014 15:31, Fam Zheng ha scritto:

Quoted 4 lines
Quoted 2 lines

Why can't it be enabled unconditionally?

So the default behavior is unchanged.

For the stand-alone executable there is no difference, is there anything that breaks for the monitor if you always do the accounting?

I don't see anything broken, it just affacts the numbers in block stats. So it should be fine to enable it unconditionally, will do a respin for that. Thanks.

Fam

author
#8 lore raw

PATCH 2/4 qemu-iotests: Add VM method qtest_cmd() to iotests.py

In reply to Fam Zheng

This will allow test case to run command in qtest protocol. It's write-only for now.

---
 tests/qemu-iotests/iotests.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
tests/qemu-iotests/iotests.py +5 -2
index e4fa9af..ca79d09 100644
@@ -153,13 +153,16 @@ class VM(object):
                              stderr=sys.stderr)
         return p.wait()
 
+    def qtest_cmd(self, cmd):
+        self._popen.stdin.write(cmd + "\n")
+
     def launch(self):
         '''Launch the VM and establish a QMP connection'''
-        devnull = open('/dev/null', 'rb')
         qemulog = open(self._qemu_log_path, 'wb')
         try:
             self._qmp = qmp.QEMUMonitorProtocol(self._monitor_path, server=True)
-            self._popen = subprocess.Popen(self._args, stdin=devnull, stdout=qemulog,
+            self._popen = subprocess.Popen(self._args, stdin=subprocess.PIPE,
+                                           stdout=qemulog,
                                            stderr=subprocess.STDOUT)
             self._qmp.accept()
         except:
Signature · 1 line
1.8.5.3
#9 lore raw

Re: [Qemu-devel] [PATCH 2/4] qemu-iotests: Add VM method qtest_cmd() to iotests.py

Quoted 19 lines · Fam Zheng

This will allow test case to run command in qtest protocol. It's write-only for now.

---
 tests/qemu-iotests/iotests.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
tests/qemu-iotests/iotests.py +3 -0
index e4fa9af..ca79d09 100644
@@ -153,13 +153,16 @@ class VM(object):
                              stderr=sys.stderr)
         return p.wait()
 
+    def qtest_cmd(self, cmd):
+        self._popen.stdin.write(cmd + "\n")
+

tests/qemu-iotests/iotests.py class VM(object): · line 166

Quoted 10 lines
tests/qemu-iotests/iotests.py +2 -2
     def launch(self):
         '''Launch the VM and establish a QMP connection'''
-        devnull = open('/dev/null', 'rb')
         qemulog = open(self._qemu_log_path, 'wb')
         try:
             self._qmp = qmp.QEMUMonitorProtocol(self._monitor_path, server=True)
-            self._popen = subprocess.Popen(self._args, stdin=devnull, stdout=qemulog,
+            self._popen = subprocess.Popen(self._args, stdin=subprocess.PIPE,
+                                           stdout=qemulog,
                                            stderr=subprocess.STDOUT)

Commit 0fd05e8dd1ee7ae143fba3d6bcc6abe3fbeaeb34 ("qemu-iotests: start vms in qtest mode") put qtest on stdio. I think that was a mistake and it should be fixed if you want to drive qtest.

Let's not mix qtest output with QEMU stderr. If you need to drive qtest, put it on a dedicated UNIX domain socket
(just like QMP).

Implement the qtest protocol as documented in qtest.c:

* Line based protocol, request/response based. Server can send async messages
* so clients should always handle many async messages before the response
* comes in.

Stefan

author
#10 lore raw

Re: [Qemu-devel] [PATCH 2/4] qemu-iotests: Add VM method qtest_cmd() to iotests.py

Quoted 39 lines · Stefan Hajnoczi
Quoted 19 lines · Fam Zheng

This will allow test case to run command in qtest protocol. It's write-only for now.

---
 tests/qemu-iotests/iotests.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
tests/qemu-iotests/iotests.py +3 -0
index e4fa9af..ca79d09 100644
@@ -153,13 +153,16 @@ class VM(object):
                              stderr=sys.stderr)
         return p.wait()
 
+    def qtest_cmd(self, cmd):
+        self._popen.stdin.write(cmd + "\n")
+

tests/qemu-iotests/iotests.py class VM(object): · line 166

Quoted 10 lines
tests/qemu-iotests/iotests.py +2 -2
     def launch(self):
         '''Launch the VM and establish a QMP connection'''
-        devnull = open('/dev/null', 'rb')
         qemulog = open(self._qemu_log_path, 'wb')
         try:
             self._qmp = qmp.QEMUMonitorProtocol(self._monitor_path, server=True)
-            self._popen = subprocess.Popen(self._args, stdin=devnull, stdout=qemulog,
+            self._popen = subprocess.Popen(self._args, stdin=subprocess.PIPE,
+                                           stdout=qemulog,
                                            stderr=subprocess.STDOUT)

Commit 0fd05e8dd1ee7ae143fba3d6bcc6abe3fbeaeb34 ("qemu-iotests: start vms in qtest mode") put qtest on stdio. I think that was a mistake and it should be fixed if you want to drive qtest.

Let's not mix qtest output with QEMU stderr. If you need to drive qtest, put it on a dedicated UNIX domain socket
(just like QMP).

Quoted 6 lines

Implement the qtest protocol as documented in qtest.c:

* Line based protocol, request/response based. Server can send async messages
* so clients should always handle many async messages before the response
* comes in.

OK, good idea, I'll respin for a better qtest support.

Fam

author
#11 lore raw

PATCH 3/4 qemu-iotests: Allow caller to disable underscore convertion for qmp

In reply to Fam Zheng

QMP command "block_set_io_throttle" expects underscores in parameters instead of dashes: {iops,bps}_{rd,wr,max}.

Add optional argument conv_keys (defaults to True, backward compatible), it will be used in IO throttling test case.

---
 tests/qemu-iotests/iotests.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
tests/qemu-iotests/iotests.py +5 -2
index ca79d09..c1f5427 100644
@@ -179,11 +179,14 @@ class VM(object):
             self._popen = None
 
     underscore_to_dash = string.maketrans('_', '-')
-    def qmp(self, cmd, **args):
+    def qmp(self, cmd, conv_keys=True, **args):
         '''Invoke a QMP command and return the result dict'''
         qmp_args = dict()
         for k in args.keys():
-            qmp_args[k.translate(self.underscore_to_dash)] = args[k]
+            if conv_keys:
+                qmp_args[k.translate(self.underscore_to_dash)] = args[k]
+            else:
+                qmp_args[k] = args[k]
 
         return self._qmp.cmd(cmd, args=qmp_args)
 
Signature · 1 line
1.8.5.3
Reviewed-by on v1 3/4
#12 lore raw

Re: [Qemu-devel] [PATCH 3/4] qemu-iotests: Allow caller to disable underscore convertion for qmp

Quoted 10 lines · Fam Zheng

QMP command "block_set_io_throttle" expects underscores in parameters instead of dashes: {iops,bps}_{rd,wr,max}.

Add optional argument conv_keys (defaults to True, backward compatible), it will be used in IO throttling test case.

---
 tests/qemu-iotests/iotests.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
#13 lore raw

Re: [Qemu-devel] [PATCH 3/4] qemu-iotests: Allow caller to disable underscore convertion for qmp

In reply to Fam Zheng

On 01/29/2014 01:40 AM, Fam Zheng wrote:

s/convertion/conversion/ in the subject

Quoted 11 lines

QMP command "block_set_io_throttle" expects underscores in parameters instead of dashes: {iops,bps}_{rd,wr,max}.

Add optional argument conv_keys (defaults to True, backward compatible), it will be used in IO throttling test case.

---
 tests/qemu-iotests/iotests.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

You know, it might be nice to get the '-'/'_' looseness into QMP itself when invoked via JSON strings over the monitor, rather than just the testsuite wrapper, since we're already inconsistent in several commands.
But that's a bigger project for another day.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
author
#14 lore raw

Re: [Qemu-devel] [PATCH 3/4] qemu-iotests: Allow caller to disable underscore convertion for qmp

Quoted 16 lines · Eric Blake

On 01/29/2014 01:40 AM, Fam Zheng wrote:

s/convertion/conversion/ in the subject

Quoted 11 lines

QMP command "block_set_io_throttle" expects underscores in parameters instead of dashes: {iops,bps}_{rd,wr,max}.

Add optional argument conv_keys (defaults to True, backward compatible), it will be used in IO throttling test case.

---
 tests/qemu-iotests/iotests.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
Quoted 5 lines

You know, it might be nice to get the '-'/'_' looseness into QMP itself when invoked via JSON strings over the monitor, rather than just the testsuite wrapper, since we're already inconsistent in several commands.
But that's a bigger project for another day.

I agree. Let's stick to this now and leave the loosing in QMP for later.

Fam

Reviewed-by Benoit Canet on v1 3/4
#15 lore raw

Re: [Qemu-devel] [PATCH 3/4] qemu-iotests: Allow caller to disable underscore convertion for qmp

In reply to Fam Zheng
Quoted 36 lines · Fam Zheng

QMP command "block_set_io_throttle" expects underscores in parameters instead of dashes: {iops,bps}_{rd,wr,max}.

Add optional argument conv_keys (defaults to True, backward compatible), it will be used in IO throttling test case.

---
 tests/qemu-iotests/iotests.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
tests/qemu-iotests/iotests.py +5 -2
index ca79d09..c1f5427 100644
@@ -179,11 +179,14 @@ class VM(object):
             self._popen = None
 
     underscore_to_dash = string.maketrans('_', '-')
-    def qmp(self, cmd, **args):
+    def qmp(self, cmd, conv_keys=True, **args):
         '''Invoke a QMP command and return the result dict'''
         qmp_args = dict()
         for k in args.keys():
-            qmp_args[k.translate(self.underscore_to_dash)] = args[k]
+            if conv_keys:
+                qmp_args[k.translate(self.underscore_to_dash)] = args[k]
+            else:
+                qmp_args[k] = args[k]
 
         return self._qmp.cmd(cmd, args=qmp_args)
 
Signature · 1 line
1.8.5.3
author
#16 lore raw

PATCH 4/4 qemu-iotests: Add 080 for IO throttling

In reply to Fam Zheng

This case utilizes qemu-io command "aio_{read,write} -a -q" to verify the effectiveness of IO throttling options.

The "-a" option will cause qemu-io requests to be accounted.

It's implemented by driving the vm timer from qtest protocol, so the throttling timers are signaled with determinied time duration. Then we verify the completed IO requests are within 110% of bps and iops limits.

---
 tests/qemu-iotests/080     | 164 +++++++++++++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/080.out |   5 ++
 tests/qemu-iotests/group   |   1 +
 3 files changed, 170 insertions(+)
 create mode 100755 tests/qemu-iotests/080
 create mode 100644 tests/qemu-iotests/080.out
tests/qemu-iotests/080 new file +164 -0
new file mode 100755
index 0000000..222bb37
@@ -0,0 +1,164 @@
+#!/usr/bin/env python
+#
+# Tests for IO throttling
+#
+# Copyright (C) 2014 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+import time
+import os
+import iotests
+from iotests import qemu_img
+
+test_img = os.path.join(iotests.test_dir, 'test.img')
+
+class ThrottleTestCase(iotests.QMPTestCase):
+    image_len = 80 * 1024 * 1024 # MB
+
+    def blockstats(self, device):
+        result = self.vm.qmp("query-blockstats")
+        for r in result['return']:
+            if r['device'] == device:
+                stat = r['stats']
+                return stat['rd_bytes'], stat['rd_operations'], stat['wr_bytes'], stat['wr_operations']
+        raise Exception("Device not found for blockstats: %s" % device)
+
+    def setUp(self):
+        qemu_img('create', '-f', iotests.imgfmt, test_img, "1G")
+        #self.vm = iotests.VM().add_drive(test_img, "bps=1024,bps_max=1")
+        self.vm = iotests.VM().add_drive(test_img)
+        self.vm.launch()
+
+    def tearDown(self):
+        self.vm.shutdown()
+        os.remove(test_img)
+
+    def do_test_throttle(self, seconds=10, **limits):
+        def check_limit(limit, num):
+            # IO throttling algorithm is discrete, allow 10% error so the test
+            # is more deterministic
+            return limit == 0 or num < seconds * limit * 1.1
+
+        nsec_per_sec = 1000000000
+
+        limits['bps_max'] = 1
+        limits['iops_max'] = 1
+
+        # Enqueue many requests to throttling queue
+        result = self.vm.qmp("block_set_io_throttle", conv_keys=False, **limits)
+        self.assert_qmp(result, 'return', {})
+
+        # Set vm clock to a known value
+        ns = nsec_per_sec
+        self.vm.qtest_cmd("clock_step %d" % ns)
+
+        # Append many requests into the throttle queue
+        # They drain bps_max and iops_max
+        # The rest requests won't get executed until qtest clock is driven
+        for i in range(1000):
+            self.vm.hmp_qemu_io("drive0", "aio_read -a -q 0 512")
+            self.vm.hmp_qemu_io("drive0", "aio_write -a -q 0 512")
+
+        start_rd_bytes, start_rd_iops, start_wr_bytes, start_wr_iops = self.blockstats('drive0')
+
+        ns += seconds * nsec_per_sec
+        self.vm.qtest_cmd("clock_step %d" % ns)
+        # wait for a while to let requests take off
+        time.sleep(1)
+        end_rd_bytes, end_rd_iops, end_wr_bytes, end_wr_iops = self.blockstats('drive0')
+
+        rd_bytes = end_rd_bytes - start_rd_bytes
+        rd_iops = end_rd_iops - start_rd_iops
+        wr_bytes = end_wr_bytes - start_wr_bytes
+        wr_iops = end_wr_iops - start_wr_iops
+
+        assert check_limit(limits['bps'], rd_bytes)
+        assert check_limit(limits['bps_rd'], rd_bytes)
+        assert check_limit(limits['bps'], wr_bytes)
+        assert check_limit(limits['bps_wr'], wr_bytes)
+        assert check_limit(limits['iops'], rd_iops)
+        assert check_limit(limits['iops_rd'], rd_iops)
+        assert check_limit(limits['iops'], wr_iops)
+        assert check_limit(limits['iops_wr'], wr_iops)
+
+    def test_bps(self):
+        self.do_test_throttle(**{
+            'device': 'drive0',
+            'bps': 1000,
+            'bps_rd': 0,
+            'bps_wr': 0,
+            'iops': 0,
+            'iops_rd': 0,
+            'iops_wr': 0,
+            })
+
+    def test_bps_rd(self):
+        self.do_test_throttle(**{
+            'device': 'drive0',
+            'bps': 0,
+            'bps_rd': 1000,
+            'bps_wr': 0,
+            'iops': 0,
+            'iops_rd': 0,
+            'iops_wr': 0,
+            })
+
+    def test_bps_wr(self):
+        self.do_test_throttle(**{
+            'device': 'drive0',
+            'bps': 0,
+            'bps_rd': 0,
+            'bps_wr': 1000,
+            'iops': 0,
+            'iops_rd': 0,
+            'iops_wr': 0,
+            })
+
+    def test_iops(self):
+        self.do_test_throttle(**{
+            'device': 'drive0',
+            'bps': 0,
+            'bps_rd': 0,
+            'bps_wr': 0,
+            'iops': 10,
+            'iops_rd': 0,
+            'iops_wr': 0,
+            })
+
+    def test_iops_rd(self):
+        self.do_test_throttle(**{
+            'device': 'drive0',
+            'bps': 0,
+            'bps_rd': 0,
+            'bps_wr': 0,
+            'iops': 0,
+            'iops_rd': 10,
+            'iops_wr': 0,
+            })
+
+    def test_iops_wr(self):
+        self.do_test_throttle(**{
+            'device': 'drive0',
+            'bps': 0,
+            'bps_rd': 0,
+            'bps_wr': 0,
+            'iops': 0,
+            'iops_rd': 0,
+            'iops_wr': 10,
+            })
+
+if __name__ == '__main__':
+    iotests.main()
tests/qemu-iotests/080.out new file +5 -0
new file mode 100644
index 0000000..3f8a935
@@ -0,0 +1,5 @@
+......
+----------------------------------------------------------------------
+Ran 6 tests
+
+OK
tests/qemu-iotests/group +1 -0
index 03c762f..013a7ef 100644
@@ -82,3 +82,4 @@
 073 rw auto
 074 rw auto
 077 rw auto
+080 rw auto
Signature · 1 line
1.8.5.3
#17 lore raw

Re: [Qemu-devel] [PATCH 4/4] qemu-iotests: Add 080 for IO throttling

Quoted 7 lines · Fam Zheng

This case utilizes qemu-io command "aio_{read,write} -a -q" to verify the effectiveness of IO throttling options.

The "-a" option will cause qemu-io requests to be accounted.

It's implemented by driving the vm timer from qtest protocol, so the throttling timers are signaled with determinied time duration. Then we

s/determinied/determined/

Quoted 4 lines
tests/qemu-iotests/080 new file +4 -0
+class ThrottleTestCase(iotests.QMPTestCase):
+    image_len = 80 * 1024 * 1024 # MB
+
+    def blockstats(self, device):

tests/qemu-iotests/080 line 41

Quoted 10 lines
tests/qemu-iotests/080 new file +10 -0
+        result = self.vm.qmp("query-blockstats")
+        for r in result['return']:
+            if r['device'] == device:
+                stat = r['stats']
+                return stat['rd_bytes'], stat['rd_operations'], stat['wr_bytes'], stat['wr_operations']
+        raise Exception("Device not found for blockstats: %s" % device)
+
+    def setUp(self):
+        qemu_img('create', '-f', iotests.imgfmt, test_img, "1G")
+        #self.vm = iotests.VM().add_drive(test_img, "bps=1024,bps_max=1")

Commented out line?

Quoted 7 lines
tests/qemu-iotests/080 new file +7 -0
+        self.vm = iotests.VM().add_drive(test_img)
+        self.vm.launch()
+
+    def tearDown(self):
+        self.vm.shutdown()
+        os.remove(test_img)
+

tests/qemu-iotests/080 line 58

Quoted 10 lines
tests/qemu-iotests/080 new file +10 -0
+    def do_test_throttle(self, seconds=10, **limits):
+        def check_limit(limit, num):
+            # IO throttling algorithm is discrete, allow 10% error so the test
+            # is more deterministic
+            return limit == 0 or num < seconds * limit * 1.1
+
+        nsec_per_sec = 1000000000
+
+        limits['bps_max'] = 1
+        limits['iops_max'] = 1

I *think* this trick is to force throttling not to allow bursts? Maybe a comment would be good to clarify. IIRC when max is 0, burst behavior is different.

tests/qemu-iotests/080 line 80

Quoted 4 lines
tests/qemu-iotests/080 new file +4 -0
+        ns += seconds * nsec_per_sec
+        self.vm.qtest_cmd("clock_step %d" % ns)
+        # wait for a while to let requests take off
+        time.sleep(1)

sleep() is evil but I'm not sure there is a better way either... :(

#18 lore raw

Re: [Qemu-devel] [PATCH 4/4] qemu-iotests: Add 080 for IO throttling

In reply to Fam Zheng
Quoted 59 lines · Fam Zheng
tests/qemu-iotests/080 new file +59 -0
+    def do_test_throttle(self, seconds=10, **limits):
+        def check_limit(limit, num):
+            # IO throttling algorithm is discrete, allow 10% error so the test
+            # is more deterministic
+            return limit == 0 or num < seconds * limit * 1.1
+
+        nsec_per_sec = 1000000000
+
+        limits['bps_max'] = 1
+        limits['iops_max'] = 1
+
+        # Enqueue many requests to throttling queue
+        result = self.vm.qmp("block_set_io_throttle", conv_keys=False, **limits)
+        self.assert_qmp(result, 'return', {})
+
+        # Set vm clock to a known value
+        ns = nsec_per_sec
+        self.vm.qtest_cmd("clock_step %d" % ns)
+
+        # Append many requests into the throttle queue
+        # They drain bps_max and iops_max
+        # The rest requests won't get executed until qtest clock is driven
+        for i in range(1000):
+            self.vm.hmp_qemu_io("drive0", "aio_read -a -q 0 512")
+            self.vm.hmp_qemu_io("drive0", "aio_write -a -q 0 512")
+
+        start_rd_bytes, start_rd_iops, start_wr_bytes, start_wr_iops = self.blockstats('drive0')
+
+        ns += seconds * nsec_per_sec
+        self.vm.qtest_cmd("clock_step %d" % ns)
+        # wait for a while to let requests take off
+        time.sleep(1)
+        end_rd_bytes, end_rd_iops, end_wr_bytes, end_wr_iops = self.blockstats('drive0')
+
+        rd_bytes = end_rd_bytes - start_rd_bytes
+        rd_iops = end_rd_iops - start_rd_iops
+        wr_bytes = end_wr_bytes - start_wr_bytes
+        wr_iops = end_wr_iops - start_wr_iops
+
+        assert check_limit(limits['bps'], rd_bytes)
+        assert check_limit(limits['bps_rd'], rd_bytes)
+        assert check_limit(limits['bps'], wr_bytes)
+        assert check_limit(limits['bps_wr'], wr_bytes)
+        assert check_limit(limits['iops'], rd_iops)
+        assert check_limit(limits['iops_rd'], rd_iops)
+        assert check_limit(limits['iops'], wr_iops)
+        assert check_limit(limits['iops_wr'], wr_iops)
+
+    def test_bps(self):
+        self.do_test_throttle(**{
+            'device': 'drive0',
+            'bps': 1000,
+            'bps_rd': 0,
+            'bps_wr': 0,
+            'iops': 0,
+            'iops_rd': 0,
+            'iops_wr': 0,
+            })
+

tests/qemu-iotests/080 line 117

Quoted 10 lines
tests/qemu-iotests/080 new file +10 -0
+    def test_bps_rd(self):
+        self.do_test_throttle(**{
+            'device': 'drive0',
+            'bps': 0,
+            'bps_rd': 1000,
+            'bps_wr': 0,
+            'iops': 0,
+            'iops_rd': 0,
+            'iops_wr': 0,
+            })

I guess you'll get more stable behavior with 1024 instead of 1000. The request themselves are 512 bytes.

As a side note, I think we'll wait for all 1000 pending requests each time QEMU shuts down. Probably not a huge time waste but even 100 requests exceed the I/O limits you've specified. Perhaps using just 100 will make the test slightly faster.

Reviewed-by Benoit Canet on v1 4/4
#19 lore raw

Re: [Qemu-devel] [PATCH 4/4] qemu-iotests: Add 080 for IO throttling

In reply to Fam Zheng
Quoted 212 lines · Fam Zheng

This case utilizes qemu-io command "aio_{read,write} -a -q" to verify the effectiveness of IO throttling options.

The "-a" option will cause qemu-io requests to be accounted.

It's implemented by driving the vm timer from qtest protocol, so the throttling timers are signaled with determinied time duration. Then we verify the completed IO requests are within 110% of bps and iops limits.

---
 tests/qemu-iotests/080     | 164 +++++++++++++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/080.out |   5 ++
 tests/qemu-iotests/group   |   1 +
 3 files changed, 170 insertions(+)
 create mode 100755 tests/qemu-iotests/080
 create mode 100644 tests/qemu-iotests/080.out
tests/qemu-iotests/080 new file +164 -0
new file mode 100755
index 0000000..222bb37
@@ -0,0 +1,164 @@
+#!/usr/bin/env python
+#
+# Tests for IO throttling
+#
+# Copyright (C) 2014 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+import time
+import os
+import iotests
+from iotests import qemu_img
+
+test_img = os.path.join(iotests.test_dir, 'test.img')
+
+class ThrottleTestCase(iotests.QMPTestCase):
+    image_len = 80 * 1024 * 1024 # MB
+
+    def blockstats(self, device):
+        result = self.vm.qmp("query-blockstats")
+        for r in result['return']:
+            if r['device'] == device:
+                stat = r['stats']
+                return stat['rd_bytes'], stat['rd_operations'], stat['wr_bytes'], stat['wr_operations']
+        raise Exception("Device not found for blockstats: %s" % device)
+
+    def setUp(self):
+        qemu_img('create', '-f', iotests.imgfmt, test_img, "1G")
+        #self.vm = iotests.VM().add_drive(test_img, "bps=1024,bps_max=1")
+        self.vm = iotests.VM().add_drive(test_img)
+        self.vm.launch()
+
+    def tearDown(self):
+        self.vm.shutdown()
+        os.remove(test_img)
+
+    def do_test_throttle(self, seconds=10, **limits):
+        def check_limit(limit, num):
+            # IO throttling algorithm is discrete, allow 10% error so the test
+            # is more deterministic
+            return limit == 0 or num < seconds * limit * 1.1
+
+        nsec_per_sec = 1000000000
+
+        limits['bps_max'] = 1
+        limits['iops_max'] = 1
+
+        # Enqueue many requests to throttling queue
+        result = self.vm.qmp("block_set_io_throttle", conv_keys=False, **limits)
+        self.assert_qmp(result, 'return', {})
+
+        # Set vm clock to a known value
+        ns = nsec_per_sec
+        self.vm.qtest_cmd("clock_step %d" % ns)
+
+        # Append many requests into the throttle queue
+        # They drain bps_max and iops_max
+        # The rest requests won't get executed until qtest clock is driven
+        for i in range(1000):
+            self.vm.hmp_qemu_io("drive0", "aio_read -a -q 0 512")
+            self.vm.hmp_qemu_io("drive0", "aio_write -a -q 0 512")
+
+        start_rd_bytes, start_rd_iops, start_wr_bytes, start_wr_iops = self.blockstats('drive0')
+
+        ns += seconds * nsec_per_sec
+        self.vm.qtest_cmd("clock_step %d" % ns)
+        # wait for a while to let requests take off
+        time.sleep(1)
+        end_rd_bytes, end_rd_iops, end_wr_bytes, end_wr_iops = self.blockstats('drive0')
+
+        rd_bytes = end_rd_bytes - start_rd_bytes
+        rd_iops = end_rd_iops - start_rd_iops
+        wr_bytes = end_wr_bytes - start_wr_bytes
+        wr_iops = end_wr_iops - start_wr_iops
+
+        assert check_limit(limits['bps'], rd_bytes)
+        assert check_limit(limits['bps_rd'], rd_bytes)
+        assert check_limit(limits['bps'], wr_bytes)
+        assert check_limit(limits['bps_wr'], wr_bytes)
+        assert check_limit(limits['iops'], rd_iops)
+        assert check_limit(limits['iops_rd'], rd_iops)
+        assert check_limit(limits['iops'], wr_iops)
+        assert check_limit(limits['iops_wr'], wr_iops)
+
+    def test_bps(self):
+        self.do_test_throttle(**{
+            'device': 'drive0',
+            'bps': 1000,
+            'bps_rd': 0,
+            'bps_wr': 0,
+            'iops': 0,
+            'iops_rd': 0,
+            'iops_wr': 0,
+            })
+
+    def test_bps_rd(self):
+        self.do_test_throttle(**{
+            'device': 'drive0',
+            'bps': 0,
+            'bps_rd': 1000,
+            'bps_wr': 0,
+            'iops': 0,
+            'iops_rd': 0,
+            'iops_wr': 0,
+            })
+
+    def test_bps_wr(self):
+        self.do_test_throttle(**{
+            'device': 'drive0',
+            'bps': 0,
+            'bps_rd': 0,
+            'bps_wr': 1000,
+            'iops': 0,
+            'iops_rd': 0,
+            'iops_wr': 0,
+            })
+
+    def test_iops(self):
+        self.do_test_throttle(**{
+            'device': 'drive0',
+            'bps': 0,
+            'bps_rd': 0,
+            'bps_wr': 0,
+            'iops': 10,
+            'iops_rd': 0,
+            'iops_wr': 0,
+            })
+
+    def test_iops_rd(self):
+        self.do_test_throttle(**{
+            'device': 'drive0',
+            'bps': 0,
+            'bps_rd': 0,
+            'bps_wr': 0,
+            'iops': 0,
+            'iops_rd': 10,
+            'iops_wr': 0,
+            })
+
+    def test_iops_wr(self):
+        self.do_test_throttle(**{
+            'device': 'drive0',
+            'bps': 0,
+            'bps_rd': 0,
+            'bps_wr': 0,
+            'iops': 0,
+            'iops_rd': 0,
+            'iops_wr': 10,
+            })
+
+if __name__ == '__main__':
+    iotests.main()
tests/qemu-iotests/080.out new file +5 -0
new file mode 100644
index 0000000..3f8a935
@@ -0,0 +1,5 @@
+......
+----------------------------------------------------------------------
+Ran 6 tests
+
+OK
tests/qemu-iotests/group +1 -0
index 03c762f..013a7ef 100644
@@ -82,3 +82,4 @@
 073 rw auto
 074 rw auto
 077 rw auto
+080 rw auto
Signature · 1 line
1.8.5.3

I like the way it's done.