From nobody Wed Nov 5 11:06:58 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504541806616914.8716788756382; Mon, 4 Sep 2017 09:16:46 -0700 (PDT) Received: from localhost ([::1]:54775 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dou3J-0004qx-JI for importer@patchew.org; Mon, 04 Sep 2017 12:16:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46897) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dotvK-0007L8-MR for qemu-devel@nongnu.org; Mon, 04 Sep 2017 12:08:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dotvF-0008Rk-Mz for qemu-devel@nongnu.org; Mon, 04 Sep 2017 12:08:30 -0400 Received: from mail-wr0-x244.google.com ([2a00:1450:400c:c0c::244]:34665) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dotvF-0008RW-Di for qemu-devel@nongnu.org; Mon, 04 Sep 2017 12:08:25 -0400 Received: by mail-wr0-x244.google.com with SMTP id n33so207260wrn.1 for ; Mon, 04 Sep 2017 09:08:25 -0700 (PDT) Received: from localhost.localdomain.localdomain ([217.110.131.66]) by smtp.gmail.com with ESMTPSA id x67sm976582wma.7.2017.09.04.09.08.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Sep 2017 09:08:23 -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=6kTUcdrrtIF5MipoeekxxsqfHda0GA+8ZHpmgcZu4D0=; b=JehbBIdFt01pOCp4FyktsV17pPwDDEJRNvyLnMzIZN9UNSdxONNSwBuMKo30/ourG5 fKoX1Cmsf6W0H4z4FKDW5hrq/9MZ2Z13i+Pv57mc6Xe+HuMiyQ0gEqz6WzL25mHVRo+0 jRN6GptPOj9N1yED0x3AJ/NpBnnhBBl0noMYJsGpOICgT2jFevYF4fEckdb6YtRLheyG MWiD6kyZZBKIMSrtZ3fK4I3FRSvvaWEtPt6MOZSD5ylf+uZEmp51STtxFIX+AJEcMDFR skIKceHC0qD4Ew2LxS30aW7/v4yBpa5Sy1Jq2bXopHlo5jFvunbmaWXZznIY/D3adC2P xTHw== 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=6kTUcdrrtIF5MipoeekxxsqfHda0GA+8ZHpmgcZu4D0=; b=WLsitA9VK18fz6cHRSLREz+uQbRhGpPaA+YvYaBuzFfwjshemugT3FUizQUGG8PPyG mZGZ+ZVXprD0luux0sz9iJi3FU0RpSZBkYOln7MksaeX/cGyl4NUElQwvM5OEqTqTMN7 Bgkfr3eDi77pnR6FgCDxhInJau2xeOrzESWSSO/2nJht8yLac3tYkrWuLwMxl8JJHS3U kO6fcwrLsknBaqhkFy8O9i3uzH78uI7Sew90Ip090RCbXO86hLwwDy0aeViOtUK4k9P0 76xfVACzah2S2Da5OSglA4NwotaEtUPwaGcsKHQvnfkBmU4uSCO2eJAYbDID8IdH+E8+ cEEw== X-Gm-Message-State: AHPjjUhVp7y/W9uYLUkm5HU20z+7Y/XNoKsUkKJXgb/F/5ObEklL7z2c uBArpRjIor0FLg== X-Google-Smtp-Source: ADKCNb6qKs7D0XFUTGtjNoagvqMJhDtNFuUWzCSd4EQqphQYLrpsZxiDYVQOgQCJu4zaS6ASvEJywg== X-Received: by 10.223.142.199 with SMTP id q65mr602521wrb.110.1504541304365; Mon, 04 Sep 2017 09:08:24 -0700 (PDT) From: Pradeep Jagadeesh X-Google-Original-From: Pradeep Jagadeesh To: "eric blake" , "greg kurz" 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 recognized. X-Received-From: 2a00:1450:400c:c0c::244 Subject: [Qemu-devel] [PATCH v10 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Alberto Garcia Reviewed-by: Greg Kurz --- blockdev.c | 53 +++--------------------------------- include/qemu/throttle-options.h | 2 ++ util/throttle.c | 59 +++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 64 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; =20 blk =3D 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; } =20 - throttle_config_init(&cfg); - cfg.buckets[THROTTLE_BPS_TOTAL].avg =3D arg->bps; - cfg.buckets[THROTTLE_BPS_READ].avg =3D arg->bps_rd; - cfg.buckets[THROTTLE_BPS_WRITE].avg =3D arg->bps_wr; - - cfg.buckets[THROTTLE_OPS_TOTAL].avg =3D arg->iops; - cfg.buckets[THROTTLE_OPS_READ].avg =3D arg->iops_rd; - cfg.buckets[THROTTLE_OPS_WRITE].avg =3D arg->iops_wr; - - if (arg->has_bps_max) { - cfg.buckets[THROTTLE_BPS_TOTAL].max =3D arg->bps_max; - } - if (arg->has_bps_rd_max) { - cfg.buckets[THROTTLE_BPS_READ].max =3D arg->bps_rd_max; - } - if (arg->has_bps_wr_max) { - cfg.buckets[THROTTLE_BPS_WRITE].max =3D arg->bps_wr_max; - } - if (arg->has_iops_max) { - cfg.buckets[THROTTLE_OPS_TOTAL].max =3D arg->iops_max; - } - if (arg->has_iops_rd_max) { - cfg.buckets[THROTTLE_OPS_READ].max =3D arg->iops_rd_max; - } - if (arg->has_iops_wr_max) { - cfg.buckets[THROTTLE_OPS_WRITE].max =3D arg->iops_wr_max; - } - - if (arg->has_bps_max_length) { - cfg.buckets[THROTTLE_BPS_TOTAL].burst_length =3D arg->bps_max_leng= th; - } - if (arg->has_bps_rd_max_length) { - cfg.buckets[THROTTLE_BPS_READ].burst_length =3D arg->bps_rd_max_le= ngth; - } - if (arg->has_bps_wr_max_length) { - cfg.buckets[THROTTLE_BPS_WRITE].burst_length =3D arg->bps_wr_max_l= ength; - } - if (arg->has_iops_max_length) { - cfg.buckets[THROTTLE_OPS_TOTAL].burst_length =3D arg->iops_max_len= gth; - } - if (arg->has_iops_rd_max_length) { - cfg.buckets[THROTTLE_OPS_READ].burst_length =3D arg->iops_rd_max_l= ength; - } - if (arg->has_iops_wr_max_length) { - cfg.buckets[THROTTLE_OPS_WRITE].burst_length =3D arg->iops_wr_max_= length; - } - - if (arg->has_iops_size) { - cfg.op_size =3D arg->iops_size; - } + iothrottle =3D qapi_BlockIOThrottle_base(arg); + throttle_set_io_limits(&cfg, iothrottle); =20 if (!throttle_is_valid(&cfg, errp)) { goto out; diff --git a/include/qemu/throttle-options.h b/include/qemu/throttle-option= s.h index f63d38c..b736185 100644 --- a/include/qemu/throttle-options.h +++ b/include/qemu/throttle-options.h @@ -11,6 +11,7 @@ #define THROTTLE_OPTIONS_H =20 #include "typedefs.h" +#include "qapi-types.h" =20 #define THROTTLE_OPTS \ { \ @@ -92,5 +93,6 @@ } =20 void throttle_parse_options(ThrottleConfig *, QemuOpts *); +void throttle_set_io_limits(ThrottleConfig *, IOThrottle *); =20 #endif diff --git a/util/throttle.c b/util/throttle.c index 95c2ecf..dcc9d5a 100644 --- a/util/throttle.c +++ b/util/throttle.c @@ -553,3 +553,62 @@ void throttle_parse_options(ThrottleConfig *throttle_c= fg, QemuOpts *opts) throttle_cfg->op_size =3D qemu_opt_get_number(opts, "throttling.iops-size", 0); } + +/* Initialize a throttle config from an IOThrottle structure + * + * @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 =3D arg->bps; + cfg->buckets[THROTTLE_BPS_READ].avg =3D arg->bps_rd; + cfg->buckets[THROTTLE_BPS_WRITE].avg =3D arg->bps_wr; + + cfg->buckets[THROTTLE_OPS_TOTAL].avg =3D arg->iops; + cfg->buckets[THROTTLE_OPS_READ].avg =3D arg->iops_rd; + cfg->buckets[THROTTLE_OPS_WRITE].avg =3D arg->iops_wr; + + if (arg->has_bps_max) { + cfg->buckets[THROTTLE_BPS_TOTAL].max =3D arg->bps_max; + } + if (arg->has_bps_rd_max) { + cfg->buckets[THROTTLE_BPS_READ].max =3D arg->bps_rd_max; + } + if (arg->has_bps_wr_max) { + cfg->buckets[THROTTLE_BPS_WRITE].max =3D arg->bps_wr_max; + } + if (arg->has_iops_max) { + cfg->buckets[THROTTLE_OPS_TOTAL].max =3D arg->iops_max; + } + if (arg->has_iops_rd_max) { + cfg->buckets[THROTTLE_OPS_READ].max =3D arg->iops_rd_max; + } + if (arg->has_iops_wr_max) { + cfg->buckets[THROTTLE_OPS_WRITE].max =3D arg->iops_wr_max; + } + + if (arg->has_bps_max_length) { + cfg->buckets[THROTTLE_BPS_TOTAL].burst_length =3D arg->bps_max_len= gth; + } + if (arg->has_bps_rd_max_length) { + cfg->buckets[THROTTLE_BPS_READ].burst_length =3D arg->bps_rd_max_l= ength; + } + if (arg->has_bps_wr_max_length) { + cfg->buckets[THROTTLE_BPS_WRITE].burst_length =3D arg->bps_wr_max_= length; + } + if (arg->has_iops_max_length) { + cfg->buckets[THROTTLE_OPS_TOTAL].burst_length =3D arg->iops_max_le= ngth; + } + if (arg->has_iops_rd_max_length) { + cfg->buckets[THROTTLE_OPS_READ].burst_length =3D arg->iops_rd_max_= length; + } + if (arg->has_iops_wr_max_length) { + cfg->buckets[THROTTLE_OPS_WRITE].burst_length =3D arg->iops_wr_max= _length; + } + + if (arg->has_iops_size) { + cfg->op_size =3D arg->iops_size; + } +} --=20 1.8.3.1