@@ -223,4 +223,12 @@ void coroutine_fn co_aio_sleep_ns(AioContext *ctx, QEMUClockType type,
* Note that this function clobbers the handlers for the file descriptor.
*/
void coroutine_fn yield_until_fd_readable(int fd);
+
+/* qemu coroutine bypass APIs */
+void qemu_coroutine_set_bypass(bool bypass);
+bool qemu_coroutine_bypassed(Coroutine *self);
+bool qemu_coroutine_self_bypassed(void);
+void qemu_coroutine_set_var(void *var);
+void *qemu_coroutine_get_var(void);
+
#endif /* QEMU_COROUTINE_H */
@@ -39,6 +39,11 @@ struct Coroutine {
Coroutine *caller;
QSLIST_ENTRY(Coroutine) pool_next;
+ bool bypass;
+
+ /* only used in bypass mode */
+ void *opaque;
+
/* Coroutines that should be woken up when we yield or terminate */
QTAILQ_HEAD(, Coroutine) co_queue_wakeup;
QTAILQ_ENTRY(Coroutine) co_queue_next;
@@ -82,13 +82,13 @@ static bool qemu_co_queue_do_restart(CoQueue *queue, bool single)
bool coroutine_fn qemu_co_queue_next(CoQueue *queue)
{
- assert(qemu_in_coroutine());
+ assert(qemu_in_coroutine() || qemu_coroutine_self_bypassed());
return qemu_co_queue_do_restart(queue, true);
}
void coroutine_fn qemu_co_queue_restart_all(CoQueue *queue)
{
- assert(qemu_in_coroutine());
+ assert(qemu_in_coroutine() || qemu_coroutine_self_bypassed());
qemu_co_queue_do_restart(queue, false);
}
@@ -137,3 +137,36 @@ void coroutine_fn qemu_coroutine_yield(void)
self->caller = NULL;
coroutine_swap(self, to);
}
+
+void qemu_coroutine_set_bypass(bool bypass)
+{
+ Coroutine *self = qemu_coroutine_self();
+
+ self->bypass = bypass;
+}
+
+bool qemu_coroutine_bypassed(Coroutine *self)
+{
+ return self->bypass;
+}
+
+bool qemu_coroutine_self_bypassed(void)
+{
+ Coroutine *self = qemu_coroutine_self();
+
+ return qemu_coroutine_bypassed(self);
+}
+
+void qemu_coroutine_set_var(void *var)
+{
+ Coroutine *self = qemu_coroutine_self();
+
+ self->opaque = var;
+}
+
+void *qemu_coroutine_get_var(void)
+{
+ Coroutine *self = qemu_coroutine_self();
+
+ return self->opaque;
+}
This patch introduces several APIs for supporting bypass qemu coroutine in case of being not necessary and for performance's sake. Signed-off-by: Ming Lei <ming.lei@canonical.com> --- include/block/coroutine.h | 8 ++++++++ include/block/coroutine_int.h | 5 +++++ qemu-coroutine-lock.c | 4 ++-- qemu-coroutine.c | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 2 deletions(-)