* [PATCH] monitor: remove more unnecessary atomics
@ 2023-05-26 8:18 Paolo Bonzini
0 siblings, 0 replies; only message in thread
From: Paolo Bonzini @ 2023-05-26 8:18 UTC (permalink / raw)
To: qemu-devel; +Cc: armbru
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2023-05-26 8:18 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-26 8:18 [PATCH] monitor: remove more unnecessary atomics Paolo Bonzini
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).