From patchwork Thu Aug 8 14:29:52 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Beno=C3=AEt_Canet?= X-Patchwork-Id: 265745 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A4FFF2C0089 for ; Fri, 9 Aug 2013 00:31:39 +1000 (EST) Received: from localhost ([::1]:40065 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V7RFZ-0005qk-DI for incoming@patchwork.ozlabs.org; Thu, 08 Aug 2013 10:31:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35122) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V7RDl-0003Y7-9u for qemu-devel@nongnu.org; Thu, 08 Aug 2013 10:29:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V7RDg-0004IW-8c for qemu-devel@nongnu.org; Thu, 08 Aug 2013 10:29:45 -0400 Received: from nodalink.pck.nerim.net ([62.212.105.220]:54883 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V7RDf-0004IF-EM for qemu-devel@nongnu.org; Thu, 08 Aug 2013 10:29:40 -0400 Received: by paradis.irqsave.net (Postfix, from userid 1002) id D14328746B6; Thu, 8 Aug 2013 16:29:38 +0200 (CEST) Received: from localhost.localdomain (unknown [192.168.77.1]) by paradis.irqsave.net (Postfix) with ESMTP id E14F48746B7; Thu, 8 Aug 2013 16:28:03 +0200 (CEST) From: =?UTF-8?q?Beno=C3=AEt=20Canet?= To: qemu-devel@nongnu.org Date: Thu, 8 Aug 2013 16:29:52 +0200 Message-Id: <1375972194-3090-5-git-send-email-benoit@irqsave.net> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1375972194-3090-1-git-send-email-benoit@irqsave.net> References: <1375972194-3090-1-git-send-email-benoit@irqsave.net> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 62.212.105.220 Cc: kwolf@redhat.com, pbonzini@redhat.com, =?UTF-8?q?Beno=C3=AEt=20Canet?= , stefanha@redhat.com Subject: [Qemu-devel] =?utf-8?q?=5BPATCH_V4_4/5=5D_block=3A_Add_support_fo?= =?utf-8?q?r_throttling_burst_max_in_QMP_and_the_command_line=2E?= X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The max parameter of the leaky bycket throttling algoritm can be used to allow the guest to do bursts. The max value is a pool of I/O that the guest can use without being throttled at all. Throttling is triggered once this pool is empty. Signed-off-by: Benoit Canet --- block/qapi.c | 26 ++++++++++++ blockdev.c | 119 ++++++++++++++++++++++++++++++++++++++++++++++-------- hmp.c | 32 +++++++++++++-- qapi-schema.json | 34 +++++++++++++++- qemu-options.hx | 4 +- qmp-commands.hx | 30 ++++++++++++-- 6 files changed, 220 insertions(+), 25 deletions(-) diff --git a/block/qapi.c b/block/qapi.c index 45f806b..5ba10f4 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -232,6 +232,32 @@ void bdrv_query_info(BlockDriverState *bs, info->inserted->iops = cfg.buckets[THROTTLE_OPS_TOTAL].ups; info->inserted->iops_rd = cfg.buckets[THROTTLE_OPS_READ].ups; info->inserted->iops_wr = cfg.buckets[THROTTLE_OPS_WRITE].ups; + + info->inserted->has_bps_max = + cfg.buckets[THROTTLE_BPS_TOTAL].max; + info->inserted->bps_max = + cfg.buckets[THROTTLE_BPS_TOTAL].max; + info->inserted->has_bps_rd_max = + cfg.buckets[THROTTLE_BPS_READ].max; + info->inserted->bps_rd_max = + cfg.buckets[THROTTLE_BPS_READ].max; + info->inserted->has_bps_wr_max = + cfg.buckets[THROTTLE_BPS_WRITE].max; + info->inserted->bps_wr_max = + cfg.buckets[THROTTLE_BPS_WRITE].max; + + info->inserted->has_iops_max = + cfg.buckets[THROTTLE_OPS_TOTAL].max; + info->inserted->iops_max = + cfg.buckets[THROTTLE_OPS_TOTAL].max; + info->inserted->has_iops_rd_max = + cfg.buckets[THROTTLE_OPS_READ].max; + info->inserted->iops_rd_max = + cfg.buckets[THROTTLE_OPS_READ].max; + info->inserted->has_iops_wr_max = + cfg.buckets[THROTTLE_OPS_WRITE].max; + info->inserted->iops_wr_max = + cfg.buckets[THROTTLE_OPS_WRITE].max; } bs0 = bs; diff --git a/blockdev.c b/blockdev.c index 7559ea5..22016a2 100644 --- a/blockdev.c +++ b/blockdev.c @@ -486,13 +486,18 @@ static DriveInfo *blockdev_init(QemuOpts *all_opts, cfg.buckets[THROTTLE_OPS_WRITE].ups = qemu_opt_get_number(opts, "throttling.iops-write", 0); - cfg.buckets[THROTTLE_BPS_TOTAL].max = 0; - cfg.buckets[THROTTLE_BPS_READ].max = 0; - cfg.buckets[THROTTLE_BPS_WRITE].max = 0; - - cfg.buckets[THROTTLE_OPS_TOTAL].max = 0; - cfg.buckets[THROTTLE_OPS_READ].max = 0; - cfg.buckets[THROTTLE_OPS_WRITE].max = 0; + cfg.buckets[THROTTLE_BPS_TOTAL].max = + qemu_opt_get_number(opts, "throttling.bps-total-max", 0); + cfg.buckets[THROTTLE_BPS_READ].max = + qemu_opt_get_number(opts, "throttling.bps-read-max", 0); + cfg.buckets[THROTTLE_BPS_WRITE].max = + qemu_opt_get_number(opts, "throttling.bps-write-max", 0); + cfg.buckets[THROTTLE_OPS_TOTAL].max = + qemu_opt_get_number(opts, "throttling.iops-total-max", 0); + cfg.buckets[THROTTLE_OPS_READ].max = + qemu_opt_get_number(opts, "throttling.iops-read-max", 0); + cfg.buckets[THROTTLE_OPS_WRITE].max = + qemu_opt_get_number(opts, "throttling.iops-write-max", 0); cfg.unit_size = BDRV_SECTOR_SIZE; cfg.op_size = 0; @@ -773,6 +778,14 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) qemu_opt_rename(all_opts, "bps_rd", "throttling.bps-read"); qemu_opt_rename(all_opts, "bps_wr", "throttling.bps-write"); + qemu_opt_rename(all_opts, "iops_max", "throttling.iops-total-max"); + qemu_opt_rename(all_opts, "iops_rd_max", "throttling.iops-read-max"); + qemu_opt_rename(all_opts, "iops_wr_max", "throttling.iops-write-max"); + + qemu_opt_rename(all_opts, "bps_max", "throttling.bps-total-max"); + qemu_opt_rename(all_opts, "bps_rd_max", "throttling.bps-read-max"); + qemu_opt_rename(all_opts, "bps_wr_max", "throttling.bps-write-max"); + qemu_opt_rename(all_opts, "readonly", "read-only"); value = qemu_opt_get(all_opts, "cache"); @@ -1257,8 +1270,22 @@ void qmp_change_blockdev(const char *device, const char *filename, /* throttling disk I/O limits */ void qmp_block_set_io_throttle(const char *device, int64_t bps, int64_t bps_rd, - int64_t bps_wr, int64_t iops, int64_t iops_rd, - int64_t iops_wr, Error **errp) + int64_t bps_wr, + int64_t iops, + int64_t iops_rd, + int64_t iops_wr, + bool has_bps_max, + int64_t bps_max, + bool has_bps_rd_max, + int64_t bps_rd_max, + bool has_bps_wr_max, + int64_t bps_wr_max, + bool has_iops_max, + int64_t iops_max, + bool has_iops_rd_max, + int64_t iops_rd_max, + bool has_iops_wr_max, + int64_t iops_wr_max, Error **errp) { ThrottleConfig cfg; BlockDriverState *bs; @@ -1269,6 +1296,7 @@ void qmp_block_set_io_throttle(const char *device, int64_t bps, int64_t bps_rd, return; } + memset(&cfg, 0, sizeof(cfg)); cfg.buckets[THROTTLE_BPS_TOTAL].ups = bps; cfg.buckets[THROTTLE_BPS_READ].ups = bps_rd; cfg.buckets[THROTTLE_BPS_WRITE].ups = bps_wr; @@ -1277,13 +1305,24 @@ void qmp_block_set_io_throttle(const char *device, int64_t bps, int64_t bps_rd, cfg.buckets[THROTTLE_OPS_READ].ups = iops_rd; cfg.buckets[THROTTLE_OPS_WRITE].ups = iops_wr; - cfg.buckets[THROTTLE_BPS_TOTAL].max = 0; - cfg.buckets[THROTTLE_BPS_READ].max = 0; - cfg.buckets[THROTTLE_BPS_WRITE].max = 0; - - cfg.buckets[THROTTLE_OPS_TOTAL].max = 0; - cfg.buckets[THROTTLE_OPS_READ].max = 0; - cfg.buckets[THROTTLE_OPS_WRITE].max = 0; + if (has_bps_max) { + cfg.buckets[THROTTLE_BPS_TOTAL].max = bps_max; + } + if (has_bps_rd_max) { + cfg.buckets[THROTTLE_BPS_READ].max = bps_rd_max; + } + if (has_bps_wr_max) { + cfg.buckets[THROTTLE_BPS_WRITE].max = bps_wr_max; + } + if (has_iops_max) { + cfg.buckets[THROTTLE_OPS_TOTAL].max = iops_max; + } + if (has_iops_rd_max) { + cfg.buckets[THROTTLE_OPS_READ].max = iops_rd_max; + } + if (has_iops_wr_max) { + cfg.buckets[THROTTLE_OPS_WRITE].max = iops_wr_max; + } cfg.unit_size = BDRV_SECTOR_SIZE; cfg.op_size = 0; @@ -1988,6 +2027,30 @@ QemuOptsList qemu_common_drive_opts = { .type = QEMU_OPT_NUMBER, .help = "limit write bytes per second", },{ + .name = "throttling.iops-total-max", + .type = QEMU_OPT_NUMBER, + .help = "I/O operations burst", + },{ + .name = "throttling.iops-read-max", + .type = QEMU_OPT_NUMBER, + .help = "I/O operations read burst", + },{ + .name = "throttling.iops-write-max", + .type = QEMU_OPT_NUMBER, + .help = "I/O operations write burst", + },{ + .name = "throttling.bps-total-max", + .type = QEMU_OPT_NUMBER, + .help = "total bytes burst", + },{ + .name = "throttling.bps-read-max", + .type = QEMU_OPT_NUMBER, + .help = "total bytes read burst", + },{ + .name = "throttling.bps-write-max", + .type = QEMU_OPT_NUMBER, + .help = "total bytes write burst", + },{ .name = "copy-on-read", .type = QEMU_OPT_BOOL, .help = "copy read data from backing file into image file", @@ -2110,6 +2173,30 @@ QemuOptsList qemu_old_drive_opts = { .type = QEMU_OPT_NUMBER, .help = "limit write bytes per second", },{ + .name = "iops_max", + .type = QEMU_OPT_NUMBER, + .help = "I/O operations burst", + },{ + .name = "iops_rd_max", + .type = QEMU_OPT_NUMBER, + .help = "I/O operations read burst", + },{ + .name = "iops_wr_max", + .type = QEMU_OPT_NUMBER, + .help = "I/O operations write burst", + },{ + .name = "bps_max", + .type = QEMU_OPT_NUMBER, + .help = "total bytes burst", + },{ + .name = "bps_rd_max", + .type = QEMU_OPT_NUMBER, + .help = "total bytes read burst", + },{ + .name = "bps_wr_max", + .type = QEMU_OPT_NUMBER, + .help = "total bytes write burst", + },{ .name = "copy-on-read", .type = QEMU_OPT_BOOL, .help = "copy read data from backing file into image file", diff --git a/hmp.c b/hmp.c index c45514b..e0c387c 100644 --- a/hmp.c +++ b/hmp.c @@ -344,14 +344,28 @@ void hmp_info_block(Monitor *mon, const QDict *qdict) { monitor_printf(mon, " I/O throttling: bps=%" PRId64 " bps_rd=%" PRId64 " bps_wr=%" PRId64 + " bps_max=%" PRId64 + " bps_rd_max=%" PRId64 + " bps_wr_max=%" PRId64 " iops=%" PRId64 " iops_rd=%" PRId64 - " iops_wr=%" PRId64 "\n", + " iops_wr=%" PRId64 + " iops_max=%" PRId64 + " iops_rd_max=%" PRId64 + " iops_wr_max=%" PRId64 "\n", info->value->inserted->bps, info->value->inserted->bps_rd, info->value->inserted->bps_wr, + info->value->inserted->bps_max, + info->value->inserted->bps_rd_max, + info->value->inserted->bps_wr_max, info->value->inserted->iops, info->value->inserted->iops_rd, - info->value->inserted->iops_wr); + info->value->inserted->iops_wr, + info->value->inserted->iops_max, + info->value->inserted->iops_rd_max, + info->value->inserted->iops_wr_max); + } else { + monitor_printf(mon, " [not inserted]"); } if (verbose) { @@ -1098,7 +1112,19 @@ void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) qdict_get_int(qdict, "bps_wr"), qdict_get_int(qdict, "iops"), qdict_get_int(qdict, "iops_rd"), - qdict_get_int(qdict, "iops_wr"), &err); + qdict_get_int(qdict, "iops_wr"), + false, /* no burst max via QMP */ + 0, + false, + 0, + false, + 0, + false, + 0, + false, + 0, + false, + 0, &err); hmp_handle_error(mon, &err); } diff --git a/qapi-schema.json b/qapi-schema.json index a51f7d2..5e5461e 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -785,6 +785,18 @@ # # @image: the info of image used (since: 1.6) # +# @bps_max: #optional total max in bytes (Since 1.7) +# +# @bps_rd_max: #optional read max in bytes (Since 1.7) +# +# @bps_wr_max: #optional write max in bytes (Since 1.7) +# +# @iops_max: #optional total I/O operations max (Since 1.7) +# +# @iops_rd_max: #optional read I/O operations max (Since 1.7) +# +# @iops_wr_max: #optional write I/O operations max (Since 1.7) +# # Since: 0.14.0 # # Notes: This interface is only found in @BlockInfo. @@ -795,7 +807,10 @@ 'encrypted': 'bool', 'encryption_key_missing': 'bool', 'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int', 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int', - 'image': 'ImageInfo' } } + 'image': 'ImageInfo', + '*bps_max': 'int', '*bps_rd_max': 'int', + '*bps_wr_max': 'int', '*iops_max': 'int', + '*iops_rd_max': 'int', '*iops_wr_max': 'int' }} ## # @BlockDeviceIoStatus: @@ -2174,6 +2189,18 @@ # # @iops_wr: write I/O operations per second # +# @bps_max: #optional total max in bytes (Since 1.7) +# +# @bps_rd_max: #optional read max in bytes (Since 1.7) +# +# @bps_wr_max: #optional write max in bytes (Since 1.7) +# +# @iops_max: #optional total I/O operations max (Since 1.7) +# +# @iops_rd_max: #optional read I/O operations max (Since 1.7) +# +# @iops_wr_max: #optional write I/O operations max (Since 1.7) +# # Returns: Nothing on success # If @device is not a valid block device, DeviceNotFound # @@ -2181,7 +2208,10 @@ ## { 'command': 'block_set_io_throttle', 'data': { 'device': 'str', 'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int', - 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int' } } + 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int', + '*bps_max': 'int', '*bps_rd_max': 'int', + '*bps_wr_max': 'int', '*iops_max': 'int', + '*iops_rd_max': 'int', '*iops_wr_max': 'int' }} ## # @block-stream: diff --git a/qemu-options.hx b/qemu-options.hx index d15338e..3aa8f9e 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -409,7 +409,9 @@ DEF("drive", HAS_ARG, QEMU_OPTION_drive, " [,cache=writethrough|writeback|none|directsync|unsafe][,format=f]\n" " [,serial=s][,addr=A][,id=name][,aio=threads|native]\n" " [,readonly=on|off][,copy-on-read=on|off]\n" - " [[,bps=b]|[[,bps_rd=r][,bps_wr=w]]][[,iops=i]|[[,iops_rd=r][,iops_wr=w]]\n" + " [[,bps=b]|[[,bps_rd=r][,bps_wr=w]]][[,iops=i]|[[,iops_rd=r]" + " [,iops_wr=w][,bps_max=bt]|[[,bps_rd_max=rt][,bps_wr_max=wt]]]" + " [[,iops_max=it]|[[,iops_rd_max=rt][,iops_wr_max=wt]]\n" " use 'file' as a drive image\n", QEMU_ARCH_ALL) STEXI @item -drive @var{option}[,@var{option}[,@var{option}[,...]]] diff --git a/qmp-commands.hx b/qmp-commands.hx index 2e59b0d..1610831 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -1389,7 +1389,7 @@ EQMP { .name = "block_set_io_throttle", - .args_type = "device:B,bps:l,bps_rd:l,bps_wr:l,iops:l,iops_rd:l,iops_wr:l", + .args_type = "device:B,bps:l,bps_rd:l,bps_wr:l,iops:l,iops_rd:l,iops_wr:l,bps_max:l?,bps_rd_max:l?,bps_wr_max:l?,iops_max:l?,iops_rd_max:l?,iops_wr_max:l?", .mhandler.cmd_new = qmp_marshal_input_block_set_io_throttle, }, @@ -1404,10 +1404,16 @@ Arguments: - "device": device name (json-string) - "bps": total throughput limit in bytes per second(json-int) - "bps_rd": read throughput limit in bytes per second(json-int) -- "bps_wr": read throughput limit in bytes per second(json-int) +- "bps_wr": write throughput limit in bytes per second(json-int) - "iops": total I/O operations per second(json-int) - "iops_rd": read I/O operations per second(json-int) - "iops_wr": write I/O operations per second(json-int) +- "bps_max": total max in bytes(json-int) +- "bps_rd_max": read max in bytes(json-int) +- "bps_wr_max": write max in bytes(json-int) +- "iops_max": total I/O operations max(json-int) +- "iops_rd_max": read I/O operations max(json-int) +- "iops_wr_max": write I/O operations max(json-int) Example: @@ -1417,7 +1423,13 @@ Example: "bps_wr": "0", "iops": "0", "iops_rd": "0", - "iops_wr": "0" } } + "iops_wr": "0", + "bps_max": "8000000", + "bps_rd_max": "0", + "bps_wr_max": "0", + "iops_max": "0", + "iops_rd_max": "0", + "iops_wr_max": "0" } } <- { "return": {} } EQMP @@ -1758,6 +1770,12 @@ Each json-object contain the following: - "iops": limit total I/O operations per second (json-int) - "iops_rd": limit read operations per second (json-int) - "iops_wr": limit write operations per second (json-int) + - "bps_max": total max in bytes(json-int) + - "bps_rd_max": read max in bytes(json-int) + - "bps_wr_max": write max in bytes(json-int) + - "iops_max": total I/O operations max(json-int) + - "iops_rd_max": read I/O operations max(json-int) + - "iops_wr_max": write I/O operations max(json-int) - "image": the detail of the image, it is a json-object containing the following: - "filename": image file name (json-string) @@ -1827,6 +1845,12 @@ Example: "iops":1000000, "iops_rd":0, "iops_wr":0, + "bps_max": "8000000", + "bps_rd_max": "0", + "bps_wr_max": "0", + "iops_max": "0", + "iops_rd_max": "0", + "iops_wr_max": "0", "image":{ "filename":"disks/test.qcow2", "format":"qcow2",