From patchwork Mon Feb 8 16:15:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 8251901 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 328C5BEEE5 for ; Mon, 8 Feb 2016 16:22:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6B26520389 for ; Mon, 8 Feb 2016 16:22:26 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A2686202EC for ; Mon, 8 Feb 2016 16:22:21 +0000 (UTC) Received: from localhost ([::1]:46253 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSoZx-0008Ha-0E for patchwork-qemu-devel@patchwork.kernel.org; Mon, 08 Feb 2016 11:22:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57358) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSoTS-0006Sj-Hs for qemu-devel@nongnu.org; Mon, 08 Feb 2016 11:15:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aSoTR-0002Ub-Cb for qemu-devel@nongnu.org; Mon, 08 Feb 2016 11:15:38 -0500 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:34774) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSoTR-0002UP-2F for qemu-devel@nongnu.org; Mon, 08 Feb 2016 11:15:37 -0500 Received: by mail-wm0-x241.google.com with SMTP id p63so16175204wmp.1 for ; Mon, 08 Feb 2016 08:15:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=9hDk1HSbTE4R+UVeMcvXTW8EMbDO/CvFDcfvJrHNt68=; b=pm90dkaC6LpRU7tGoL1v0mHXYvN6bJI5y9eN1vSx9gL+pG5yjOD2gb3k0rkqw4JKJD TJ7VFTpf07OOJ/BGfSUnONTWt1O0gLc4gFAr3+WEfMW69FoZV9+nFgDPccEDGhBdcS2N eWFY2NftpIJ+7NbP3OeerW0v5OwO4zlDhCrilKFlPpMn+ffxl3ol7vCxIGlhYoTBkBHw tGiILXpxWHo+MgJQ7V8eQ4OPm2Ut4PrW3bsguimhqL1BarsSOEv74CMBJliL4a7jrwXc ksFGTk8S9WSiQbvyiWCQ0E0I5/k9OM14zUQekL1QQVnM5HTDup7JoazdY7T5SDCrPIEV WJvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=9hDk1HSbTE4R+UVeMcvXTW8EMbDO/CvFDcfvJrHNt68=; b=LN+cEeeNjBXlWao+wQ4Ve9AysygEcJNEiEctUHjuiV5PZF4A5cjb2VDOPPUkg1L3tk wTGR/i9uFj/mPAG5kdahxJ4ULgYyF+87FwLDuI2rIaOcfN5pqMS/GagVvKvHYdpONmtE Mi5q9v2YoqvY7WB7jemrzT2c8NWEbTAVFIowNgD5af+WKsR8YyWA/klkbg2tQiYBf0sp HPTs1irBg/VSKCokpnO755sUKLcaaVp6DovZA+daiRUjzIMfiH0Blze2+5AvxZ7AFemh IqIX+zNZcqekUPamjSd/w3peueHB/XdXc/OK369j/qYWJ5bsMgEJuE0rImGFxH4EDA99 crwA== X-Gm-Message-State: AG10YOQohjjypxbqM5g2Eb39YUPrXdkcRy1WN7uV+tSbNblUedW2NNEIhjAWYEViEoC9ig== X-Received: by 10.28.137.213 with SMTP id l204mr54472636wmd.100.1454948136614; Mon, 08 Feb 2016 08:15:36 -0800 (PST) Received: from donizetti.lan (94-39-141-130.adsl-ull.clienti.tiscali.it. [94.39.141.130]) by smtp.gmail.com with ESMTPSA id v2sm13305429wmd.24.2016.02.08.08.15.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Feb 2016 08:15:36 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 8 Feb 2016 17:15:07 +0100 Message-Id: <1454948107-11844-17-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1454948107-11844-1-git-send-email-pbonzini@redhat.com> References: <1454948107-11844-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::241 Cc: stefanha@redhat.com Subject: [Qemu-devel] [PATCH 16/16] aio: push aio_context_acquire/release down to dispatching X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. Signed-off-by: Paolo Bonzini --- aio-posix.c | 15 ++++++--------- aio-win32.c | 15 +++++++-------- async.c | 2 ++ 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/aio-posix.c b/aio-posix.c index cbdc6e4..015d41a 100644 --- a/aio-posix.c +++ b/aio-posix.c @@ -334,7 +334,9 @@ bool aio_dispatch(AioContext *ctx) if (!node->deleted && (revents & (G_IO_IN | G_IO_HUP | G_IO_ERR)) && node->io_read) { + aio_context_acquire(ctx); node->io_read(node->opaque); + aio_context_release(ctx); /* aio_notify() does not count as progress */ if (node->opaque != &ctx->notifier) { @@ -344,7 +346,9 @@ bool aio_dispatch(AioContext *ctx) if (!node->deleted && (revents & (G_IO_OUT | G_IO_ERR)) && node->io_write) { + aio_context_acquire(ctx); node->io_write(node->opaque); + aio_context_release(ctx); progress = true; } @@ -360,7 +364,9 @@ bool aio_dispatch(AioContext *ctx) qemu_lockcnt_dec(&ctx->list_lock); /* Run our timers */ + aio_context_acquire(ctx); progress |= timerlistgroup_run_timers(&ctx->tlg); + aio_context_release(ctx); return progress; } @@ -418,7 +424,6 @@ bool aio_poll_internal(AioContext *ctx, bool blocking) bool progress; int64_t timeout; - aio_context_acquire(ctx); progress = false; /* aio_notify can avoid the expensive event_notifier_set if @@ -447,9 +452,6 @@ bool aio_poll_internal(AioContext *ctx, bool blocking) timeout = blocking ? aio_compute_timeout(ctx) : 0; /* wait until next event */ - if (timeout) { - aio_context_release(ctx); - } if (aio_epoll_check_poll(ctx, pollfds, npfd, timeout)) { AioHandler epoll_handler; @@ -464,9 +466,6 @@ bool aio_poll_internal(AioContext *ctx, bool blocking) if (blocking) { atomic_sub(&ctx->notify_me, 2); } - if (timeout) { - aio_context_acquire(ctx); - } aio_notify_accept(ctx); @@ -485,8 +484,6 @@ bool aio_poll_internal(AioContext *ctx, bool blocking) progress = true; } - aio_context_release(ctx); - return progress; } diff --git a/aio-win32.c b/aio-win32.c index 862f48c..7e90dfd 100644 --- a/aio-win32.c +++ b/aio-win32.c @@ -245,7 +245,9 @@ static bool aio_dispatch_handlers(AioContext *ctx, HANDLE event) if (!node->deleted && (revents || event_notifier_get_handle(node->e) == event) && node->io_notify) { + aio_context_acquire(ctx); node->io_notify(node->e); + aio_context_release(ctx); /* aio_notify() does not count as progress */ if (node->e != &ctx->notifier) { @@ -256,11 +258,15 @@ static bool aio_dispatch_handlers(AioContext *ctx, HANDLE event) if (!node->deleted && (node->io_read || node->io_write)) { if ((revents & G_IO_IN) && node->io_read) { + aio_context_acquire(ctx); node->io_read(node->opaque); + aio_context_release(ctx); progress = true; } if ((revents & G_IO_OUT) && node->io_write) { + aio_context_acquire(ctx); node->io_write(node->opaque); + aio_context_release(ctx); progress = true; } @@ -305,7 +311,6 @@ bool aio_poll_internal(AioContext *ctx, bool blocking) int count; int timeout; - aio_context_acquire(ctx); progress = false; /* aio_notify can avoid the expensive event_notifier_set if @@ -347,17 +352,11 @@ bool aio_poll_internal(AioContext *ctx, bool blocking) timeout = blocking && !have_select_revents ? qemu_timeout_ns_to_ms(aio_compute_timeout(ctx)) : 0; - if (timeout) { - aio_context_release(ctx); - } ret = WaitForMultipleObjects(count, events, FALSE, timeout); if (blocking) { assert(first); atomic_sub(&ctx->notify_me, 2); } - if (timeout) { - aio_context_acquire(ctx); - } if (first) { aio_notify_accept(ctx); @@ -380,8 +379,8 @@ bool aio_poll_internal(AioContext *ctx, bool blocking) progress |= aio_dispatch_handlers(ctx, event); } while (count > 0); + aio_context_acquire(ctx); progress |= timerlistgroup_run_timers(&ctx->tlg); - aio_context_release(ctx); return progress; } diff --git a/async.c b/async.c index bc7e142..9eab833 100644 --- a/async.c +++ b/async.c @@ -88,7 +88,9 @@ int aio_bh_poll(AioContext *ctx) ret = 1; } bh->idle = 0; + aio_context_acquire(ctx); aio_bh_call(bh); + aio_context_release(ctx); } }