From nobody Wed Dec 17 05:30:40 2025 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; 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 1500387626008295.32198952457156; Tue, 18 Jul 2017 07:20:26 -0700 (PDT) Received: from localhost ([::1]:56781 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTMJ-0001zr-Tm for importer@patchew.org; Tue, 18 Jul 2017 10:20:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52886) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTKQ-0000L0-0N for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXTKO-0007Y0-KK for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34526) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXTKL-0007TT-9k; Tue, 18 Jul 2017 10:18:17 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4927B7A160; Tue, 18 Jul 2017 14:18:16 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-175.str.redhat.com [10.33.192.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2A3916F940; Tue, 18 Jul 2017 14:18:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4927B7A160 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 4927B7A160 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 18 Jul 2017 16:17:47 +0200 Message-Id: <1500387486-5469-3-git-send-email-kwolf@redhat.com> In-Reply-To: <1500387486-5469-1-git-send-email-kwolf@redhat.com> References: <1500387486-5469-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 18 Jul 2017 14:18:16 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 02/21] block: add clock_type field to ThrottleGroup 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: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Manos Pitsidianakis Clock type in throttling is currently inferred by the ThrottleTimer's clock type even though it is a per-ThrottleGroup property; it doesn't make sense to have different clock types in the same group. Moving this to a field in ThrottleGroup can simplify some of the throttle functions. Signed-off-by: Manos Pitsidianakis Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- block/throttle-groups.c | 20 ++++++++++---------- fsdev/qemu-fsdev-throttle.c | 2 +- include/qemu/throttle.h | 1 + tests/test-throttle.c | 4 ++-- util/throttle.c | 4 +++- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/block/throttle-groups.c b/block/throttle-groups.c index da2b490..71af3f7 100644 --- a/block/throttle-groups.c +++ b/block/throttle-groups.c @@ -61,6 +61,7 @@ typedef struct ThrottleGroup { QLIST_HEAD(, BlockBackendPublic) head; BlockBackend *tokens[2]; bool any_timer_armed[2]; + QEMUClockType clock_type; =20 /* These two are protected by the global throttle_groups_lock */ unsigned refcount; @@ -98,6 +99,12 @@ ThrottleState *throttle_group_incref(const char *name) if (!tg) { tg =3D g_new0(ThrottleGroup, 1); tg->name =3D g_strdup(name); + tg->clock_type =3D QEMU_CLOCK_REALTIME; + + if (qtest_enabled()) { + /* For testing block IO throttling only */ + tg->clock_type =3D QEMU_CLOCK_VIRTUAL; + } qemu_mutex_init(&tg->lock); throttle_init(&tg->ts); QLIST_INIT(&tg->head); @@ -310,7 +317,7 @@ static void schedule_next_request(BlockBackend *blk, bo= ol is_write) token =3D blk; } else { ThrottleTimers *tt =3D &blk_get_public(token)->throttle_timers; - int64_t now =3D qemu_clock_get_ns(tt->clock_type); + int64_t now =3D qemu_clock_get_ns(tg->clock_type); timer_mod(tt->timers[is_write], now); tg->any_timer_armed[is_write] =3D true; } @@ -430,7 +437,7 @@ void throttle_group_config(BlockBackend *blk, ThrottleC= onfig *cfg) if (timer_pending(tt->timers[1])) { tg->any_timer_armed[1] =3D false; } - throttle_config(ts, tt, cfg); + throttle_config(ts, tg->clock_type, tt, cfg); qemu_mutex_unlock(&tg->lock); =20 throttle_group_restart_blk(blk); @@ -497,13 +504,6 @@ void throttle_group_register_blk(BlockBackend *blk, co= nst char *groupname) BlockBackendPublic *blkp =3D blk_get_public(blk); ThrottleState *ts =3D throttle_group_incref(groupname); ThrottleGroup *tg =3D container_of(ts, ThrottleGroup, ts); - int clock_type =3D QEMU_CLOCK_REALTIME; - - if (qtest_enabled()) { - /* For testing block IO throttling only */ - clock_type =3D QEMU_CLOCK_VIRTUAL; - } - blkp->throttle_state =3D ts; =20 qemu_mutex_lock(&tg->lock); @@ -518,7 +518,7 @@ void throttle_group_register_blk(BlockBackend *blk, con= st char *groupname) =20 throttle_timers_init(&blkp->throttle_timers, blk_get_aio_context(blk), - clock_type, + tg->clock_type, read_timer_cb, write_timer_cb, blk); diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c index 7ae4e86..453fb1e 100644 --- a/fsdev/qemu-fsdev-throttle.c +++ b/fsdev/qemu-fsdev-throttle.c @@ -86,7 +86,7 @@ void fsdev_throttle_init(FsThrottle *fst) fsdev_throttle_read_timer_cb, fsdev_throttle_write_timer_cb, fst); - throttle_config(&fst->ts, &fst->tt, &fst->cfg); + throttle_config(&fst->ts, QEMU_CLOCK_REALTIME, &fst->tt, &fst->cfg= ); qemu_co_queue_init(&fst->throttled_reqs[0]); qemu_co_queue_init(&fst->throttled_reqs[1]); } diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h index 9109657..8d2fd77 100644 --- a/include/qemu/throttle.h +++ b/include/qemu/throttle.h @@ -139,6 +139,7 @@ bool throttle_enabled(ThrottleConfig *cfg); bool throttle_is_valid(ThrottleConfig *cfg, Error **errp); =20 void throttle_config(ThrottleState *ts, + QEMUClockType clock_type, ThrottleTimers *tt, ThrottleConfig *cfg); =20 diff --git a/tests/test-throttle.c b/tests/test-throttle.c index a9201b1..2d9cd46 100644 --- a/tests/test-throttle.c +++ b/tests/test-throttle.c @@ -228,7 +228,7 @@ static void test_config_functions(void) read_timer_cb, write_timer_cb, &ts); /* structure reset by throttle_init previous_leak should be null */ g_assert(!ts.previous_leak); - throttle_config(&ts, &tt, &orig_cfg); + throttle_config(&ts, QEMU_CLOCK_VIRTUAL, &tt, &orig_cfg); =20 /* has previous leak been initialized by throttle_config ? */ g_assert(ts.previous_leak); @@ -486,7 +486,7 @@ static bool do_test_accounting(bool is_ops, /* are we t= esting bps or ops */ throttle_init(&ts); throttle_timers_init(&tt, ctx, QEMU_CLOCK_VIRTUAL, read_timer_cb, write_timer_cb, &ts); - throttle_config(&ts, &tt, &cfg); + throttle_config(&ts, QEMU_CLOCK_VIRTUAL, &tt, &cfg); =20 /* account a read */ throttle_account(&ts, false, size); diff --git a/util/throttle.c b/util/throttle.c index 3570ed2..3e94807 100644 --- a/util/throttle.c +++ b/util/throttle.c @@ -399,10 +399,12 @@ static void throttle_cancel_timer(QEMUTimer *timer) /* Used to configure the throttle * * @ts: the throttle state we are working on + * @clock_type: the group's clock_type * @tt: the throttle timers we use in this aio context * @cfg: the config to set */ void throttle_config(ThrottleState *ts, + QEMUClockType clock_type, ThrottleTimers *tt, ThrottleConfig *cfg) { @@ -414,7 +416,7 @@ void throttle_config(ThrottleState *ts, throttle_fix_bucket(&ts->cfg.buckets[i]); } =20 - ts->previous_leak =3D qemu_clock_get_ns(tt->clock_type); + ts->previous_leak =3D qemu_clock_get_ns(clock_type); =20 for (i =3D 0; i < 2; i++) { throttle_cancel_timer(tt->timers[i]); --=20 1.8.3.1