From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Stefan Hajnoczi <stefanha@redhat.com>,
Brian Song <hibriansong@gmail.com>,
qemu-block@nongnu.org, Bernd Schubert <bschubert@ddn.com>,
Kevin Wolf <kwolf@redhat.com>,
h0lyalg0rithm@git.sr.ht, Fam Zheng <fam@euphon.net>
Subject: [RFC 2/3] aio-posix: enable IORING_SETUP_SINGLE_ISSUER
Date: Thu, 24 Jul 2025 16:47:01 -0400 [thread overview]
Message-ID: <20250724204702.576637-3-stefanha@redhat.com> (raw)
In-Reply-To: <20250724204702.576637-1-stefanha@redhat.com>
IORING_SETUP_SINGLE_ISSUER enables optimizations in the host Linux
kernel's io_uring code when the io_uring context is only used from a
single thread. This is true is QEMU because io_uring SQEs are submitted
from the same thread that processes the CQEs.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
util/fdmon-io_uring.c | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/util/fdmon-io_uring.c b/util/fdmon-io_uring.c
index 28b93c8ab9..4798439097 100644
--- a/util/fdmon-io_uring.c
+++ b/util/fdmon-io_uring.c
@@ -456,13 +456,30 @@ static const FDMonOps fdmon_io_uring_ops = {
.add_sqe = fdmon_io_uring_add_sqe,
};
+static inline bool is_creating_iothread(void)
+{
+ return qemu_get_thread_id() != getpid();
+}
+
void fdmon_io_uring_setup(AioContext *ctx, Error **errp)
{
int ret;
+ /* TODO only enable these flags if they are available in the host's kernel headers */
+ unsigned flags = 0;
ctx->io_uring_fd_tag = NULL;
- ret = io_uring_queue_init(FDMON_IO_URING_ENTRIES, &ctx->fdmon_io_uring, 0);
+ /*
+ * The main thread's AioContexts are created from the main loop thread but
+ * may be accessed from multiple threads (e.g. vCPUs or the migration
+ * thread). IOThread AioContexts are only accessed from the IOThread
+ * itself.
+ */
+ if (is_creating_iothread()) {
+ flags = IORING_SETUP_SINGLE_ISSUER;
+ }
+
+ ret = io_uring_queue_init(FDMON_IO_URING_ENTRIES, &ctx->fdmon_io_uring, flags);
if (ret != 0) {
error_setg_errno(errp, -ret, "Failed to initialize io_uring");
return;
--
2.50.1
next prev parent reply other threads:[~2025-07-24 20:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-24 20:46 [RFC 0/3] aio-posix: enable io_uring SINGLE_ISSUER and TASKRUN flags Stefan Hajnoczi
2025-07-24 20:47 ` [RFC 1/3] iothread: create AioContext in iothread_run() Stefan Hajnoczi
2025-07-24 20:47 ` Stefan Hajnoczi [this message]
2025-07-24 20:47 ` [RFC 3/3] aio-posix: enable IORING_SETUP_COOP_TASKRUN | IORING_SETUP_TASKRUN_FLAG Stefan Hajnoczi
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=20250724204702.576637-3-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=bschubert@ddn.com \
--cc=fam@euphon.net \
--cc=h0lyalg0rithm@git.sr.ht \
--cc=hibriansong@gmail.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).