From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35800) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZH3aU-0002AO-VJ for qemu-devel@nongnu.org; Mon, 20 Jul 2015 01:26:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZH3aR-0003ni-QH for qemu-devel@nongnu.org; Mon, 20 Jul 2015 01:26:02 -0400 Received: from mail-wg0-x232.google.com ([2a00:1450:400c:c00::232]:33234) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZH3aR-0003mv-IO for qemu-devel@nongnu.org; Mon, 20 Jul 2015 01:25:59 -0400 Received: by wgmn9 with SMTP id n9so121702838wgm.0 for ; Sun, 19 Jul 2015 22:25:58 -0700 (PDT) Sender: Paolo Bonzini References: <1437250916-18905-1-git-send-email-pbonzini@redhat.com> <1437250916-18905-3-git-send-email-pbonzini@redhat.com> <20150720022708.GA17582@ad.nay.redhat.com> From: Paolo Bonzini Message-ID: <55AC8663.7020405@redhat.com> Date: Mon, 20 Jul 2015 07:25:55 +0200 MIME-Version: 1.0 In-Reply-To: <20150720022708.GA17582@ad.nay.redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH 2/2] AioContext: optimize clearing the EventNotifier List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: kwolf@redhat.com, lersek@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com, rjones@redhat.com On 20/07/2015 04:27, Fam Zheng wrote: > For aio-posix, how about keeping the optimization local which doesn't need > atomic operation? (no idea for win32 :) > > diff --git a/aio-posix.c b/aio-posix.c > index 5c8b266..7e98123 100644 > --- a/aio-posix.c > +++ b/aio-posix.c > @@ -236,6 +236,7 @@ bool aio_poll(AioContext *ctx, bool blocking) > int i, ret; > bool progress; > int64_t timeout; > + int aio_notifier_idx = -1; > > aio_context_acquire(ctx); > progress = false; > @@ -256,11 +257,18 @@ bool aio_poll(AioContext *ctx, bool blocking) > assert(npfd == 0); > > /* fill pollfds */ > + i = 0; > QLIST_FOREACH(node, &ctx->aio_handlers, node) { > if (!node->deleted && node->pfd.events) { > add_pollfd(node); > + if (node->pfd.fd == event_notifier_get_fd(&ctx->notifier)) { > + assert(aio_notifier_idx == -1); > + aio_notifier_idx = i; > + } > + i++; > } > } That's a good idea. Since aio_set_fd_handler uses QLIST_INSERT_HEAD, perhaps we can be sure that aio_notifier_idx is always the last one (i.e. i-1)? And the same can be done on Windows, I think. > + if (pollfds[aio_notifier_idx].revents & (G_IO_IN | G_IO_HUP | G_IO_ERR)) { > + event_notifier_test_and_clear(&ctx->notifier); > + } Might as well zero pollfds[aio_notifier_idx].revents after clearing it. The atomic operation is not too expensive, so it would really be more about simplicity than about speed. Not that simplicity is a bad thing! I'll send v2 of the first patch, you can look at doing the optimization. Thanks! Paolo