From nobody Mon Feb 9 16:19:02 2026 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.zoho.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 1492690033120646.0796361839978; Thu, 20 Apr 2017 05:07:13 -0700 (PDT) Received: from localhost ([::1]:53549 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1Arf-00037S-A0 for importer@patchew.org; Thu, 20 Apr 2017 08:07:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38554) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1Amh-0007W5-P9 for qemu-devel@nongnu.org; Thu, 20 Apr 2017 08:02:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d1Ama-0002yK-1L for qemu-devel@nongnu.org; Thu, 20 Apr 2017 08:02:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43726) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d1Alt-0002RK-0f; Thu, 20 Apr 2017 08:01:13 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D8854C7050; Thu, 20 Apr 2017 12:01:11 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-9.ams2.redhat.com [10.36.117.9]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v3KC0w3v002037; Thu, 20 Apr 2017 08:01:10 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D8854C7050 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=pbonzini@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com D8854C7050 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 20 Apr 2017 14:00:48 +0200 Message-Id: <20170420120058.28404-8-pbonzini@redhat.com> In-Reply-To: <20170420120058.28404-1-pbonzini@redhat.com> References: <20170420120058.28404-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 20 Apr 2017 12:01:12 +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] [PATCH 07/17] throttle-groups: do not use qemu_co_enter_next 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-block@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" Prepare for removing this function; always restart throttled requests from coroutine context. This will matter when restarting throttled requests will have to acquire a CoMutex. Signed-off-by: Paolo Bonzini --- block/throttle-groups.c | 65 +++++++++++++++++++++++++++++++++++++++++++--= ---- 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/block/throttle-groups.c b/block/throttle-groups.c index 69bfbd4..d66bf62 100644 --- a/block/throttle-groups.c +++ b/block/throttle-groups.c @@ -260,6 +260,18 @@ static bool throttle_group_schedule_timer(BlockBackend= *blk, bool is_write) return must_wait; } =20 +/* Start the next pending I/O request for a BlockBackend. + * + * @blk: the current BlockBackend + * @is_write: the type of operation (read/write) + */ +static bool throttle_group_co_restart_queue(BlockBackend *blk, bool is_wri= te) +{ + BlockBackendPublic *blkp =3D blk_get_public(blk); + + return qemu_co_queue_next(&blkp->throttled_reqs[is_write]); +} + /* Look for the next pending I/O request and schedule it. * * This assumes that tg->lock is held. @@ -287,7 +299,7 @@ static void schedule_next_request(BlockBackend *blk, bo= ol is_write) if (!must_wait) { /* Give preference to requests from the current blk */ if (qemu_in_coroutine() && - qemu_co_queue_next(&blkp->throttled_reqs[is_write])) { + throttle_group_co_restart_queue(blk, is_write)) { token =3D blk; } else { ThrottleTimers *tt =3D &blk_get_public(token)->throttle_timers; @@ -340,18 +352,57 @@ void coroutine_fn throttle_group_co_io_limits_interce= pt(BlockBackend *blk, qemu_mutex_unlock(&tg->lock); } =20 -void throttle_group_restart_blk(BlockBackend *blk) +typedef struct { + BlockBackend *blk; + bool is_write; + int ret; +} RestartData; + +static void throttle_group_restart_queue_entry(void *opaque) { - BlockBackendPublic *blkp =3D blk_get_public(blk); + RestartData *data =3D opaque; + + data->ret =3D throttle_group_co_restart_queue(data->blk, data->is_writ= e); +} + +static int throttle_group_restart_queue(BlockBackend *blk, bool is_write) +{ + Coroutine *co; + RestartData rd =3D { + .blk =3D blk, + .is_write =3D is_write + }; + + aio_context_acquire(blk_get_aio_context(blk)); + co =3D qemu_coroutine_create(throttle_group_restart_queue_entry, &rd); + /* The request doesn't start until after throttle_group_restart_queue_= entry + * returns, so the coroutine cannot yield. + */ + qemu_coroutine_enter(co); + aio_context_release(blk_get_aio_context(blk)); + return rd.ret; +} + +static void throttle_group_restart_blk_entry(void *opaque) +{ + BlockBackend *blk =3D opaque; int i; =20 for (i =3D 0; i < 2; i++) { - while (qemu_co_enter_next(&blkp->throttled_reqs[i])) { + while (throttle_group_co_restart_queue(blk, i)) { ; } } } =20 +void throttle_group_restart_blk(BlockBackend *blk) +{ + Coroutine *co; + + co =3D qemu_coroutine_create(throttle_group_restart_blk_entry, blk); + qemu_coroutine_enter(co); +} + /* Update the throttle configuration for a particular group. Similar * to throttle_config(), but guarantees atomicity within the * throttling group. @@ -376,8 +427,8 @@ void throttle_group_config(BlockBackend *blk, ThrottleC= onfig *cfg) throttle_config(ts, tt, cfg); qemu_mutex_unlock(&tg->lock); =20 - qemu_co_enter_next(&blkp->throttled_reqs[0]); - qemu_co_enter_next(&blkp->throttled_reqs[1]); + throttle_group_restart_queue(blk, 0); + throttle_group_restart_queue(blk, 1); } =20 /* Get the throttle configuration from a particular group. Similar to @@ -417,7 +468,7 @@ static void timer_cb(BlockBackend *blk, bool is_write) =20 /* Run the request that was waiting for this timer */ aio_context_acquire(blk_get_aio_context(blk)); - empty_queue =3D !qemu_co_enter_next(&blkp->throttled_reqs[is_write]); + empty_queue =3D !throttle_group_restart_queue(blk, is_write); aio_context_release(blk_get_aio_context(blk)); =20 /* If the request queue was empty then we have to take care of --=20 2.9.3