From patchwork Thu Jun 29 15:10:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pradeep Jagadeesh X-Patchwork-Id: 782334 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wz3Ff1Yb0z9s3T for ; Fri, 30 Jun 2017 01:18:14 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="t0TObfVA"; dkim-atps=neutral Received: from localhost ([::1]:39934 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQbCt-0005Y4-TN for incoming@patchwork.ozlabs.org; Thu, 29 Jun 2017 11:18:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32925) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQb6Y-000061-LJ for qemu-devel@nongnu.org; Thu, 29 Jun 2017 11:11:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQb6S-00031B-C6 for qemu-devel@nongnu.org; Thu, 29 Jun 2017 11:11:38 -0400 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]:34448) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQb6S-00030u-37 for qemu-devel@nongnu.org; Thu, 29 Jun 2017 11:11:32 -0400 Received: by mail-wr0-x243.google.com with SMTP id k67so36931845wrc.1 for ; Thu, 29 Jun 2017 08:11:32 -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=xecWyyfqe8Pv66Idqb5Tt3s7RKs7L7BjrRN8rU9FZEQ=; b=t0TObfVANkExbudq57Ju8b6QRINbMLlfBQLyobcuKGMhYFixsKlB9CSvErMuW31R6G kjGgopJgsxmJs4pvWSGIED7iSk4TLR+r4VD+F+SLAYxPSliQLl052edMSXssXVCDJEFh TQXxOexGyl0FcqOuaZ0gBODtJ8FapjwH3oQIF0xMxH8I6/yrYBEThvPb0bR71ZvewJLe oB7ofMJCGG1+eGbeL2phanUHaP+rizaCwT/Ybln6cF9781DumFTwKZ4CETItHRx1VmFS loFAOTSZAe9R3kyn8lqRX8iZhJbzeINBix3nXdb7LDPzTgi1Iv85KaY9DrWgzsUYCj1/ 1S8w== 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=xecWyyfqe8Pv66Idqb5Tt3s7RKs7L7BjrRN8rU9FZEQ=; b=HUF2u2VZ1Iq3wZ1aOvuHMKlkUZ+29hT0V4/U129ePoa1wNqttQrSWPYTdU87O2Ho0n uokgrE4g5LM0WnLjg9eo/OjO/sziMbVuVrH5o0yzrI+u4GN8ZXxTCkGmf9S/rZ01f2AZ mvKaQje8Hap8lxRxLJKIvsyOq/BiX9PMWqpZsfAEvAheD5+xKb8sls3Sb6Xru84fs+5o rYWN8XUaJPaLYBTbNukLOF7o6xWx/Gu03MxMcpXkJ6xScCFkACQ0OyVu/0MYDGefctTU Tmr9Oes4f01RzhBP+mmrUpVX7PsmK4wa8qDG5l1k1vUb7Rc9yiPsjy9WEBWtoH99xuQt c0bQ== X-Gm-Message-State: AKS2vOx3LRko/3l7gLYewReaXWsxf1YKfvYvqJ33lw1YQt6H9zC21pkY CzhxQg1qFZFzWQ== X-Received: by 10.223.153.65 with SMTP id x59mr24901421wrb.32.1498749091055; Thu, 29 Jun 2017 08:11:31 -0700 (PDT) Received: from localhost.localdomain.localdomain ([217.110.131.66]) by smtp.gmail.com with ESMTPSA id r142sm1679641wmg.24.2017.06.29.08.11.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Jun 2017 08:11:30 -0700 (PDT) From: Pradeep Jagadeesh X-Google-Original-From: Pradeep Jagadeesh To: "eric blake" , "greg kurz" Date: Thu, 29 Jun 2017 11:10:53 -0400 Message-Id: <1498749056-38565-4-git-send-email-pradeep.jagadeesh@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1498749056-38565-1-git-send-email-pradeep.jagadeesh@huawei.com> References: <1498749056-38565-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::243 Subject: [Qemu-devel] [PATCH 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 | 4 +++ util/throttle.c | 59 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 50 deletions(-) diff --git a/blockdev.c b/blockdev.c index a95ea41..8090798 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2579,6 +2579,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, @@ -2596,56 +2597,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 659a410..ac4f221 100644 --- a/include/qemu/throttle-options.h +++ b/include/qemu/throttle-options.h @@ -10,6 +10,8 @@ #ifndef THROTTLE_OPTIONS_H #define THROTTLE_OPTIONS_H +#include "qmp-commands.h" + #define THROTTLE_OPTS \ { \ .name = "throttling.iops-total",\ @@ -91,4 +93,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 a751126..2cf9ec5 100644 --- a/util/throttle.c +++ b/util/throttle.c @@ -565,3 +565,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; + } +}