From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org, Peter Maydell <peter.maydell@linaro.org>
Cc: "Fam Zheng" <fam@euphon.net>, "Kevin Wolf" <kwolf@redhat.com>,
"Eduardo Habkost" <ehabkost@redhat.com>,
qemu-block@nongnu.org, "Max Reitz" <mreitz@redhat.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Cleber Rosa" <crosa@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>
Subject: [PULL 2/3] async: always set ctx->notified in aio_notify()
Date: Mon, 17 Aug 2020 16:16:33 +0100 [thread overview]
Message-ID: <20200817151634.35563-3-stefanha@redhat.com> (raw)
In-Reply-To: <20200817151634.35563-1-stefanha@redhat.com>
aio_notify() does not set ctx->notified when called with
ctx->aio_notify_me disabled. Therefore aio_notify_me needs to be enabled
during polling.
This is suboptimal since expensive event_notifier_set(&ctx->notifier)
and event_notifier_test_and_clear(&ctx->notifier) calls are required
when ctx->aio_notify_me is enabled.
Change aio_notify() so that aio->notified is always set, regardless of
ctx->aio_notify_me. This will make polling cheaper since
ctx->aio_notify_me can remain disabled. Move the
event_notifier_test_and_clear() to the fd handler function (which is now
no longer an empty function so "dummy" has been dropped from its name).
The next patch takes advantage of this by optimizing polling in
util/aio-posix.c.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-id: 20200806131802.569478-3-stefanha@redhat.com
[Paolo Bonzini pointed out that the smp_wmb() in aio_notify_accept()
should be smp_wb() but the comment should be smp_wmb() instead of
smp_wb(). Fixed.
--Stefan]
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
util/async.c | 32 +++++++++++++++++++++-----------
1 file changed, 21 insertions(+), 11 deletions(-)
diff --git a/util/async.c b/util/async.c
index d9f987e133..4266745dee 100644
--- a/util/async.c
+++ b/util/async.c
@@ -419,25 +419,32 @@ LuringState *aio_get_linux_io_uring(AioContext *ctx)
void aio_notify(AioContext *ctx)
{
- /* Write e.g. bh->scheduled before reading ctx->notify_me. Pairs
+ /*
+ * Write e.g. bh->flags before writing ctx->notified. Pairs with smp_mb in
+ * aio_notify_accept.
+ */
+ smp_wmb();
+ atomic_set(&ctx->notified, true);
+
+ /*
+ * Write ctx->notified before reading ctx->notify_me. Pairs
* with smp_mb in aio_ctx_prepare or aio_poll.
*/
smp_mb();
if (atomic_read(&ctx->notify_me)) {
event_notifier_set(&ctx->notifier);
- atomic_mb_set(&ctx->notified, true);
}
}
void aio_notify_accept(AioContext *ctx)
{
- if (atomic_xchg(&ctx->notified, false)
-#ifdef WIN32
- || true
-#endif
- ) {
- event_notifier_test_and_clear(&ctx->notifier);
- }
+ atomic_set(&ctx->notified, false);
+
+ /*
+ * Write ctx->notified before reading e.g. bh->flags. Pairs with smp_wmb
+ * in aio_notify.
+ */
+ smp_mb();
}
static void aio_timerlist_notify(void *opaque, QEMUClockType type)
@@ -445,8 +452,11 @@ static void aio_timerlist_notify(void *opaque, QEMUClockType type)
aio_notify(opaque);
}
-static void aio_context_notifier_dummy_cb(EventNotifier *e)
+static void aio_context_notifier_cb(EventNotifier *e)
{
+ AioContext *ctx = container_of(e, AioContext, notifier);
+
+ event_notifier_test_and_clear(&ctx->notifier);
}
/* Returns true if aio_notify() was called (e.g. a BH was scheduled) */
@@ -508,7 +518,7 @@ AioContext *aio_context_new(Error **errp)
aio_set_event_notifier(ctx, &ctx->notifier,
false,
- aio_context_notifier_dummy_cb,
+ aio_context_notifier_cb,
aio_context_notifier_poll);
#ifdef CONFIG_LINUX_AIO
ctx->linux_aio = NULL;
--
2.26.2
next prev parent reply other threads:[~2020-08-17 15:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-17 15:16 [PULL 0/3] Block patches Stefan Hajnoczi
2020-08-17 15:16 ` [PULL 1/3] async: rename event_notifier_dummy_cb/poll() Stefan Hajnoczi
2020-08-17 15:16 ` Stefan Hajnoczi [this message]
2020-08-17 15:16 ` [PULL 3/3] aio-posix: keep aio_notify_me disabled during polling Stefan Hajnoczi
2020-08-21 19:08 ` [PULL 0/3] Block patches Peter Maydell
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=20200817151634.35563-3-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=crosa@redhat.com \
--cc=ehabkost@redhat.com \
--cc=fam@euphon.net \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@redhat.com \
--cc=qemu-block@nongnu.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 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).