From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47734) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V1FVb-00008C-7f for qemu-devel@nongnu.org; Mon, 22 Jul 2013 08:46:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V1FII-0007EE-CB for qemu-devel@nongnu.org; Mon, 22 Jul 2013 08:33:01 -0400 Received: from nodalink.pck.nerim.net ([62.212.105.220]:46696 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V1FIH-0007Ds-Cu for qemu-devel@nongnu.org; Mon, 22 Jul 2013 08:32:50 -0400 From: =?UTF-8?q?Beno=C3=AEt=20Canet?= Date: Mon, 22 Jul 2013 14:33:26 +0200 Message-Id: <1374496406-27205-5-git-send-email-benoit@irqsave.net> In-Reply-To: <1374496406-27205-1-git-send-email-benoit@irqsave.net> References: <1374496406-27205-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_4/4=5D_block=3A_Add_iops=5Fsector?= =?utf-8?q?=5Fcount_to_do_the_iops_accounting_for_a_given_io_size?= =?utf-8?q?=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 This feature can be used in case where users are avoiding the iops limit = by doing jumbo I/Os hammering the storage backend. Signed-off-by: Benoit Canet --- block.c | 8 +++++++- block/qapi.c | 4 ++++ blockdev.c | 22 +++++++++++++++++++++- hmp.c | 8 ++++++-- include/block/block_int.h | 1 + qapi-schema.json | 10 ++++++++-- qemu-options.hx | 2 +- qmp-commands.hx | 8 ++++++-- 8 files changed, 54 insertions(+), 9 deletions(-) diff --git a/block.c b/block.c index 2d6e9b4..cfa890d 100644 --- a/block.c +++ b/block.c @@ -337,6 +337,12 @@ static bool bdrv_is_any_threshold_exceeded(BlockDriv= erState *bs, int nb_sectors, bool is_write) { bool bps_ret, iops_ret; + double ios =3D 1.0; + + if (bs->io_limits.iops_sector_count) { + ios =3D ((double) nb_sectors) / bs->io_limits.iops_sector_count; + ios =3D MAX(ios, 1.0); + } =20 /* check if any bandwith or per IO threshold has been exceeded */ bps_ret =3D bdrv_is_bps_threshold_exceeded(bs, is_write); @@ -360,7 +366,7 @@ static bool bdrv_is_any_threshold_exceeded(BlockDrive= rState *bs, int nb_sectors, /* the IO is authorized so do the accounting and return false */ bs->leaky_buckets.bytes[is_write] +=3D (int64_t)nb_sectors * BDRV_SECTOR_SIZE; - bs->leaky_buckets.ios[is_write]++; + bs->leaky_buckets.ios[is_write] +=3D ios; =20 return false; } diff --git a/block/qapi.c b/block/qapi.c index 03f1604..f81081c 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -259,6 +259,10 @@ void bdrv_query_info(BlockDriverState *bs, 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]; + info->inserted->has_iops_sector_count =3D + bs->io_limits.iops_sector_count; + info->inserted->iops_sector_count =3D + bs->io_limits.iops_sector_count; } =20 bs0 =3D bs; diff --git a/blockdev.c b/blockdev.c index 9bda359..8ddd710 100644 --- a/blockdev.c +++ b/blockdev.c @@ -352,6 +352,11 @@ static bool do_check_io_limits(BlockIOLimit *io_limi= ts, Error **errp) return false; } =20 + if (io_limits->iops_sector_count < 0) { + error_setg(errp, "iops_sector_count must be 0 or greater"); + return false; + } + return true; } =20 @@ -563,6 +568,10 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInter= faceType block_default_type) qemu_opt_get_number(opts, "iops_wr_threshold", io_limits.iops[BLOCK_IO_LIMIT_WRITE] / THROT= TLE_HZ); =20 + io_limits.iops_sector_count =3D + qemu_opt_get_number(opts, "iops_sector_count"= , 0); +=20 + if (!do_check_io_limits(&io_limits, &error)) { error_report("%s", error_get_pretty(error)); error_free(error); @@ -1260,7 +1269,9 @@ void qmp_block_set_io_throttle(const char *device, = int64_t bps, int64_t bps_rd, bool has_iops_rd_threshold, int64_t iops_rd_threshold, bool has_iops_wr_threshold, - int64_t iops_wr_threshold, Error **errp) + int64_t iops_wr_threshold, + bool has_iops_sector_count, + int64_t iops_sector_count, Error **errp) { BlockIOLimit io_limits; BlockDriverState *bs; @@ -1283,6 +1294,7 @@ void qmp_block_set_io_throttle(const char *device, = int64_t bps, int64_t bps_rd, io_limits.iops_threshold[BLOCK_IO_LIMIT_TOTAL] =3D iops / THROTTLE_H= Z; 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; + io_limits.iops_sector_count =3D 0; =20 /* override them with givens values if present */ if (has_bps_threshold) { @@ -1304,6 +1316,10 @@ void qmp_block_set_io_throttle(const char *device,= int64_t bps, int64_t bps_rd, io_limits.iops_threshold[BLOCK_IO_LIMIT_WRITE] =3D iops_wr_thres= hold; } =20 + if (has_iops_sector_count) { + io_limits.iops_sector_count =3D iops_sector_count; + } + if (!do_check_io_limits(&io_limits, errp)) { return; } @@ -2007,6 +2023,10 @@ QemuOptsList qemu_common_drive_opts =3D { .type =3D QEMU_OPT_NUMBER, .help =3D "write bytes threshold", },{ + .name =3D "iops_sector_count", + .type =3D QEMU_OPT_NUMBER, + .help =3D "when limiting by iops max size of an I/O in secto= r", + },{ .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 d75aa99..3912305 100644 --- a/hmp.c +++ b/hmp.c @@ -347,7 +347,8 @@ void hmp_info_block(Monitor *mon, const QDict *qdict) " iops_wr=3D%" PRId64 " iops_threshold=3D%" PRId64 " iops_rd_threshold=3D%" PRId64 - " iops_wr_threshold=3D%" PRId64 "\n", + " iops_wr_threshold=3D%" PRId64 + " iops_sector_count=3D%" PRId64 "\n", info->value->inserted->bps, info->value->inserted->bps_rd, info->value->inserted->bps_wr, @@ -359,7 +360,8 @@ void hmp_info_block(Monitor *mon, const QDict *qdict) info->value->inserted->iops_wr, info->value->inserted->iops_threshold, info->value->inserted->iops_rd_threshold, - info->value->inserted->iops_wr_threshold); + info->value->inserted->iops_wr_threshold, + info->value->inserted->iops_sector_count); } else { monitor_printf(mon, " [not inserted]"); } @@ -1120,6 +1122,8 @@ void hmp_block_set_io_throttle(Monitor *mon, const = QDict *qdict) false, 0, false, + 0, + false, /* No default I/O size */ 0, &err); hmp_handle_error(mon, &err); } diff --git a/include/block/block_int.h b/include/block/block_int.h index e32ad1f..74d7503 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -76,6 +76,7 @@ typedef struct BlockIOLimit { int64_t iops[3]; int64_t bps_threshold[3]; int64_t iops_threshold[3]; + int64_t iops_sector_count; } BlockIOLimit; =20 typedef struct BlockIOBaseValue { diff --git a/qapi-schema.json b/qapi-schema.json index a6f3792..d579fda 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -781,6 +781,8 @@ # # @iops_wr_threshold: #optional write I/O operations threshold (Since 1.= 6) # +# @iops_sector_count: #optional an I/O size in sector (Since 1.6) +# # Since: 0.14.0 # # Notes: This interface is only found in @BlockInfo. @@ -794,7 +796,8 @@ 'image': 'ImageInfo', '*bps_threshold': 'int', '*bps_rd_threshold': 'int', '*bps_wr_threshold': 'int', '*iops_threshold': 'int', - '*iops_rd_threshold': 'int', '*iops_wr_threshold': 'int' }} + '*iops_rd_threshold': 'int', '*iops_wr_threshold': 'int', + '*iops_sector_count': 'int' } } =20 ## # @BlockDeviceIoStatus: @@ -2185,6 +2188,8 @@ # # @iops_wr_threshold: #optional write I/O operations threshold (Since 1.= 6) # +# @iops_sector_count: #optional an I/O size in sector (Since 1.6) +# # Returns: Nothing on success # If @device is not a valid block device, DeviceNotFound # @@ -2195,7 +2200,8 @@ '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' }} + '*iops_rd_threshold': 'int', '*iops_wr_threshold': 'int', + '*iops_sector_count': 'int' }} =20 ## # @block-stream: diff --git a/qemu-options.hx b/qemu-options.hx index 4d5ee66..2f417b8 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][,bps_threshold=3Dbt]|[[,bps_rd_threshold=3Drt][,b= ps_wr_threshold=3Dwt]]][[,iops_threshold=3Dit]|[[,iops_rd_threshold=3Drt]= [,iops_wr_threshold=3Dwt]]\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][,iops_sector_count=3Dcnt]]\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 11c638a..b40db2f 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,bps_threshold:l?,bps_rd_threshold:l?,bps_wr_threshold:l?,iop= s_threshold:l?,iops_rd_threshold:l?,iops_wr_threshold: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?,iops_sector_coun= t:l?", .mhandler.cmd_new =3D qmp_marshal_input_block_set_io_throttle, }, =20 @@ -1410,6 +1410,7 @@ Arguments: - "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) +- "iops_sector_count": I/O sector count when limiting(json-int) =20 Example: =20 @@ -1425,7 +1426,8 @@ Example: "bps_wr_threshold": "0", "iops_threshold": "0", "iops_rd_threshold": "0", - "iops_wr_threshold": "0" = }=C2=A0} + "iops_wr_threshold": "0", + "iops_sector_count": "0" = } } <- { "return": {} } =20 EQMP @@ -1772,6 +1774,7 @@ Each json-object contain the following: - "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= ) + - "iops_sector_count": I/O sector count when limiting(json-int= ) - "image": the detail of the image, it is a json-object contain= ing the following: - "filename": image file name (json-string) @@ -1847,6 +1850,7 @@ Example: "iops_threshold": "0", "iops_rd_threshold": "0", "iops_wr_threshold": "0", + "iops_sector_count": "0", "image":{ "filename":"disks/test.qcow2", "format":"qcow2", --=20 1.7.10.4