{"id":807107,"url":"http://patchwork.ozlabs.org/api/1.0/patches/807107/?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":"<1504016587-39779-2-git-send-email-pradeep.jagadeesh@huawei.com>","date":"2017-08-29T14:23:02","name":"[v8,1/6] throttle: factor out duplicate code","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"4140aef1b67a8c5fc74201af6fd5caf56e397ad9","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/1504016587-39779-2-git-send-email-pradeep.jagadeesh@huawei.com/mbox/","series":[{"id":377,"url":"http://patchwork.ozlabs.org/api/1.0/series/377/?format=json","date":"2017-08-29T14:23:01","name":"fsdev: qmp interface for io throttling","version":8,"mbox":"http://patchwork.ozlabs.org/series/377/mbox/"}],"check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/807107/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=2001:4830:134:3::11; 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=\"L/8xyxlq\"; dkim-atps=neutral"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\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 3xhWDY4HHlz9t16\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed, 30 Aug 2017 00:27:09 +1000 (AEST)","from localhost ([::1]:45224 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 1dmhTv-0004CG-G0\n\tfor incoming@patchwork.ozlabs.org; Tue, 29 Aug 2017 10:27:07 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:53734)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <pradeepkiruvale@gmail.com>) id 1dmhR1-0001iu-Rm\n\tfor qemu-devel@nongnu.org; Tue, 29 Aug 2017 10:24:12 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <pradeepkiruvale@gmail.com>) id 1dmhQv-0004Di-H9\n\tfor qemu-devel@nongnu.org; Tue, 29 Aug 2017 10:24:07 -0400","from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]:35523)\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 1dmhQv-0004Cr-7D\n\tfor qemu-devel@nongnu.org; Tue, 29 Aug 2017 10:24:01 -0400","by mail-wr0-x241.google.com with SMTP id a47so2408389wra.2\n\tfor <qemu-devel@nongnu.org>; Tue, 29 Aug 2017 07:23:59 -0700 (PDT)","from localhost.localdomain.localdomain ([217.110.131.66])\n\tby smtp.gmail.com with ESMTPSA id\n\t15sm2540487wmv.45.2017.08.29.07.23.57\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tTue, 29 Aug 2017 07:23:58 -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=irDKxKGkaoOLI6Ox8CLrOXgSHf87WhGrI0kxMmsev4c=;\n\tb=L/8xyxlq6mWoz/lqp1tl6eXj2bggGJJ0IHJ4FLieb6DtWqQ4qDhYlYQepkt3v3gDDB\n\tAzYZOMuGS55FKrwLQfNIAoG4aEkb6qXbU4ecqMZrpbElDUFvVi9I/pUGm4lLqUbT8fxy\n\t6DV8j0REsQwwre/nnx6/wQccloGOfOCi4llj/D/fmYKre8lNpYpYb99JKJBBQL+Mx/OX\n\tlR3wxh7K5pP4IKtQNmL9/z/S/ulN+EAgPu7AplRAklLGKqfH47nzcGhULjuc8gMYiGOP\n\tPfRgOhPstGsNCW0QuGsIfy3EsADCmir5Ujx+0Q4N1SRUqXaD9p6MkHP4WsNKq+vIZaYO\n\t1Dpg==","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=irDKxKGkaoOLI6Ox8CLrOXgSHf87WhGrI0kxMmsev4c=;\n\tb=Bi6unIyzG5OhyY/AvtPes/gYH0xjbQ4k2g1ivwQ+hNWEPy4UUYh1glAeXR1xJeR61m\n\tmLPL/SJLF5WGe2+KjM8lH8uEk9vSTw3JG67UNEBVtqSOhdOwdSgmY3igYpX76Ii9ijT/\n\tKQZNzlSNxJZknL5S881vVBhIg4ibX9Wqda1/HL3p7YgRgjtxRjP+cpjmaIcW4JJK4pw3\n\tTAAIAmTTGEOg0BPcjFwgloO+Gql9HzLGVe+gzjqJiastR5gnQmx4dflZqKb0XIe/JGGm\n\tKCxvnuR9eTgHwjGmKXkegPd7qZ2bPx1tiBSMWNOwxw45hK0pNMyrp026jDKVuscQnNcF\n\tf4LA==","X-Gm-Message-State":"AHYfb5hNvGVaYLXUTYyOn3toybGzxx6j6frMulr/i4DCh6MkVE0c+7Cn\n\tKBK0vzpOxPLA3A==","X-Received":"by 10.223.196.151 with SMTP id m23mr340798wrf.38.1504016638686; \n\tTue, 29 Aug 2017 07:23:58 -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":"Tue, 29 Aug 2017 10:23:02 -0400","Message-Id":"<1504016587-39779-2-git-send-email-pradeep.jagadeesh@huawei.com>","X-Mailer":"git-send-email 1.8.3.1","In-Reply-To":"<1504016587-39779-1-git-send-email-pradeep.jagadeesh@huawei.com>","References":"<1504016587-39779-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::241","Subject":"[Qemu-devel] [PATCH v8 1/6] throttle: factor out duplicate 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 factor out the duplicate throttle code that was present in\nblock and fsdev devices.\n\nSigned-off-by: Pradeep Jagadeesh <pradeep.jagadeesh@huawei.com>\nReviewed-by: Alberto Garcia <berto@igalia.com>\n---\n blockdev.c                      | 44 +----------------------------------\n fsdev/qemu-fsdev-throttle.c     | 44 ++---------------------------------\n include/qemu/throttle-options.h |  4 ++++\n include/qemu/throttle.h         |  4 ++--\n include/qemu/typedefs.h         |  1 +\n util/throttle.c                 | 51 +++++++++++++++++++++++++++++++++++++++++\n 6 files changed, 61 insertions(+), 87 deletions(-)","diff":"diff --git a/blockdev.c b/blockdev.c\nindex 02cd69b..780ae58 100644\n--- a/blockdev.c\n+++ b/blockdev.c\n@@ -388,49 +388,7 @@ static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags,\n     }\n \n     if (throttle_cfg) {\n-        throttle_config_init(throttle_cfg);\n-        throttle_cfg->buckets[THROTTLE_BPS_TOTAL].avg =\n-            qemu_opt_get_number(opts, \"throttling.bps-total\", 0);\n-        throttle_cfg->buckets[THROTTLE_BPS_READ].avg  =\n-            qemu_opt_get_number(opts, \"throttling.bps-read\", 0);\n-        throttle_cfg->buckets[THROTTLE_BPS_WRITE].avg =\n-            qemu_opt_get_number(opts, \"throttling.bps-write\", 0);\n-        throttle_cfg->buckets[THROTTLE_OPS_TOTAL].avg =\n-            qemu_opt_get_number(opts, \"throttling.iops-total\", 0);\n-        throttle_cfg->buckets[THROTTLE_OPS_READ].avg =\n-            qemu_opt_get_number(opts, \"throttling.iops-read\", 0);\n-        throttle_cfg->buckets[THROTTLE_OPS_WRITE].avg =\n-            qemu_opt_get_number(opts, \"throttling.iops-write\", 0);\n-\n-        throttle_cfg->buckets[THROTTLE_BPS_TOTAL].max =\n-            qemu_opt_get_number(opts, \"throttling.bps-total-max\", 0);\n-        throttle_cfg->buckets[THROTTLE_BPS_READ].max  =\n-            qemu_opt_get_number(opts, \"throttling.bps-read-max\", 0);\n-        throttle_cfg->buckets[THROTTLE_BPS_WRITE].max =\n-            qemu_opt_get_number(opts, \"throttling.bps-write-max\", 0);\n-        throttle_cfg->buckets[THROTTLE_OPS_TOTAL].max =\n-            qemu_opt_get_number(opts, \"throttling.iops-total-max\", 0);\n-        throttle_cfg->buckets[THROTTLE_OPS_READ].max =\n-            qemu_opt_get_number(opts, \"throttling.iops-read-max\", 0);\n-        throttle_cfg->buckets[THROTTLE_OPS_WRITE].max =\n-            qemu_opt_get_number(opts, \"throttling.iops-write-max\", 0);\n-\n-        throttle_cfg->buckets[THROTTLE_BPS_TOTAL].burst_length =\n-            qemu_opt_get_number(opts, \"throttling.bps-total-max-length\", 1);\n-        throttle_cfg->buckets[THROTTLE_BPS_READ].burst_length  =\n-            qemu_opt_get_number(opts, \"throttling.bps-read-max-length\", 1);\n-        throttle_cfg->buckets[THROTTLE_BPS_WRITE].burst_length =\n-            qemu_opt_get_number(opts, \"throttling.bps-write-max-length\", 1);\n-        throttle_cfg->buckets[THROTTLE_OPS_TOTAL].burst_length =\n-            qemu_opt_get_number(opts, \"throttling.iops-total-max-length\", 1);\n-        throttle_cfg->buckets[THROTTLE_OPS_READ].burst_length =\n-            qemu_opt_get_number(opts, \"throttling.iops-read-max-length\", 1);\n-        throttle_cfg->buckets[THROTTLE_OPS_WRITE].burst_length =\n-            qemu_opt_get_number(opts, \"throttling.iops-write-max-length\", 1);\n-\n-        throttle_cfg->op_size =\n-            qemu_opt_get_number(opts, \"throttling.iops-size\", 0);\n-\n+        throttle_parse_options(throttle_cfg, opts);\n         if (!throttle_is_valid(throttle_cfg, errp)) {\n             return;\n         }\ndiff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c\nindex 49eebb5..0e6fb86 100644\n--- a/fsdev/qemu-fsdev-throttle.c\n+++ b/fsdev/qemu-fsdev-throttle.c\n@@ -16,6 +16,7 @@\n #include \"qemu/error-report.h\"\n #include \"qemu-fsdev-throttle.h\"\n #include \"qemu/iov.h\"\n+#include \"qemu/throttle-options.h\"\n \n static void fsdev_throttle_read_timer_cb(void *opaque)\n {\n@@ -31,48 +32,7 @@ static void fsdev_throttle_write_timer_cb(void *opaque)\n \n void fsdev_throttle_parse_opts(QemuOpts *opts, FsThrottle *fst, Error **errp)\n {\n-    throttle_config_init(&fst->cfg);\n-    fst->cfg.buckets[THROTTLE_BPS_TOTAL].avg =\n-        qemu_opt_get_number(opts, \"throttling.bps-total\", 0);\n-    fst->cfg.buckets[THROTTLE_BPS_READ].avg  =\n-        qemu_opt_get_number(opts, \"throttling.bps-read\", 0);\n-    fst->cfg.buckets[THROTTLE_BPS_WRITE].avg =\n-        qemu_opt_get_number(opts, \"throttling.bps-write\", 0);\n-    fst->cfg.buckets[THROTTLE_OPS_TOTAL].avg =\n-        qemu_opt_get_number(opts, \"throttling.iops-total\", 0);\n-    fst->cfg.buckets[THROTTLE_OPS_READ].avg =\n-        qemu_opt_get_number(opts, \"throttling.iops-read\", 0);\n-    fst->cfg.buckets[THROTTLE_OPS_WRITE].avg =\n-        qemu_opt_get_number(opts, \"throttling.iops-write\", 0);\n-\n-    fst->cfg.buckets[THROTTLE_BPS_TOTAL].max =\n-        qemu_opt_get_number(opts, \"throttling.bps-total-max\", 0);\n-    fst->cfg.buckets[THROTTLE_BPS_READ].max  =\n-        qemu_opt_get_number(opts, \"throttling.bps-read-max\", 0);\n-    fst->cfg.buckets[THROTTLE_BPS_WRITE].max =\n-        qemu_opt_get_number(opts, \"throttling.bps-write-max\", 0);\n-    fst->cfg.buckets[THROTTLE_OPS_TOTAL].max =\n-        qemu_opt_get_number(opts, \"throttling.iops-total-max\", 0);\n-    fst->cfg.buckets[THROTTLE_OPS_READ].max =\n-        qemu_opt_get_number(opts, \"throttling.iops-read-max\", 0);\n-    fst->cfg.buckets[THROTTLE_OPS_WRITE].max =\n-        qemu_opt_get_number(opts, \"throttling.iops-write-max\", 0);\n-\n-    fst->cfg.buckets[THROTTLE_BPS_TOTAL].burst_length =\n-        qemu_opt_get_number(opts, \"throttling.bps-total-max-length\", 1);\n-    fst->cfg.buckets[THROTTLE_BPS_READ].burst_length  =\n-        qemu_opt_get_number(opts, \"throttling.bps-read-max-length\", 1);\n-    fst->cfg.buckets[THROTTLE_BPS_WRITE].burst_length =\n-        qemu_opt_get_number(opts, \"throttling.bps-write-max-length\", 1);\n-    fst->cfg.buckets[THROTTLE_OPS_TOTAL].burst_length =\n-        qemu_opt_get_number(opts, \"throttling.iops-total-max-length\", 1);\n-    fst->cfg.buckets[THROTTLE_OPS_READ].burst_length =\n-        qemu_opt_get_number(opts, \"throttling.iops-read-max-length\", 1);\n-    fst->cfg.buckets[THROTTLE_OPS_WRITE].burst_length =\n-        qemu_opt_get_number(opts, \"throttling.iops-write-max-length\", 1);\n-    fst->cfg.op_size =\n-        qemu_opt_get_number(opts, \"throttling.iops-size\", 0);\n-\n+    throttle_parse_options(&fst->cfg, opts);\n     throttle_is_valid(&fst->cfg, errp);\n }\n \ndiff --git a/include/qemu/throttle-options.h b/include/qemu/throttle-options.h\nindex 3133d1c..f63d38c 100644\n--- a/include/qemu/throttle-options.h\n+++ b/include/qemu/throttle-options.h\n@@ -10,6 +10,8 @@\n #ifndef THROTTLE_OPTIONS_H\n #define THROTTLE_OPTIONS_H\n \n+#include \"typedefs.h\"\n+\n #define THROTTLE_OPTS \\\n           { \\\n             .name = \"throttling.iops-total\",\\\n@@ -89,4 +91,6 @@\n             .help = \"when limiting by iops max size of an I/O in bytes\",\\\n         }\n \n+void throttle_parse_options(ThrottleConfig *, QemuOpts *);\n+\n #endif\ndiff --git a/include/qemu/throttle.h b/include/qemu/throttle.h\nindex d056008..75d930c 100644\n--- a/include/qemu/throttle.h\n+++ b/include/qemu/throttle.h\n@@ -89,10 +89,10 @@ typedef struct LeakyBucket {\n  * However it allows to keep the code clean and the bucket field is reset to\n  * zero at the right time.\n  */\n-typedef struct ThrottleConfig {\n+struct ThrottleConfig {\n     LeakyBucket buckets[BUCKETS_COUNT]; /* leaky buckets */\n     uint64_t op_size;         /* size of an operation in bytes */\n-} ThrottleConfig;\n+};\n \n typedef struct ThrottleState {\n     ThrottleConfig cfg;       /* configuration */\ndiff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h\nindex 39bc835..90fe0f9 100644\n--- a/include/qemu/typedefs.h\n+++ b/include/qemu/typedefs.h\n@@ -100,6 +100,7 @@ typedef struct uWireSlave uWireSlave;\n typedef struct VirtIODevice VirtIODevice;\n typedef struct Visitor Visitor;\n typedef struct node_info NodeInfo;\n+typedef struct ThrottleConfig ThrottleConfig;\n typedef void SaveStateHandler(QEMUFile *f, void *opaque);\n typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);\n \ndiff --git a/util/throttle.c b/util/throttle.c\nindex b2a52b8..95c2ecf 100644\n--- a/util/throttle.c\n+++ b/util/throttle.c\n@@ -27,6 +27,7 @@\n #include \"qemu/throttle.h\"\n #include \"qemu/timer.h\"\n #include \"block/aio.h\"\n+#include \"qemu/throttle-options.h\"\n \n /* This function make a bucket leak\n  *\n@@ -502,3 +503,53 @@ void throttle_account(ThrottleState *ts, bool is_write, uint64_t size)\n     }\n }\n \n+/* parse the throttle options\n+ *\n+ * @opts: qemu options\n+ * @throttle_cfg: throttle configuration\n+ */\n+void throttle_parse_options(ThrottleConfig *throttle_cfg, QemuOpts *opts)\n+{\n+    throttle_config_init(throttle_cfg);\n+    throttle_cfg->buckets[THROTTLE_BPS_TOTAL].avg =\n+        qemu_opt_get_number(opts, \"throttling.bps-total\", 0);\n+    throttle_cfg->buckets[THROTTLE_BPS_READ].avg  =\n+        qemu_opt_get_number(opts, \"throttling.bps-read\", 0);\n+    throttle_cfg->buckets[THROTTLE_BPS_WRITE].avg =\n+        qemu_opt_get_number(opts, \"throttling.bps-write\", 0);\n+    throttle_cfg->buckets[THROTTLE_OPS_TOTAL].avg =\n+        qemu_opt_get_number(opts, \"throttling.iops-total\", 0);\n+    throttle_cfg->buckets[THROTTLE_OPS_READ].avg =\n+        qemu_opt_get_number(opts, \"throttling.iops-read\", 0);\n+    throttle_cfg->buckets[THROTTLE_OPS_WRITE].avg =\n+        qemu_opt_get_number(opts, \"throttling.iops-write\", 0);\n+\n+    throttle_cfg->buckets[THROTTLE_BPS_TOTAL].max =\n+        qemu_opt_get_number(opts, \"throttling.bps-total-max\", 0);\n+    throttle_cfg->buckets[THROTTLE_BPS_READ].max  =\n+        qemu_opt_get_number(opts, \"throttling.bps-read-max\", 0);\n+    throttle_cfg->buckets[THROTTLE_BPS_WRITE].max =\n+        qemu_opt_get_number(opts, \"throttling.bps-write-max\", 0);\n+    throttle_cfg->buckets[THROTTLE_OPS_TOTAL].max =\n+        qemu_opt_get_number(opts, \"throttling.iops-total-max\", 0);\n+    throttle_cfg->buckets[THROTTLE_OPS_READ].max =\n+        qemu_opt_get_number(opts, \"throttling.iops-read-max\", 0);\n+    throttle_cfg->buckets[THROTTLE_OPS_WRITE].max =\n+        qemu_opt_get_number(opts, \"throttling.iops-write-max\", 0);\n+\n+    throttle_cfg->buckets[THROTTLE_BPS_TOTAL].burst_length =\n+        qemu_opt_get_number(opts, \"throttling.bps-total-max-length\", 1);\n+    throttle_cfg->buckets[THROTTLE_BPS_READ].burst_length  =\n+        qemu_opt_get_number(opts, \"throttling.bps-read-max-length\", 1);\n+    throttle_cfg->buckets[THROTTLE_BPS_WRITE].burst_length =\n+        qemu_opt_get_number(opts, \"throttling.bps-write-max-length\", 1);\n+    throttle_cfg->buckets[THROTTLE_OPS_TOTAL].burst_length =\n+        qemu_opt_get_number(opts, \"throttling.iops-total-max-length\", 1);\n+    throttle_cfg->buckets[THROTTLE_OPS_READ].burst_length =\n+        qemu_opt_get_number(opts, \"throttling.iops-read-max-length\", 1);\n+    throttle_cfg->buckets[THROTTLE_OPS_WRITE].burst_length =\n+        qemu_opt_get_number(opts, \"throttling.iops-write-max-length\", 1);\n+\n+    throttle_cfg->op_size =\n+        qemu_opt_get_number(opts, \"throttling.iops-size\", 0);\n+}\n","prefixes":["v8","1/6"]}