From patchwork Tue Jul 23 12:21:05 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: 261059 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 A189A2C0097 for ; Tue, 23 Jul 2013 22:21:32 +1000 (EST) Received: from localhost ([::1]:37699 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V1bar-0006Ok-Bq for incoming@patchwork.ozlabs.org; Tue, 23 Jul 2013 08:21:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40332) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V1bZZ-0005S5-3N for qemu-devel@nongnu.org; Tue, 23 Jul 2013 08:20:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V1bZU-0008Io-Pg for qemu-devel@nongnu.org; Tue, 23 Jul 2013 08:20:09 -0400 Received: from nodalink.pck.nerim.net ([62.212.105.220]:47406 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V1bZT-0008Es-Pq for qemu-devel@nongnu.org; Tue, 23 Jul 2013 08:20:04 -0400 Received: by paradis.irqsave.net (Postfix, from userid 1002) id 2C533874679; Tue, 23 Jul 2013 14:20:03 +0200 (CEST) Received: from localhost.localdomain (unknown [192.168.77.1]) by paradis.irqsave.net (Postfix) with ESMTP id CF9B6874671; Tue, 23 Jul 2013 14:19:19 +0200 (CEST) From: =?UTF-8?q?Beno=C3=AEt=20Canet?= To: qemu-devel@nongnu.org Date: Tue, 23 Jul 2013 14:21:05 +0200 Message-Id: <1374582067-9063-4-git-send-email-benoit@irqsave.net> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1374582067-9063-1-git-send-email-benoit@irqsave.net> References: <1374582067-9063-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, =?UTF-8?q?Beno=C3=AEt=20Canet?= , stefanha@redhat.com Subject: [Qemu-devel] =?utf-8?q?=5BPATCH_V2_for-1=2E6_3/5=5D_block=3A_Add_?= =?utf-8?q?support_for_throttling_burst_threshold_in_QMP_and_the_co?= =?utf-8?q?mmand_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 thresholds of the leaky bucket algorithm can be used to allow some burstiness. Signed-off-by: Benoit Canet --- block/qapi.c | 24 +++++++++++++ blockdev.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++------- hmp.c | 32 +++++++++++++++-- qapi-schema.json | 34 ++++++++++++++++-- qemu-options.hx | 2 +- qmp-commands.hx | 30 ++++++++++++++-- 6 files changed, 205 insertions(+), 22 deletions(-) diff --git a/block/qapi.c b/block/qapi.c index a4bc411..03f1604 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -235,6 +235,30 @@ void bdrv_query_info(BlockDriverState *bs, bs->io_limits.iops[BLOCK_IO_LIMIT_READ]; info->inserted->iops_wr = bs->io_limits.iops[BLOCK_IO_LIMIT_WRITE]; + info->inserted->has_bps_threshold = + bs->io_limits.bps_threshold[BLOCK_IO_LIMIT_TOTAL]; + info->inserted->bps_threshold = + bs->io_limits.bps_threshold[BLOCK_IO_LIMIT_TOTAL]; + info->inserted->has_bps_rd_threshold = + bs->io_limits.bps_threshold[BLOCK_IO_LIMIT_READ]; + info->inserted->bps_rd_threshold = + bs->io_limits.bps_threshold[BLOCK_IO_LIMIT_READ]; + info->inserted->has_bps_wr_threshold = + bs->io_limits.bps_threshold[BLOCK_IO_LIMIT_WRITE]; + info->inserted->bps_wr_threshold = + bs->io_limits.bps_threshold[BLOCK_IO_LIMIT_WRITE]; + info->inserted->has_iops_threshold = + bs->io_limits.iops_threshold[BLOCK_IO_LIMIT_TOTAL]; + info->inserted->iops_threshold = + bs->io_limits.iops_threshold[BLOCK_IO_LIMIT_TOTAL]; + info->inserted->iops_rd_threshold = + bs->io_limits.iops_threshold[BLOCK_IO_LIMIT_READ]; + info->inserted->has_iops_rd_threshold = + bs->io_limits.iops_threshold[BLOCK_IO_LIMIT_READ]; + info->inserted->has_iops_wr_threshold = + bs->io_limits.iops_threshold[BLOCK_IO_LIMIT_WRITE]; + info->inserted->iops_wr_threshold = + bs->io_limits.iops_threshold[BLOCK_IO_LIMIT_WRITE]; } bs0 = bs; diff --git a/blockdev.c b/blockdev.c index a78fba4..9bda359 100644 --- a/blockdev.c +++ b/blockdev.c @@ -341,6 +341,17 @@ static bool do_check_io_limits(BlockIOLimit *io_limits, Error **errp) return false; } + if (io_limits->bps_threshold[BLOCK_IO_LIMIT_TOTAL] < 0 || + io_limits->bps_threshold[BLOCK_IO_LIMIT_WRITE] < 0 || + io_limits->bps_threshold[BLOCK_IO_LIMIT_READ] < 0 || + io_limits->iops_threshold[BLOCK_IO_LIMIT_TOTAL] < 0 || + io_limits->iops_threshold[BLOCK_IO_LIMIT_WRITE] < 0 || + io_limits->iops_threshold[BLOCK_IO_LIMIT_READ] < 0) { + error_setg(errp, + "threshold values must be 0 or greater"); + return false; + } + return true; } @@ -523,24 +534,34 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) qemu_opt_get_number(opts, "bps_rd", 0); io_limits.bps[BLOCK_IO_LIMIT_WRITE] = qemu_opt_get_number(opts, "bps_wr", 0); + /* bps thresholds */ + io_limits.bps_threshold[BLOCK_IO_LIMIT_TOTAL] = + qemu_opt_get_number(opts, "bps_threshold", + io_limits.bps[BLOCK_IO_LIMIT_TOTAL] / THROTTLE_HZ); + io_limits.bps_threshold[BLOCK_IO_LIMIT_READ] = + qemu_opt_get_number(opts, "bps_rd_threshold", + io_limits.bps[BLOCK_IO_LIMIT_READ] / THROTTLE_HZ); + io_limits.bps_threshold[BLOCK_IO_LIMIT_WRITE] = + qemu_opt_get_number(opts, "bps_wr_threshold", + io_limits.bps[BLOCK_IO_LIMIT_WRITE] / THROTTLE_HZ); + io_limits.iops[BLOCK_IO_LIMIT_TOTAL] = qemu_opt_get_number(opts, "iops", 0); io_limits.iops[BLOCK_IO_LIMIT_READ] = qemu_opt_get_number(opts, "iops_rd", 0); io_limits.iops[BLOCK_IO_LIMIT_WRITE] = qemu_opt_get_number(opts, "iops_wr", 0); - io_limits.bps_threshold[BLOCK_IO_LIMIT_TOTAL] = - io_limits.bps[BLOCK_IO_LIMIT_TOTAL] / THROTTLE_HZ; - io_limits.bps_threshold[BLOCK_IO_LIMIT_READ] = - io_limits.bps[BLOCK_IO_LIMIT_READ] / THROTTLE_HZ; - io_limits.bps_threshold[BLOCK_IO_LIMIT_WRITE] = - io_limits.bps[BLOCK_IO_LIMIT_WRITE] / THROTTLE_HZ; - io_limits.iops_threshold[BLOCK_IO_LIMIT_TOTAL] = - io_limits.iops[BLOCK_IO_LIMIT_TOTAL] / THROTTLE_HZ; + + /* iops thresholds */ + io_limits.iops_threshold[BLOCK_IO_LIMIT_TOTAL] = + qemu_opt_get_number(opts, "iops_threshold", + io_limits.iops[BLOCK_IO_LIMIT_TOTAL] / THROTTLE_HZ); io_limits.iops_threshold[BLOCK_IO_LIMIT_READ] = - io_limits.iops[BLOCK_IO_LIMIT_READ] / THROTTLE_HZ; - io_limits.iops_threshold[BLOCK_IO_LIMIT_WRITE] = - io_limits.iops[BLOCK_IO_LIMIT_WRITE] / THROTTLE_HZ; + qemu_opt_get_number(opts, "iops_rd_threshold", + io_limits.iops[BLOCK_IO_LIMIT_READ] / THROTTLE_HZ); + io_limits.iops_threshold[BLOCK_IO_LIMIT_WRITE] = + qemu_opt_get_number(opts, "iops_wr_threshold", + io_limits.iops[BLOCK_IO_LIMIT_WRITE] / THROTTLE_HZ); if (!do_check_io_limits(&io_limits, &error)) { error_report("%s", error_get_pretty(error)); @@ -1224,8 +1245,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_threshold, + int64_t bps_threshold, + bool has_bps_rd_threshold, + int64_t bps_rd_threshold, + bool has_bps_wr_threshold, + int64_t bps_wr_threshold, + bool has_iops_threshold, + int64_t iops_threshold, + bool has_iops_rd_threshold, + int64_t iops_rd_threshold, + bool has_iops_wr_threshold, + int64_t iops_wr_threshold, Error **errp) { BlockIOLimit io_limits; BlockDriverState *bs; @@ -1249,6 +1284,26 @@ void qmp_block_set_io_throttle(const char *device, int64_t bps, int64_t bps_rd, io_limits.iops_threshold[BLOCK_IO_LIMIT_READ] = iops_rd / THROTTLE_HZ; io_limits.iops_threshold[BLOCK_IO_LIMIT_WRITE] = iops_wr / THROTTLE_HZ; + /* override them with givens values if present */ + if (has_bps_threshold) { + io_limits.bps_threshold[BLOCK_IO_LIMIT_TOTAL] = bps_threshold; + } + if (has_bps_rd_threshold) { + io_limits.bps_threshold[BLOCK_IO_LIMIT_READ] = bps_rd_threshold; + } + if (has_bps_wr_threshold) { + io_limits.bps_threshold[BLOCK_IO_LIMIT_WRITE] = bps_wr_threshold; + } + if (has_iops_threshold) { + io_limits.iops_threshold[BLOCK_IO_LIMIT_TOTAL] = iops_threshold; + } + if (has_iops_rd_threshold) { + io_limits.iops_threshold[BLOCK_IO_LIMIT_READ] = iops_rd_threshold; + } + if (has_iops_wr_threshold) { + io_limits.iops_threshold[BLOCK_IO_LIMIT_WRITE] = iops_wr_threshold; + } + if (!do_check_io_limits(&io_limits, errp)) { return; } @@ -1916,6 +1971,18 @@ QemuOptsList qemu_common_drive_opts = { .type = QEMU_OPT_NUMBER, .help = "limit write operations per second", },{ + .name = "iops_threshold", + .type = QEMU_OPT_NUMBER, + .help = "total I/O operations threshold", + },{ + .name = "iops_rd_threshold", + .type = QEMU_OPT_NUMBER, + .help = "read operations threshold", + },{ + .name = "iops_wr_threshold", + .type = QEMU_OPT_NUMBER, + .help = "write operations threshold", + },{ .name = "bps", .type = QEMU_OPT_NUMBER, .help = "limit total bytes per second", @@ -1928,6 +1995,18 @@ QemuOptsList qemu_common_drive_opts = { .type = QEMU_OPT_NUMBER, .help = "limit write bytes per second", },{ + .name = "bps_threshold", + .type = QEMU_OPT_NUMBER, + .help = "total bytes threshold", + },{ + .name = "bps_rd_threshold", + .type = QEMU_OPT_NUMBER, + .help = "read bytes threshold", + },{ + .name = "bps_wr_threshold", + .type = QEMU_OPT_NUMBER, + .help = "write bytes threshold", + },{ .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 dc4d8d4..d75aa99 100644 --- a/hmp.c +++ b/hmp.c @@ -340,14 +340,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_threshold=%" PRId64 + " bps_rd_threshold=%" PRId64 + " bps_wr_threshold=%" PRId64 " iops=%" PRId64 " iops_rd=%" PRId64 - " iops_wr=%" PRId64 "\n", + " iops_wr=%" PRId64 + " iops_threshold=%" PRId64 + " iops_rd_threshold=%" PRId64 + " iops_wr_threshold=%" PRId64 "\n", info->value->inserted->bps, info->value->inserted->bps_rd, info->value->inserted->bps_wr, + info->value->inserted->bps_threshold, + info->value->inserted->bps_rd_threshold, + info->value->inserted->bps_wr_threshold, info->value->inserted->iops, info->value->inserted->iops_rd, - info->value->inserted->iops_wr); + info->value->inserted->iops_wr, + info->value->inserted->iops_threshold, + info->value->inserted->iops_rd_threshold, + info->value->inserted->iops_wr_threshold); + } else { + monitor_printf(mon, " [not inserted]"); } if (verbose) { @@ -1094,7 +1108,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 threshold 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 7b9fef1..a6f3792 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -769,6 +769,18 @@ # # @image: the info of image used (since: 1.6) # +# @bps_threshold: #optional total threshold in bytes (Since 1.6) +# +# @bps_rd_threshold: #optional read threshold in bytes (Since 1.6) +# +# @bps_wr_threshold: #optional write threshold in bytes (Since 1.6) +# +# @iops_threshold: #optional total I/O operations threshold (Since 1.6) +# +# @iops_rd_threshold: #optional read I/O operations threshold (Since 1.6) +# +# @iops_wr_threshold: #optional write I/O operations threshold (Since 1.6) +# # Since: 0.14.0 # # Notes: This interface is only found in @BlockInfo. @@ -779,7 +791,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_threshold': 'int', '*bps_rd_threshold': 'int', + '*bps_wr_threshold': 'int', '*iops_threshold': 'int', + '*iops_rd_threshold': 'int', '*iops_wr_threshold': 'int' }} ## # @BlockDeviceIoStatus: @@ -2158,6 +2173,18 @@ # # @iops_wr: write I/O operations per second # +# @bps_threshold: #optional total threshold in bytes (Since 1.6) +# +# @bps_rd_threshold: #optional read threshold in bytes (Since 1.6) +# +# @bps_wr_threshold: #optional write threshold in bytes (Since 1.6) +# +# @iops_threshold: #optional total I/O operations threshold (Since 1.6) +# +# @iops_rd_threshold: #optional read I/O operations threshold (Since 1.6) +# +# @iops_wr_threshold: #optional write I/O operations threshold (Since 1.6) +# # Returns: Nothing on success # If @device is not a valid block device, DeviceNotFound # @@ -2165,7 +2192,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_threshold': 'int', '*bps_rd_threshold': 'int', + '*bps_wr_threshold': 'int', '*iops_threshold': 'int', + '*iops_rd_threshold': 'int', '*iops_wr_threshold': 'int' }} ## # @block-stream: diff --git a/qemu-options.hx b/qemu-options.hx index 4e98b4f..4d5ee66 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -409,7 +409,7 @@ 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_threshold=bt]|[[,bps_rd_threshold=rt][,bps_wr_threshold=wt]]][[,iops_threshold=it]|[[,iops_rd_threshold=rt][,iops_wr_threshold=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 e075df4..11c638a 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -1385,7 +1385,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_threshold:l?,bps_rd_threshold:l?,bps_wr_threshold:l?,iops_threshold:l?,iops_rd_threshold:l?,iops_wr_threshold:l?", .mhandler.cmd_new = qmp_marshal_input_block_set_io_throttle, }, @@ -1400,10 +1400,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_threshold": total threshold in bytes(json-int) +- "bps_rd_threshold": read threshold in bytes(json-int) +- "bps_wr_threshold": write threshold in bytes(json-int) +- "iops_threshold": total I/O operations threshold(json-int) +- "iops_rd_threshold": read I/O operations threshold(json-int) +- "iops_wr_threshold": write I/O operations threshold(json-int) Example: @@ -1413,7 +1419,13 @@ Example: "bps_wr": "0", "iops": "0", "iops_rd": "0", - "iops_wr": "0" } } + "iops_wr": "0", + "bps_threshold": "8000000", + "bps_rd_threshold": "0", + "bps_wr_threshold": "0", + "iops_threshold": "0", + "iops_rd_threshold": "0", + "iops_wr_threshold": "0" } } <- { "return": {} } EQMP @@ -1754,6 +1766,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_threshold": total threshold in bytes(json-int) + - "bps_rd_threshold": read threshold in bytes(json-int) + - "bps_wr_threshold": write threshold in bytes(json-int) + - "iops_threshold": total I/O operations threshold(json-int) + - "iops_rd_threshold": read I/O operations threshold(json-int) + - "iops_wr_threshold": write I/O operations threshold(json-int) - "image": the detail of the image, it is a json-object containing the following: - "filename": image file name (json-string) @@ -1823,6 +1841,12 @@ Example: "iops":1000000, "iops_rd":0, "iops_wr":0, + "bps_threshold": "8000000", + "bps_rd_threshold": "0", + "bps_wr_threshold": "0", + "iops_threshold": "0", + "iops_rd_threshold": "0", + "iops_wr_threshold": "0", "image":{ "filename":"disks/test.qcow2", "format":"qcow2",