From nobody Sat May 4 06:03:08 2024 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 1503581270187765.6941338839787; Thu, 24 Aug 2017 06:27:50 -0700 (PDT) Received: from localhost ([::1]:48637 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dksAm-0004U6-SK for importer@patchew.org; Thu, 24 Aug 2017 09:27:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41979) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dks90-0003JW-Gs for qemu-devel@nongnu.org; Thu, 24 Aug 2017 09:25:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dks8w-0003Tb-Dh for qemu-devel@nongnu.org; Thu, 24 Aug 2017 09:25:58 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:53888) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dks8w-000335-1B; Thu, 24 Aug 2017 09:25:54 -0400 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1dks8H-0002oO-V2; Thu, 24 Aug 2017 15:25:14 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1dks80-0007cn-Nm; Thu, 24 Aug 2017 16:24:56 +0300 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=WG5VivUZEVe2RCzp7eXbp7oG3+NOgkhRVNGKnvHILIU=; b=dk6MXGLt8tkSv5W9EaV/496/riJj71ztNzVNCROdhkHaO43Ju4o6w1pUn35whM3QJIisWeR8BcKueXNvDhRbH7yM8Mria/qjcxdY8rHL+E0C3FPmfgg6aDdZqTb+StJ61O4RSzGio4oim28LNn5iq+1gj8Af8ezsAVehbrjm2wZiVc/CeCzOCGO7iC3cUg6ao62JlAWPVpKJo2yVm2CNZx1F9KwD8LwhtqjQlpmsu6pjrAHybIH0qarQ4NRU0lwxYrUamKI22i4OFW+gcqreeFUYKESzLMlo7WdKhm0bmBM0UCr3Nf0EMSBqifuSFaagDBDaWz/f10ArmdaHV3NJOw==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Thu, 24 Aug 2017 16:24:43 +0300 Message-Id: <49aab2711d02f285567f3b3b13a113847af33812.1503580370.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH v2 1/7] throttle: Fix wrong variable name in the header documentation 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-block@nongnu.org, Manos Pitsidianakis 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" The level of the burst bucket is stored in bkt.burst_level, not bkt.burst_length. Signed-off-by: Alberto Garcia Reviewed-by: Manos Pitsidianakis --- include/qemu/throttle.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h index d056008c18..66a8ac10a4 100644 --- a/include/qemu/throttle.h +++ b/include/qemu/throttle.h @@ -63,7 +63,7 @@ typedef enum { * - The bkt.avg rate does not apply until the bucket is full, * allowing the user to do bursts until then. The I/O limit during * bursts is bkt.max. To enforce this limit we keep an additional - * bucket in bkt.burst_length that leaks at a rate of bkt.max units + * bucket in bkt.burst_level that leaks at a rate of bkt.max units * per second. * * - Because of all of the above, the user can perform I/O at a --=20 2.11.0 From nobody Sat May 4 06:03:08 2024 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 1503581536845196.36844465910303; Thu, 24 Aug 2017 06:32:16 -0700 (PDT) Received: from localhost ([::1]:48666 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dksF5-0008Vx-O3 for importer@patchew.org; Thu, 24 Aug 2017 09:32:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41977) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dks90-0003JU-Gh for qemu-devel@nongnu.org; Thu, 24 Aug 2017 09:26:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dks8w-0003U1-GB for qemu-devel@nongnu.org; Thu, 24 Aug 2017 09:25:58 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:53893) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dks8w-000339-1t; Thu, 24 Aug 2017 09:25:54 -0400 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1dks8H-0002oN-V4; Thu, 24 Aug 2017 15:25:14 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1dks80-0007cp-Os; Thu, 24 Aug 2017 16:24:56 +0300 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=vYXLlm26x4quiIx+vrPnFr4ce7RsOelgS74XahQvaK4=; b=cnIJkPtTQCfu9wT3yNwv0oiMBPiIkfaMyuMKDsRR1K2+agsfkSdrlmPYXXqZqURepApKqSfAq8Jdbw2iOyDRaK49VrxPV8/ptYUYaTAUZRNyD7/xQ3xCLCtb+gQa4n7cqa9fLe+FN6Ol4hjivh5wAfa+2Y/W9wusnRqhPSzptOUf2WAk8cK0lBNg6TpAiQlMV/fRHTQjw/+Ezqr3LCCFwZaGnvP7KAaqQpjjj9I9BjDjKJXJUALXpfk3mny3nmovqj94gQJaQfkC/k3qatQwuMc3gmv5OLXGi/cnTvwZOnp5K+HuBKB1nPT4ybbAqkyeij4bIgADszp/BPZBYTsFDA==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Thu, 24 Aug 2017 16:24:44 +0300 Message-Id: <31aae6645f0d1fbf3860fb2b528b757236f0c0a7.1503580370.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH v2 2/7] throttle: Update the throttle_fix_bucket() documentation 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-block@nongnu.org, Manos Pitsidianakis 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" The way the throttling algorithm works is that requests start being throttled once the bucket level exceeds the burst limit. When we get there the bucket leaks at the level set by the user (bkt->avg), and that leak rate is what prevents guest I/O from exceeding the desired limit. If we don't allow bursts (i.e. bkt->max =3D=3D 0) then we can start throttling requests immediately. The problem with keeping the threshold at 0 is that it only allows one request at a time, and as soon as there's a bit of I/O from the guest every other request will be throttled and performance will suffer considerably. That can even make the guest unable to reach the throttle limit if that limit is high enough, and that happens regardless of the block scheduler used by the guest. Increasing that threshold gives flexibility to the guest, allowing it to perform short bursts of I/O before being throttled. Increasing the threshold too much does not make a difference in the long run (because it's the leak rate what defines the actual throughput) but it does allow the guest to perform longer initial bursts and exceed the throttle limit for a short while. A burst value of bkt->avg / 10 allows the guest to perform 100ms' worth of I/O at the target rate without being throttled. Signed-off-by: Alberto Garcia Reviewed-by: Eric Blake --- util/throttle.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/util/throttle.c b/util/throttle.c index b2a52b8b34..9a6bda813c 100644 --- a/util/throttle.c +++ b/util/throttle.c @@ -366,14 +366,9 @@ static void throttle_fix_bucket(LeakyBucket *bkt) /* zero bucket level */ bkt->level =3D bkt->burst_level =3D 0; =20 - /* The following is done to cope with the Linux CFQ block scheduler - * which regroup reads and writes by block of 100ms in the guest. - * When they are two process one making reads and one making writes cfq - * make a pattern looking like the following: - * WWWWWWWWWWWRRRRRRRRRRRRRRWWWWWWWWWWWWWwRRRRRRRRRRRRRRRRR - * Having a max burst value of 100ms of the average will help smooth t= he - * throttling - */ + /* If bkt->max is 0 we still want to allow short bursts of I/O + * from the guest, otherwise every other request will be throttled + * and performance will suffer considerably. */ min =3D bkt->avg / 10; if (bkt->avg && !bkt->max) { bkt->max =3D min; --=20 2.11.0 From nobody Sat May 4 06:03:08 2024 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 1503581269924383.9130748522815; Thu, 24 Aug 2017 06:27:49 -0700 (PDT) Received: from localhost ([::1]:48636 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dksAm-0004Tl-66 for importer@patchew.org; Thu, 24 Aug 2017 09:27:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41973) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dks90-0003JQ-G1 for qemu-devel@nongnu.org; Thu, 24 Aug 2017 09:25:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dks8w-0003U8-GH for qemu-devel@nongnu.org; Thu, 24 Aug 2017 09:25:58 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:53891) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dks8w-000338-1G; Thu, 24 Aug 2017 09:25:54 -0400 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1dks8H-0002oP-U7; Thu, 24 Aug 2017 15:25:14 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1dks80-0007cs-Po; Thu, 24 Aug 2017 16:24:56 +0300 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=iI5TjUxdwjsPS/HExeGQ1+SUPyfdc3l8cWNmfwaNK3Y=; b=NpEk6IIJ5bm0VT2cQjMQnHfIkNy6b2cBP9M+3c6pk8d1AOuUfZX5C4CgGJESTO2k7RnqiIkDcKMMnciOVKlXYCEwm4+SkTUZMGjsEoeUvaPLZgFY+RqW9QsVGqhn2Htz58XZYRbcRu+O/KqwYEL/3OVuSfgZN98bPQVFuTdRaNKjc7UBFtSCNhOqEja25j9KEk0HP+NJhezIGVMYjlyFtezaDnmeipnvpX683GySxL6zClxxc3EK66oQLNxOcTr4iKg3aIwx1XMHYi4vFpfisxdRpBQPIou+14xq0MKG7FCy+n0KCaSEzTLvm0u8GLbXpuuCLOrd0K7zxZ8h9yjunQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Thu, 24 Aug 2017 16:24:45 +0300 Message-Id: <763ffc40a26b17d54cf93f5a999e4656049fcf0c.1503580370.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH v2 3/7] throttle: Make throttle_is_valid() a bit less verbose 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-block@nongnu.org, Manos Pitsidianakis 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" Use a pointer to the bucket instead of repeating cfg->buckets[i] all the time. This makes the code more concise and will help us expand the checks later and save a few line breaks. Signed-off-by: Alberto Garcia Reviewed-by: Eric Blake --- util/throttle.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/util/throttle.c b/util/throttle.c index 9a6bda813c..bde56fe3de 100644 --- a/util/throttle.c +++ b/util/throttle.c @@ -324,32 +324,31 @@ bool throttle_is_valid(ThrottleConfig *cfg, Error **e= rrp) } =20 for (i =3D 0; i < BUCKETS_COUNT; i++) { - if (cfg->buckets[i].avg < 0 || - cfg->buckets[i].max < 0 || - cfg->buckets[i].avg > THROTTLE_VALUE_MAX || - cfg->buckets[i].max > THROTTLE_VALUE_MAX) { + LeakyBucket *bkt =3D &cfg->buckets[i]; + if (bkt->avg < 0 || bkt->max < 0 || + bkt->avg > THROTTLE_VALUE_MAX || bkt->max > THROTTLE_VALUE_MAX= ) { error_setg(errp, "bps/iops/max values must be within [0, %lld]= ", THROTTLE_VALUE_MAX); return false; } =20 - if (!cfg->buckets[i].burst_length) { + if (!bkt->burst_length) { error_setg(errp, "the burst length cannot be 0"); return false; } =20 - if (cfg->buckets[i].burst_length > 1 && !cfg->buckets[i].max) { + if (bkt->burst_length > 1 && !bkt->max) { error_setg(errp, "burst length set without burst rate"); return false; } =20 - if (cfg->buckets[i].max && !cfg->buckets[i].avg) { + if (bkt->max && !bkt->avg) { error_setg(errp, "bps_max/iops_max require corresponding" " bps/iops values"); return false; } =20 - if (cfg->buckets[i].max && cfg->buckets[i].max < cfg->buckets[i].a= vg) { + if (bkt->max && bkt->max < bkt->avg) { error_setg(errp, "bps_max/iops_max cannot be lower than bps/io= ps"); return false; } --=20 2.11.0 From nobody Sat May 4 06:03:08 2024 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 1503581273796478.5077627845038; Thu, 24 Aug 2017 06:27:53 -0700 (PDT) Received: from localhost ([::1]:48639 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dksAq-0004W2-I5 for importer@patchew.org; Thu, 24 Aug 2017 09:27:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41976) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dks90-0003JT-GH for qemu-devel@nongnu.org; Thu, 24 Aug 2017 09:25:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dks8w-0003Tp-Eu for qemu-devel@nongnu.org; Thu, 24 Aug 2017 09:25:58 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:53884) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dks8w-00032y-1T; Thu, 24 Aug 2017 09:25:54 -0400 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1dks8H-0002oQ-Sl; Thu, 24 Aug 2017 15:25:14 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1dks80-0007cw-Qm; Thu, 24 Aug 2017 16:24:56 +0300 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=1HRMARnXJOjzafJeuMIL/6Ux2YfytMrdsEEih3I13SU=; b=H8rTnXjXf6vvDKTixwmcHfo/bRCrN+Wc1bCAfrLhHBPC5+62OM3YCllSnRSYXzFi8cF9jqL821pzjZicEjCxXlSlEAdPeX7cg27Fbn2nUgoBWnzU7J5NfBYfC0Dlwuf4t+XMfbmQWSD8Vwl+ZvuinGKT+lZWteWXgdRWDLIgi7EgudNAd8kgf01VwbHnAqF/iF5xDurJSDpNyN4zXXUVoCIdiIfITGICRS6ZCqlaiIBtw8iqsD4N8XVJ7a80+SlVsBaYx5R7W0bqT09O7t07diHz2gSmizm8NzuZDLBBAwigFP4C00WZKQbauY3kguRRKm1kxvOY5q9HQjIpi944KA==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Thu, 24 Aug 2017 16:24:46 +0300 Message-Id: <5b0b9e1ac6eb208d709eddc7b09e7669a523bff3.1503580370.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH v2 4/7] throttle: Remove throttle_fix_bucket() / throttle_unfix_bucket() 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-block@nongnu.org, Manos Pitsidianakis 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" The throttling code can change internally the value of bkt->max if it hasn't been set by the user. The problem with this is that if we want to retrieve the original value we have to undo this change first. This is ugly and unnecessary: this patch removes the throttle_fix_bucket() and throttle_unfix_bucket() functions completely and moves the logic to throttle_compute_wait(). Signed-off-by: Alberto Garcia Reviewed-by: Manos Pitsidianakis --- util/throttle.c | 62 +++++++++++++++++++++--------------------------------= ---- 1 file changed, 23 insertions(+), 39 deletions(-) diff --git a/util/throttle.c b/util/throttle.c index bde56fe3de..4e80a7ea54 100644 --- a/util/throttle.c +++ b/util/throttle.c @@ -95,23 +95,36 @@ static int64_t throttle_do_compute_wait(double limit, d= ouble extra) int64_t throttle_compute_wait(LeakyBucket *bkt) { double extra; /* the number of extra units blocking the io */ + double bucket_size; /* I/O before throttling to bkt->avg */ + double burst_bucket_size; /* Before throttling to bkt->max */ =20 if (!bkt->avg) { return 0; } =20 - /* If the bucket is full then we have to wait */ - extra =3D bkt->level - bkt->max * bkt->burst_length; + if (!bkt->max) { + /* If bkt->max is 0 we still want to allow short bursts of I/O + * from the guest, otherwise every other request will be throttled + * and performance will suffer considerably. */ + bucket_size =3D bkt->avg / 10; + burst_bucket_size =3D 0; + } else { + /* If we have a burst limit then we have to wait until all I/O + * at burst rate has finished before throttling to bkt->avg */ + bucket_size =3D bkt->max * bkt->burst_length; + burst_bucket_size =3D bkt->max / 10; + } + + /* If the main bucket is full then we have to wait */ + extra =3D bkt->level - bucket_size; if (extra > 0) { return throttle_do_compute_wait(bkt->avg, extra); } =20 - /* If the bucket is not full yet we have to make sure that we - * fulfill the goal of bkt->max units per second. */ + /* If the main bucket is not full yet we still have to check the + * burst bucket in order to enforce the burst limit */ if (bkt->burst_length > 1) { - /* We use 1/10 of the max value to smooth the throttling. - * See throttle_fix_bucket() for more details. */ - extra =3D bkt->burst_level - bkt->max / 10; + extra =3D bkt->burst_level - burst_bucket_size; if (extra > 0) { return throttle_do_compute_wait(bkt->max, extra); } @@ -357,31 +370,6 @@ bool throttle_is_valid(ThrottleConfig *cfg, Error **er= rp) return true; } =20 -/* fix bucket parameters */ -static void throttle_fix_bucket(LeakyBucket *bkt) -{ - double min; - - /* zero bucket level */ - bkt->level =3D bkt->burst_level =3D 0; - - /* If bkt->max is 0 we still want to allow short bursts of I/O - * from the guest, otherwise every other request will be throttled - * and performance will suffer considerably. */ - min =3D bkt->avg / 10; - if (bkt->avg && !bkt->max) { - bkt->max =3D min; - } -} - -/* undo internal bucket parameter changes (see throttle_fix_bucket()) */ -static void throttle_unfix_bucket(LeakyBucket *bkt) -{ - if (bkt->max < bkt->avg) { - bkt->max =3D 0; - } -} - /* Used to configure the throttle * * @ts: the throttle state we are working on @@ -396,8 +384,10 @@ void throttle_config(ThrottleState *ts, =20 ts->cfg =3D *cfg; =20 + /* Zero bucket level */ for (i =3D 0; i < BUCKETS_COUNT; i++) { - throttle_fix_bucket(&ts->cfg.buckets[i]); + ts->cfg.buckets[i].level =3D 0; + ts->cfg.buckets[i].burst_level =3D 0; } =20 ts->previous_leak =3D qemu_clock_get_ns(clock_type); @@ -410,13 +400,7 @@ void throttle_config(ThrottleState *ts, */ void throttle_get_config(ThrottleState *ts, ThrottleConfig *cfg) { - int i; - *cfg =3D ts->cfg; - - for (i =3D 0; i < BUCKETS_COUNT; i++) { - throttle_unfix_bucket(&cfg->buckets[i]); - } } =20 =20 --=20 2.11.0 From nobody Sat May 4 06:03:08 2024 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 1503581271793338.74652507486553; Thu, 24 Aug 2017 06:27:51 -0700 (PDT) Received: from localhost ([::1]:48638 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dksAo-0004Vl-KR for importer@patchew.org; Thu, 24 Aug 2017 09:27:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41975) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dks90-0003JS-GD for qemu-devel@nongnu.org; Thu, 24 Aug 2017 09:26:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dks8w-0003U3-FN for qemu-devel@nongnu.org; Thu, 24 Aug 2017 09:25:58 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:53895) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dks8w-00033B-1e; Thu, 24 Aug 2017 09:25:54 -0400 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1dks8H-0002oR-V2; Thu, 24 Aug 2017 15:25:14 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1dks80-0007cz-Rr; Thu, 24 Aug 2017 16:24:56 +0300 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=+onwn0uejyWc2y/Lwsfhw6ey1BT2En522ZR8UeWoDKU=; b=h++8EUfkcnVH8bXx5SiHndVj24y8D4FBgpxT1LrSgcys43D8OCKny3deGFwHrA49GLqyUO1MicEGM/dfZS3e2Hdu/N3RSjs60PmCV8KxLTapjYUoaPwtpZ9NeZ4dE+r/krluQyRFQviYUS587hkR4ajCpvZD8pQtuAyGOVebvpw/MXvGLtTMqe+dgWxn9nk5rB/1bDtbUIFyTeOixygY74b2xP5VZV53CCifp2rBUhUsdMIFiWC7mfIuZBlBiLV8yndW/yVojlu4UoP13JxxXvN+opJp5vzD0pIZQwwGGnVvv8gXmMGbd+iQHf/XeEENNZ8kA3OI70vNpkw1cuBzbA==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Thu, 24 Aug 2017 16:24:47 +0300 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH v2 5/7] throttle: Make LeakyBucket.avg and LeakyBucket.max integer types 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-block@nongnu.org, Manos Pitsidianakis 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" Both the throttling limits set with the throttling.iops-* and throttling.bps-* options and their QMP equivalents defined in the BlockIOThrottle struct are integer values. Those limits are also reported in the BlockDeviceInfo struct and they are integers there as well. Therefore there's no reason to store them internally as double and do the conversion everytime we're setting or querying them, so this patch uses uint64_t for those types. Let's also use an unsigned type because we don't allow negative values anyway. LeakyBucket.level and LeakyBucket.burst_level do however remain double because their value changes depending on the fraction of time elapsed since the previous I/O operation. Signed-off-by: Alberto Garcia Reviewed-by: Eric Blake --- include/qemu/throttle.h | 4 ++-- tests/test-throttle.c | 3 ++- util/throttle.c | 7 +++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h index 66a8ac10a4..6e31155fd4 100644 --- a/include/qemu/throttle.h +++ b/include/qemu/throttle.h @@ -77,8 +77,8 @@ typedef enum { */ =20 typedef struct LeakyBucket { - double avg; /* average goal in units per second */ - double max; /* leaky bucket max burst in units */ + uint64_t avg; /* average goal in units per second */ + uint64_t max; /* leaky bucket max burst in units */ double level; /* bucket level in units */ double burst_level; /* bucket level in units (for computing burs= ts) */ unsigned burst_length; /* max length of the burst period, in second= s */ diff --git a/tests/test-throttle.c b/tests/test-throttle.c index 768f11dfed..41c0dd2529 100644 --- a/tests/test-throttle.c +++ b/tests/test-throttle.c @@ -284,13 +284,14 @@ static void test_enabled(void) for (i =3D 0; i < BUCKETS_COUNT; i++) { throttle_config_init(&cfg); set_cfg_value(false, i, 150); + g_assert(throttle_is_valid(&cfg, NULL)); g_assert(throttle_enabled(&cfg)); } =20 for (i =3D 0; i < BUCKETS_COUNT; i++) { throttle_config_init(&cfg); set_cfg_value(false, i, -150); - g_assert(!throttle_enabled(&cfg)); + g_assert(!throttle_is_valid(&cfg, NULL)); } } =20 diff --git a/util/throttle.c b/util/throttle.c index 4e80a7ea54..80660ffd2c 100644 --- a/util/throttle.c +++ b/util/throttle.c @@ -106,13 +106,13 @@ int64_t throttle_compute_wait(LeakyBucket *bkt) /* If bkt->max is 0 we still want to allow short bursts of I/O * from the guest, otherwise every other request will be throttled * and performance will suffer considerably. */ - bucket_size =3D bkt->avg / 10; + bucket_size =3D (double) bkt->avg / 10; burst_bucket_size =3D 0; } else { /* If we have a burst limit then we have to wait until all I/O * at burst rate has finished before throttling to bkt->avg */ bucket_size =3D bkt->max * bkt->burst_length; - burst_bucket_size =3D bkt->max / 10; + burst_bucket_size =3D (double) bkt->max / 10; } =20 /* If the main bucket is full then we have to wait */ @@ -338,8 +338,7 @@ bool throttle_is_valid(ThrottleConfig *cfg, Error **err= p) =20 for (i =3D 0; i < BUCKETS_COUNT; i++) { LeakyBucket *bkt =3D &cfg->buckets[i]; - if (bkt->avg < 0 || bkt->max < 0 || - bkt->avg > THROTTLE_VALUE_MAX || bkt->max > THROTTLE_VALUE_MAX= ) { + if (bkt->avg > THROTTLE_VALUE_MAX || bkt->max > THROTTLE_VALUE_MAX= ) { error_setg(errp, "bps/iops/max values must be within [0, %lld]= ", THROTTLE_VALUE_MAX); return false; --=20 2.11.0 From nobody Sat May 4 06:03:08 2024 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 1503581535415995.474157332526; Thu, 24 Aug 2017 06:32:15 -0700 (PDT) Received: from localhost ([::1]:48665 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dksF4-0008Ts-99 for importer@patchew.org; Thu, 24 Aug 2017 09:32:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41974) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dks90-0003JR-G5 for qemu-devel@nongnu.org; Thu, 24 Aug 2017 09:26:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dks8w-0003Tt-F9 for qemu-devel@nongnu.org; Thu, 24 Aug 2017 09:25:58 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:53879) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dks8w-000333-1b; Thu, 24 Aug 2017 09:25:54 -0400 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1dks8H-0002oS-V5; Thu, 24 Aug 2017 15:25:14 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1dks80-0007d2-Sm; Thu, 24 Aug 2017 16:24:56 +0300 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=WPu4vA9UMwJ1WESSWBWzo4EjSQ39E/uduFLZUL93VwI=; b=L6jly3ecwDeXLvTl1YkSGZ13oo7yy/zyJJLry2l4Egz+XqKmQb9bMhSt/DlUQTt71PTUXh3DWEPMrvsfVnMP4fQQTIua2V+i5kU1e7pOqFBeeETKo8S41c54u8FYXegOT2iWu2Q0i1aFrmbRqMK8pITy9rs5Gngi9JGKENsSEZIzH9Vi4AmpbEA2mlr6tXOgONPHOvoW22ZgZDvV+qsqDQgiUNHAVtBUD18JlXfiZzhY2fYVUWRPDRmpU2lrwnCg+mAuQgc8SwsDHv5WRskI4c7xBHB1ef8uWLERhsFNKT5XEd8L4M+H0ub6TXxiWUfk9ysT6Q532qgiVXNFMCjpLw==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Thu, 24 Aug 2017 16:24:48 +0300 Message-Id: <1b2e3049803f71cafb2e1fa1be4fb47147a0d398.1503580370.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH v2 6/7] throttle: Make burst_length 64bit and add range checks 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-block@nongnu.org, Manos Pitsidianakis 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" LeakyBucket.burst_length is defined as an unsigned integer but the code never checks for overflows and it only makes sure that the value is not 0. In practice this means that the user can set something like throttling.iops-total-max-length=3D4294967300 despite being larger than UINT_MAX and the final value after casting to unsigned int will be 4. This patch changes the data type to uint64_t. This does not increase the storage size of LeakyBucket, and allows us to assign the value directly from qemu_opt_get_number() or BlockIOThrottle and then do the checks directly in throttle_is_valid(). The value of burst_length does not have a specific upper limit, but since the bucket size is defined by max * burst_length we have to prevent overflows. Instead of going for UINT64_MAX or something similar this patch reuses THROTTLE_VALUE_MAX, which allows I/O bursts of 1 GiB/s for 10 days in a row. Signed-off-by: Alberto Garcia Reviewed-by: Eric Blake --- include/qemu/throttle.h | 2 +- util/throttle.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h index 6e31155fd4..8e01885d29 100644 --- a/include/qemu/throttle.h +++ b/include/qemu/throttle.h @@ -81,7 +81,7 @@ typedef struct LeakyBucket { uint64_t max; /* leaky bucket max burst in units */ double level; /* bucket level in units */ double burst_level; /* bucket level in units (for computing burs= ts) */ - unsigned burst_length; /* max length of the burst period, in second= s */ + uint64_t burst_length; /* max length of the burst period, in second= s */ } LeakyBucket; =20 /* The following structure is used to configure a ThrottleState diff --git a/util/throttle.c b/util/throttle.c index 80660ffd2c..b8c524336c 100644 --- a/util/throttle.c +++ b/util/throttle.c @@ -354,6 +354,11 @@ bool throttle_is_valid(ThrottleConfig *cfg, Error **er= rp) return false; } =20 + if (bkt->max && bkt->burst_length > THROTTLE_VALUE_MAX / bkt->max)= { + error_setg(errp, "burst length too high for this burst rate"); + return false; + } + if (bkt->max && !bkt->avg) { error_setg(errp, "bps_max/iops_max require corresponding" " bps/iops values"); --=20 2.11.0 From nobody Sat May 4 06:03:08 2024 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 1503581415210521.2232764468051; Thu, 24 Aug 2017 06:30:15 -0700 (PDT) Received: from localhost ([::1]:48651 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dksD7-0006aG-UI for importer@patchew.org; Thu, 24 Aug 2017 09:30:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41978) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dks90-0003JV-H7 for qemu-devel@nongnu.org; Thu, 24 Aug 2017 09:25:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dks8w-0003Tk-F7 for qemu-devel@nongnu.org; Thu, 24 Aug 2017 09:25:58 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:53880) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dks8w-00032w-1p; Thu, 24 Aug 2017 09:25:54 -0400 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1dks8I-0002oT-0A; Thu, 24 Aug 2017 15:25:14 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1dks80-0007d5-Ts; Thu, 24 Aug 2017 16:24:56 +0300 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=q7knSfV2azmaT/l6eDoPb8zHv90vDcfkOQn8+4I5Z1w=; b=bROrmgpynegkOxq7h70RvV0MQ6mqAjHuPB59YD8sGqePL2QdaU7PQ+LVQ3rC1re2jZjkIlC2Yvjy81HG5nr4unUASkrR7Oq1U1fau3WBd2gGuIducENjGugi6sKtSEfaZbuQXYmUz61zuDp3DH8jq6Ps1E0P3BrZTbQ1HD7oVItmYQCyI/RdkK77Jo/HgouYYjQL7vES8XN+o5pu3gaaqEgeRcN6cE4f5QXiPCEO12FWrjpendo19YHnKUu/LbzA1Bn8pVre0FLFwkLIFwUEUcoRnSisGUxXUIAGgV05nkZE14BXncIETM/5Jsa4GqD4WiSBNGZ5DlbdsqDtQEuXrA==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Thu, 24 Aug 2017 16:24:49 +0300 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH v2 7/7] throttle: Test the valid range of config values 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-block@nongnu.org, Manos Pitsidianakis 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" Signed-off-by: Alberto Garcia --- tests/test-throttle.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 77 insertions(+) diff --git a/tests/test-throttle.c b/tests/test-throttle.c index 41c0dd2529..bf7a5a648a 100644 --- a/tests/test-throttle.c +++ b/tests/test-throttle.c @@ -378,6 +378,82 @@ static void test_is_valid(void) test_is_valid_for_value(1, true); } =20 +static void test_ranges(void) +{ + int i; + + for (i =3D 0; i < BUCKETS_COUNT; i++) { + LeakyBucket *b =3D &cfg.buckets[i]; + throttle_config_init(&cfg); + + /* avg =3D 0 means throttling is disabled, but the config is valid= */ + b->avg =3D 0; + g_assert(throttle_is_valid(&cfg, NULL)); + g_assert(!throttle_enabled(&cfg)); + + /* These are valid configurations (values <=3D THROTTLE_VALUE_MAX)= */ + b->avg =3D 1; + g_assert(throttle_is_valid(&cfg, NULL)); + + b->avg =3D THROTTLE_VALUE_MAX; + g_assert(throttle_is_valid(&cfg, NULL)); + + b->avg =3D THROTTLE_VALUE_MAX; + b->max =3D THROTTLE_VALUE_MAX; + g_assert(throttle_is_valid(&cfg, NULL)); + + /* Values over THROTTLE_VALUE_MAX are not allowed */ + b->avg =3D THROTTLE_VALUE_MAX + 1; + g_assert(!throttle_is_valid(&cfg, NULL)); + + b->avg =3D THROTTLE_VALUE_MAX; + b->max =3D THROTTLE_VALUE_MAX + 1; + g_assert(!throttle_is_valid(&cfg, NULL)); + + /* burst_length must be between 1 and THROTTLE_VALUE_MAX */ + b->avg =3D 1; + b->max =3D 1; + b->burst_length =3D 0; + g_assert(!throttle_is_valid(&cfg, NULL)); + + b->avg =3D 1; + b->max =3D 1; + b->burst_length =3D 1; + g_assert(throttle_is_valid(&cfg, NULL)); + + b->avg =3D 1; + b->max =3D 1; + b->burst_length =3D THROTTLE_VALUE_MAX; + g_assert(throttle_is_valid(&cfg, NULL)); + + b->avg =3D 1; + b->max =3D 1; + b->burst_length =3D THROTTLE_VALUE_MAX + 1; + g_assert(!throttle_is_valid(&cfg, NULL)); + + /* burst_length * max cannot exceed THROTTLE_VALUE_MAX */ + b->avg =3D 1; + b->max =3D 2; + b->burst_length =3D THROTTLE_VALUE_MAX / 2; + g_assert(throttle_is_valid(&cfg, NULL)); + + b->avg =3D 1; + b->max =3D 3; + b->burst_length =3D THROTTLE_VALUE_MAX / 2; + g_assert(!throttle_is_valid(&cfg, NULL)); + + b->avg =3D 1; + b->max =3D THROTTLE_VALUE_MAX; + b->burst_length =3D 1; + g_assert(throttle_is_valid(&cfg, NULL)); + + b->avg =3D 1; + b->max =3D THROTTLE_VALUE_MAX; + b->burst_length =3D 2; + g_assert(!throttle_is_valid(&cfg, NULL)); + } +} + static void test_max_is_missing_limit(void) { int i; @@ -669,6 +745,7 @@ int main(int argc, char **argv) g_test_add_func("/throttle/config/enabled", test_enabled); g_test_add_func("/throttle/config/conflicting", test_conflicting_confi= g); g_test_add_func("/throttle/config/is_valid", test_is_valid); + g_test_add_func("/throttle/config/ranges", test_ranges); g_test_add_func("/throttle/config/max", test_max_is_missing_li= mit); g_test_add_func("/throttle/config/iops_size", test_iops_size_is_missing_limit); --=20 2.11.0