[{"id":1765286,"web_url":"http://patchwork.ozlabs.org/comment/1765286/","msgid":"<20170908142729.1008e033@bahia>","list_archive_url":null,"date":"2017-09-08T12:27:29","subject":"Re: [Qemu-devel] [PATCH v10 3/6] throttle: move out function to\n\treuse the code","submitter":{"id":69178,"url":"http://patchwork.ozlabs.org/api/people/69178/","name":"Greg Kurz","email":"groug@kaod.org"},"content":"On Mon,  4 Sep 2017 12:07:44 -0400\nPradeep Jagadeesh <pradeepkiruvale@gmail.com> wrote:\n\n> This patch move out the throttle code to util/throttle.c to maximize\n> the reusability of the code.The same code is also used by fsdev.\n\ns/.The same code is also used by fsdev/. The same code will also be used by fsdev/\n\n> Signed-off-by: Pradeep Jagadeesh <pradeep.jagadeesh@huawei.com>\n> Reviewed-by: Alberto Garcia <berto@igalia.com>\n\nReviewed-by: Greg Kurz <groug@kaod.org>\n\n> ---\n>  blockdev.c                      | 53 +++---------------------------------\n>  include/qemu/throttle-options.h |  2 ++\n>  util/throttle.c                 | 59 +++++++++++++++++++++++++++++++++++++++++\n>  3 files changed, 64 insertions(+), 50 deletions(-)\n> \n> diff --git a/blockdev.c b/blockdev.c\n> index 780ae58..1caf2e0 100644\n> --- a/blockdev.c\n> +++ b/blockdev.c\n> @@ -2571,6 +2571,7 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp)\n>      BlockDriverState *bs;\n>      BlockBackend *blk;\n>      AioContext *aio_context;\n> +    IOThrottle *iothrottle;\n>  \n>      blk = qmp_get_blk(arg->has_device ? arg->device : NULL,\n>                        arg->has_id ? arg->id : NULL,\n> @@ -2588,56 +2589,8 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp)\n>          goto out;\n>      }\n>  \n> -    throttle_config_init(&cfg);\n> -    cfg.buckets[THROTTLE_BPS_TOTAL].avg = arg->bps;\n> -    cfg.buckets[THROTTLE_BPS_READ].avg  = arg->bps_rd;\n> -    cfg.buckets[THROTTLE_BPS_WRITE].avg = arg->bps_wr;\n> -\n> -    cfg.buckets[THROTTLE_OPS_TOTAL].avg = arg->iops;\n> -    cfg.buckets[THROTTLE_OPS_READ].avg  = arg->iops_rd;\n> -    cfg.buckets[THROTTLE_OPS_WRITE].avg = arg->iops_wr;\n> -\n> -    if (arg->has_bps_max) {\n> -        cfg.buckets[THROTTLE_BPS_TOTAL].max = arg->bps_max;\n> -    }\n> -    if (arg->has_bps_rd_max) {\n> -        cfg.buckets[THROTTLE_BPS_READ].max = arg->bps_rd_max;\n> -    }\n> -    if (arg->has_bps_wr_max) {\n> -        cfg.buckets[THROTTLE_BPS_WRITE].max = arg->bps_wr_max;\n> -    }\n> -    if (arg->has_iops_max) {\n> -        cfg.buckets[THROTTLE_OPS_TOTAL].max = arg->iops_max;\n> -    }\n> -    if (arg->has_iops_rd_max) {\n> -        cfg.buckets[THROTTLE_OPS_READ].max = arg->iops_rd_max;\n> -    }\n> -    if (arg->has_iops_wr_max) {\n> -        cfg.buckets[THROTTLE_OPS_WRITE].max = arg->iops_wr_max;\n> -    }\n> -\n> -    if (arg->has_bps_max_length) {\n> -        cfg.buckets[THROTTLE_BPS_TOTAL].burst_length = arg->bps_max_length;\n> -    }\n> -    if (arg->has_bps_rd_max_length) {\n> -        cfg.buckets[THROTTLE_BPS_READ].burst_length = arg->bps_rd_max_length;\n> -    }\n> -    if (arg->has_bps_wr_max_length) {\n> -        cfg.buckets[THROTTLE_BPS_WRITE].burst_length = arg->bps_wr_max_length;\n> -    }\n> -    if (arg->has_iops_max_length) {\n> -        cfg.buckets[THROTTLE_OPS_TOTAL].burst_length = arg->iops_max_length;\n> -    }\n> -    if (arg->has_iops_rd_max_length) {\n> -        cfg.buckets[THROTTLE_OPS_READ].burst_length = arg->iops_rd_max_length;\n> -    }\n> -    if (arg->has_iops_wr_max_length) {\n> -        cfg.buckets[THROTTLE_OPS_WRITE].burst_length = arg->iops_wr_max_length;\n> -    }\n> -\n> -    if (arg->has_iops_size) {\n> -        cfg.op_size = arg->iops_size;\n> -    }\n> +    iothrottle = qapi_BlockIOThrottle_base(arg);\n> +    throttle_set_io_limits(&cfg, iothrottle);\n>  \n>      if (!throttle_is_valid(&cfg, errp)) {\n>          goto out;\n> diff --git a/include/qemu/throttle-options.h b/include/qemu/throttle-options.h\n> index f63d38c..b736185 100644\n> --- a/include/qemu/throttle-options.h\n> +++ b/include/qemu/throttle-options.h\n> @@ -11,6 +11,7 @@\n>  #define THROTTLE_OPTIONS_H\n>  \n>  #include \"typedefs.h\"\n> +#include \"qapi-types.h\"\n>  \n>  #define THROTTLE_OPTS \\\n>            { \\\n> @@ -92,5 +93,6 @@\n>          }\n>  \n>  void throttle_parse_options(ThrottleConfig *, QemuOpts *);\n> +void throttle_set_io_limits(ThrottleConfig *, IOThrottle *);\n>  \n>  #endif\n> diff --git a/util/throttle.c b/util/throttle.c\n> index 95c2ecf..dcc9d5a 100644\n> --- a/util/throttle.c\n> +++ b/util/throttle.c\n> @@ -553,3 +553,62 @@ void throttle_parse_options(ThrottleConfig *throttle_cfg, QemuOpts *opts)\n>      throttle_cfg->op_size =\n>          qemu_opt_get_number(opts, \"throttling.iops-size\", 0);\n>  }\n> +\n> +/* Initialize a throttle config from an IOThrottle structure\n> + *\n> + * @arg: iothrottle limits\n> + * @cfg: throttle configuration\n> + */\n> +void throttle_set_io_limits(ThrottleConfig *cfg, IOThrottle *arg)\n> +{\n> +    throttle_config_init(cfg);\n> +    cfg->buckets[THROTTLE_BPS_TOTAL].avg = arg->bps;\n> +    cfg->buckets[THROTTLE_BPS_READ].avg  = arg->bps_rd;\n> +    cfg->buckets[THROTTLE_BPS_WRITE].avg = arg->bps_wr;\n> +\n> +    cfg->buckets[THROTTLE_OPS_TOTAL].avg = arg->iops;\n> +    cfg->buckets[THROTTLE_OPS_READ].avg  = arg->iops_rd;\n> +    cfg->buckets[THROTTLE_OPS_WRITE].avg = arg->iops_wr;\n> +\n> +    if (arg->has_bps_max) {\n> +        cfg->buckets[THROTTLE_BPS_TOTAL].max = arg->bps_max;\n> +    }\n> +    if (arg->has_bps_rd_max) {\n> +        cfg->buckets[THROTTLE_BPS_READ].max = arg->bps_rd_max;\n> +    }\n> +    if (arg->has_bps_wr_max) {\n> +        cfg->buckets[THROTTLE_BPS_WRITE].max = arg->bps_wr_max;\n> +    }\n> +    if (arg->has_iops_max) {\n> +        cfg->buckets[THROTTLE_OPS_TOTAL].max = arg->iops_max;\n> +    }\n> +    if (arg->has_iops_rd_max) {\n> +        cfg->buckets[THROTTLE_OPS_READ].max = arg->iops_rd_max;\n> +    }\n> +    if (arg->has_iops_wr_max) {\n> +        cfg->buckets[THROTTLE_OPS_WRITE].max = arg->iops_wr_max;\n> +    }\n> +\n> +    if (arg->has_bps_max_length) {\n> +        cfg->buckets[THROTTLE_BPS_TOTAL].burst_length = arg->bps_max_length;\n> +    }\n> +    if (arg->has_bps_rd_max_length) {\n> +        cfg->buckets[THROTTLE_BPS_READ].burst_length = arg->bps_rd_max_length;\n> +    }\n> +    if (arg->has_bps_wr_max_length) {\n> +        cfg->buckets[THROTTLE_BPS_WRITE].burst_length = arg->bps_wr_max_length;\n> +    }\n> +    if (arg->has_iops_max_length) {\n> +        cfg->buckets[THROTTLE_OPS_TOTAL].burst_length = arg->iops_max_length;\n> +    }\n> +    if (arg->has_iops_rd_max_length) {\n> +        cfg->buckets[THROTTLE_OPS_READ].burst_length = arg->iops_rd_max_length;\n> +    }\n> +    if (arg->has_iops_wr_max_length) {\n> +        cfg->buckets[THROTTLE_OPS_WRITE].burst_length = arg->iops_wr_max_length;\n> +    }\n> +\n> +    if (arg->has_iops_size) {\n> +        cfg->op_size = arg->iops_size;\n> +    }\n> +}","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=208.118.235.17; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","Received":["from lists.gnu.org (lists.gnu.org [208.118.235.17])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xpc6c52tLz9t38\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri,  8 Sep 2017 22:28:08 +1000 (AEST)","from localhost ([::1]:45222 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dqIOD-0001px-EU\n\tfor incoming@patchwork.ozlabs.org; Fri, 08 Sep 2017 08:28:05 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:43782)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <groug@kaod.org>) id 1dqINs-0001pb-5b\n\tfor qemu-devel@nongnu.org; Fri, 08 Sep 2017 08:27:45 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <groug@kaod.org>) id 1dqINo-0008AQ-U9\n\tfor qemu-devel@nongnu.org; Fri, 08 Sep 2017 08:27:44 -0400","from 10.mo177.mail-out.ovh.net ([46.105.73.133]:53291)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <groug@kaod.org>) id 1dqINo-000891-Ki\n\tfor qemu-devel@nongnu.org; Fri, 08 Sep 2017 08:27:40 -0400","from player714.ha.ovh.net (b6.ovh.net [213.186.33.56])\n\tby mo177.mail-out.ovh.net (Postfix) with ESMTP id 1E00E79BB2\n\tfor <qemu-devel@nongnu.org>; Fri,  8 Sep 2017 14:27:37 +0200 (CEST)","from bahia (gar31-1-82-66-74-139.fbx.proxad.net [82.66.74.139])\n\t(Authenticated sender: groug@kaod.org)\n\tby player714.ha.ovh.net (Postfix) with ESMTPSA id C08FE3C00A6;\n\tFri,  8 Sep 2017 14:27:30 +0200 (CEST)"],"Date":"Fri, 8 Sep 2017 14:27:29 +0200","From":"Greg Kurz <groug@kaod.org>","To":"Pradeep Jagadeesh <pradeepkiruvale@gmail.com>","Message-ID":"<20170908142729.1008e033@bahia>","In-Reply-To":"<1504541267-36954-4-git-send-email-pradeep.jagadeesh@huawei.com>","References":"<1504541267-36954-1-git-send-email-pradeep.jagadeesh@huawei.com>\n\t<1504541267-36954-4-git-send-email-pradeep.jagadeesh@huawei.com>","X-Mailer":"Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-redhat-linux-gnu)","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha1;\n\tboundary=\"Sig_/lSso=A9Q6HUOtxSHaVAlbXh\";\n\tprotocol=\"application/pgp-signature\"","X-Ovh-Tracer-Id":"10140136037856025051","X-VR-SPAMSTATE":"OK","X-VR-SPAMSCORE":"-100","X-VR-SPAMCAUSE":"gggruggvucftvghtrhhoucdtuddrfeelledrfeeggdehvdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"46.105.73.133","Subject":"Re: [Qemu-devel] [PATCH v10 3/6] throttle: move out function to\n\treuse the code","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"alberto garcia <berto@igalia.com>, qemu-devel@nongnu.org,\n\tMarkus Armbruster <armbru@redhat.com>,\n\tPradeep Jagadeesh <pradeep.jagadeesh@huawei.com>,\n\tjani kokkonen <jani.kokkonen@huawei.com>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}}]