All of lore.kernel.org
 help / color / mirror / Atom feed
From: James Le Cuirot <chewi@gentoo.org>
To: qemu-devel@nongnu.org
Subject: Re: [PATCH 3/3] win32: fix main-loop busy loop on socket/fd event
Date: Tue, 1 Oct 2019 22:20:26 +0100	[thread overview]
Message-ID: <20191001222026.30a69801@symphony.aura-online.co.uk> (raw)
In-Reply-To: <20191001132609.23184-4-marcandre.lureau@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 2588 bytes --]

On Tue,  1 Oct 2019 17:26:09 +0400
Marc-André Lureau <marcandre.lureau@redhat.com> wrote:

> Commit 05e514b1d4d5bd4209e2c8bbc76ff05c85a235f3 introduced an AIO
> context optimization to avoid calling event_notifier_test_and_clear() on
> ctx->notifier. On Windows, the same notifier is being used to wakeup the
> wait on socket events (see commit
> d3385eb448e38f828c78f8f68ec5d79c66a58b5d).
> 
> The ctx->notifier event is added to the gpoll sources in
> aio_set_event_notifier(), aio_ctx_check() should clear the event
> regardless of ctx->notified, since Windows sets the event by itself,
> bypassing the aio->notified. This fixes qemu not clearing the event
> resulting in a busy loop.
> 
> Paolo suggested to me on irc to call event_notifier_test_and_clear()
> after select() >0 from aio-win32.c's aio_prepare. Unfortunately, not all
> fds associated with ctx->notifiers are in AIO fd handlers set.
> (qemu_set_nonblock() in util/oslib-win32.c calls qemu_fd_register()).
> 
> This is essentially a v2 of a patch that was sent earlier:
> https://lists.gnu.org/archive/html/qemu-devel/2017-01/msg00420.html
> 
> that resurfaced when James investigated Spice performance issues on Windows:
> https://gitlab.freedesktop.org/spice/spice/issues/36
> 
> In order to test that patch, I simply tried running test-char on
> win32, and it hangs. Applying that patch solves it. QIO idle sources
> are not dispatched. I haven't investigated much further, I suspect
> source priorities and busy looping still come into play.
> 
> This version keeps the "notified" field, so event_notifier_poll()
> should still work as expected.
> 
> Cc: James Le Cuirot <chewi@gentoo.org>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  util/async.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/util/async.c b/util/async.c
> index 4e4c7af51e..ca83e32c7f 100644
> --- a/util/async.c
> +++ b/util/async.c
> @@ -354,7 +354,11 @@ void aio_notify(AioContext *ctx)
>  
>  void aio_notify_accept(AioContext *ctx)
>  {
> -    if (atomic_xchg(&ctx->notified, false)) {
> +    if (atomic_xchg(&ctx->notified, false)
> +#ifdef WIN32
> +        || true
> +#endif
> +    ) {
>          event_notifier_test_and_clear(&ctx->notifier);
>      }
>  }

I can confirm that this updated patch fixes my performance issue. The
idle CPU usage drops from around 35% to around 2%. Moving the mouse now
makes the usage go up, not down. :) Many thanks!

Regards,
-- 
James Le Cuirot (chewi)
Gentoo Linux Developer

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2019-10-01 22:32 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-01 13:26 [PATCH 0/3] Some win32 fixes Marc-André Lureau
2019-10-01 13:26 ` [PATCH 1/3] util: WSAEWOULDBLOCK on connect should map to EINPROGRESS Marc-André Lureau
2019-10-01 13:56   ` Philippe Mathieu-Daudé
2019-10-01 13:26 ` [PATCH 2/3] tests: skip serial test on windows Marc-André Lureau
2019-10-01 13:48   ` Philippe Mathieu-Daudé
2019-10-01 13:26 ` [PATCH 3/3] win32: fix main-loop busy loop on socket/fd event Marc-André Lureau
2019-10-01 21:20   ` James Le Cuirot [this message]
2019-10-01 13:39 ` [PATCH 0/3] Some win32 fixes Paolo Bonzini
2019-10-01 13:44   ` Peter Maydell
2019-10-01 13:54     ` Philippe Mathieu-Daudé
2019-10-01 14:43     ` Stefan Weil
2019-10-01 14:03 ` Alex Bennée
2019-10-01 14:11 ` Thomas Huth

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=20191001222026.30a69801@symphony.aura-online.co.uk \
    --to=chewi@gentoo.org \
    --cc=qemu-devel@nongnu.org \
    /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.