From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33602) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZNLMY-00043A-OJ for qemu-devel@nongnu.org; Thu, 06 Aug 2015 09:37:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZNLMU-0003Q8-Sd for qemu-devel@nongnu.org; Thu, 06 Aug 2015 09:37:37 -0400 From: Paolo Bonzini Date: Thu, 6 Aug 2015 15:36:08 +0200 Message-Id: <1438868176-20364-11-git-send-email-pbonzini@redhat.com> In-Reply-To: <1438868176-20364-1-git-send-email-pbonzini@redhat.com> References: <1438868176-20364-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 10/18] async: optimize aio_bh_poll List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, famz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org Avoid entering the slow path of qemu_lockcnt_dec_and_lock if no bottom half has to be deleted. If a bottom half deletes itself, it will be picked up on the next visit of the list, or when the AioContext itself is finalized. Signed-off-by: Paolo Bonzini --- async.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/async.c b/async.c index 198c53d..1fce3e4 100644 --- a/async.c +++ b/async.c @@ -64,19 +64,24 @@ int aio_bh_poll(AioContext *ctx) { QEMUBH *bh, **bhp, *next; int ret; + bool deleted = false; qemu_lockcnt_inc(&ctx->list_lock); ret = 0; for (bh = atomic_rcu_read(&ctx->first_bh); bh; bh = next) { next = atomic_rcu_read(&bh->next); + if (bh->deleted) { + deleted = true; + continue; + } /* The atomic_xchg is paired with the one in qemu_bh_schedule. The * implicit memory barrier ensures that the callback sees all writes * done by the scheduling thread. It also ensures that the scheduling * thread sees the zero before bh->cb has run, and thus will call * aio_notify again if necessary. */ - if (!bh->deleted && atomic_xchg(&bh->scheduled, 0)) { + if (atomic_xchg(&bh->scheduled, 0)) { /* Idle BHs don't count as progress */ if (!bh->idle) { ret = 1; @@ -89,6 +94,11 @@ int aio_bh_poll(AioContext *ctx) } /* remove deleted bhs */ + if (!deleted) { + qemu_lockcnt_dec(&ctx->list_lock); + return ret; + } + if (qemu_lockcnt_dec_and_lock(&ctx->list_lock)) { bhp = &ctx->first_bh; while (*bhp) { @@ -102,7 +112,6 @@ int aio_bh_poll(AioContext *ctx) } qemu_lockcnt_unlock(&ctx->list_lock); } - return ret; } -- 2.4.3