[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 18/20] monitor: introduce qmp_dispatcher_co_wake
|
From: |
Paolo Bonzini |
|
Subject: |
[PULL 18/20] monitor: introduce qmp_dispatcher_co_wake |
|
Date: |
Thu, 25 May 2023 16:15:30 +0200 |
This makes it possible to turn qmp_dispatcher_co_busy into a static
variable.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
monitor/monitor-internal.h | 2 +-
monitor/monitor.c | 26 +-------------------------
monitor/qmp.c | 32 +++++++++++++++++++++++++++++---
3 files changed, 31 insertions(+), 29 deletions(-)
diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h
index 61c9b6916db3..252de856812f 100644
--- a/monitor/monitor-internal.h
+++ b/monitor/monitor-internal.h
@@ -165,7 +165,6 @@ typedef QTAILQ_HEAD(MonitorList, Monitor) MonitorList;
extern IOThread *mon_iothread;
extern Coroutine *qmp_dispatcher_co;
extern bool qmp_dispatcher_co_shutdown;
-extern bool qmp_dispatcher_co_busy;
extern QmpCommandList qmp_commands, qmp_cap_negotiation_commands;
extern QemuMutex monitor_lock;
extern MonitorList mon_list;
@@ -183,6 +182,7 @@ void monitor_fdsets_cleanup(void);
void qmp_send_response(MonitorQMP *mon, const QDict *rsp);
void monitor_data_destroy_qmp(MonitorQMP *mon);
void coroutine_fn monitor_qmp_dispatcher_co(void *data);
+void qmp_dispatcher_co_wake(void);
int get_monitor_def(Monitor *mon, int64_t *pval, const char *name);
void handle_hmp_command(MonitorHMP *mon, const char *cmdline);
diff --git a/monitor/monitor.c b/monitor/monitor.c
index 042a1ab918f9..dc352f9e9d95 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -62,27 +62,6 @@ Coroutine *qmp_dispatcher_co;
*/
bool qmp_dispatcher_co_shutdown;
-/*
- * qmp_dispatcher_co_busy is used for synchronisation between the
- * monitor thread and the main thread to ensure that the dispatcher
- * coroutine never gets scheduled a second time when it's already
- * scheduled (scheduling the same coroutine twice is forbidden).
- *
- * It is true if the coroutine is active and processing requests.
- * Additional requests may then be pushed onto mon->qmp_requests,
- * and @qmp_dispatcher_co_shutdown may be set without further ado.
- * @qmp_dispatcher_co_busy must not be woken up in this case.
- *
- * If false, you also have to set @qmp_dispatcher_co_busy to true and
- * wake up @qmp_dispatcher_co after pushing the new requests.
- *
- * The coroutine will automatically change this variable back to false
- * before it yields. Nobody else may set the variable to false.
- *
- * Access must be atomic for thread safety.
- */
-bool qmp_dispatcher_co_busy;
-
/*
* Protects mon_list, monitor_qapi_event_state, coroutine_mon,
* monitor_destroyed.
@@ -685,9 +664,7 @@ void monitor_cleanup(void)
WITH_QEMU_LOCK_GUARD(&monitor_lock) {
qmp_dispatcher_co_shutdown = true;
}
- if (!qatomic_xchg(&qmp_dispatcher_co_busy, true)) {
- aio_co_wake(qmp_dispatcher_co);
- }
+ qmp_dispatcher_co_wake();
AIO_WAIT_WHILE_UNLOCKED(NULL,
(aio_poll(iohandler_get_aio_context(), false),
@@ -742,7 +719,6 @@ void monitor_init_globals(void)
* rid of those assumptions.
*/
qmp_dispatcher_co = qemu_coroutine_create(monitor_qmp_dispatcher_co, NULL);
- qatomic_mb_set(&qmp_dispatcher_co_busy, true);
aio_co_schedule(iohandler_get_aio_context(), qmp_dispatcher_co);
}
diff --git a/monitor/qmp.c b/monitor/qmp.c
index dfc215632865..613b74ec74a7 100644
--- a/monitor/qmp.c
+++ b/monitor/qmp.c
@@ -33,6 +33,27 @@
#include "qapi/qmp/qlist.h"
#include "trace.h"
+/*
+ * qmp_dispatcher_co_busy is used for synchronisation between the
+ * monitor thread and the main thread to ensure that the dispatcher
+ * coroutine never gets scheduled a second time when it's already
+ * scheduled (scheduling the same coroutine twice is forbidden).
+ *
+ * It is true if the coroutine is active and processing requests.
+ * Additional requests may then be pushed onto mon->qmp_requests,
+ * and @qmp_dispatcher_co_shutdown may be set without further ado.
+ * @qmp_dispatcher_co_busy must not be woken up in this case.
+ *
+ * If false, you also have to set @qmp_dispatcher_co_busy to true and
+ * wake up @qmp_dispatcher_co after pushing the new requests.
+ *
+ * The coroutine will automatically change this variable back to false
+ * before it yields. Nobody else may set the variable to false.
+ *
+ * Access must be atomic for thread safety.
+ */
+static bool qmp_dispatcher_co_busy = true;
+
struct QMPRequest {
/* Owner of the request */
MonitorQMP *mon;
@@ -334,6 +355,13 @@ void coroutine_fn monitor_qmp_dispatcher_co(void *data)
qatomic_set(&qmp_dispatcher_co, NULL);
}
+void qmp_dispatcher_co_wake(void)
+{
+ if (!qatomic_xchg(&qmp_dispatcher_co_busy, true)) {
+ aio_co_wake(qmp_dispatcher_co);
+ }
+}
+
static void handle_qmp_command(void *opaque, QObject *req, Error *err)
{
MonitorQMP *mon = opaque;
@@ -395,9 +423,7 @@ static void handle_qmp_command(void *opaque, QObject *req,
Error *err)
}
/* Kick the dispatcher routine */
- if (!qatomic_xchg(&qmp_dispatcher_co_busy, true)) {
- aio_co_wake(qmp_dispatcher_co);
- }
+ qmp_dispatcher_co_wake();
}
static void monitor_qmp_read(void *opaque, const uint8_t *buf, int size)
--
2.40.1
- [PULL 02/20] meson.build: Fix glib -Wno-unused-function workaround, (continued)
- [PULL 02/20] meson.build: Fix glib -Wno-unused-function workaround, Paolo Bonzini, 2023/05/25
- [PULL 01/20] target/i386: EPYC-Rome model without XSAVES, Paolo Bonzini, 2023/05/25
- [PULL 05/20] tests/docker: simplify HOST_ARCH definition, Paolo Bonzini, 2023/05/25
- [PULL 08/20] usb/ohci: Set pad to 0 after frame update, Paolo Bonzini, 2023/05/25
- [PULL 04/20] meson: move -no-pie from linker to compiler, Paolo Bonzini, 2023/05/25
- [PULL 07/20] Makefile: remove $(TESTS_PYTHON), Paolo Bonzini, 2023/05/25
- [PULL 03/20] meson: fix rule for qemu-ga installer, Paolo Bonzini, 2023/05/25
- [PULL 13/20] monitor: allow calling monitor_resume under mon_lock, Paolo Bonzini, 2023/05/25
- [PULL 17/20] monitor: cleanup fetching of QMP requests, Paolo Bonzini, 2023/05/25
- [PULL 20/20] monitor: do not use mb_read/mb_set, Paolo Bonzini, 2023/05/25
- [PULL 18/20] monitor: introduce qmp_dispatcher_co_wake,
Paolo Bonzini <=
- [PULL 06/20] tests/vm: fix and simplify HOST_ARCH definition, Paolo Bonzini, 2023/05/25
- [PULL 10/20] softmmu/ioport.c: QOMify MemoryRegionPortioList, Paolo Bonzini, 2023/05/25
- [PULL 09/20] softmmu/ioport.c: allocate MemoryRegionPortioList ports on the heap, Paolo Bonzini, 2023/05/25
- [PULL 14/20] monitor: add more *_locked() functions, Paolo Bonzini, 2023/05/25
- [PULL 11/20] softmmu/ioport.c: make MemoryRegionPortioList owner of portio_list MemoryRegions, Paolo Bonzini, 2023/05/25
- [PULL 12/20] monitor: use QEMU_LOCK_GUARD a bit more, Paolo Bonzini, 2023/05/25
- [PULL 16/20] monitor: cleanup detection of qmp_dispatcher_co shutting down, Paolo Bonzini, 2023/05/25
- [PULL 15/20] monitor: do not use mb_read/mb_set for suspend_cnt, Paolo Bonzini, 2023/05/25
- [PULL 19/20] monitor: extract request dequeuing to a new function, Paolo Bonzini, 2023/05/25
- Re: [PULL 00/20] Misc patches for 2023-05-25, Richard Henderson, 2023/05/25