qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: armbru@redhat.com
Subject: [PATCH] monitor: remove more unnecessary atomics
Date: Fri, 26 May 2023 10:18:08 +0200	[thread overview]
Message-ID: <20230526081808.423277-1-pbonzini@redhat.com> (raw)

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



                 reply	other threads:[~2023-05-26  8:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20230526081808.423277-1-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=armbru@redhat.com \
    --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).