summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/liburing.h1
-rw-r--r--src/queue.c26
-rw-r--r--src/setup.c4
3 files changed, 26 insertions, 5 deletions
diff --git a/src/liburing.h b/src/liburing.h
index 2651b3d..ccefc40 100644
--- a/src/liburing.h
+++ b/src/liburing.h
@@ -46,6 +46,7 @@ struct io_uring_cq {
struct io_uring {
struct io_uring_sq sq;
struct io_uring_cq cq;
+ unsigned flags;
int ring_fd;
};
diff --git a/src/queue.c b/src/queue.c
index 5bbb279..eec26c9 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -63,6 +63,17 @@ int io_uring_wait_cqe(struct io_uring *ring, struct io_uring_cqe **cqe_ptr)
}
/*
+ * Returns true if we're not using SQ thread (thus nobody submits but us)
+ * or if IORING_SQ_NEED_WAKEUP is set, so dormouse should be explicitly
+ * awekened.
+ */
+static inline int sq_ring_needs_enter(struct io_uring *ring)
+{
+ return !(ring->flags & IORING_SETUP_SQPOLL) ||
+ (*ring->sq.kflags & IORING_SQ_NEED_WAKEUP);
+}
+
+/*
* Submit sqes acquired from io_uring_get_sqe() to the kernel.
*
* Returns number of sqes submitted
@@ -125,10 +136,17 @@ int io_uring_submit(struct io_uring *ring)
}
submit:
- ret = io_uring_enter(ring->ring_fd, submitted, 0,
- IORING_ENTER_GETEVENTS, NULL);
- if (ret < 0)
- return -errno;
+ if (sq_ring_needs_enter(ring)) {
+ unsigned flags = 0;
+
+ if ((*ring->sq.kflags & IORING_SQ_NEED_WAKEUP))
+ flags |= IORING_ENTER_SQ_WAKEUP;
+
+ ret = io_uring_enter(ring->ring_fd, submitted, 0, flags, NULL);
+ if (ret < 0)
+ return -errno;
+ } else
+ ret = submitted;
return ret;
}
diff --git a/src/setup.c b/src/setup.c
index 73f35de..9da3c19 100644
--- a/src/setup.c
+++ b/src/setup.c
@@ -69,8 +69,10 @@ int io_uring_queue_mmap(int fd, struct io_uring_params *p, struct io_uring *ring
memset(ring, 0, sizeof(*ring));
ret = io_uring_mmap(fd, p, &ring->sq, &ring->cq);
- if (!ret)
+ if (!ret) {
+ ring->flags = p->flags;
ring->ring_fd = fd;
+ }
return ret;
}