All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Fam Zheng <famz@redhat.com>
Cc: qemu-devel@nongnu.org, stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCH 2/3] AioContext: acquire/release AioContext during aio_poll
Date: Thu, 26 Feb 2015 14:21:14 +0100	[thread overview]
Message-ID: <54EF1DCA.4020202@redhat.com> (raw)
In-Reply-To: <20150225054541.GA5293@ad.nay.redhat.com>



On 25/02/2015 06:45, Fam Zheng wrote:
> On Fri, 02/20 17:26, Paolo Bonzini wrote:
>> This is the first step in pushing down acquire/release, and will let
>> rfifolock drop the contention callback feature.
>>
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> ---
>>  aio-posix.c         |  9 +++++++++
>>  aio-win32.c         |  8 ++++++++
>>  include/block/aio.h | 15 ++++++++-------
>>  3 files changed, 25 insertions(+), 7 deletions(-)
>>
>> diff --git a/aio-posix.c b/aio-posix.c
>> index 4a30b77..292ae84 100644
>> --- a/aio-posix.c
>> +++ b/aio-posix.c
>> @@ -238,6 +238,7 @@ bool aio_poll(AioContext *ctx, bool blocking)
>>      bool progress;
>>      int64_t timeout;
>>  
>> +    aio_context_acquire(ctx);
>>      was_dispatching = ctx->dispatching;
>>      progress = false;
>>  
>> @@ -267,7 +268,13 @@ bool aio_poll(AioContext *ctx, bool blocking)
>>      timeout = blocking ? aio_compute_timeout(ctx) : 0;
>>  
>>      /* wait until next event */
>> +    if (timeout) {
>> +        aio_context_release(ctx);
>> +    }
>>      ret = qemu_poll_ns((GPollFD *)pollfds, npfd, timeout);
>> +    if (timeout) {
>> +        aio_context_acquire(ctx);
>> +    }
>>  
>>      /* if we have any readable fds, dispatch event */
>>      if (ret > 0) {
>> @@ -285,5 +292,7 @@ bool aio_poll(AioContext *ctx, bool blocking)
>>      }
>>  
>>      aio_set_dispatching(ctx, was_dispatching);
>> +    aio_context_release(ctx);
>> +
>>      return progress;
>>  }
>> diff --git a/aio-win32.c b/aio-win32.c
>> index e6f4ced..233d8f5 100644
>> --- a/aio-win32.c
>> +++ b/aio-win32.c
>> @@ -283,6 +283,7 @@ bool aio_poll(AioContext *ctx, bool blocking)
>>      int count;
>>      int timeout;
>>  
>> +    aio_context_acquire(ctx);
>>      have_select_revents = aio_prepare(ctx);
>>      if (have_select_revents) {
>>          blocking = false;
>> @@ -323,7 +324,13 @@ bool aio_poll(AioContext *ctx, bool blocking)
>>  
>>          timeout = blocking
>>              ? qemu_timeout_ns_to_ms(aio_compute_timeout(ctx)) : 0;
>> +        if (timeout) {
>> +            aio_context_release(ctx);
> 
> Why are the unlock/lock pairs around poll conditional?

Both iothread.c and os_host_main_loop_wait are doing it, IIRC it was
measurably faster.

In particular, iothread.c was completely avoiding acquire/release around
non-blocking aio_poll and this patch does not have exactly the same behavior,
but it is trying to be close:

-        aio_context_acquire(iothread->ctx);
-        blocking = true;
-        while (!iothread->stopping && aio_poll(iothread->ctx, blocking)) {
-            /* Progress was made, keep going */
-            blocking = false;
-        }
-        aio_context_release(iothread->ctx);

The exact same behavior can be done easily directly in aio_poll, for this
RFC I'm keeping the code a little simpler.

Paolo

> 
> Fam
> 
>> +        }
>>          ret = WaitForMultipleObjects(count, events, FALSE, timeout);
>> +        if (timeout) {
>> +            aio_context_acquire(ctx);
>> +        }
>>          aio_set_dispatching(ctx, true);
>>  
>>          if (first && aio_bh_poll(ctx)) {

  reply	other threads:[~2015-02-26 13:21 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-20 16:26 [Qemu-devel] [PATCH RFC 0/3] iothread: release iothread around aio_poll Paolo Bonzini
2015-02-20 16:26 ` [Qemu-devel] [PATCH 1/3] aio-posix: move pollfds to thread-local storage Paolo Bonzini
2015-03-06 16:50   ` Stefan Hajnoczi
2015-02-20 16:26 ` [Qemu-devel] [PATCH 2/3] AioContext: acquire/release AioContext during aio_poll Paolo Bonzini
2015-02-25  5:45   ` Fam Zheng
2015-02-26 13:21     ` Paolo Bonzini [this message]
2015-03-06 17:15   ` Stefan Hajnoczi
2015-07-08  2:18   ` Fam Zheng
2015-07-08  7:52     ` Paolo Bonzini
2015-02-20 16:26 ` [Qemu-devel] [PATCH 3/3] iothread: release iothread around aio_poll Paolo Bonzini
2015-03-06 17:16   ` Stefan Hajnoczi
2015-03-31 10:35 ` [Qemu-devel] [PATCH RFC 0/3] " Paolo Bonzini
2015-03-31 14:33   ` Stefan Hajnoczi
2015-04-21 15:40   ` Stefan Hajnoczi
2015-04-21 15:54     ` Paolo Bonzini
2015-04-22 10:26       ` Stefan Hajnoczi
2015-03-31 14:03 ` Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54EF1DCA.4020202@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=famz@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.