From: Paolo Bonzini <pbonzini@redhat.com>
To: Fam Zheng <famz@redhat.com>
Cc: kwolf@redhat.com, lersek@redhat.com, qemu-devel@nongnu.org,
stefanha@redhat.com, rjones@redhat.com
Subject: Re: [Qemu-devel] [PATCH 2/2] AioContext: optimize clearing the EventNotifier
Date: Mon, 20 Jul 2015 07:25:55 +0200 [thread overview]
Message-ID: <55AC8663.7020405@redhat.com> (raw)
In-Reply-To: <20150720022708.GA17582@ad.nay.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
next prev parent reply other threads:[~2015-07-20 5:26 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-18 20:21 [Qemu-devel] [PATCH 0/2] AioContext: fix missing wakeups due to event_notifier_test_and_clear Paolo Bonzini
2015-07-18 20:21 ` [Qemu-devel] [PATCH 1/2] AioContext: fix broken placement of event_notifier_test_and_clear Paolo Bonzini
2015-07-20 3:55 ` Fam Zheng
2015-07-20 5:32 ` Paolo Bonzini
2015-07-18 20:21 ` [Qemu-devel] [PATCH 2/2] AioContext: optimize clearing the EventNotifier Paolo Bonzini
2015-07-20 2:27 ` Fam Zheng
2015-07-20 5:25 ` Paolo Bonzini [this message]
2015-07-20 5:34 ` Paolo Bonzini
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=55AC8663.7020405@redhat.com \
--to=pbonzini@redhat.com \
--cc=famz@redhat.com \
--cc=kwolf@redhat.com \
--cc=lersek@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rjones@redhat.com \
--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).