From nobody Wed Nov 5 16:42:16 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.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 1496923438203554.1658646632332; Thu, 8 Jun 2017 05:03:58 -0700 (PDT) Received: from localhost ([::1]:48850 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIwAO-0008Ut-Kc for importer@patchew.org; Thu, 08 Jun 2017 08:03:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46092) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIw3u-0001pG-9t for qemu-devel@nongnu.org; Thu, 08 Jun 2017 07:57:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIw3q-0001uP-2n for qemu-devel@nongnu.org; Thu, 08 Jun 2017 07:57:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40230) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dIw3p-0001uD-QP for qemu-devel@nongnu.org; Thu, 08 Jun 2017 07:57:10 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C090380C1A; Thu, 8 Jun 2017 11:57:08 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-24.pek2.redhat.com [10.72.12.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7FB7B17DC9; Thu, 8 Jun 2017 11:57:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C090380C1A Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C090380C1A From: Fam Zheng To: qemu-devel@nongnu.org Date: Thu, 8 Jun 2017 19:56:32 +0800 Message-Id: <20170608115643.18859-13-famz@redhat.com> In-Reply-To: <20170608115643.18859-1-famz@redhat.com> References: <20170608115643.18859-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 08 Jun 2017 11:57:08 +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 v3 12/23] 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: peter.maydell@linaro.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: Paolo Bonzini 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. Reviewed-by: Alberto Garcia Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini Message-Id: <20170605123908.18777-9-pbonzini@redhat.com> Signed-off-by: Fam Zheng --- block/throttle-groups.c | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/block/throttle-groups.c b/block/throttle-groups.c index 85169ec..8bf1031 100644 --- a/block/throttle-groups.c +++ b/block/throttle-groups.c @@ -260,6 +260,20 @@ 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. Return whether + * any request was actually pending. + * + * @blk: the current BlockBackend + * @is_write: the type of operation (read/write) + */ +static bool coroutine_fn throttle_group_co_restart_queue(BlockBackend *blk, + bool is_write) +{ + 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 +301,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,15 +354,21 @@ void coroutine_fn throttle_group_co_io_limits_interce= pt(BlockBackend *blk, qemu_mutex_unlock(&tg->lock); } =20 -static void throttle_group_restart_queue(BlockBackend *blk, bool is_write) +typedef struct { + BlockBackend *blk; + bool is_write; +} RestartData; + +static void coroutine_fn throttle_group_restart_queue_entry(void *opaque) { + RestartData *data =3D opaque; + BlockBackend *blk =3D data->blk; + bool is_write =3D data->is_write; BlockBackendPublic *blkp =3D blk_get_public(blk); ThrottleGroup *tg =3D container_of(blkp->throttle_state, ThrottleGroup= , ts); bool empty_queue; =20 - aio_context_acquire(blk_get_aio_context(blk)); - empty_queue =3D !qemu_co_enter_next(&blkp->throttled_reqs[is_write]); - aio_context_release(blk_get_aio_context(blk)); + empty_queue =3D !throttle_group_co_restart_queue(blk, is_write); =20 /* If the request queue was empty then we have to take care of * scheduling the next one */ @@ -359,6 +379,18 @@ static void throttle_group_restart_queue(BlockBackend = *blk, bool is_write) } } =20 +static void throttle_group_restart_queue(BlockBackend *blk, bool is_write) +{ + Coroutine *co; + RestartData rd =3D { + .blk =3D blk, + .is_write =3D is_write + }; + + co =3D qemu_coroutine_create(throttle_group_restart_queue_entry, &rd); + aio_co_enter(blk_get_aio_context(blk), co); +} + void throttle_group_restart_blk(BlockBackend *blk) { BlockBackendPublic *blkp =3D blk_get_public(blk); --=20 2.9.4