From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35307) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2YNX-00026R-0V for qemu-devel@nongnu.org; Thu, 25 Jul 2013 23:07:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V2YNT-0000GR-5g for qemu-devel@nongnu.org; Thu, 25 Jul 2013 23:07:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:10725) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2YNS-0000GH-N3 for qemu-devel@nongnu.org; Thu, 25 Jul 2013 23:07:35 -0400 Date: Fri, 26 Jul 2013 11:07:24 +0800 From: Fam Zheng Message-ID: <20130726030724.GD8103@T430s.nay.redhat.com> References: <1374596968-20181-1-git-send-email-benoit@irqsave.net> <1374596968-20181-4-git-send-email-benoit@irqsave.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1374596968-20181-4-git-send-email-benoit@irqsave.net> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH V3 for-1.6 3/5] block: Add support for throttling burst threshold in QMP and the command line. Reply-To: famz@redhat.com List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?iso-8859-1?Q?Beno=EEt?= Canet Cc: kwolf@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com On Tue, 07/23 18:29, Beno=EEt Canet wrote: > The thresholds of the leaky bucket algorithm can be used to allow some > burstiness. >=20 > 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(-) >=20 > 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_= TOTAL]; > + info->inserted->bps_threshold =3D > + bs->io_limits.bps_threshold[BLOCK_IO_LIMIT_= TOTAL]; > + info->inserted->has_bps_rd_threshold =3D > + bs->io_limits.bps_threshold[BLOCK_IO_LIMIT_= READ]; > + info->inserted->bps_rd_threshold =3D > + bs->io_limits.bps_threshold[BLOCK_IO_LIMIT_= READ]; > + info->inserted->has_bps_wr_threshold =3D > + bs->io_limits.bps_threshold[BLOCK_IO_LIMIT_= WRITE]; > + info->inserted->bps_wr_threshold =3D > + bs->io_limits.bps_threshold[BLOCK_IO_LIMIT_= WRITE]; > + info->inserted->has_iops_threshold =3D > + bs->io_limits.iops_threshold[BLOCK_IO_LIMIT= _TOTAL]; > + info->inserted->iops_threshold =3D > + bs->io_limits.iops_threshold[BLOCK_IO_LIMIT= _TOTAL]; > + info->inserted->iops_rd_threshold =3D > + bs->io_limits.iops_threshold[BLOCK_IO_LIMIT= _READ]; > + info->inserted->has_iops_rd_threshold =3D > + bs->io_limits.iops_threshold[BLOCK_IO_LIMIT= _READ]; > + info->inserted->has_iops_wr_threshold =3D > + bs->io_limits.iops_threshold[BLOCK_IO_LIMIT= _WRITE]; > + info->inserted->iops_wr_threshold =3D > + bs->io_limits.iops_threshold[BLOCK_IO_LIMIT= _WRITE]; > } > =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_li= mits, 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, BlockIn= terfaceType 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] / THRO= TTLE_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] / THROT= TLE_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] / THRO= TTLE_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] / THROT= TLE_HZ; > - io_limits.bps_threshold[BLOCK_IO_LIMIT_READ] =3D > - io_limits.bps[BLOCK_IO_LIMIT_READ] / THROTT= LE_HZ; > - io_limits.bps_threshold[BLOCK_IO_LIMIT_WRITE] =3D > - io_limits.bps[BLOCK_IO_LIMIT_WRITE] / THROT= TLE_HZ; > - io_limits.iops_threshold[BLOCK_IO_LIMIT_TOTAL] =3D > - io_limits.iops[BLOCK_IO_LIMIT_TOTAL] / THRO= TTLE_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] / THR= OTTLE_HZ); > io_limits.iops_threshold[BLOCK_IO_LIMIT_READ] =3D > - io_limits.iops[BLOCK_IO_LIMIT_READ] / THROT= TLE_HZ; > - io_limits.iops_threshold[BLOCK_IO_LIMIT_WRITE] =3D > - io_limits.iops[BLOCK_IO_LIMIT_WRITE] / THRO= TTLE_HZ; > + qemu_opt_get_number(opts, "iops_rd_threshold", > + io_limits.iops[BLOCK_IO_LIMIT_READ] / THRO= TTLE_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] / THR= OTTLE_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, con= st 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 i= ops_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 *devic= e, int64_t bps, int64_t bps_rd, > io_limits.iops_threshold[BLOCK_IO_LIMIT_READ] =3D iops_rd / THROT= TLE_HZ; > io_limits.iops_threshold[BLOCK_IO_LIMIT_WRITE] =3D iops_wr / THROT= TLE_HZ; > =20 > + /* override them with givens values if present */ > + if (has_bps_threshold) { > + io_limits.bps_threshold[BLOCK_IO_LIMIT_TOTAL] =3D bps_threshol= d; > + } > + if (has_bps_rd_threshold) { > + io_limits.bps_threshold[BLOCK_IO_LIMIT_READ] =3D bps_rd_thresh= old; > + } > + if (has_bps_wr_threshold) { > + io_limits.bps_threshold[BLOCK_IO_LIMIT_WRITE] =3D bps_wr_thres= hold; > + } > + if (has_iops_threshold) { > + io_limits.iops_threshold[BLOCK_IO_LIMIT_TOTAL] =3D iops_thresh= old; > + } > + if (has_iops_rd_threshold) { > + io_limits.iops_threshold[BLOCK_IO_LIMIT_READ] =3D iops_rd_thre= shold; > + } > + if (has_iops_wr_threshold) { > + io_limits.iops_threshold[BLOCK_IO_LIMIT_WRITE] =3D iops_wr_thr= eshold; > + } > + > 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 fil= e", > 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 *qd= ict) > { > 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, con= st 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) Could you document how is @bps_threshold used and what is the difference with @bps, please? Maybe it's obvious in "leaky bucket" context, but users doesn't care the implementation algorithm, they may ask why they need @bps and @bps_threshold? And my understanding on this is: after setting @iops_threshold to 10000, the very first 10000 ops are guaranteed not throttled, in just one shot. After that, throttling algorithm is enabled, and @iops_threshold is reset to ineffective. Is it so? > +# > +# @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': = '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' }= } > =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][,= format=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]|[[,i= ops_rd=3Dr][,iops_wr=3Dw]]\n" > + " [[,bps=3Db]|[[,bps_rd=3Dr][,bps_wr=3Dw]]][[,iops=3Di]|[[,i= ops_rd=3Dr][,iops_wr=3Dw][,bps_threshold=3Dbt]|[[,bps_rd_threshold=3Drt][= ,bps_wr_threshold=3Dwt]]][[,iops_threshold=3Dit]|[[,iops_rd_threshold=3Dr= t][,iops_wr_threshold=3Dwt]]\n" This line is so long, can you wrap it? > " 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?,i= ops_threshold:l?,iops_rd_threshold:l?,iops_wr_threshold:l?", Same here. > .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": "80000= 00", > + "bps_rd_threshold": "0"= , > + "bps_wr_threshold": "0"= , > + "iops_threshold": "0", > + "iops_rd_threshold": "0= ", > + "iops_wr_threshold": "0= " }=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-in= t) > + - "iops_wr_threshold": write I/O operations threshold(json-i= nt) > - "image": the detail of the image, it is a json-object conta= ining > 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 >=20 >=20 --=20 Fam