[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 23/27] coroutine-lock: qemu_co_queue_restart_all is a coroutine-on
From: |
Paolo Bonzini |
Subject: |
[PULL 23/27] coroutine-lock: qemu_co_queue_restart_all is a coroutine-only qemu_co_enter_all |
Date: |
Thu, 12 May 2022 19:25:01 +0200 |
qemu_co_queue_restart_all is basically the same as qemu_co_enter_all
but without a QemuLockable argument. That's perfectly fine, but only as
long as the function is marked coroutine_fn. If used outside coroutine
context, qemu_co_queue_wait will attempt to take the lock and that
is just broken: if you are calling qemu_co_queue_restart_all outside
coroutine context, the lock is going to be a QemuMutex which cannot be
taken twice by the same thread.
The patch adds the marker to qemu_co_queue_restart_all and to its sole
non-coroutine_fn caller; it then reimplements the function in terms of
qemu_co_enter_all_impl, to remove duplicated code and to clarify that the
latter also works in coroutine context.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20220427130830.150180-4-pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
block/io.c | 2 +-
include/qemu/coroutine.h | 7 ++++---
util/qemu-coroutine-lock.c | 21 ++++++---------------
3 files changed, 11 insertions(+), 19 deletions(-)
diff --git a/block/io.c b/block/io.c
index 9769ec53b0..789e6373d5 100644
--- a/block/io.c
+++ b/block/io.c
@@ -751,7 +751,7 @@ void bdrv_drain_all(void)
*
* This function should be called when a tracked request is completing.
*/
-static void tracked_request_end(BdrvTrackedRequest *req)
+static void coroutine_fn tracked_request_end(BdrvTrackedRequest *req)
{
if (req->serialising) {
qatomic_dec(&req->bs->serialising_in_flight);
diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h
index e5954635f6..43df7a7e66 100644
--- a/include/qemu/coroutine.h
+++ b/include/qemu/coroutine.h
@@ -216,10 +216,11 @@ void coroutine_fn qemu_co_queue_wait_impl(CoQueue *queue,
QemuLockable *lock);
bool coroutine_fn qemu_co_queue_next(CoQueue *queue);
/**
- * Empties the CoQueue; all coroutines are woken up.
- * OK to run from coroutine and non-coroutine context.
+ * Empties the CoQueue and queues the coroutine to run after
+ * the currently-running coroutine yields.
+ * Used from coroutine context, use qemu_co_enter_all outside.
*/
-void qemu_co_queue_restart_all(CoQueue *queue);
+void coroutine_fn qemu_co_queue_restart_all(CoQueue *queue);
/**
* Removes the next coroutine from the CoQueue, and wake it up. Unlike
diff --git a/util/qemu-coroutine-lock.c b/util/qemu-coroutine-lock.c
index 5b0342faed..9ad24ab1af 100644
--- a/util/qemu-coroutine-lock.c
+++ b/util/qemu-coroutine-lock.c
@@ -67,21 +67,6 @@ void coroutine_fn qemu_co_queue_wait_impl(CoQueue *queue,
QemuLockable *lock)
}
}
-void qemu_co_queue_restart_all(CoQueue *queue)
-{
- Coroutine *next;
-
- if (QSIMPLEQ_EMPTY(&queue->entries)) {
- return false;
- }
-
- while ((next = QSIMPLEQ_FIRST(&queue->entries)) != NULL) {
- QSIMPLEQ_REMOVE_HEAD(&queue->entries, co_queue_next);
- aio_co_wake(next);
- }
- return true;
-}
-
bool qemu_co_enter_next_impl(CoQueue *queue, QemuLockable *lock)
{
Coroutine *next;
@@ -115,6 +100,12 @@ void qemu_co_enter_all_impl(CoQueue *queue, QemuLockable
*lock)
}
}
+void coroutine_fn qemu_co_queue_restart_all(CoQueue *queue)
+{
+ /* No unlock/lock needed in coroutine context. */
+ qemu_co_enter_all_impl(queue, NULL);
+}
+
bool qemu_co_queue_empty(CoQueue *queue)
{
return QSIMPLEQ_FIRST(&queue->entries) == NULL;
--
2.36.0
- [PULL 21/27] coroutine-lock: qemu_co_queue_next is a coroutine-only qemu_co_enter_next, (continued)
- [PULL 21/27] coroutine-lock: qemu_co_queue_next is a coroutine-only qemu_co_enter_next, Paolo Bonzini, 2022/05/12
- [PULL 22/27] coroutine-lock: introduce qemu_co_queue_enter_all, Paolo Bonzini, 2022/05/12
- [PULL 08/27] tests/qtest/libqos/pci: Introduce pio_limit, Paolo Bonzini, 2022/05/12
- [PULL 04/27] checkpatch: fix g_malloc check, Paolo Bonzini, 2022/05/12
- [PULL 07/27] hw/xen/xen_pt: Resolve igd_passthrough_isa_bridge_create() indirection, Paolo Bonzini, 2022/05/12
- [PULL 09/27] tests/qtest/libqos: Skip hotplug tests if pci root bus is not hotpluggable, Paolo Bonzini, 2022/05/12
- [PULL 10/27] tests/qtest/libqos: Add generic pci host bridge in arm-virt machine, Paolo Bonzini, 2022/05/12
- [PULL 13/27] machine: add mem compound property, Paolo Bonzini, 2022/05/12
- [PULL 15/27] machine: move more memory validation to Machine object, Paolo Bonzini, 2022/05/12
- [PULL 19/27] net: slirp: add support for CFI-friendly timer API, Paolo Bonzini, 2022/05/12
- [PULL 23/27] coroutine-lock: qemu_co_queue_restart_all is a coroutine-only qemu_co_enter_all,
Paolo Bonzini <=
- [PULL 25/27] meson: link libpng independent of vnc, Paolo Bonzini, 2022/05/12
- [PULL 26/27] vl: make machine type deprecation a warning, Paolo Bonzini, 2022/05/12
- [PULL 24/27] vhost-backend: do not depend on CONFIG_VHOST_VSOCK, Paolo Bonzini, 2022/05/12
- [PULL 27/27] vmxcap: add tertiary execution controls, Paolo Bonzini, 2022/05/12
- Re: [PULL 00/27] Misc patches for 2022-05-12, Richard Henderson, 2022/05/12