* [PATCH] iothread: defer AioContext GSource usage
@ 2025-02-20 4:05 Stefan Hajnoczi
2025-03-10 15:49 ` Kevin Wolf
0 siblings, 1 reply; 2+ messages in thread
From: Stefan Hajnoczi @ 2025-02-20 4:05 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-block, Kevin Wolf, Stefan Hajnoczi
Getting the GSource for the AioContext stops fdmon-io_uring from working
because it is not compatible with the glib event loop. Defer the GSource
code until the glib event loop is actually used. For typical IOThreads
this may never be the case and we can use fdmon-io_uring.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
include/system/iothread.h | 1 +
iothread.c | 22 +++++++++++++---------
2 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/include/system/iothread.h b/include/system/iothread.h
index d95c17a645..51ae2f1a78 100644
--- a/include/system/iothread.h
+++ b/include/system/iothread.h
@@ -33,6 +33,7 @@ struct IOThread {
bool stopping; /* has iothread_stop() been called? */
bool running; /* should iothread_run() continue? */
int thread_id;
+ char *g_source_name;
/* AioContext poll parameters */
int64_t poll_max_ns;
diff --git a/iothread.c b/iothread.c
index 589bcd3552..2c2b27208d 100644
--- a/iothread.c
+++ b/iothread.c
@@ -67,7 +67,14 @@ static void *iothread_run(void *opaque)
* changed in previous aio_poll()
*/
if (iothread->running && qatomic_read(&iothread->run_gcontext)) {
+ GSource *source = aio_get_g_source(iothread->ctx);
+
+ g_source_set_name(source, iothread->g_source_name);
+ g_source_attach(source, iothread->worker_context);
+ g_source_unref(source);
+
g_main_loop_run(iothread->main_loop);
+ assert(!iothread->running);
}
}
@@ -136,18 +143,14 @@ static void iothread_instance_finalize(Object *obj)
iothread->main_loop = NULL;
}
qemu_sem_destroy(&iothread->init_done_sem);
+
+ g_free(iothread->g_source_name);
+ iothread->g_source_name = NULL;
}
-static void iothread_init_gcontext(IOThread *iothread, const char *thread_name)
+static void iothread_init_gcontext(IOThread *iothread)
{
- GSource *source;
- g_autofree char *name = g_strdup_printf("%s aio-context", thread_name);
-
iothread->worker_context = g_main_context_new();
- source = aio_get_g_source(iothread_get_aio_context(iothread));
- g_source_set_name(source, name);
- g_source_attach(source, iothread->worker_context);
- g_source_unref(source);
iothread->main_loop = g_main_loop_new(iothread->worker_context, TRUE);
}
@@ -192,12 +195,13 @@ static void iothread_init(EventLoopBase *base, Error **errp)
thread_name = g_strdup_printf("IO %s",
object_get_canonical_path_component(OBJECT(base)));
+ iothread->g_source_name = g_strdup_printf("%s aio-context", thread_name);
/*
* Init one GMainContext for the iothread unconditionally, even if
* it's not used
*/
- iothread_init_gcontext(iothread, thread_name);
+ iothread_init_gcontext(iothread);
iothread_set_aio_context_params(base, &local_error);
if (local_error) {
--
2.48.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-03-10 15:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-20 4:05 [PATCH] iothread: defer AioContext GSource usage Stefan Hajnoczi
2025-03-10 15:49 ` Kevin Wolf
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).