From patchwork Tue Aug 29 14:23:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pradeep X-Patchwork-Id: 9927495 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4E6AF60383 for ; Tue, 29 Aug 2017 14:26:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 444102893B for ; Tue, 29 Aug 2017 14:26:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 392922893D; Tue, 29 Aug 2017 14:26:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 11C8A2894D for ; Tue, 29 Aug 2017 14:26:15 +0000 (UTC) Received: from localhost ([::1]:45212 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dmhSN-0001ns-W6 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 29 Aug 2017 10:25:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53686) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dmhQx-0001g3-JK for qemu-devel@nongnu.org; Tue, 29 Aug 2017 10:24:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dmhQv-0004Do-US for qemu-devel@nongnu.org; Tue, 29 Aug 2017 10:24:03 -0400 Received: from mail-wr0-x244.google.com ([2a00:1450:400c:c0c::244]:33294) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dmhQv-0004DS-Ke for qemu-devel@nongnu.org; Tue, 29 Aug 2017 10:24:01 -0400 Received: by mail-wr0-x244.google.com with SMTP id k94so2410554wrc.0 for ; Tue, 29 Aug 2017 07:24:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=rzDROED0CTzRR0Srkya+UDdqlCvGx1/jjY45f0aZWqU=; b=O1+B3GvIXV2Evsx5k46yWl/h5nLF+pE0jdKh1N4Ng1ytqW16wRLGl41KW7bwWRZGvB yTyOkX9i687uZWr4Ln2CCubPRGnb6E+PbqBFEAUaYxeSw705u4IwhWUqjxe75gL7yk8z 3X8j+lKPJHxtxTISRm0nSbw3Sk/endyR6jvCRVSvAPDHLCRBRSQtWJ3aoaFx8U4T4mEI pGamvbb59inPDySHv4kmpeWr0xs2hE6Te7D2Og5jru8RWZewYADohKbHwVNhgxqi/lCZ Qt8/ZFkyEQtAWMakh4L1s0QK96mEvrBbwoIqdHx5w0Zk8yGDMMP6nWjboiK1N2eZNe18 qCKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=rzDROED0CTzRR0Srkya+UDdqlCvGx1/jjY45f0aZWqU=; b=Su1LK5eqLaOav3ZdfDUYHX87qVUmxxSnGATVvMmkld+MYH9+5xq8aBUmZv7koSPKzz vEZd6KYRV/6KKNI4Kr57AVWoVcae/IypqY70x1SCBAHwV9EZhYVR8Df8o6Rn9az3jVe6 9qz1sDAzhqJoiGqBk6Tt4HUqLNnxPrXclNuF/6woMG3Ulqzr5bOP4oEyz1uMsjACk+UU Tt3wGjxZxcMWbvjKlVV55EMgTzdtalF27s7LNxtOW3QNS9MJWPOGXflr8kpso8VRbpK4 26HsjgtXNgjNmAZ+QwDdHS7PmmstYStZK88LsGU6LQJfMIc9Wq5UtofT11qCVzi7rCJ5 PXbQ== X-Gm-Message-State: AHYfb5jNS2BZOJJVyGIo9vIp4P5sa4ahVFQu6C/g58fVNnGz+ryZwJEr 5+/+BCK9tWpK4w== X-Received: by 10.223.184.187 with SMTP id i56mr324055wrf.323.1504016640544; Tue, 29 Aug 2017 07:24:00 -0700 (PDT) Received: from localhost.localdomain.localdomain ([217.110.131.66]) by smtp.gmail.com with ESMTPSA id 15sm2540487wmv.45.2017.08.29.07.23.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Aug 2017 07:24:00 -0700 (PDT) From: Pradeep Jagadeesh X-Google-Original-From: Pradeep Jagadeesh To: "eric blake" , "greg kurz" Date: Tue, 29 Aug 2017 10:23:04 -0400 Message-Id: <1504016587-39779-4-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 recognized. X-Received-From: 2a00:1450:400c:c0c::244 Subject: [Qemu-devel] [PATCH v8 3/6] throttle: move out function to reuse the code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org, jani kokkonen , alberto garcia , Pradeep Jagadeesh , Markus Armbruster Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This patch move out the throttle code to util/throttle.c to maximize the reusability of the code.The same code is also used by fsdev. Signed-off-by: Pradeep Jagadeesh --- blockdev.c | 53 +++--------------------------------- include/qemu/throttle-options.h | 3 +++ util/throttle.c | 59 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 50 deletions(-) diff --git a/blockdev.c b/blockdev.c index 780ae58..1caf2e0 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2571,6 +2571,7 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp) BlockDriverState *bs; BlockBackend *blk; AioContext *aio_context; + IOThrottle *iothrottle; blk = qmp_get_blk(arg->has_device ? arg->device : NULL, arg->has_id ? arg->id : NULL, @@ -2588,56 +2589,8 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp) goto out; } - throttle_config_init(&cfg); - cfg.buckets[THROTTLE_BPS_TOTAL].avg = arg->bps; - cfg.buckets[THROTTLE_BPS_READ].avg = arg->bps_rd; - cfg.buckets[THROTTLE_BPS_WRITE].avg = arg->bps_wr; - - cfg.buckets[THROTTLE_OPS_TOTAL].avg = arg->iops; - cfg.buckets[THROTTLE_OPS_READ].avg = arg->iops_rd; - cfg.buckets[THROTTLE_OPS_WRITE].avg = arg->iops_wr; - - if (arg->has_bps_max) { - cfg.buckets[THROTTLE_BPS_TOTAL].max = arg->bps_max; - } - if (arg->has_bps_rd_max) { - cfg.buckets[THROTTLE_BPS_READ].max = arg->bps_rd_max; - } - if (arg->has_bps_wr_max) { - cfg.buckets[THROTTLE_BPS_WRITE].max = arg->bps_wr_max; - } - if (arg->has_iops_max) { - cfg.buckets[THROTTLE_OPS_TOTAL].max = arg->iops_max; - } - if (arg->has_iops_rd_max) { - cfg.buckets[THROTTLE_OPS_READ].max = arg->iops_rd_max; - } - if (arg->has_iops_wr_max) { - cfg.buckets[THROTTLE_OPS_WRITE].max = arg->iops_wr_max; - } - - if (arg->has_bps_max_length) { - cfg.buckets[THROTTLE_BPS_TOTAL].burst_length = arg->bps_max_length; - } - if (arg->has_bps_rd_max_length) { - cfg.buckets[THROTTLE_BPS_READ].burst_length = arg->bps_rd_max_length; - } - if (arg->has_bps_wr_max_length) { - cfg.buckets[THROTTLE_BPS_WRITE].burst_length = arg->bps_wr_max_length; - } - if (arg->has_iops_max_length) { - cfg.buckets[THROTTLE_OPS_TOTAL].burst_length = arg->iops_max_length; - } - if (arg->has_iops_rd_max_length) { - cfg.buckets[THROTTLE_OPS_READ].burst_length = arg->iops_rd_max_length; - } - if (arg->has_iops_wr_max_length) { - cfg.buckets[THROTTLE_OPS_WRITE].burst_length = arg->iops_wr_max_length; - } - - if (arg->has_iops_size) { - cfg.op_size = arg->iops_size; - } + iothrottle = qapi_BlockIOThrottle_base(arg); + throttle_set_io_limits(&cfg, iothrottle); if (!throttle_is_valid(&cfg, errp)) { goto out; diff --git a/include/qemu/throttle-options.h b/include/qemu/throttle-options.h index f63d38c..a9deb8e 100644 --- a/include/qemu/throttle-options.h +++ b/include/qemu/throttle-options.h @@ -11,6 +11,7 @@ #define THROTTLE_OPTIONS_H #include "typedefs.h" +#include "qapi-types.h" #define THROTTLE_OPTS \ { \ @@ -93,4 +94,6 @@ void throttle_parse_options(ThrottleConfig *, QemuOpts *); +void throttle_set_io_limits(ThrottleConfig *, IOThrottle *); + #endif diff --git a/util/throttle.c b/util/throttle.c index 95c2ecf..2d00532 100644 --- a/util/throttle.c +++ b/util/throttle.c @@ -553,3 +553,62 @@ void throttle_parse_options(ThrottleConfig *throttle_cfg, QemuOpts *opts) throttle_cfg->op_size = qemu_opt_get_number(opts, "throttling.iops-size", 0); } + +/* set the throttle limits + * + * @arg: iothrottle limits + * @cfg: throttle configuration + */ +void throttle_set_io_limits(ThrottleConfig *cfg, IOThrottle *arg) +{ + throttle_config_init(cfg); + cfg->buckets[THROTTLE_BPS_TOTAL].avg = arg->bps; + cfg->buckets[THROTTLE_BPS_READ].avg = arg->bps_rd; + cfg->buckets[THROTTLE_BPS_WRITE].avg = arg->bps_wr; + + cfg->buckets[THROTTLE_OPS_TOTAL].avg = arg->iops; + cfg->buckets[THROTTLE_OPS_READ].avg = arg->iops_rd; + cfg->buckets[THROTTLE_OPS_WRITE].avg = arg->iops_wr; + + if (arg->has_bps_max) { + cfg->buckets[THROTTLE_BPS_TOTAL].max = arg->bps_max; + } + if (arg->has_bps_rd_max) { + cfg->buckets[THROTTLE_BPS_READ].max = arg->bps_rd_max; + } + if (arg->has_bps_wr_max) { + cfg->buckets[THROTTLE_BPS_WRITE].max = arg->bps_wr_max; + } + if (arg->has_iops_max) { + cfg->buckets[THROTTLE_OPS_TOTAL].max = arg->iops_max; + } + if (arg->has_iops_rd_max) { + cfg->buckets[THROTTLE_OPS_READ].max = arg->iops_rd_max; + } + if (arg->has_iops_wr_max) { + cfg->buckets[THROTTLE_OPS_WRITE].max = arg->iops_wr_max; + } + + if (arg->has_bps_max_length) { + cfg->buckets[THROTTLE_BPS_TOTAL].burst_length = arg->bps_max_length; + } + if (arg->has_bps_rd_max_length) { + cfg->buckets[THROTTLE_BPS_READ].burst_length = arg->bps_rd_max_length; + } + if (arg->has_bps_wr_max_length) { + cfg->buckets[THROTTLE_BPS_WRITE].burst_length = arg->bps_wr_max_length; + } + if (arg->has_iops_max_length) { + cfg->buckets[THROTTLE_OPS_TOTAL].burst_length = arg->iops_max_length; + } + if (arg->has_iops_rd_max_length) { + cfg->buckets[THROTTLE_OPS_READ].burst_length = arg->iops_rd_max_length; + } + if (arg->has_iops_wr_max_length) { + cfg->buckets[THROTTLE_OPS_WRITE].burst_length = arg->iops_wr_max_length; + } + + if (arg->has_iops_size) { + cfg->op_size = arg->iops_size; + } +}