qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v5] Use io_uring_register_ring_fd() to skip fd operations


From: Sam Li
Subject: [PATCH v5] Use io_uring_register_ring_fd() to skip fd operations
Date: Tue, 31 May 2022 16:48:47 +0800

Linux recently added a new io_uring(7) optimization API that QEMU
doesn't take advantage of yet. The liburing library that QEMU uses
has added a corresponding new API calling io_uring_register_ring_fd().
When this API is called after creating the ring, the io_uring_submit()
library function passes a flag to the io_uring_enter(2) syscall
allowing it to skip the ring file descriptor fdget()/fdput()
operations. This saves some CPU cycles.

Signed-off-by: Sam Li <faithilikerun@gmail.com>
---
 block/io_uring.c | 13 ++++++++++++-
 meson.build      |  1 +
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/block/io_uring.c b/block/io_uring.c
index 0b401512b9..4d691d8373 100644
--- a/block/io_uring.c
+++ b/block/io_uring.c
@@ -17,6 +17,9 @@
 #include "qemu/coroutine.h"
 #include "qapi/error.h"
 #include "trace.h"
+#ifdef CONFIG_LIBURING_REGISTER_RING_FD
+    io_uring_register_ring_fd(&s->ring);
+#endif
 
 /* io_uring ring size */
 #define MAX_ENTRIES 128
@@ -434,8 +437,16 @@ LuringState *luring_init(Error **errp)
     }
 
     ioq_init(&s->io_q);
-    return s;
+    if (io_uring_register_ring_fd(&s->ring) < 0) {
+        /*
+         * Only warn about this error: we will fallback to the non-optimized
+         * io_uring operations.
+         */
+        error_reportf_err(*errp,
+                          "failed to register linux io_uring ring file 
descriptor");
+    }
 
+    return s;
 }
 
 void luring_cleanup(LuringState *s)
diff --git a/meson.build b/meson.build
index 9ebc00f032..927e6ec1a4 100644
--- a/meson.build
+++ b/meson.build
@@ -1733,6 +1733,7 @@ config_host_data.set('CONFIG_LIBNFS', libnfs.found())
 config_host_data.set('CONFIG_LIBSSH', libssh.found())
 config_host_data.set('CONFIG_LINUX_AIO', libaio.found())
 config_host_data.set('CONFIG_LINUX_IO_URING', linux_io_uring.found())
+config_host_data.set('CONFIG_LIBURING_REGISTER_RING_FD', 
cc.has_function('io_uring_register_ring_fd', prefix: '#include <liburing.h>'))
 config_host_data.set('CONFIG_LIBPMEM', libpmem.found())
 config_host_data.set('CONFIG_NUMA', numa.found())
 config_host_data.set('CONFIG_OPENGL', opengl.found())
-- 
2.35.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]