From nobody Fri May 3 18:16:20 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 1502122631320860.7620418348803; Mon, 7 Aug 2017 09:17:11 -0700 (PDT) Received: from localhost ([::1]:38365 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dekiL-00015U-G1 for importer@patchew.org; Mon, 07 Aug 2017 12:17:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41706) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dekhK-0000fo-MY for qemu-devel@nongnu.org; Mon, 07 Aug 2017 12:16:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dekhC-0002jo-8c for qemu-devel@nongnu.org; Mon, 07 Aug 2017 12:16:03 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:56947) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dekhB-0002jG-R9; Mon, 07 Aug 2017 12:15:58 -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 1dekh7-0003L1-9x; Mon, 07 Aug 2017 18:15:53 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1dekgp-00010v-Ns; Mon, 07 Aug 2017 19:15:35 +0300 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Message-Id:Date:Subject:Cc:To:From; bh=mj9lwtUzJJ+gwsi8w5GnLXRqxyOLqpEYE2/1HZ1BhyQ=; b=iAVXmaJSZ4NSuNPKoYetJQ7aAUhrt7xHx3vKMoCAiJOrI1QJUHG7TqATDqJJ1kz6DHEAt/jf+AoHjESbre8/Xt7ooBZMx9+I1MF1bj+v19YTIxE9TZgqAOx7K3/7c3XHePEe9WmOZjLnGZuUOflYN3w+0m5VPjgY2yvgKLVWRm1VucwDQSFmal1LyGgPzWR0hSm+tVX4tIYsmueweS/0AxbnkfbdmfSo6tY99Ex9V3mV/y4WehPbYnMUyJM9zfrd093Kh6ca+XB0p6ypWqETFfMRjwNaKDUPF4lJB+5XY1nzbo/q21N5NS0m1TMEYRUqZJcAaj9dL99GI6U0w0cniA==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Mon, 7 Aug 2017 19:15:29 +0300 Message-Id: <20170807161529.3779-1-berto@igalia.com> X-Mailer: git-send-email 2.11.0 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 for-2.10] 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 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. There's one particular instance of the previous code where bkt->max could have a non-integer value: that's in throttle_fix_bucket() when bkt->max is initialized to bkt->avg / 10. This is now an integer division and the result is rounded. We don't need to worry about this because: a) with the magnitudes we're dealing with (bytes per second, I/O operations per second) the limits are likely to be always multiples of 10. b) even if they weren't this doesn't affect the actual limits, only the algorithm that makes the throttling smoother. Signed-off-by: Alberto Garcia Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- include/qemu/throttle.h | 4 ++-- util/throttle.c | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h index d056008c18..ec37ac0fcb 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 b2a52b8b34..7856931f67 100644 --- a/util/throttle.c +++ b/util/throttle.c @@ -111,7 +111,7 @@ int64_t throttle_compute_wait(LeakyBucket *bkt) 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 - (double) bkt->max / 10; if (extra > 0) { return throttle_do_compute_wait(bkt->max, extra); } @@ -361,8 +361,6 @@ bool throttle_is_valid(ThrottleConfig *cfg, Error **err= p) /* fix bucket parameters */ static void throttle_fix_bucket(LeakyBucket *bkt) { - double min; - /* zero bucket level */ bkt->level =3D bkt->burst_level =3D 0; =20 @@ -374,9 +372,8 @@ static void throttle_fix_bucket(LeakyBucket *bkt) * Having a max burst value of 100ms of the average will help smooth t= he * throttling */ - min =3D bkt->avg / 10; if (bkt->avg && !bkt->max) { - bkt->max =3D min; + bkt->max =3D (bkt->avg + 5) / 10; } } =20 --=20 2.11.0