From patchwork Mon Sep 4 16:07:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pradeep Jagadeesh X-Patchwork-Id: 809753 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="UnqyTmnT"; dkim-atps=neutral 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 3xmFCb1bB3z9sNr for ; Tue, 5 Sep 2017 02:09:15 +1000 (AEST) Received: from localhost ([::1]:54734 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dotw1-0007OT-56 for incoming@patchwork.ozlabs.org; Mon, 04 Sep 2017 12:09:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46862) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dotvJ-0007KJ-1d for qemu-devel@nongnu.org; Mon, 04 Sep 2017 12:08:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dotvD-0008R0-MK for qemu-devel@nongnu.org; Mon, 04 Sep 2017 12:08:28 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:33839) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dotvD-0008QL-D8 for qemu-devel@nongnu.org; Mon, 04 Sep 2017 12:08:23 -0400 Received: by mail-wm0-x244.google.com with SMTP id r75so722856wmf.1 for ; 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=irDKxKGkaoOLI6Ox8CLrOXgSHf87WhGrI0kxMmsev4c=; b=UnqyTmnToqv4TMo5KAVTHxfitiwjlbHUcqcU8swDF2ZjXcTycV6SBS8F/vbN8JCvuc r6uTIWryLCeKTeOjXChFjxAlpFm3RwCGlqOG1heRz9jkHOA0BDAvbtDmhx7vUaGEWS33 SV1mKBeL7Q2Xsm3NnnUqRc8SwNKdiCpZ6CGFY/D0bDd8gTtxISnve+sjo6ckIxisEO6x /hPvUr1JYXclUclzBtLOGFgWOJxf66de3t47uLeIUSBowyemMH4uDh4Pw5Q/NlNTIfTT fNDejbXqzhCIj3nButSZp/klaygG+u4C/klJnON745a5JqDqhL8wnOsZw55B0F/yzMki 1mRQ== 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=irDKxKGkaoOLI6Ox8CLrOXgSHf87WhGrI0kxMmsev4c=; b=lsg5XNYnLb8wokyzgSVCo12H73kWUppd5glL9QGLUB5KTAM9BNxy7ejCw+QKM64yxd V/GSU/catc0Xy5h7Lolzq/Rty8CPF21fHGM7LGQUtF7VAQXo+cZ+RqHQL6byrGKOMMvf bLmtEzsHz7AaWON7QPnBCNOzTClL5zF523X6LC5odP+znhLy+hFLuuuBv9xWwB5sutM6 OcJe8U+rML1++UDoOyyiaAE8aWAHLKFjyN+vwBOPsBv5iuNMgzGN3KlT4yd9kHgu5ppo aETiUIg6eXeeZhEpzobB4YsP35XXOWUMs2h8QnpnzRhCVZHdTfQu5OdK4c38epBDusWO Px1A== X-Gm-Message-State: AHPjjUiBmWVRthesedVMg4bpv2DM5c1hy0vJZ6KhYQRA0dCn9OzMew1x u1x8sIJXtsLjkg== X-Google-Smtp-Source: ADKCNb7XixnNj286/XXzsGFzTGpXy2Zzcg9DNxlKQ+U2UmvmgJWVzygoC59n9Ey51XNlDL50ZjbdYg== X-Received: by 10.28.45.209 with SMTP id t200mr794718wmt.168.1504541302294; Mon, 04 Sep 2017 09:08:22 -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.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Sep 2017 09:08:21 -0700 (PDT) From: Pradeep Jagadeesh X-Google-Original-From: Pradeep Jagadeesh To: "eric blake" , "greg kurz" Date: Mon, 4 Sep 2017 12:07:42 -0400 Message-Id: <1504541267-36954-2-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:c09::244 Subject: [Qemu-devel] [PATCH v10 1/6] throttle: factor out duplicate 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 factor out the duplicate throttle code that was present in block and fsdev devices. Signed-off-by: Pradeep Jagadeesh Reviewed-by: Alberto Garcia Reviewed-by: Greg Kurz --- blockdev.c | 44 +---------------------------------- fsdev/qemu-fsdev-throttle.c | 44 ++--------------------------------- include/qemu/throttle-options.h | 4 ++++ include/qemu/throttle.h | 4 ++-- include/qemu/typedefs.h | 1 + util/throttle.c | 51 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 61 insertions(+), 87 deletions(-) diff --git a/blockdev.c b/blockdev.c index 02cd69b..780ae58 100644 --- a/blockdev.c +++ b/blockdev.c @@ -388,49 +388,7 @@ static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags, } if (throttle_cfg) { - throttle_config_init(throttle_cfg); - throttle_cfg->buckets[THROTTLE_BPS_TOTAL].avg = - qemu_opt_get_number(opts, "throttling.bps-total", 0); - throttle_cfg->buckets[THROTTLE_BPS_READ].avg = - qemu_opt_get_number(opts, "throttling.bps-read", 0); - throttle_cfg->buckets[THROTTLE_BPS_WRITE].avg = - qemu_opt_get_number(opts, "throttling.bps-write", 0); - throttle_cfg->buckets[THROTTLE_OPS_TOTAL].avg = - qemu_opt_get_number(opts, "throttling.iops-total", 0); - throttle_cfg->buckets[THROTTLE_OPS_READ].avg = - qemu_opt_get_number(opts, "throttling.iops-read", 0); - throttle_cfg->buckets[THROTTLE_OPS_WRITE].avg = - qemu_opt_get_number(opts, "throttling.iops-write", 0); - - throttle_cfg->buckets[THROTTLE_BPS_TOTAL].max = - qemu_opt_get_number(opts, "throttling.bps-total-max", 0); - throttle_cfg->buckets[THROTTLE_BPS_READ].max = - qemu_opt_get_number(opts, "throttling.bps-read-max", 0); - throttle_cfg->buckets[THROTTLE_BPS_WRITE].max = - qemu_opt_get_number(opts, "throttling.bps-write-max", 0); - throttle_cfg->buckets[THROTTLE_OPS_TOTAL].max = - qemu_opt_get_number(opts, "throttling.iops-total-max", 0); - throttle_cfg->buckets[THROTTLE_OPS_READ].max = - qemu_opt_get_number(opts, "throttling.iops-read-max", 0); - throttle_cfg->buckets[THROTTLE_OPS_WRITE].max = - qemu_opt_get_number(opts, "throttling.iops-write-max", 0); - - throttle_cfg->buckets[THROTTLE_BPS_TOTAL].burst_length = - qemu_opt_get_number(opts, "throttling.bps-total-max-length", 1); - throttle_cfg->buckets[THROTTLE_BPS_READ].burst_length = - qemu_opt_get_number(opts, "throttling.bps-read-max-length", 1); - throttle_cfg->buckets[THROTTLE_BPS_WRITE].burst_length = - qemu_opt_get_number(opts, "throttling.bps-write-max-length", 1); - throttle_cfg->buckets[THROTTLE_OPS_TOTAL].burst_length = - qemu_opt_get_number(opts, "throttling.iops-total-max-length", 1); - throttle_cfg->buckets[THROTTLE_OPS_READ].burst_length = - qemu_opt_get_number(opts, "throttling.iops-read-max-length", 1); - throttle_cfg->buckets[THROTTLE_OPS_WRITE].burst_length = - qemu_opt_get_number(opts, "throttling.iops-write-max-length", 1); - - throttle_cfg->op_size = - qemu_opt_get_number(opts, "throttling.iops-size", 0); - + throttle_parse_options(throttle_cfg, opts); if (!throttle_is_valid(throttle_cfg, errp)) { return; } diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c index 49eebb5..0e6fb86 100644 --- a/fsdev/qemu-fsdev-throttle.c +++ b/fsdev/qemu-fsdev-throttle.c @@ -16,6 +16,7 @@ #include "qemu/error-report.h" #include "qemu-fsdev-throttle.h" #include "qemu/iov.h" +#include "qemu/throttle-options.h" static void fsdev_throttle_read_timer_cb(void *opaque) { @@ -31,48 +32,7 @@ static void fsdev_throttle_write_timer_cb(void *opaque) void fsdev_throttle_parse_opts(QemuOpts *opts, FsThrottle *fst, Error **errp) { - throttle_config_init(&fst->cfg); - fst->cfg.buckets[THROTTLE_BPS_TOTAL].avg = - qemu_opt_get_number(opts, "throttling.bps-total", 0); - fst->cfg.buckets[THROTTLE_BPS_READ].avg = - qemu_opt_get_number(opts, "throttling.bps-read", 0); - fst->cfg.buckets[THROTTLE_BPS_WRITE].avg = - qemu_opt_get_number(opts, "throttling.bps-write", 0); - fst->cfg.buckets[THROTTLE_OPS_TOTAL].avg = - qemu_opt_get_number(opts, "throttling.iops-total", 0); - fst->cfg.buckets[THROTTLE_OPS_READ].avg = - qemu_opt_get_number(opts, "throttling.iops-read", 0); - fst->cfg.buckets[THROTTLE_OPS_WRITE].avg = - qemu_opt_get_number(opts, "throttling.iops-write", 0); - - fst->cfg.buckets[THROTTLE_BPS_TOTAL].max = - qemu_opt_get_number(opts, "throttling.bps-total-max", 0); - fst->cfg.buckets[THROTTLE_BPS_READ].max = - qemu_opt_get_number(opts, "throttling.bps-read-max", 0); - fst->cfg.buckets[THROTTLE_BPS_WRITE].max = - qemu_opt_get_number(opts, "throttling.bps-write-max", 0); - fst->cfg.buckets[THROTTLE_OPS_TOTAL].max = - qemu_opt_get_number(opts, "throttling.iops-total-max", 0); - fst->cfg.buckets[THROTTLE_OPS_READ].max = - qemu_opt_get_number(opts, "throttling.iops-read-max", 0); - fst->cfg.buckets[THROTTLE_OPS_WRITE].max = - qemu_opt_get_number(opts, "throttling.iops-write-max", 0); - - fst->cfg.buckets[THROTTLE_BPS_TOTAL].burst_length = - qemu_opt_get_number(opts, "throttling.bps-total-max-length", 1); - fst->cfg.buckets[THROTTLE_BPS_READ].burst_length = - qemu_opt_get_number(opts, "throttling.bps-read-max-length", 1); - fst->cfg.buckets[THROTTLE_BPS_WRITE].burst_length = - qemu_opt_get_number(opts, "throttling.bps-write-max-length", 1); - fst->cfg.buckets[THROTTLE_OPS_TOTAL].burst_length = - qemu_opt_get_number(opts, "throttling.iops-total-max-length", 1); - fst->cfg.buckets[THROTTLE_OPS_READ].burst_length = - qemu_opt_get_number(opts, "throttling.iops-read-max-length", 1); - fst->cfg.buckets[THROTTLE_OPS_WRITE].burst_length = - qemu_opt_get_number(opts, "throttling.iops-write-max-length", 1); - fst->cfg.op_size = - qemu_opt_get_number(opts, "throttling.iops-size", 0); - + throttle_parse_options(&fst->cfg, opts); throttle_is_valid(&fst->cfg, errp); } diff --git a/include/qemu/throttle-options.h b/include/qemu/throttle-options.h index 3133d1c..f63d38c 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 "typedefs.h" + #define THROTTLE_OPTS \ { \ .name = "throttling.iops-total",\ @@ -89,4 +91,6 @@ .help = "when limiting by iops max size of an I/O in bytes",\ } +void throttle_parse_options(ThrottleConfig *, QemuOpts *); + #endif diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h index d056008..75d930c 100644 --- a/include/qemu/throttle.h +++ b/include/qemu/throttle.h @@ -89,10 +89,10 @@ typedef struct LeakyBucket { * However it allows to keep the code clean and the bucket field is reset to * zero at the right time. */ -typedef struct ThrottleConfig { +struct ThrottleConfig { LeakyBucket buckets[BUCKETS_COUNT]; /* leaky buckets */ uint64_t op_size; /* size of an operation in bytes */ -} ThrottleConfig; +}; typedef struct ThrottleState { ThrottleConfig cfg; /* configuration */ diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h index 39bc835..90fe0f9 100644 --- a/include/qemu/typedefs.h +++ b/include/qemu/typedefs.h @@ -100,6 +100,7 @@ typedef struct uWireSlave uWireSlave; typedef struct VirtIODevice VirtIODevice; typedef struct Visitor Visitor; typedef struct node_info NodeInfo; +typedef struct ThrottleConfig ThrottleConfig; typedef void SaveStateHandler(QEMUFile *f, void *opaque); typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id); diff --git a/util/throttle.c b/util/throttle.c index b2a52b8..95c2ecf 100644 --- a/util/throttle.c +++ b/util/throttle.c @@ -27,6 +27,7 @@ #include "qemu/throttle.h" #include "qemu/timer.h" #include "block/aio.h" +#include "qemu/throttle-options.h" /* This function make a bucket leak * @@ -502,3 +503,53 @@ void throttle_account(ThrottleState *ts, bool is_write, uint64_t size) } } +/* parse the throttle options + * + * @opts: qemu options + * @throttle_cfg: throttle configuration + */ +void throttle_parse_options(ThrottleConfig *throttle_cfg, QemuOpts *opts) +{ + throttle_config_init(throttle_cfg); + throttle_cfg->buckets[THROTTLE_BPS_TOTAL].avg = + qemu_opt_get_number(opts, "throttling.bps-total", 0); + throttle_cfg->buckets[THROTTLE_BPS_READ].avg = + qemu_opt_get_number(opts, "throttling.bps-read", 0); + throttle_cfg->buckets[THROTTLE_BPS_WRITE].avg = + qemu_opt_get_number(opts, "throttling.bps-write", 0); + throttle_cfg->buckets[THROTTLE_OPS_TOTAL].avg = + qemu_opt_get_number(opts, "throttling.iops-total", 0); + throttle_cfg->buckets[THROTTLE_OPS_READ].avg = + qemu_opt_get_number(opts, "throttling.iops-read", 0); + throttle_cfg->buckets[THROTTLE_OPS_WRITE].avg = + qemu_opt_get_number(opts, "throttling.iops-write", 0); + + throttle_cfg->buckets[THROTTLE_BPS_TOTAL].max = + qemu_opt_get_number(opts, "throttling.bps-total-max", 0); + throttle_cfg->buckets[THROTTLE_BPS_READ].max = + qemu_opt_get_number(opts, "throttling.bps-read-max", 0); + throttle_cfg->buckets[THROTTLE_BPS_WRITE].max = + qemu_opt_get_number(opts, "throttling.bps-write-max", 0); + throttle_cfg->buckets[THROTTLE_OPS_TOTAL].max = + qemu_opt_get_number(opts, "throttling.iops-total-max", 0); + throttle_cfg->buckets[THROTTLE_OPS_READ].max = + qemu_opt_get_number(opts, "throttling.iops-read-max", 0); + throttle_cfg->buckets[THROTTLE_OPS_WRITE].max = + qemu_opt_get_number(opts, "throttling.iops-write-max", 0); + + throttle_cfg->buckets[THROTTLE_BPS_TOTAL].burst_length = + qemu_opt_get_number(opts, "throttling.bps-total-max-length", 1); + throttle_cfg->buckets[THROTTLE_BPS_READ].burst_length = + qemu_opt_get_number(opts, "throttling.bps-read-max-length", 1); + throttle_cfg->buckets[THROTTLE_BPS_WRITE].burst_length = + qemu_opt_get_number(opts, "throttling.bps-write-max-length", 1); + throttle_cfg->buckets[THROTTLE_OPS_TOTAL].burst_length = + qemu_opt_get_number(opts, "throttling.iops-total-max-length", 1); + throttle_cfg->buckets[THROTTLE_OPS_READ].burst_length = + qemu_opt_get_number(opts, "throttling.iops-read-max-length", 1); + throttle_cfg->buckets[THROTTLE_OPS_WRITE].burst_length = + qemu_opt_get_number(opts, "throttling.iops-write-max-length", 1); + + throttle_cfg->op_size = + qemu_opt_get_number(opts, "throttling.iops-size", 0); +} From patchwork Mon Sep 4 16:07:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pradeep Jagadeesh X-Patchwork-Id: 809757 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=208.118.235.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Bbidqhn0"; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 3xmFJk47Vdz9s7m for ; Tue, 5 Sep 2017 02:13:42 +1000 (AEST) Received: from localhost ([::1]:54762 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dou0K-0002p6-II for incoming@patchwork.ozlabs.org; Mon, 04 Sep 2017 12:13:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46882) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dotvJ-0007Kd-Mi for qemu-devel@nongnu.org; Mon, 04 Sep 2017 12:08:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dotvE-0008RS-Mc for qemu-devel@nongnu.org; Mon, 04 Sep 2017 12:08:29 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:33075) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dotvE-0008RA-GM for qemu-devel@nongnu.org; Mon, 04 Sep 2017 12:08:24 -0400 Received: by mail-wm0-x244.google.com with SMTP id 187so726460wmn.0 for ; Mon, 04 Sep 2017 09:08:24 -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=PMWb39TG6i90d/bBdYkgh1s4O4E5BpKYtBUKz04GHyM=; b=Bbidqhn0CLjik2+jTQ3pmnhi4ZjXabf8oozdg/X6+ooKCE9rEyQ/Q46GVZ7IAYNHXY uDmEkVz7+xFdDkC7877PUpsxqrGNgBx0pyCeeNcEzlstfRiSqRBbBbhibPYGdapfc1a5 Q7hrwOzmnV2xnGv1VYvDqE4+n0Kk+YlNd7HAlMEID45kwUN88baf1nQOd1s1j9tUd1+x nglgJCIwU7GWrEdiuYwsk/D2zPkv6sdOSa7JAeNywWen5ef9yyK4hSumvu1bJY1Reiah rmzV72paTb1Y/GN+aDHtwKNZr9z5gte3KS/Y8GLS+HTUrJbtVhakFxSgZ9mKO+XMvIxl ve2A== 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=PMWb39TG6i90d/bBdYkgh1s4O4E5BpKYtBUKz04GHyM=; b=HR1rhY9+rmYmGO7Z1XKk5snl0wxNW4szMPUsPQtUPeZJxzmOCoWCfAYgqWNn5DPfH5 mlRCGJH2qTsDPR67de7AcIGr9o+lTDuWNUoiovvC0eIKq748bOyWgR0X2gYtkLDBYhKB RJKjBFy/lPp2IaFNhgHV367T6T75YuFub/G4TXe/8zdvKmHdOynK7Og9Lz3ALC1H7rWr 9KwmEwCJgi1oXkVkO025ZAu7lguCIZY4qggA5r+q2RvVI7fSu8ti1HmUdoJ6GnIl+hOq FmNVgHAPuQqxm+UjjPd94YUGNHzpnGSIvboNEvZPGFm8D3bA6fb/0Bd1rehJjHFDex7X gblQ== X-Gm-Message-State: AHPjjUhPx70pQHlJe4SpD2bJ37UprDbrX5NLySnSt9JJm5j+z5Mu2BT7 a5zZpYNh4jSwEg== X-Google-Smtp-Source: ADKCNb4dHyC8hT8zSfVxxu1es0NXCsRuKSbw3y9iwfa6GNPiiuJcpr16WWTDFLq4P3zrDIJhFuKupA== X-Received: by 10.28.131.211 with SMTP id f202mr763934wmd.187.1504541303474; Mon, 04 Sep 2017 09:08:23 -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.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Sep 2017 09:08:22 -0700 (PDT) From: Pradeep Jagadeesh X-Google-Original-From: Pradeep Jagadeesh To: "eric blake" , "greg kurz" Date: Mon, 4 Sep 2017 12:07:43 -0400 Message-Id: <1504541267-36954-3-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:c09::244 Subject: [Qemu-devel] [PATCH v10 2/6] qmp: Create IOThrottle structure 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: jani kokkonen , alberto garcia , Pradeep Jagadeesh , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This patch enables qmp interfaces for the fsdev devices. This provides two interfaces one for querying info of all the fsdev devices. The second one to set the IO limits for the required fsdev device. Signed-off-by: Pradeep Jagadeesh Reviewed-by: Greg Kurz Reviewed-by: Eric Blake Reviewed-by: Alberto Garcia Reviewed-by: Markus Armbruster --- qapi/block-core.json | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 833c602..a01074c 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -1819,11 +1819,13 @@ 'data': 'BlockIOThrottle' } ## -# @BlockIOThrottle: -# -# A set of parameters describing block throttling. +# == QAPI IOThrottle definitions +## + +## +# @IOThrottle: # -# @device: Block device name (deprecated, use @id instead) +# A set of parameters describing IO throttling # # @id: The name or QOM path of the guest device (since: 2.8) # @@ -1889,12 +1891,11 @@ # # @iops_size: an I/O size in bytes (Since 1.7) # -# @group: throttle group name (Since 2.4) # -# Since: 1.1 +# Since: 2.11 ## -{ 'struct': 'BlockIOThrottle', - 'data': { '*device': 'str', '*id': 'str', 'bps': 'int', 'bps_rd': 'int', +{ 'struct': 'IOThrottle', + 'data': { '*id': 'str', 'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int', 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int', '*bps_max': 'int', '*bps_rd_max': 'int', '*bps_wr_max': 'int', '*iops_max': 'int', @@ -1902,7 +1903,22 @@ '*bps_max_length': 'int', '*bps_rd_max_length': 'int', '*bps_wr_max_length': 'int', '*iops_max_length': 'int', '*iops_rd_max_length': 'int', '*iops_wr_max_length': 'int', - '*iops_size': 'int', '*group': 'str' } } + '*iops_size': 'int' } } + +## +# @BlockIOThrottle: +# +# A set of parameters describing block throttling. +# +# @device: Block device name (deprecated, use @id instead) +# +# @group: throttle group name (Since 2.4) +# +# Since: 1.1 +## +{ 'struct': 'BlockIOThrottle', + 'base': 'IOThrottle', + 'data': { '*device': 'str', '*group': 'str' } } ## # @block-stream: From patchwork Mon Sep 4 16:07:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pradeep Jagadeesh X-Patchwork-Id: 809759 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=208.118.235.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="JehbBIdF"; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 3xmFMj3qGLz9t2W for ; Tue, 5 Sep 2017 02:16:17 +1000 (AEST) Received: from localhost ([::1]:54774 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dou2p-0004Vw-GJ for incoming@patchwork.ozlabs.org; Mon, 04 Sep 2017 12:16:15 -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) 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) 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) 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+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 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; 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..b736185 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 \ { \ @@ -92,5 +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 95c2ecf..dcc9d5a 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); } + +/* 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 = 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; + } +} From patchwork Mon Sep 4 16:07:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pradeep Jagadeesh X-Patchwork-Id: 809758 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=208.118.235.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="dUdLz7Qf"; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 3xmFLT05RNz9s7m for ; Tue, 5 Sep 2017 02:15:13 +1000 (AEST) Received: from localhost ([::1]:54766 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dou1l-0003eD-UK for incoming@patchwork.ozlabs.org; Mon, 04 Sep 2017 12:15:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46902) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dotvL-0007LT-67 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 1dotvG-0008S2-Iv for qemu-devel@nongnu.org; Mon, 04 Sep 2017 12:08:31 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:37924) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dotvG-0008Ro-CW for qemu-devel@nongnu.org; Mon, 04 Sep 2017 12:08:26 -0400 Received: by mail-wm0-x244.google.com with SMTP id u26so699764wma.5 for ; Mon, 04 Sep 2017 09:08:26 -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=0A09PHsWtkbl3qVkFa3DyhICvvM1yY42z7IfzxkBSHc=; b=dUdLz7Qf1+uBCRVv29stsNCWl3n8GF9zwh6qSV0Ripzj2LNo36wE5+8zzmZufPnrjv htVdHla6e/Khqrq5/+wMPDLCABS2+wTWReqKEwe1CKREcQf54sEXSzbYstCiKlRWfUfi JzcljPcvwbkFX4iO77Kxc7JZhJHCi33PvpPRuUaqSpKNmxte/PBf6dzdfknJZQg9dxuA uZkue26seH+5fBXekdpYP0nYhPbslwXeqKOtCXqtXwUTXP3KDqEx99VPW4NA1PvclM9D II3oHxDhnE8B8N/wXGQAn/CCFz/3xli4J4tXF2vKEq2LgCx5Gl16fc8NUbdrBA+JE34D hWfw== 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=0A09PHsWtkbl3qVkFa3DyhICvvM1yY42z7IfzxkBSHc=; b=q3KBd0l1t6Eo9s382IuV+PGBc7ZT7gj8sjsLtzxRGPObevsn7I9UYpptPTdDGzXZP3 6279HV+LBuGJwlZncRXydLV7jr5WqMS3pBzST6o6v+bsmHrZhu9APcPXyi/13h6OUFtK bqAtzApojcB4lWziBDV102Wk7qYQDWnYuXRbWIziAcmmKZFam+9PIp2QgaKaWfV9a0JU Exm4Mz+YNZY5jIrxBdDYW527TDAexllX+DN57Vmc38Bmcs8CCqetYag3b4sGzUgC6XKU k86MeAqFtjiWKhMGZpY7ykXPg948fxde3KQzqcQRTlMjUcTcnGcOpIZD5pMdw3cbztGO GnHw== X-Gm-Message-State: AHPjjUjIWiFIvJkMoNkNUmhuskuB/pZhwsLcgaSW0YwH5OBPv+ZsxZF5 WrTJExyedRKyzQ== X-Google-Smtp-Source: ADKCNb6UFROlyBB/dmmwyMsKNxIxUjC3YN2kj4iyhw8ZGVAh7vqXIRiFPkiguMi+LHYDlp4jRh7qQA== X-Received: by 10.28.217.85 with SMTP id q82mr743258wmg.89.1504541305425; 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.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); 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:45 -0400 Message-Id: <1504541267-36954-5-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:c09::244 Subject: [Qemu-devel] [PATCH v10 4/6] hmp: create a throttle initialization function for code reusability 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 , "Dr. David Alan Gilbert" Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This patch creates a throttle initialization function to maximize the code reusability. The same code is also used by fsdev. Acked-by: Dr. David Alan Gilbert Signed-off-by: Pradeep Jagadeesh Reviewed-by: Alberto Garcia Reviewed-by: Greg Kurz --- hmp.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/hmp.c b/hmp.c index fd80dce..2dbfb80 100644 --- a/hmp.c +++ b/hmp.c @@ -1758,20 +1758,27 @@ void hmp_change(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, &err); } +static void hmp_initialize_io_throttle(IOThrottle *iot, const QDict *qdict) +{ + iot->bps = qdict_get_int(qdict, "bps"); + iot->bps_rd = qdict_get_int(qdict, "bps_rd"); + iot->bps_wr = qdict_get_int(qdict, "bps_wr"); + iot->iops = qdict_get_int(qdict, "iops"); + iot->iops_rd = qdict_get_int(qdict, "iops_rd"); + iot->iops_wr = qdict_get_int(qdict, "iops_wr"); +} + void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) { Error *err = NULL; + IOThrottle *iothrottle; BlockIOThrottle throttle = { .has_device = true, .device = (char *) qdict_get_str(qdict, "device"), - .bps = qdict_get_int(qdict, "bps"), - .bps_rd = qdict_get_int(qdict, "bps_rd"), - .bps_wr = qdict_get_int(qdict, "bps_wr"), - .iops = qdict_get_int(qdict, "iops"), - .iops_rd = qdict_get_int(qdict, "iops_rd"), - .iops_wr = qdict_get_int(qdict, "iops_wr"), }; + iothrottle = qapi_BlockIOThrottle_base(&throttle); + hmp_initialize_io_throttle(iothrottle, qdict); qmp_block_set_io_throttle(&throttle, &err); hmp_handle_error(mon, &err); } From patchwork Mon Sep 4 16:07:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pradeep Jagadeesh X-Patchwork-Id: 809755 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=208.118.235.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="to1JtHk1"; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 3xmFGF0hBsz9s7m for ; Tue, 5 Sep 2017 02:11:31 +1000 (AEST) Received: from localhost ([::1]:54751 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dotyD-00015d-En for incoming@patchwork.ozlabs.org; Mon, 04 Sep 2017 12:11:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46916) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dotvN-0007Mh-Ga for qemu-devel@nongnu.org; Mon, 04 Sep 2017 12:08:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dotvH-0008SM-Sb for qemu-devel@nongnu.org; Mon, 04 Sep 2017 12:08:33 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:35916) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dotvH-0008S9-IQ for qemu-devel@nongnu.org; Mon, 04 Sep 2017 12:08:27 -0400 Received: by mail-wm0-x241.google.com with SMTP id p17so708524wmd.3 for ; Mon, 04 Sep 2017 09:08:27 -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=Bs+bxCF8jrU9e1Smx4QoH3EBcFUasbz2H4vC/zrnmpM=; b=to1JtHk1QM+PEmVeCZocgUQZcd+tNmlIEBvki7A7fA3FArwrMuaHNmh1gn+S1tkJTp 0vMD9x1xZZ0vYn741znyrBqkIi54fguzp3SIYRvJjrupM2SR4dGM2HWttUz5UBvShWQP A8LTan3sn/wNExWBXyknpYqeY5JbZDYyMYT5l2MnlLhVJIZgOPFn1UxKofttj7dWna0M StvbibaQRbdkQLJ/Xm/lOOKAOonOVKRsUTehBP4yDhzQNrwelDx+eTNLcX0c1sAxnMWq 9rVlF+p+dsE2kXFrbWghmR1xYf64KjmaaNx509BL/x7RtMEAyLQFg3rPyVio3hJScZEI FlEA== 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=Bs+bxCF8jrU9e1Smx4QoH3EBcFUasbz2H4vC/zrnmpM=; b=kwcc8MOkapWQUAOCsAtQMi4IihW2ERkZyZrWynLZ+EeA+WTstc7W1QDtjNVOXmI4yy y2kl2ZwoPWzt75XIwBDTZ8aGljIwc1rdMkni8fhEhYmJPYFtabQXTZbSijaX+BDajz37 SivDL0c0VywnTtlQWeQqqlmZsgstMkzlaLbGZRJ4m4uOusJB0OH9SFxa+Fw1FCZ64Sat TSeS7uMSvUheB6gFMbHJFmWp6kmrgn3KxLbXCdm0VNNqm41dSsJ1xULpDVBYDlI3yI1Z FZqyKf28rLFg1cXhoOfbHSvsWKF1GxXgaNAYEm3Hjk+AbYdiZGYhk4z4SrPDT/ZUP7A5 lG4w== X-Gm-Message-State: AHPjjUjboxlOsFRf3GMjnjaDsUO11wDnBovzqbM8AafCVYqxmW4wAhSH hHA78fkoc7hyLE6o X-Google-Smtp-Source: ADKCNb6mTMk4WJIzzdjGfut4tYvKi8GNl0jr2yjWNxI/YdP07qfPUruSV+mdvhYPgzkHkL6zI5XMSg== X-Received: by 10.28.24.138 with SMTP id 132mr794890wmy.61.1504541306429; Mon, 04 Sep 2017 09:08:26 -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.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Sep 2017 09:08:25 -0700 (PDT) From: Pradeep Jagadeesh X-Google-Original-From: Pradeep Jagadeesh To: "eric blake" , "greg kurz" Date: Mon, 4 Sep 2017 12:07:46 -0400 Message-Id: <1504541267-36954-6-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:c09::241 Subject: [Qemu-devel] [PATCH v10 5/6] fsdev: QMP interface for throttling 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: alberto garcia , Markus Armbruster , qemu-devel@nongnu.org, "Dr. David Alan Gilbert" , Pradeep Jagadeesh , jani kokkonen Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This patch introduces qmp interfaces for the fsdev devices. This provides two interfaces one for querying info of all the fsdev devices. The second one to set the IO limits for the required fsdev device. Signed-off-by: Pradeep Jagadeesh --- Makefile | 4 ++ fsdev/qemu-fsdev-dummy.c | 11 ++++ fsdev/qemu-fsdev-throttle.c | 145 ++++++++++++++++++++++++++++++++++++++++++-- fsdev/qemu-fsdev-throttle.h | 9 ++- fsdev/qemu-fsdev.c | 30 +++++++++ monitor.c | 5 ++ qapi-schema.json | 3 + qapi/fsdev.json | 81 +++++++++++++++++++++++++ qmp.c | 14 +++++ 9 files changed, 294 insertions(+), 8 deletions(-) create mode 100644 qapi/fsdev.json diff --git a/Makefile b/Makefile index 81447b1..ec31ffa 100644 --- a/Makefile +++ b/Makefile @@ -414,6 +414,10 @@ qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \ $(SRC_PATH)/qapi/crypto.json $(SRC_PATH)/qapi/rocker.json \ $(SRC_PATH)/qapi/trace.json +ifdef CONFIG_VIRTFS +qapi-modules += $(SRC_PATH)/qapi/fsdev.json +endif + qapi-types.c qapi-types.h :\ $(qapi-modules) $(SRC_PATH)/scripts/qapi-types.py $(qapi-py) $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py \ diff --git a/fsdev/qemu-fsdev-dummy.c b/fsdev/qemu-fsdev-dummy.c index 6dc0fbc..28c82d2 100644 --- a/fsdev/qemu-fsdev-dummy.c +++ b/fsdev/qemu-fsdev-dummy.c @@ -14,8 +14,19 @@ #include "qemu-fsdev.h" #include "qemu/config-file.h" #include "qemu/module.h" +#include "qmp-commands.h" int qemu_fsdev_add(QemuOpts *opts) { return 0; } + +void qmp_fsdev_set_io_throttle(IOThrottle *arg, Error **errp) +{ + return; +} + +IOThrottleList *qmp_query_fsdev_io_throttle(Error **errp) +{ + return NULL; +} diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c index 0e6fb86..525352e 100644 --- a/fsdev/qemu-fsdev-throttle.c +++ b/fsdev/qemu-fsdev-throttle.c @@ -16,6 +16,7 @@ #include "qemu/error-report.h" #include "qemu-fsdev-throttle.h" #include "qemu/iov.h" +#include "qemu/main-loop.h" #include "qemu/throttle-options.h" static void fsdev_throttle_read_timer_cb(void *opaque) @@ -30,6 +31,141 @@ static void fsdev_throttle_write_timer_cb(void *opaque) qemu_co_enter_next(&fst->throttled_reqs[true]); } +typedef struct { + FsThrottle *fst; + bool is_write; +} RestartData; + +static bool coroutine_fn throttle_co_restart_queue(FsThrottle *fst, + bool is_write) +{ + return qemu_co_queue_next(&fst->throttled_reqs[is_write]); +} + +static void schedule_next_request(FsThrottle *fst, bool is_write) +{ + bool must_wait = throttle_schedule_timer(&fst->ts, &fst->tt, is_write); + if (!must_wait) { + if (qemu_in_coroutine() && + throttle_co_restart_queue(fst, is_write)) { + return; + } else { + int64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME); + timer_mod(fst->tt.timers[is_write], now); + } + } +} + +static void coroutine_fn throttle_restart_queue_entry(void *opaque) +{ + RestartData *data = opaque; + bool is_write = data->is_write; + bool empty_queue = !throttle_co_restart_queue(data->fst, is_write); + if (empty_queue) { + schedule_next_request(data->fst, is_write); + } +} + +static void throttle_restart_queues(FsThrottle *fst) +{ + Coroutine *co; + RestartData rd = { + .fst = fst, + .is_write = true + }; + + co = qemu_coroutine_create(throttle_restart_queue_entry, &rd); + aio_co_enter(fst->ctx, co); + + rd.is_write = false; + + co = qemu_coroutine_create(throttle_restart_queue_entry, &rd); + aio_co_enter(fst->ctx, co); +} + +static void coroutine_fn fsdev_throttle_config(FsThrottle *fst) +{ + if (throttle_enabled(&fst->cfg)) { + throttle_config(&fst->ts, QEMU_CLOCK_REALTIME, &fst->cfg); + } else { + throttle_restart_queues(fst); + } +} + +void fsdev_set_io_throttle(IOThrottle *arg, FsThrottle *fst, Error **errp) +{ + ThrottleConfig cfg; + + throttle_set_io_limits(&cfg, arg); + + if (throttle_is_valid(&cfg, errp)) { + fst->cfg = cfg; + fsdev_throttle_config(fst); + } +} + +void fsdev_get_io_throttle(FsThrottle *fst, IOThrottle **fs9pcfg, + char *fsdevice) +{ + ThrottleConfig cfg = fst->cfg; + IOThrottle *fscfg = g_malloc0(sizeof(*fscfg)); + + fscfg->has_id = true; + fscfg->id = g_strdup(fsdevice); + fscfg->bps = cfg.buckets[THROTTLE_BPS_TOTAL].avg; + fscfg->bps_rd = cfg.buckets[THROTTLE_BPS_READ].avg; + fscfg->bps_wr = cfg.buckets[THROTTLE_BPS_WRITE].avg; + + fscfg->iops = cfg.buckets[THROTTLE_OPS_TOTAL].avg; + fscfg->iops_rd = cfg.buckets[THROTTLE_OPS_READ].avg; + fscfg->iops_wr = cfg.buckets[THROTTLE_OPS_WRITE].avg; + + fscfg->has_bps_max = cfg.buckets[THROTTLE_BPS_TOTAL].max; + fscfg->bps_max = cfg.buckets[THROTTLE_BPS_TOTAL].max; + fscfg->has_bps_rd_max = cfg.buckets[THROTTLE_BPS_READ].max; + fscfg->bps_rd_max = cfg.buckets[THROTTLE_BPS_READ].max; + fscfg->has_bps_wr_max = cfg.buckets[THROTTLE_BPS_WRITE].max; + fscfg->bps_wr_max = cfg.buckets[THROTTLE_BPS_WRITE].max; + + fscfg->has_iops_max = cfg.buckets[THROTTLE_OPS_TOTAL].max; + fscfg->iops_max = cfg.buckets[THROTTLE_OPS_TOTAL].max; + fscfg->has_iops_rd_max = cfg.buckets[THROTTLE_OPS_READ].max; + fscfg->iops_rd_max = cfg.buckets[THROTTLE_OPS_READ].max; + fscfg->has_iops_wr_max = cfg.buckets[THROTTLE_OPS_WRITE].max; + fscfg->iops_wr_max = cfg.buckets[THROTTLE_OPS_WRITE].max; + + fscfg->has_bps_max_length = fscfg->has_bps_max; + fscfg->bps_max_length = + cfg.buckets[THROTTLE_BPS_TOTAL].burst_length; + fscfg->has_bps_rd_max_length = fscfg->has_bps_rd_max; + fscfg->bps_rd_max_length = + cfg.buckets[THROTTLE_BPS_READ].burst_length; + fscfg->has_bps_wr_max_length = fscfg->has_bps_wr_max; + fscfg->bps_wr_max_length = + cfg.buckets[THROTTLE_BPS_WRITE].burst_length; + + fscfg->has_iops_max_length = fscfg->has_iops_max; + fscfg->iops_max_length = + cfg.buckets[THROTTLE_OPS_TOTAL].burst_length; + fscfg->has_iops_rd_max_length = fscfg->has_iops_rd_max; + fscfg->iops_rd_max_length = + cfg.buckets[THROTTLE_OPS_READ].burst_length; + fscfg->has_iops_wr_max_length = fscfg->has_iops_wr_max; + fscfg->iops_wr_max_length = + cfg.buckets[THROTTLE_OPS_WRITE].burst_length; + + fscfg->bps_max_length = cfg.buckets[THROTTLE_BPS_TOTAL].burst_length; + fscfg->bps_rd_max_length = cfg.buckets[THROTTLE_BPS_READ].burst_length; + fscfg->bps_wr_max_length = cfg.buckets[THROTTLE_BPS_WRITE].burst_length; + fscfg->iops_max_length = cfg.buckets[THROTTLE_OPS_TOTAL].burst_length; + fscfg->iops_rd_max_length = cfg.buckets[THROTTLE_OPS_READ].burst_length; + fscfg->iops_wr_max_length = cfg.buckets[THROTTLE_OPS_WRITE].burst_length; + + fscfg->iops_size = cfg.op_size; + + *fs9pcfg = fscfg; +} + void fsdev_throttle_parse_opts(QemuOpts *opts, FsThrottle *fst, Error **errp) { throttle_parse_options(&fst->cfg, opts); @@ -40,8 +176,9 @@ void fsdev_throttle_init(FsThrottle *fst) { if (throttle_enabled(&fst->cfg)) { throttle_init(&fst->ts); + fst->ctx = qemu_get_aio_context(); throttle_timers_init(&fst->tt, - qemu_get_aio_context(), + fst->ctx, QEMU_CLOCK_REALTIME, fsdev_throttle_read_timer_cb, fsdev_throttle_write_timer_cb, @@ -62,11 +199,7 @@ void coroutine_fn fsdev_co_throttle_request(FsThrottle *fst, bool is_write, } throttle_account(&fst->ts, is_write, iov_size(iov, iovcnt)); - - if (!qemu_co_queue_empty(&fst->throttled_reqs[is_write]) && - !throttle_schedule_timer(&fst->ts, &fst->tt, is_write)) { - qemu_co_queue_next(&fst->throttled_reqs[is_write]); - } + schedule_next_request(fst, is_write); } } diff --git a/fsdev/qemu-fsdev-throttle.h b/fsdev/qemu-fsdev-throttle.h index e418643..bfeab40 100644 --- a/fsdev/qemu-fsdev-throttle.h +++ b/fsdev/qemu-fsdev-throttle.h @@ -15,8 +15,6 @@ #ifndef _FSDEV_THROTTLE_H #define _FSDEV_THROTTLE_H -#include "block/aio.h" -#include "qemu/main-loop.h" #include "qemu/coroutine.h" #include "qapi/error.h" #include "qemu/throttle.h" @@ -25,6 +23,7 @@ typedef struct FsThrottle { ThrottleState ts; ThrottleTimers tt; ThrottleConfig cfg; + AioContext *ctx; CoQueue throttled_reqs[2]; } FsThrottle; @@ -36,4 +35,10 @@ void coroutine_fn fsdev_co_throttle_request(FsThrottle *, bool , struct iovec *, int); void fsdev_throttle_cleanup(FsThrottle *); + +void fsdev_set_io_throttle(IOThrottle *, FsThrottle *, Error **errp); + +void fsdev_get_io_throttle(FsThrottle *, IOThrottle **iothp, + char *); + #endif /* _FSDEV_THROTTLE_H */ diff --git a/fsdev/qemu-fsdev.c b/fsdev/qemu-fsdev.c index 266e442..0f701fc 100644 --- a/fsdev/qemu-fsdev.c +++ b/fsdev/qemu-fsdev.c @@ -16,6 +16,7 @@ #include "qemu-common.h" #include "qemu/config-file.h" #include "qemu/error-report.h" +#include "qmp-commands.h" static QTAILQ_HEAD(FsDriverEntry_head, FsDriverListEntry) fsdriver_entries = QTAILQ_HEAD_INITIALIZER(fsdriver_entries); @@ -98,3 +99,32 @@ FsDriverEntry *get_fsdev_fsentry(char *id) } return NULL; } + +void qmp_fsdev_set_io_throttle(IOThrottle *arg, Error **errp) +{ + + FsDriverEntry *fse; + + fse = get_fsdev_fsentry(arg->has_id ? arg->id : NULL); + if (!fse) { + error_setg(errp, "Not a valid fsdev device"); + return; + } + + fsdev_set_io_throttle(arg, &fse->fst, errp); +} + +IOThrottleList *qmp_query_fsdev_io_throttle(Error **errp) +{ + IOThrottleList *head = NULL, *p_next; + struct FsDriverListEntry *fsle; + + QTAILQ_FOREACH(fsle, &fsdriver_entries, next) { + p_next = g_new0(IOThrottleList, 1); + fsdev_get_io_throttle(&fsle->fse.fst, &p_next->value, + fsle->fse.fsdev_id); + p_next->next = head; + head = p_next; + } + return head; +} diff --git a/monitor.c b/monitor.c index e0f8801..eebda1c 100644 --- a/monitor.c +++ b/monitor.c @@ -998,6 +998,11 @@ static void qmp_unregister_commands_hack(void) && !defined(TARGET_S390X) qmp_unregister_command(&qmp_commands, "query-cpu-definitions"); #endif +#ifndef CONFIG_VIRTFS + qmp_unregister_command(&qmp_commands, "fsdev-set-io-throttle"); + qmp_unregister_command(&qmp_commands, "query-fsdev-io-throttle"); +#endif + } void monitor_init_qmp_commands(void) diff --git a/qapi-schema.json b/qapi-schema.json index 802ea53..8cf8140 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -81,6 +81,9 @@ # QAPI block definitions { 'include': 'qapi/block.json' } +# QAPI fsdev definitions +{ 'include': 'qapi/fsdev.json' } + # QAPI event definitions { 'include': 'qapi/event.json' } diff --git a/qapi/fsdev.json b/qapi/fsdev.json new file mode 100644 index 0000000..21d074d --- /dev/null +++ b/qapi/fsdev.json @@ -0,0 +1,81 @@ +# -*- Mode: Python -*- + +## +# == QAPI fsdev definitions +## + +## +# @fsdev-set-io-throttle: +# +# Change I/O limits for a 9p/fsdev device. +# +# I/O limits can be enabled by setting throttle value to non-zero number. +# +# I/O limits can be disabled by setting all throttle values to 0. +# +# Returns: Nothing on success +# If @device is not a valid fsdev device, GenericError +# +# Since: 2.10 +# +# Example: +# +# -> { "execute": "fsdev-set-io-throttle", +# "arguments": { "id": "id0-1-0", +# "bps": 1000000, +# "bps_rd": 0, +# "bps_wr": 0, +# "iops": 0, +# "iops_rd": 0, +# "iops_wr": 0, +# "bps_max": 8000000, +# "bps_rd_max": 0, +# "bps_wr_max": 0, +# "iops_max": 0, +# "iops_rd_max": 0, +# "iops_wr_max": 0, +# "bps_max_length": 60, +# "iops_size": 0 } } +# <- { "returns": {} } +## +{ 'command': 'fsdev-set-io-throttle', 'boxed': true, + 'data': 'IOThrottle' } +## +# @query-fsdev-io-throttle: +# +# Returns: a list of @IOThrottle describing I/O throttle +# values of each fsdev device +# +# Since: 2.10 +# +# Example: +# +# -> { "Execute": "query-fsdev-io-throttle" } +# <- { "returns" : [ +# { +# "id": "id0-hd0", +# "bps":1000000, +# "bps_rd":0, +# "bps_wr":0, +# "iops":1000000, +# "iops_rd":0, +# "iops_wr":0, +# "bps_max": 8000000, +# "bps_rd_max": 0, +# "bps_wr_max": 0, +# "iops_max": 0, +# "iops_rd_max": 0, +# "iops_wr_max": 0, +# "bps_max_length": 0, +# "bps_rd_max_length": 0, +# "bps_wr_max_length": 0, +# "iops_max_length": 0, +# "iops_rd_max_length": 0, +# "iops_wr_max_length": 0, +# "iops_size": 0 +# } +# ] +# } +# +## +{ 'command': 'query-fsdev-io-throttle', 'returns': [ 'IOThrottle' ] } diff --git a/qmp.c b/qmp.c index b86201e..eed91e5 100644 --- a/qmp.c +++ b/qmp.c @@ -130,6 +130,20 @@ void qmp_cpu_add(int64_t id, Error **errp) } } +#if defined(_WIN64) || defined(_WIN32) || defined(__FreeBSD__) + +void qmp_fsdev_set_io_throttle(IOThrottle *arg, Error **errp) +{ + return; +} + +IOThrottleList *qmp_query_fsdev_io_throttle(Error **errp) +{ + return NULL; +} + +#endif + #ifndef CONFIG_VNC /* If VNC support is enabled, the "true" query-vnc command is defined in the VNC subsystem */ From patchwork Mon Sep 4 16:07:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pradeep Jagadeesh X-Patchwork-Id: 809754 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="q2PmZNcs"; dkim-atps=neutral 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 3xmFCc31Bgz9t2Z for ; Tue, 5 Sep 2017 02:09:16 +1000 (AEST) Received: from localhost ([::1]:54735 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dotw2-0007Qj-Db for incoming@patchwork.ozlabs.org; Mon, 04 Sep 2017 12:09:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46919) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dotvN-0007Ml-JD for qemu-devel@nongnu.org; Mon, 04 Sep 2017 12:08:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dotvI-0008Sg-PB for qemu-devel@nongnu.org; Mon, 04 Sep 2017 12:08:33 -0400 Received: from mail-wr0-x244.google.com ([2a00:1450:400c:c0c::244]:37002) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dotvI-0008SQ-Gf for qemu-devel@nongnu.org; Mon, 04 Sep 2017 12:08:28 -0400 Received: by mail-wr0-x244.google.com with SMTP id y15so427803wrc.4 for ; Mon, 04 Sep 2017 09:08:28 -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=I1r1tpvzl6FUU7WmoVoNKIvgjHuTvvgLC1VwRYxmr0U=; b=q2PmZNcsTGdqvX0AGu5D9ZLRTt9IAJsEzFEvMtRy1eJKTdO4smp7KT6x+tsE8galcP +R7u8NT1+UfpQva4OlPQTF+6gogiHshmVn4wCM+8h8yMfkvqlyo0njtEwGjaXOBpac8x yHECny8akTm653wR7PyOBW6ML9dtW3S0vL+qPjsc5IBvpw092XDGb0/En2PqQzyumbri fWIjdNbcj7bBcCQEH+hFIweuApMku97PKIfB/Lx9hkhWUsjyn3t7pR2608l0EzMzXxl5 GqfZzRM5FuTuuAJffzuz8g+YueditE5drAzS7ISxYIrVKKTHcZ0lEJ/P5yiaUpzZsKLS gCeQ== 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=I1r1tpvzl6FUU7WmoVoNKIvgjHuTvvgLC1VwRYxmr0U=; b=OU2VkzZlxTj2+pOnqr/3WpTaXVtFTwloG5oqhPf4KHyBsOGSJCgVHcw9iAex3HpaQC ER5dnblv1xeCXZ3C2pYSzsAwasC9Z/Cdl2qs/CeExqbZI5Hqdo0vHG4q9fFThMBRAom8 z1xx4CB+6r2JJh32/E5WP7cc8BK401fyA7hyKy6IF/NXLkFEsHZ99Eyw+YCtJJr7O2a0 Gdtv5JNnNiiSfpSWM+dthiJFsUC7s3GOeZJ6leyXiNO5/kY012yoKmZAKovRmjpzhy7l POZqz56Awv1JoI2NGhjgYhGD5UEZajXvAETyqHU846NOFZ5CmsDVEEPGek7mq1T6ZboS 85GA== X-Gm-Message-State: AHPjjUj7ut+mI3jn2UWKS1VkhSfRDN67/haEKJ9WScrJgS+ulfN9sfWw Jb1E5+313Ovwzf5I X-Google-Smtp-Source: ADKCNb4fOEPvUA/NDB9XAoURgf+AVyleiCEYnl7MLFv1jd/DXWDOWrKOSs/TfBl6JFGEA0kr0/zg7A== X-Received: by 10.223.167.154 with SMTP id j26mr589090wrc.292.1504541307544; Mon, 04 Sep 2017 09:08:27 -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.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Sep 2017 09:08:26 -0700 (PDT) From: Pradeep Jagadeesh X-Google-Original-From: Pradeep Jagadeesh To: "eric blake" , "greg kurz" Date: Mon, 4 Sep 2017 12:07:47 -0400 Message-Id: <1504541267-36954-7-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 6/6] fsdev: hmp interface for throttling 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 , "Dr. David Alan Gilbert" Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This patch introduces hmp interfaces for the fsdev devices. Signed-off-by: Pradeep Jagadeesh --- hmp-commands-info.hx | 18 ++++++++++++++++ hmp-commands.hx | 19 +++++++++++++++++ hmp.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ hmp.h | 4 ++++ 4 files changed, 101 insertions(+) diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index d9df238..07ed338 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -84,6 +84,24 @@ STEXI Show block device statistics. ETEXI +#if defined(CONFIG_VIRTFS) + + { + .name = "fsdev_iothrottle", + .args_type = "", + .params = "", + .help = "show fsdev iothrottle information", + .cmd = hmp_info_fsdev_iothrottle, + }, + +#endif + +STEXI +@item info fsdev_iothrottle +@findex fsdev_iothrottle +Show fsdev device throttle info. +ETEXI + { .name = "block-jobs", .args_type = "", diff --git a/hmp-commands.hx b/hmp-commands.hx index 1941e19..aef9f79 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1680,6 +1680,25 @@ STEXI Change I/O throttle limits for a block drive to @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} ETEXI +#if defined(CONFIG_VIRTFS) + + { + .name = "fsdev_set_io_throttle", + .args_type = "device:B,bps:l,bps_rd:l,bps_wr:l,iops:l,iops_rd:l,iops_wr:l", + .params = "device bps bps_rd bps_wr iops iops_rd iops_wr", + .help = "change I/O throttle limits for a fs devices", + .cmd = hmp_fsdev_set_io_throttle, + }, + +#endif + +STEXI +@item fsdev_set_io_throttle @var{device} @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} +@findex fsdev_set_io_throttle +Change I/O throttle limits for a fs devices to @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} +ETEXI + + { .name = "set_password", .args_type = "protocol:s,password:s,connected:s?", diff --git a/hmp.c b/hmp.c index 2dbfb80..6e63cf1 100644 --- a/hmp.c +++ b/hmp.c @@ -1783,6 +1783,66 @@ void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, &err); } +#ifdef CONFIG_VIRTFS + +void hmp_fsdev_set_io_throttle(Monitor *mon, const QDict *qdict) +{ + Error *err = NULL; + IOThrottle throttle = { + .has_id = true, + .id = (char *) qdict_get_str(qdict, "device"), + }; + + hmp_initialize_io_throttle(&throttle, qdict); + qmp_fsdev_set_io_throttle(&throttle, &err); + hmp_handle_error(mon, &err); +} + +static void print_fsdev_throttle_config(Monitor *mon, IOThrottle *fscfg) +{ + monitor_printf(mon, "%s", fscfg->id); + monitor_printf(mon, " I/O throttling:" + " bps=%" PRId64 + " bps_rd=%" PRId64 " bps_wr=%" PRId64 + " bps_max=%" PRId64 + " bps_rd_max=%" PRId64 + " bps_wr_max=%" PRId64 + " iops=%" PRId64 " iops_rd=%" PRId64 + " iops_wr=%" PRId64 + " iops_max=%" PRId64 + " iops_rd_max=%" PRId64 + " iops_wr_max=%" PRId64 + " iops_size=%" PRId64 + "\n", + fscfg->bps, + fscfg->bps_rd, + fscfg->bps_wr, + fscfg->bps_max, + fscfg->bps_rd_max, + fscfg->bps_wr_max, + fscfg->iops, + fscfg->iops_rd, + fscfg->iops_wr, + fscfg->iops_max, + fscfg->iops_rd_max, + fscfg->iops_wr_max, + fscfg->iops_size); +} + +void hmp_info_fsdev_iothrottle(Monitor *mon, const QDict *qdict) +{ + Error *err = NULL; + IOThrottleList *fsdev_list, *info; + fsdev_list = qmp_query_fsdev_io_throttle(&err); + + for (info = fsdev_list; info; info = info->next) { + print_fsdev_throttle_config(mon, info->value); + } + qapi_free_IOThrottleList(fsdev_list); +} + +#endif + void hmp_block_stream(Monitor *mon, const QDict *qdict) { Error *error = NULL; diff --git a/hmp.h b/hmp.h index 1ff4552..d700d7d 100644 --- a/hmp.h +++ b/hmp.h @@ -81,6 +81,10 @@ void hmp_set_password(Monitor *mon, const QDict *qdict); void hmp_expire_password(Monitor *mon, const QDict *qdict); void hmp_eject(Monitor *mon, const QDict *qdict); void hmp_change(Monitor *mon, const QDict *qdict); +#ifdef CONFIG_VIRTFS +void hmp_fsdev_set_io_throttle(Monitor *mon, const QDict *qdict); +void hmp_info_fsdev_iothrottle(Monitor *mon, const QDict *qdict); +#endif void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict); void hmp_block_stream(Monitor *mon, const QDict *qdict); void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict);