From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43460) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V1fRr-0005h4-4e for qemu-devel@nongnu.org; Tue, 23 Jul 2013 12:28:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V1fRm-0000TF-6g for qemu-devel@nongnu.org; Tue, 23 Jul 2013 12:28:27 -0400 Received: from nodalink.pck.nerim.net ([62.212.105.220]:47659 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V1fRl-0000Sv-6p for qemu-devel@nongnu.org; Tue, 23 Jul 2013 12:28:22 -0400 From: =?UTF-8?q?Beno=C3=AEt=20Canet?= Date: Tue, 23 Jul 2013 18:29:26 +0200 Message-Id: <1374596968-20181-4-git-send-email-benoit@irqsave.net> In-Reply-To: <1374596968-20181-1-git-send-email-benoit@irqsave.net> References: <1374596968-20181-1-git-send-email-benoit@irqsave.net> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] =?utf-8?q?=5BPATCH_V3_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?= List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, =?UTF-8?q?Beno=C3=AEt=20Canet?= , stefanha@redhat.com 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 =3D bs->io_limits.iops[BLOCK_IO_LIMIT_WRITE]; + info->inserted->has_bps_threshold =3D + bs->io_limits.bps_threshold[BLOCK_IO_LIMIT_TO= TAL]; + info->inserted->bps_threshold =3D + bs->io_limits.bps_threshold[BLOCK_IO_LIMIT_TO= TAL]; + info->inserted->has_bps_rd_threshold =3D + bs->io_limits.bps_threshold[BLOCK_IO_LIMIT_RE= AD]; + info->inserted->bps_rd_threshold =3D + bs->io_limits.bps_threshold[BLOCK_IO_LIMIT_RE= AD]; + info->inserted->has_bps_wr_threshold =3D + bs->io_limits.bps_threshold[BLOCK_IO_LIMIT_WR= ITE]; + info->inserted->bps_wr_threshold =3D + bs->io_limits.bps_threshold[BLOCK_IO_LIMIT_WR= ITE]; + info->inserted->has_iops_threshold =3D + bs->io_limits.iops_threshold[BLOCK_IO_LIMIT_T= OTAL]; + info->inserted->iops_threshold =3D + bs->io_limits.iops_threshold[BLOCK_IO_LIMIT_T= OTAL]; + info->inserted->iops_rd_threshold =3D + bs->io_limits.iops_threshold[BLOCK_IO_LIMIT_R= EAD]; + info->inserted->has_iops_rd_threshold =3D + bs->io_limits.iops_threshold[BLOCK_IO_LIMIT_R= EAD]; + info->inserted->has_iops_wr_threshold =3D + bs->io_limits.iops_threshold[BLOCK_IO_LIMIT_W= RITE]; + info->inserted->iops_wr_threshold =3D + bs->io_limits.iops_threshold[BLOCK_IO_LIMIT_W= RITE]; } =20 bs0 =3D bs; diff --git a/blockdev.c b/blockdev.c index 491e4d0..241ebe8 100644 --- a/blockdev.c +++ b/blockdev.c @@ -341,6 +341,17 @@ static bool do_check_io_limits(BlockIOLimit *io_limi= ts, Error **errp) return false; } =20 + 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; } =20 @@ -523,24 +534,34 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInte= rfaceType block_default_type) qemu_opt_get_number(opts, "bps_rd", 0); io_limits.bps[BLOCK_IO_LIMIT_WRITE] =3D qemu_opt_get_number(opts, "bps_wr", 0); + /* bps thresholds */ + io_limits.bps_threshold[BLOCK_IO_LIMIT_TOTAL] =3D + qemu_opt_get_number(opts, "bps_threshold", + io_limits.bps[BLOCK_IO_LIMIT_TOTAL] / THROTT= LE_HZ); + io_limits.bps_threshold[BLOCK_IO_LIMIT_READ] =3D + qemu_opt_get_number(opts, "bps_rd_threshold", + io_limits.bps[BLOCK_IO_LIMIT_READ] / THROTTL= E_HZ); + io_limits.bps_threshold[BLOCK_IO_LIMIT_WRITE] =3D + qemu_opt_get_number(opts, "bps_wr_threshold", + io_limits.bps[BLOCK_IO_LIMIT_WRITE] / THROTT= LE_HZ); + io_limits.iops[BLOCK_IO_LIMIT_TOTAL] =3D qemu_opt_get_number(opts, "iops", 0); io_limits.iops[BLOCK_IO_LIMIT_READ] =3D qemu_opt_get_number(opts, "iops_rd", 0); io_limits.iops[BLOCK_IO_LIMIT_WRITE] =3D qemu_opt_get_number(opts, "iops_wr", 0); - io_limits.bps_threshold[BLOCK_IO_LIMIT_TOTAL] =3D - io_limits.bps[BLOCK_IO_LIMIT_TOTAL] / THROTTL= E_HZ; - io_limits.bps_threshold[BLOCK_IO_LIMIT_READ] =3D - io_limits.bps[BLOCK_IO_LIMIT_READ] / THROTTLE= _HZ; - io_limits.bps_threshold[BLOCK_IO_LIMIT_WRITE] =3D - io_limits.bps[BLOCK_IO_LIMIT_WRITE] / THROTTL= E_HZ; - io_limits.iops_threshold[BLOCK_IO_LIMIT_TOTAL] =3D - io_limits.iops[BLOCK_IO_LIMIT_TOTAL] / THROTT= LE_HZ; + + /* iops thresholds */ + io_limits.iops_threshold[BLOCK_IO_LIMIT_TOTAL] =3D + qemu_opt_get_number(opts, "iops_threshold", + io_limits.iops[BLOCK_IO_LIMIT_TOTAL] / THROT= TLE_HZ); io_limits.iops_threshold[BLOCK_IO_LIMIT_READ] =3D - io_limits.iops[BLOCK_IO_LIMIT_READ] / THROTTL= E_HZ; - io_limits.iops_threshold[BLOCK_IO_LIMIT_WRITE] =3D - io_limits.iops[BLOCK_IO_LIMIT_WRITE] / THROTT= LE_HZ; + qemu_opt_get_number(opts, "iops_rd_threshold", + io_limits.iops[BLOCK_IO_LIMIT_READ] / THROTT= LE_HZ); + io_limits.iops_threshold[BLOCK_IO_LIMIT_WRITE] =3D + qemu_opt_get_number(opts, "iops_wr_threshold", + io_limits.iops[BLOCK_IO_LIMIT_WRITE] / THROT= TLE_HZ); =20 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, =20 /* 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 iop= s_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] =3D iops_rd / THROTTL= E_HZ; io_limits.iops_threshold[BLOCK_IO_LIMIT_WRITE] =3D iops_wr / THROTTL= E_HZ; =20 + /* override them with givens values if present */ + if (has_bps_threshold) { + io_limits.bps_threshold[BLOCK_IO_LIMIT_TOTAL] =3D bps_threshold; + } + if (has_bps_rd_threshold) { + io_limits.bps_threshold[BLOCK_IO_LIMIT_READ] =3D bps_rd_threshol= d; + } + if (has_bps_wr_threshold) { + io_limits.bps_threshold[BLOCK_IO_LIMIT_WRITE] =3D bps_wr_thresho= ld; + } + if (has_iops_threshold) { + io_limits.iops_threshold[BLOCK_IO_LIMIT_TOTAL] =3D iops_threshol= d; + } + if (has_iops_rd_threshold) { + io_limits.iops_threshold[BLOCK_IO_LIMIT_READ] =3D iops_rd_thresh= old; + } + if (has_iops_wr_threshold) { + io_limits.iops_threshold[BLOCK_IO_LIMIT_WRITE] =3D iops_wr_thres= hold; + } + if (!do_check_io_limits(&io_limits, errp)) { return; } @@ -1916,6 +1971,18 @@ QemuOptsList qemu_common_drive_opts =3D { .type =3D QEMU_OPT_NUMBER, .help =3D "limit write operations per second", },{ + .name =3D "iops_threshold", + .type =3D QEMU_OPT_NUMBER, + .help =3D "total I/O operations threshold", + },{ + .name =3D "iops_rd_threshold", + .type =3D QEMU_OPT_NUMBER, + .help =3D "read operations threshold", + },{ + .name =3D "iops_wr_threshold", + .type =3D QEMU_OPT_NUMBER, + .help =3D "write operations threshold", + },{ .name =3D "bps", .type =3D QEMU_OPT_NUMBER, .help =3D "limit total bytes per second", @@ -1928,6 +1995,18 @@ QemuOptsList qemu_common_drive_opts =3D { .type =3D QEMU_OPT_NUMBER, .help =3D "limit write bytes per second", },{ + .name =3D "bps_threshold", + .type =3D QEMU_OPT_NUMBER, + .help =3D "total bytes threshold", + },{ + .name =3D "bps_rd_threshold", + .type =3D QEMU_OPT_NUMBER, + .help =3D "read bytes threshold", + },{ + .name =3D "bps_wr_threshold", + .type =3D QEMU_OPT_NUMBER, + .help =3D "write bytes threshold", + },{ .name =3D "copy-on-read", .type =3D QEMU_OPT_BOOL, .help =3D "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 *qdic= t) { monitor_printf(mon, " I/O throttling: bps=3D%" PRId64 " bps_rd=3D%" PRId64 " bps_wr=3D%" PRId64 + " bps_threshold=3D%" PRId64 + " bps_rd_threshold=3D%" PRId64 + " bps_wr_threshold=3D%" PRId64 " iops=3D%" PRId64 " iops_rd=3D%" PRId64 - " iops_wr=3D%" PRId64 "\n", + " iops_wr=3D%" PRId64 + " iops_threshold=3D%" PRId64 + " iops_rd_threshold=3D%" PRId64 + " iops_wr_threshold=3D%" 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]"); } =20 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); } =20 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' }} =20 ## # @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': 'i= nt', - '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' }} =20 ## # @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=3Dwritethrough|writeback|none|directsync|unsafe][,fo= rmat=3Df]\n" " [,serial=3Ds][,addr=3DA][,id=3Dname][,aio=3Dthreads|native]\= n" " [,readonly=3Don|off][,copy-on-read=3Don|off]\n" - " [[,bps=3Db]|[[,bps_rd=3Dr][,bps_wr=3Dw]]][[,iops=3Di]|[[,iop= s_rd=3Dr][,iops_wr=3Dw]]\n" + " [[,bps=3Db]|[[,bps_rd=3Dr][,bps_wr=3Dw]]][[,iops=3Di]|[[,iop= s_rd=3Dr][,iops_wr=3Dw][,bps_threshold=3Dbt]|[[,bps_rd_threshold=3Drt][,b= ps_wr_threshold=3Dwt]]][[,iops_threshold=3Dit]|[[,iops_rd_threshold=3Drt]= [,iops_wr_threshold=3Dwt]]\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 =20 { .name =3D "block_set_io_throttle", - .args_type =3D "device:B,bps:l,bps_rd:l,bps_wr:l,iops:l,iops_rd= :l,iops_wr:l", + .args_type =3D "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?,iop= s_threshold:l?,iops_rd_threshold:l?,iops_wr_threshold:l?", .mhandler.cmd_new =3D qmp_marshal_input_block_set_io_throttle, }, =20 @@ -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) =20 Example: =20 @@ -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" = }=C2=A0} <- { "return": {} } =20 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 contain= ing 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", --=20 1.7.10.4