From nobody Sun Apr 13 08:39:43 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 1487583606667697.1690449190435; Mon, 20 Feb 2017 01:40:06 -0800 (PST) Received: from localhost ([::1]:36944 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cfkRx-0003Zu-0R for importer@patchew.org; Mon, 20 Feb 2017 04:40:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60024) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cfkLr-0006uC-7o for qemu-devel@nongnu.org; Mon, 20 Feb 2017 04:33:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cfkLk-0007Eb-7T for qemu-devel@nongnu.org; Mon, 20 Feb 2017 04:33:46 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33704) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cfkLk-0007ET-09 for qemu-devel@nongnu.org; Mon, 20 Feb 2017 04:33:40 -0500 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 33FACC05092E; Mon, 20 Feb 2017 09:33:40 +0000 (UTC) Received: from localhost (ovpn-116-137.ams2.redhat.com [10.36.116.137]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9DC082D5BB; Mon, 20 Feb 2017 09:33:39 +0000 (UTC) From: Stefan Hajnoczi To: Date: Mon, 20 Feb 2017 09:32:51 +0000 Message-Id: <20170220093304.20515-12-stefanha@redhat.com> In-Reply-To: <20170220093304.20515-1-stefanha@redhat.com> References: <20170220093304.20515-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 20 Feb 2017 09:33:40 +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 11/24] aio: push aio_context_acquire/release down to dispatching 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 , Stefan Hajnoczi , Paolo Bonzini 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 The AioContext data structures are now protected by list_lock and/or they are walked with FOREACH_RCU primitives. There is no need anymore to acquire the AioContext for the entire duration of aio_dispatch. Instead, just acquire it before and after invoking the callbacks. The next step is then to push it further down. Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini Reviewed-by: Fam Zheng Reviewed-by: Daniel P. Berrange Message-id: 20170213135235.12274-12-pbonzini@redhat.com Signed-off-by: Stefan Hajnoczi --- util/aio-posix.c | 25 +++++++++++-------------- util/aio-win32.c | 15 +++++++-------- util/async.c | 2 ++ 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/util/aio-posix.c b/util/aio-posix.c index a8d7090..b590c5a 100644 --- a/util/aio-posix.c +++ b/util/aio-posix.c @@ -402,7 +402,9 @@ static bool aio_dispatch_handlers(AioContext *ctx) (revents & (G_IO_IN | G_IO_HUP | G_IO_ERR)) && aio_node_check(ctx, node->is_external) && node->io_read) { + aio_context_acquire(ctx); node->io_read(node->opaque); + aio_context_release(ctx); =20 /* aio_notify() does not count as progress */ if (node->opaque !=3D &ctx->notifier) { @@ -413,7 +415,9 @@ static bool aio_dispatch_handlers(AioContext *ctx) (revents & (G_IO_OUT | G_IO_ERR)) && aio_node_check(ctx, node->is_external) && node->io_write) { + aio_context_acquire(ctx); node->io_write(node->opaque); + aio_context_release(ctx); progress =3D true; } =20 @@ -450,7 +454,9 @@ bool aio_dispatch(AioContext *ctx, bool dispatch_fds) } =20 /* Run our timers */ + aio_context_acquire(ctx); progress |=3D timerlistgroup_run_timers(&ctx->tlg); + aio_context_release(ctx); =20 return progress; } @@ -597,9 +603,6 @@ bool aio_poll(AioContext *ctx, bool blocking) int64_t timeout; int64_t start =3D 0; =20 - aio_context_acquire(ctx); - progress =3D false; - /* aio_notify can avoid the expensive event_notifier_set if * everything (file descriptors, bottom halves, timers) will * be re-evaluated before the next blocking poll(). This is @@ -617,9 +620,11 @@ bool aio_poll(AioContext *ctx, bool blocking) start =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME); } =20 - if (try_poll_mode(ctx, blocking)) { - progress =3D true; - } else { + aio_context_acquire(ctx); + progress =3D try_poll_mode(ctx, blocking); + aio_context_release(ctx); + + if (!progress) { assert(npfd =3D=3D 0); =20 /* fill pollfds */ @@ -636,9 +641,6 @@ bool aio_poll(AioContext *ctx, bool blocking) timeout =3D blocking ? aio_compute_timeout(ctx) : 0; =20 /* wait until next event */ - if (timeout) { - aio_context_release(ctx); - } if (aio_epoll_check_poll(ctx, pollfds, npfd, timeout)) { AioHandler epoll_handler; =20 @@ -650,9 +652,6 @@ bool aio_poll(AioContext *ctx, bool blocking) } else { ret =3D qemu_poll_ns(pollfds, npfd, timeout); } - if (timeout) { - aio_context_acquire(ctx); - } } =20 if (blocking) { @@ -717,8 +716,6 @@ bool aio_poll(AioContext *ctx, bool blocking) progress =3D true; } =20 - aio_context_release(ctx); - return progress; } =20 diff --git a/util/aio-win32.c b/util/aio-win32.c index 900524c..ab6d0e5 100644 --- a/util/aio-win32.c +++ b/util/aio-win32.c @@ -266,7 +266,9 @@ static bool aio_dispatch_handlers(AioContext *ctx, HAND= LE event) (revents || event_notifier_get_handle(node->e) =3D=3D event) && node->io_notify) { node->pfd.revents =3D 0; + aio_context_acquire(ctx); node->io_notify(node->e); + aio_context_release(ctx); =20 /* aio_notify() does not count as progress */ if (node->e !=3D &ctx->notifier) { @@ -278,11 +280,15 @@ static bool aio_dispatch_handlers(AioContext *ctx, HA= NDLE event) (node->io_read || node->io_write)) { node->pfd.revents =3D 0; if ((revents & G_IO_IN) && node->io_read) { + aio_context_acquire(ctx); node->io_read(node->opaque); + aio_context_release(ctx); progress =3D true; } if ((revents & G_IO_OUT) && node->io_write) { + aio_context_acquire(ctx); node->io_write(node->opaque); + aio_context_release(ctx); progress =3D true; } =20 @@ -329,7 +335,6 @@ bool aio_poll(AioContext *ctx, bool blocking) int count; int timeout; =20 - aio_context_acquire(ctx); progress =3D false; =20 /* aio_notify can avoid the expensive event_notifier_set if @@ -371,17 +376,11 @@ bool aio_poll(AioContext *ctx, bool blocking) =20 timeout =3D blocking && !have_select_revents ? qemu_timeout_ns_to_ms(aio_compute_timeout(ctx)) : 0; - if (timeout) { - aio_context_release(ctx); - } ret =3D WaitForMultipleObjects(count, events, FALSE, timeout); if (blocking) { assert(first); atomic_sub(&ctx->notify_me, 2); } - if (timeout) { - aio_context_acquire(ctx); - } =20 if (first) { aio_notify_accept(ctx); @@ -404,8 +403,8 @@ bool aio_poll(AioContext *ctx, bool blocking) progress |=3D aio_dispatch_handlers(ctx, event); } while (count > 0); =20 + aio_context_acquire(ctx); progress |=3D timerlistgroup_run_timers(&ctx->tlg); - aio_context_release(ctx); return progress; } diff --git a/util/async.c b/util/async.c index 9cac702..aec8016 100644 --- a/util/async.c +++ b/util/async.c @@ -114,7 +114,9 @@ int aio_bh_poll(AioContext *ctx) ret =3D 1; } bh->idle =3D 0; + aio_context_acquire(ctx); aio_bh_call(bh); + aio_context_release(ctx); } if (bh->deleted) { deleted =3D true; --=20 2.9.3