From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35289) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZH7yJ-0004ur-2z for qemu-devel@nongnu.org; Mon, 20 Jul 2015 06:06:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZH7yF-0000g7-62 for qemu-devel@nongnu.org; Mon, 20 Jul 2015 06:06:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41420) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZH7yE-0000g1-RR for qemu-devel@nongnu.org; Mon, 20 Jul 2015 06:06:51 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 6C573ADAE6 for ; Mon, 20 Jul 2015 10:06:50 +0000 (UTC) Date: Mon, 20 Jul 2015 18:06:48 +0800 From: Fam Zheng Message-ID: <20150720100648.GA22650@ad.nay.redhat.com> References: <1437370031-9070-1-git-send-email-pbonzini@redhat.com> <20150720074625.GA20738@ad.nay.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150720074625.GA20738@ad.nay.redhat.com> Subject: Re: [Qemu-devel] [PATCH v2] AioContext: fix broken placement of event_notifier_test_and_clear List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: kwolf@redhat.com, lersek@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com, rjones@redhat.com On Mon, 07/20 15:46, Fam Zheng wrote: > On Mon, 07/20 07:27, Paolo Bonzini wrote: > > diff --git a/aio-win32.c b/aio-win32.c > > index ea655b0..7afc999 100644 > > --- a/aio-win32.c > > +++ b/aio-win32.c > > @@ -337,10 +337,11 @@ bool aio_poll(AioContext *ctx, bool blocking) > > aio_context_acquire(ctx); > > } > > > > - if (first && aio_bh_poll(ctx)) { > > - progress = true; > > + if (first) { > > + event_notifier_test_and_clear(&ctx->notifier); > > I'm looking at optimizing it but I don't fully understand the relationship > between aio_prepare and WaitForMultipleObjects. Do they get the same set of > events? What if a new event comes in between, for example, thread worker calls > aio_notify()? > After some reading I think WaitForMultipleObjects is for event notifiers and aio_prepare is for select() on fd events. It's a bit trickier than aio-posix, in the first iteration there could be another event masking ctx->notifier so we don't know if we need to clear it. But since MSDN says: """ ... the return value minus WAIT_OBJECT_0 indicates the lpHandles array index of the object that satisfied the wait. If more than one object became signaled during the call, this is the array index of the signaled object with the smallest index value of all the signaled objects. """ Maybe we can reverse events[] so that ctx->notifier will be the 0th one. And I think we can always remove it after first iteration, am I right? Fam