summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2022-03-04 07:59:04 -0700
committerJens Axboe <axboe@kernel.dk>2022-03-08 06:02:44 -0700
commitb02125e164ea2604efbf443224fe5679ef0047c1 (patch)
tree00ecd9d2ea41fbd19a1a3e221c28445119b663fd
parentda4480fcf69e26e3a3cfb4cadb0e30705abde119 (diff)
downloadliburing-b02125e164ea2604efbf443224fe5679ef0047c1.tar.gz
liburing-b02125e164ea2604efbf443224fe5679ef0047c1.tar.bz2
Add preliminary support for using a registered ring fd
Add a specific ->enter_ring_fd member to the ring, and just set it to the normal ring fd at init time. Add an internal flag to track whether or not we're actually using a registered fd for the ring itself, and set the appropriate io_uring_enter(2) if so. Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--src/include/liburing.h5
-rw-r--r--src/int_flags.h8
-rw-r--r--src/queue.c26
-rw-r--r--src/setup.c3
4 files changed, 33 insertions, 9 deletions
diff --git a/src/include/liburing.h b/src/include/liburing.h
index ef5a4cd..0799a50 100644
--- a/src/include/liburing.h
+++ b/src/include/liburing.h
@@ -76,7 +76,10 @@ struct io_uring {
int ring_fd;
unsigned features;
- unsigned pad[3];
+ int enter_ring_fd;
+ __u8 int_flags;
+ __u8 pad[3];
+ unsigned pad2;
};
/*
diff --git a/src/int_flags.h b/src/int_flags.h
new file mode 100644
index 0000000..b9270ae
--- /dev/null
+++ b/src/int_flags.h
@@ -0,0 +1,8 @@
+#ifndef LIBURING_INT_FLAGS
+#define LIBURING_INT_FLAGS
+
+enum {
+ INT_FLAG_REG_RING = 1,
+};
+
+#endif
diff --git a/src/queue.c b/src/queue.c
index ef09eb5..f17c024 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -4,6 +4,7 @@
#include "lib.h"
#include "syscall.h"
#include "liburing.h"
+#include "int_flags.h"
#include "liburing/compat.h"
#include "liburing/io_uring.h"
@@ -118,7 +119,9 @@ static int _io_uring_get_cqe(struct io_uring *ring, struct io_uring_cqe **cqe_pt
if (!need_enter)
break;
- ret = ____sys_io_uring_enter2(ring->ring_fd, data->submit,
+ if (ring->int_flags & INT_FLAG_REG_RING)
+ flags |= IORING_ENTER_REGISTERED_RING;
+ ret = ____sys_io_uring_enter2(ring->enter_ring_fd, data->submit,
data->wait_nr, flags, data->arg,
data->sz);
if (ret < 0) {
@@ -180,8 +183,11 @@ again:
goto done;
if (cq_ring_needs_flush(ring)) {
- ____sys_io_uring_enter(ring->ring_fd, 0, 0,
- IORING_ENTER_GETEVENTS, NULL);
+ int flags = IORING_ENTER_GETEVENTS;
+
+ if (ring->int_flags & INT_FLAG_REG_RING)
+ flags |= IORING_ENTER_REGISTERED_RING;
+ ____sys_io_uring_enter(ring->enter_ring_fd, 0, 0, flags, NULL);
overflow_checked = true;
goto again;
}
@@ -376,9 +382,11 @@ static int __io_uring_submit(struct io_uring *ring, unsigned submitted,
if (sq_ring_needs_enter(ring, &flags) || wait_nr) {
if (wait_nr || (ring->flags & IORING_SETUP_IOPOLL))
flags |= IORING_ENTER_GETEVENTS;
+ if (ring->int_flags & INT_FLAG_REG_RING)
+ flags |= IORING_ENTER_REGISTERED_RING;
- ret = ____sys_io_uring_enter(ring->ring_fd, submitted, wait_nr,
- flags, NULL);
+ ret = ____sys_io_uring_enter(ring->enter_ring_fd, submitted,
+ wait_nr, flags, NULL);
} else
ret = submitted;
@@ -417,6 +425,10 @@ struct io_uring_sqe *io_uring_get_sqe(struct io_uring *ring)
int __io_uring_sqring_wait(struct io_uring *ring)
{
- return ____sys_io_uring_enter(ring->ring_fd, 0, 0,
- IORING_ENTER_SQ_WAIT, NULL);
+ int flags = IORING_ENTER_SQ_WAIT;
+
+ if (ring->int_flags & INT_FLAG_REG_RING)
+ flags |= IORING_ENTER_REGISTERED_RING;
+
+ return ____sys_io_uring_enter(ring->enter_ring_fd, 0, 0, flags, NULL);
}
diff --git a/src/setup.c b/src/setup.c
index 544adaf..12a1cd5 100644
--- a/src/setup.c
+++ b/src/setup.c
@@ -91,7 +91,8 @@ int io_uring_queue_mmap(int fd, struct io_uring_params *p, struct io_uring *ring
ret = io_uring_mmap(fd, p, &ring->sq, &ring->cq);
if (!ret) {
ring->flags = p->flags;
- ring->ring_fd = fd;
+ ring->ring_fd = ring->enter_ring_fd = fd;
+ ring->int_flags = 0;
}
return ret;
}