qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/3] async: always set ctx->notified in aio_notify()


From: Stefan Hajnoczi
Subject: [PATCH 2/3] async: always set ctx->notified in aio_notify()
Date: Tue, 4 Aug 2020 06:28:03 +0100

aio_notify() does not set ctx->notified when called with
ctx->aio_notify_me disabled. In order to poll ctx->notified it is
therefore necessary to enable ctx->aio_notify_me.

This is suboptimal since expensive event_notifier_set(&ctx->notifier)
and event_notifier_test_and_clear(&ctx->notifier) calls required when
ctx->aio_notify_me is enabled.

Change aio_notify() me so that aio->notified is always set, regardless
of ctx->aio_notify_me. This will allow polling to work cheaply with
ctx->aio_notify_me 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>
---
 util/async.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/util/async.c b/util/async.c
index d9f987e133..3e68b5b757 100644
--- a/util/async.c
+++ b/util/async.c
@@ -425,19 +425,14 @@ void aio_notify(AioContext *ctx)
     smp_mb();
     if (atomic_read(&ctx->notify_me)) {
         event_notifier_set(&ctx->notifier);
-        atomic_mb_set(&ctx->notified, true);
     }
+
+    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_mb_set(&ctx->notified, false);
 }
 
 static void aio_timerlist_notify(void *opaque, QEMUClockType type)
@@ -445,8 +440,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 +506,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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]