{"id":809759,"url":"http://patchwork.ozlabs.org/api/1.0/patches/809759/?format=json","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/1.0/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<1504541267-36954-4-git-send-email-pradeep.jagadeesh@huawei.com>","date":"2017-09-04T16:07:44","name":"[v10,3/6] throttle: move out function to reuse the code","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"7c9d15f9ef850fa701b77c45a33b6dd2689e19ff","submitter":{"id":69852,"url":"http://patchwork.ozlabs.org/api/1.0/people/69852/?format=json","name":"Pradeep Jagadeesh","email":"pradeepkiruvale@gmail.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/1504541267-36954-4-git-send-email-pradeep.jagadeesh@huawei.com/mbox/","series":[{"id":1415,"url":"http://patchwork.ozlabs.org/api/1.0/series/1415/?format=json","date":"2017-09-04T16:07:42","name":"fsdev: qmp interface for io throttling","version":10,"mbox":"http://patchwork.ozlabs.org/series/1415/mbox/"}],"check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/809759/checks/","tags":{},"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>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"JehbBIdF\"; dkim-atps=neutral"],"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 3xmFMj3qGLz9t2W\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue,  5 Sep 2017 02:16:17 +1000 (AEST)","from localhost ([::1]:54774 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 1dou2p-0004Vw-GJ\n\tfor incoming@patchwork.ozlabs.org; Mon, 04 Sep 2017 12:16:15 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:46897)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <pradeepkiruvale@gmail.com>) id 1dotvK-0007L8-MR\n\tfor qemu-devel@nongnu.org; Mon, 04 Sep 2017 12:08:36 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <pradeepkiruvale@gmail.com>) id 1dotvF-0008Rk-Mz\n\tfor qemu-devel@nongnu.org; Mon, 04 Sep 2017 12:08:30 -0400","from mail-wr0-x244.google.com ([2a00:1450:400c:c0c::244]:34665)\n\tby eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)\n\t(Exim 4.71) (envelope-from <pradeepkiruvale@gmail.com>)\n\tid 1dotvF-0008RW-Di\n\tfor qemu-devel@nongnu.org; Mon, 04 Sep 2017 12:08:25 -0400","by mail-wr0-x244.google.com with SMTP id n33so207260wrn.1\n\tfor <qemu-devel@nongnu.org>; Mon, 04 Sep 2017 09:08:25 -0700 (PDT)","from localhost.localdomain.localdomain ([217.110.131.66])\n\tby smtp.gmail.com with ESMTPSA id\n\tx67sm976582wma.7.2017.09.04.09.08.23\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tMon, 04 Sep 2017 09:08:23 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references;\n\tbh=6kTUcdrrtIF5MipoeekxxsqfHda0GA+8ZHpmgcZu4D0=;\n\tb=JehbBIdFt01pOCp4FyktsV17pPwDDEJRNvyLnMzIZN9UNSdxONNSwBuMKo30/ourG5\n\tfKoX1Cmsf6W0H4z4FKDW5hrq/9MZ2Z13i+Pv57mc6Xe+HuMiyQ0gEqz6WzL25mHVRo+0\n\tjRN6GptPOj9N1yED0x3AJ/NpBnnhBBl0noMYJsGpOICgT2jFevYF4fEckdb6YtRLheyG\n\tMWiD6kyZZBKIMSrtZ3fK4I3FRSvvaWEtPt6MOZSD5ylf+uZEmp51STtxFIX+AJEcMDFR\n\tskIKceHC0qD4Ew2LxS30aW7/v4yBpa5Sy1Jq2bXopHlo5jFvunbmaWXZznIY/D3adC2P\n\txTHw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references;\n\tbh=6kTUcdrrtIF5MipoeekxxsqfHda0GA+8ZHpmgcZu4D0=;\n\tb=WLsitA9VK18fz6cHRSLREz+uQbRhGpPaA+YvYaBuzFfwjshemugT3FUizQUGG8PPyG\n\tmZGZ+ZVXprD0luux0sz9iJi3FU0RpSZBkYOln7MksaeX/cGyl4NUElQwvM5OEqTqTMN7\n\tBgkfr3eDi77pnR6FgCDxhInJau2xeOrzESWSSO/2nJht8yLac3tYkrWuLwMxl8JJHS3U\n\tkO6fcwrLsknBaqhkFy8O9i3uzH78uI7Sew90Ip090RCbXO86hLwwDy0aeViOtUK4k9P0\n\t76xfVACzah2S2Da5OSglA4NwotaEtUPwaGcsKHQvnfkBmU4uSCO2eJAYbDID8IdH+E8+\n\tcEEw==","X-Gm-Message-State":"AHPjjUhVp7y/W9uYLUkm5HU20z+7Y/XNoKsUkKJXgb/F/5ObEklL7z2c\n\tuBArpRjIor0FLg==","X-Google-Smtp-Source":"ADKCNb6qKs7D0XFUTGtjNoagvqMJhDtNFuUWzCSd4EQqphQYLrpsZxiDYVQOgQCJu4zaS6ASvEJywg==","X-Received":"by 10.223.142.199 with SMTP id q65mr602521wrb.110.1504541304365; \n\tMon, 04 Sep 2017 09:08:24 -0700 (PDT)","From":"Pradeep Jagadeesh <pradeepkiruvale@gmail.com>","X-Google-Original-From":"Pradeep Jagadeesh <pradeep.jagadeesh@huawei.com>","To":"\"eric blake\" <eblake@redhat.com>,\n\t\"greg kurz\" <groug@kaod.org>","Date":"Mon,  4 Sep 2017 12:07:44 -0400","Message-Id":"<1504541267-36954-4-git-send-email-pradeep.jagadeesh@huawei.com>","X-Mailer":"git-send-email 1.8.3.1","In-Reply-To":"<1504541267-36954-1-git-send-email-pradeep.jagadeesh@huawei.com>","References":"<1504541267-36954-1-git-send-email-pradeep.jagadeesh@huawei.com>","X-detected-operating-system":"by eggs.gnu.org: Genre and OS details not\n\trecognized.","X-Received-From":"2a00:1450:400c:c0c::244","Subject":"[Qemu-devel] [PATCH v10 3/6] throttle: move out function to reuse\n\tthe 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":"qemu-devel@nongnu.org, jani kokkonen <jani.kokkonen@huawei.com>,\n\talberto garcia <berto@igalia.com>,\n\tPradeep Jagadeesh <pradeep.jagadeesh@huawei.com>,\n\tMarkus Armbruster <armbru@redhat.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>"},"content":"This patch move out the throttle code to util/throttle.c to maximize\nthe reusability of the code.The same code is also used by fsdev.\n\nSigned-off-by: Pradeep Jagadeesh <pradeep.jagadeesh@huawei.com>\nReviewed-by: Alberto Garcia <berto@igalia.com>\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(-)","diff":"diff --git a/blockdev.c b/blockdev.c\nindex 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;\ndiff --git a/include/qemu/throttle-options.h b/include/qemu/throttle-options.h\nindex 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\ndiff --git a/util/throttle.c b/util/throttle.c\nindex 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+}\n","prefixes":["v10","3/6"]}