From nobody Sun May 5 20:18:26 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 1502980269928416.952062872017; Thu, 17 Aug 2017 07:31:09 -0700 (PDT) Received: from localhost ([::1]:55615 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diLpE-0006zt-Mj for importer@patchew.org; Thu, 17 Aug 2017 10:31:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36154) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diLnT-0005hH-Br for qemu-devel@nongnu.org; Thu, 17 Aug 2017 10:29:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diLnQ-0006uU-5U for qemu-devel@nongnu.org; Thu, 17 Aug 2017 10:29:19 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:48675) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1diLnP-0006iX-PQ; Thu, 17 Aug 2017 10:29:16 -0400 Received: from a88-114-101-76.elisa-laajakaista.fi ([88.114.101.76] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1diLmm-00044A-Vy; Thu, 17 Aug 2017 16:28:37 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1diLmZ-0001vw-AJ; Thu, 17 Aug 2017 17:28:23 +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=FH1KUNp76+dqyZNF+Npc1xEBuAplrAFN+rb45LeW2No=; b=pTZo2zTlFoyfkYMtUhNENBFGZfCvbSKVmPv4ffz8Lrm9V581dnlitFSTJfuMjpsaWchqnNHxCVwYXiBeUC5vKZGL3XE5LKieHlK1cksiZ7dUC5aflPhdoAYUQwAHCKh7NSmkc7dGMXTiKV//ZUBlIVEfstk+fQYoj9pUufYi9LXIB2ZjGfS94kImI+I3QcmhcjiopyvIOewblvXXbTTbgpvfaconP+sqWsyYwFbovkaFyIarze6Lsct9DiGSas9wFvunFpjs+hgmzpWhdVKOOpR1yCq3QIcKixyKMm2JqZKPZFjatIXisCQCtt6OV+oPnUb9RmRXi1ZgrNiDAc06xg==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Thu, 17 Aug 2017 17:28:12 +0300 Message-Id: <427228619067b0a029d2ae7706a3743a6da38128.1502979710.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 1/4] 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 , Stefan Hajnoczi , 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_lenght. 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 Sun May 5 20:18:26 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 1502980526261531.1861826705732; Thu, 17 Aug 2017 07:35:26 -0700 (PDT) Received: from localhost ([::1]:55799 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diLtN-00026i-2v for importer@patchew.org; Thu, 17 Aug 2017 10:35:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36157) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diLnT-0005hK-CQ for qemu-devel@nongnu.org; Thu, 17 Aug 2017 10:29:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diLnQ-0006um-6g for qemu-devel@nongnu.org; Thu, 17 Aug 2017 10:29:19 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:48670) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1diLnP-0006iS-Pa; Thu, 17 Aug 2017 10:29:16 -0400 Received: from a88-114-101-76.elisa-laajakaista.fi ([88.114.101.76] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1diLmn-00044B-24; Thu, 17 Aug 2017 16:28:37 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1diLmZ-0001vy-BX; Thu, 17 Aug 2017 17:28:23 +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=mWOm5E9tZoVNOiKR874+gOXUwgTpPhQA2hDnT9md6Kux+S4rJHUvSQXWb/+XnidGzgrcU6WoCtPiEP09HJgCdzRN67AYGhGlYzO8HPgrUxbp9u/DYDQZEaDootoRLVFXx9U3E5I5I1EjBzahEx+dhZERKy9NScvBe9VM4FZzsY16gEakFj9tHPtWf7klfvaPl2uOyZ2ZqdrFmOzbSFTJtZP0nTeVWfhrnfZDszQVq9wEY9XNUG7tq9NLXMSl7iYwj7bk+yc2pf841qTR/WQtKkgTWZYZi3zF0Qt/3hrvtYPc54kNWDHos1edNW3dcSRgJe02a62FBe7LLT1viDdw8w==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Thu, 17 Aug 2017 17:28:13 +0300 Message-Id: <5991d93d80c91f41e9ddd682d4d5292e275bbd62.1502979710.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 2/4] 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 , Stefan Hajnoczi , 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 --- 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 Sun May 5 20:18:26 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 1502980256292585.1811842459284; Thu, 17 Aug 2017 07:30:56 -0700 (PDT) Received: from localhost ([::1]:55610 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diLp1-0006r5-5f for importer@patchew.org; Thu, 17 Aug 2017 10:30:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36155) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diLnT-0005hI-Be for qemu-devel@nongnu.org; Thu, 17 Aug 2017 10:29:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diLnQ-0006ue-5e for qemu-devel@nongnu.org; Thu, 17 Aug 2017 10:29:19 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:48676) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1diLnP-0006iT-Pe; Thu, 17 Aug 2017 10:29:16 -0400 Received: from a88-114-101-76.elisa-laajakaista.fi ([88.114.101.76] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1diLmn-000449-1s; Thu, 17 Aug 2017 16:28:37 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1diLmZ-0001w0-Cu; Thu, 17 Aug 2017 17:28:23 +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=caI6IjdFyvYAE6+cwcpKBOfaEvW/HmJwdTBzdx2GWqk=; b=riqiiw+kaQ+KBi3HtbmMfs2G9uDN7pefPQBHnUkr2DdmQ93cdx4M4fbr0Y/YJC7LSHIkbh2pFehDi9ZR1Qup8cWf9Rp3MVfAL6X6H+svHAkZZDEghcEILCvGphxOH21H3KB45oPEAn9A5Pd2rj3gLxV6zGckTqHBKRT3wZbN+wRuqKI/j8alyang/jK49uaDPiT+MmYma3kE1idC9Opape5V4sdtfGdjWx9/BPp75cdZ9hCFUNQRSq1JTjvnl9J5WGwn6vR7v3qjAi/oeXpC/F9z96Nqdk7ENRHiOew0hP99oKDvRpVaJvUXEJ+xzNOaTWEw+qcz02Kc8i+FN0mNaQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Thu, 17 Aug 2017 17:28:14 +0300 Message-Id: <112e28c8da085ffd59381d86f3acb0b8f75d5f9a.1502979710.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 3/4] 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 , Stefan Hajnoczi , 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 9a6bda813c..1f29cf9918 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); } @@ -358,31 +371,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 @@ -397,8 +385,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); @@ -411,13 +401,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 Sun May 5 20:18:26 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 1502980401423635.377205292211; Thu, 17 Aug 2017 07:33:21 -0700 (PDT) Received: from localhost ([::1]:55697 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diLrL-0000M5-W8 for importer@patchew.org; Thu, 17 Aug 2017 10:33:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36156) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diLnT-0005hJ-C0 for qemu-devel@nongnu.org; Thu, 17 Aug 2017 10:29:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diLnQ-0006uk-6d for qemu-devel@nongnu.org; Thu, 17 Aug 2017 10:29:19 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:48672) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1diLnP-0006iW-PX; Thu, 17 Aug 2017 10:29:16 -0400 Received: from a88-114-101-76.elisa-laajakaista.fi ([88.114.101.76] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1diLmn-00044C-1t; Thu, 17 Aug 2017 16:28:37 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1diLmZ-0001w2-EF; Thu, 17 Aug 2017 17:28:23 +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=ZRNVCCbHWHXeJ5qop39nxE97NF6RnkwXwVIXMCbRetI=; b=HxQNBzIMbAJxIudg41XHzdqNQGbOYHsWe5cEE7nBUCnT65/ZFqQ7h2jIU5jVlO7aJ/NYpxIUhraIOusRNRPriKFXDGYSc0sDTwb3S4Pp8NwnVR0Pp105vFvhqMCagmiyZkOfj+ZQuyiHjdTiX390OBYLenHmLOVlT+dsU3PxumDEQZTQnqjS+cGNCpqh/5gEgNKV9fFA0rEjXXOePJEXkSUUq8UcS65mlFtwxUUaP0AakhRlz7z+Xu4JZ19OQBtQw9VXlA589dp8vh5QOfeHiNstYJTMIHLSAiWfo8IVQqRoFKWu1OOQdIe0NM0MEzWWhS8evCJl89oPPSyXtuYI5g==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Thu, 17 Aug 2017 17:28:15 +0300 Message-Id: <01b7212cc910cea55e4a1ac8d4704afaff0647b4.1502979710.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 4/4] 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 , Stefan Hajnoczi , 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 int64_t for those types. 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: Manos Pitsidianakis --- include/qemu/throttle.h | 4 ++-- util/throttle.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h index 66a8ac10a4..c466f6ccaa 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 */ + int64_t avg; /* average goal in units per second */ + int64_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/util/throttle.c b/util/throttle.c index 1f29cf9918..55a2451a14 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 */ --=20 2.11.0