qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>, qemu-devel@nongnu.org
Cc: Fam Zheng <fam@euphon.net>, qemu-block@nongnu.org
Subject: Re: [PATCH v2 3/3] aio-posix: keep aio_notify_me disabled during polling
Date: Wed, 5 Aug 2020 18:37:45 +0200	[thread overview]
Message-ID: <8e066cf0-e5f9-283c-eedd-47974bf4bbac@redhat.com> (raw)
In-Reply-To: <20200805100051.361547-4-stefanha@redhat.com>

On 05/08/20 12:00, Stefan Hajnoczi wrote:
> +
> +        /*
> +         * aio_notify can avoid the expensive event_notifier_set if
> +         * everything (file descriptors, bottom halves, timers) will
> +         * be re-evaluated before the next blocking poll().  This is
> +         * already true when aio_poll is called with blocking == false;
> +         * if blocking == true, it is only true after poll() returns,
> +         * so disable the optimization now.
> +         */
> +        if (use_notify_me) {
> +            atomic_set(&ctx->notify_me, atomic_read(&ctx->notify_me) + 2);
> +            /*
> +             * Write ctx->notify_me before reading ctx->notified.  Pairs with
> +             * smp_mb in aio_notify().
> +             */
> +            smp_mb();
> +
> +            /* Don't block if aio_notify() was called */
> +            if (atomic_read(&ctx->notified)) {
> +                timeout = 0;
> +            }

Aha, this is the trick: "timeout = 0" also applies if a timer was moved 
early.  In this case you uselessly keep notify_me set for a bit, but 
it's okay. Nice!

The code can be simplified a bit more, since the use_notify_me variable 
is just "timeout":

    use_notify_me = (timeout != 0);
    if (use_notify_me) {
         /*
          * aio_notify can avoid the expensive event_notifier_set if
          * everything (file descriptors, bottom halves, timers) will
          * be re-evaluated before the next blocking poll().  This is
          * already true when aio_poll is called with blocking == false;
          * if blocking == true, it is only true after poll() returns,
          * so disable the optimization now.
          */
         atomic_set(&ctx->notify_me, atomic_read(&ctx->notify_me) + 2);
         /*
          * Write ctx->notify_me before reading ctx->notified.  Pairs with
          * smp_mb in aio_notify().
          */
         smp_mb();
 
         /* Don't block if aio_notify() was called */
         if (atomic_read(&ctx->notified)) {
             timeout = 0;
         }
     }
     if (timeout || ctx->fdmon_ops->need_wait(ctx)) {
         ret = ctx->fdmon_ops->wait(ctx, &ready_list, timeout);
     }
     if (use_notify_me) {
         /* Finish the poll before clearing the flag.  */
         atomic_store_release(&ctx->notify_me,
                              atomic_read(&ctx->notify_me) - 2);
     }

Paolo



  reply	other threads:[~2020-08-05 16:38 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-05 10:00 [PATCH v2 0/3] aio-posix: keep aio_notify_me disabled during polling Stefan Hajnoczi
2020-08-05 10:00 ` [PATCH v2 1/3] async: rename event_notifier_dummy_cb/poll() Stefan Hajnoczi
2020-08-06  7:10   ` Philippe Mathieu-Daudé
2020-08-05 10:00 ` [PATCH v2 2/3] async: always set ctx->notified in aio_notify() Stefan Hajnoczi
2020-08-05 16:26   ` Paolo Bonzini
2020-08-05 10:00 ` [PATCH v2 3/3] aio-posix: keep aio_notify_me disabled during polling Stefan Hajnoczi
2020-08-05 16:37   ` Paolo Bonzini [this message]
2020-08-06 10:52     ` 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=8e066cf0-e5f9-283c-eedd-47974bf4bbac@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=fam@euphon.net \
    --cc=qemu-block@nongnu.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).