From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: <qemu-block@nongnu.org>, Kevin Wolf <kwolf@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: [PATCH] iothread: defer AioContext GSource usage
Date: Thu, 20 Feb 2025 12:05:36 +0800 [thread overview]
Message-ID: <20250220040536.195180-1-stefanha@redhat.com> (raw)
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
next reply other threads:[~2025-02-20 4:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-20 4:05 Stefan Hajnoczi [this message]
2025-03-10 15:49 ` [PATCH] iothread: defer AioContext GSource usage Kevin Wolf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250220040536.195180-1-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).