[PATCH] monitor: remove more unnecessary atomics

Paolo Bonzini posted 1 patch 1 year, 6 months ago
Failed in applying to current master (apply log)
monitor/monitor.c | 7 ++++---
monitor/qmp.c     | 7 ++++++-
2 files changed, 10 insertions(+), 4 deletions(-)
[PATCH] monitor: remove more unnecessary atomics
Posted by Paolo Bonzini 1 year, 6 months ago
Simplify monitor_cleanup by:

- using main_loop_wait() to poll both the block layer AioContext
  and the I/O handlers

- using a bottom half to clear qmp_dispatcher_co; this removes the
  atomics but also forces an exit out of main_loop_wait.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 monitor/monitor.c | 7 ++++---
 monitor/qmp.c     | 7 ++++++-
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/monitor/monitor.c b/monitor/monitor.c
index dc352f9e9d95..01d6aabf41db 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -666,9 +666,10 @@ void monitor_cleanup(void)
     }
     qmp_dispatcher_co_wake();
 
-    AIO_WAIT_WHILE_UNLOCKED(NULL,
-                   (aio_poll(iohandler_get_aio_context(), false),
-                    qatomic_read(&qmp_dispatcher_co)));
+    /* Loop until sync_with_main_loop_bh runs.  */
+    while (qmp_dispatcher_co) {
+        main_loop_wait(false);
+    }
 
     /*
      * We need to explicitly stop the I/O thread (but not destroy it),
diff --git a/monitor/qmp.c b/monitor/qmp.c
index c8e0156974d9..8b465d80fb1a 100644
--- a/monitor/qmp.c
+++ b/monitor/qmp.c
@@ -271,6 +271,11 @@ static QMPRequest *monitor_qmp_dispatcher_pop_any(void)
     }
 }
 
+static void sync_with_main_loop_bh(void *opaque)
+{
+    qmp_dispatcher_co = NULL;
+}
+
 void coroutine_fn monitor_qmp_dispatcher_co(void *data)
 {
     QMPRequest *req_obj;
@@ -365,7 +370,7 @@ void coroutine_fn monitor_qmp_dispatcher_co(void *data)
         aio_co_schedule(iohandler_get_aio_context(), qmp_dispatcher_co);
         qemu_coroutine_yield();
     }
-    qatomic_set(&qmp_dispatcher_co, NULL);
+    aio_bh_schedule_oneshot(qemu_get_aio_context(), sync_with_main_loop_bh, NULL);
 }
 
 void qmp_dispatcher_co_wake(void)
-- 
2.40.1