[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5 01/12] coroutine: add flag to re-queue at front of CoQueue
From: |
Stefan Hajnoczi |
Subject: |
[PATCH v5 01/12] coroutine: add flag to re-queue at front of CoQueue |
Date: |
Tue, 27 Sep 2022 15:34:20 -0400 |
When a coroutine wakes up it may determine that it must re-queue.
Normally coroutines are pushed onto the back of the CoQueue, but for
fairness it may be necessary to push it onto the front of the CoQueue.
Add a flag to specify that the coroutine should be pushed onto the front
of the CoQueue. A later patch will use this to ensure fairness in the
bounce buffer CoQueue used by the blkio BlockDriver.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
include/qemu/coroutine.h | 15 +++++++++++++--
util/qemu-coroutine-lock.c | 9 +++++++--
2 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h
index 08c5bb3c76..3f418a67f6 100644
--- a/include/qemu/coroutine.h
+++ b/include/qemu/coroutine.h
@@ -198,14 +198,25 @@ typedef struct CoQueue {
*/
void qemu_co_queue_init(CoQueue *queue);
+typedef enum {
+ /*
+ * Enqueue at front instead of back. Use this to re-queue a request when
+ * its wait condition is not satisfied after being woken up.
+ */
+ CO_QUEUE_WAIT_FRONT = 0x1,
+} CoQueueWaitFlags;
+
/**
* Adds the current coroutine to the CoQueue and transfers control to the
* caller of the coroutine. The mutex is unlocked during the wait and
* locked again afterwards.
*/
#define qemu_co_queue_wait(queue, lock) \
- qemu_co_queue_wait_impl(queue, QEMU_MAKE_LOCKABLE(lock))
-void coroutine_fn qemu_co_queue_wait_impl(CoQueue *queue, QemuLockable *lock);
+ qemu_co_queue_wait_impl(queue, QEMU_MAKE_LOCKABLE(lock), 0)
+#define qemu_co_queue_wait_flags(queue, lock, flags) \
+ qemu_co_queue_wait_impl(queue, QEMU_MAKE_LOCKABLE(lock), (flags))
+void coroutine_fn qemu_co_queue_wait_impl(CoQueue *queue, QemuLockable *lock,
+ CoQueueWaitFlags flags);
/**
* Removes the next coroutine from the CoQueue, and queue it to run after
diff --git a/util/qemu-coroutine-lock.c b/util/qemu-coroutine-lock.c
index 9ad24ab1af..0516bd2ff3 100644
--- a/util/qemu-coroutine-lock.c
+++ b/util/qemu-coroutine-lock.c
@@ -39,10 +39,15 @@ void qemu_co_queue_init(CoQueue *queue)
QSIMPLEQ_INIT(&queue->entries);
}
-void coroutine_fn qemu_co_queue_wait_impl(CoQueue *queue, QemuLockable *lock)
+void coroutine_fn qemu_co_queue_wait_impl(CoQueue *queue, QemuLockable *lock,
+ CoQueueWaitFlags flags)
{
Coroutine *self = qemu_coroutine_self();
- QSIMPLEQ_INSERT_TAIL(&queue->entries, self, co_queue_next);
+ if (flags & CO_QUEUE_WAIT_FRONT) {
+ QSIMPLEQ_INSERT_HEAD(&queue->entries, self, co_queue_next);
+ } else {
+ QSIMPLEQ_INSERT_TAIL(&queue->entries, self, co_queue_next);
+ }
if (lock) {
qemu_lockable_unlock(lock);
--
2.37.3
- [PATCH v5 00/12] blkio: add libblkio BlockDriver, Stefan Hajnoczi, 2022/09/27
- [PATCH v5 01/12] coroutine: add flag to re-queue at front of CoQueue,
Stefan Hajnoczi <=
- [PATCH v5 02/12] blkio: add libblkio block driver, Stefan Hajnoczi, 2022/09/27
- [PATCH v5 03/12] numa: call ->ram_block_removed() in ram_block_notifer_remove(), Stefan Hajnoczi, 2022/09/27
- [PATCH v5 05/12] block: use BdrvRequestFlags type for supported flag fields, Stefan Hajnoczi, 2022/09/27
- [PATCH v5 04/12] block: pass size to bdrv_unregister_buf(), Stefan Hajnoczi, 2022/09/27
- [PATCH v5 06/12] block: add BDRV_REQ_REGISTERED_BUF request flag, Stefan Hajnoczi, 2022/09/27
- [PATCH v5 07/12] block: return errors from bdrv_register_buf(), Stefan Hajnoczi, 2022/09/27
- [PATCH v5 08/12] block: add BlockRAMRegistrar, Stefan Hajnoczi, 2022/09/27
- [PATCH v5 09/12] exec/cpu-common: add qemu_ram_get_fd(), Stefan Hajnoczi, 2022/09/27