With IORING_SETUP_SQ_REWIND, the kernel doesn't use the SQ headers and always submits SQEs with indices in a range [0, nr_submit), where nr_submit is the syscall argument. Add liburing support for that. The head is now kept to be 0, and tail effectively tracks the number of entries to submit, which matches the normal formula to_submit = (tail - head) mod N Signed-off-by: Pavel Begunkov --- src/include/liburing.h | 5 ++++- src/include/liburing/io_uring.h | 12 ++++++++++++ src/queue.c | 5 +++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/include/liburing.h b/src/include/liburing.h index 8a882a08..4758c955 100644 --- a/src/include/liburing.h +++ b/src/include/liburing.h @@ -1918,9 +1918,12 @@ IOURINGINLINE struct io_uring_sqe *_io_uring_get_sqe(struct io_uring *ring) LIBURING_NOEXCEPT { struct io_uring_sq *sq = &ring->sq; - unsigned head = io_uring_load_sq_head(ring), tail = sq->sqe_tail; + unsigned head = 0, tail = sq->sqe_tail; struct io_uring_sqe *sqe; + if (!(ring->flags & IORING_SETUP_SQ_REWIND)) + head = io_uring_load_sq_head(ring); + if (tail - head >= sq->ring_entries) return NULL; diff --git a/src/include/liburing/io_uring.h b/src/include/liburing/io_uring.h index 8e8b8e6a..2696b43d 100644 --- a/src/include/liburing/io_uring.h +++ b/src/include/liburing/io_uring.h @@ -233,6 +233,18 @@ enum io_uring_sqe_flags_bit { */ #define IORING_SETUP_SQE_MIXED (1U << 19) +/* + * When set, io_uring ignores SQ head and tail and fetches SQEs to submit + * starting from index 0 instead from the index stored in the head pointer. + * IOW, the user should place all SQE at the beginning of the SQ memory + * before issuing a submission syscall. + * + * It requires IORING_SETUP_NO_SQARRAY and is incompatible with + * IORING_SETUP_SQPOLL. The user must also never change the SQ head and tail + * values and keep it set to 0. Any other value is undefined behaviour. + */ +#define IORING_SETUP_SQ_REWIND (1U << 20) + enum io_uring_op { IORING_OP_NOP, IORING_OP_READV, diff --git a/src/queue.c b/src/queue.c index c8ada7e8..00995ace 100644 --- a/src/queue.c +++ b/src/queue.c @@ -205,6 +205,11 @@ static unsigned __io_uring_flush_sq(struct io_uring *ring) struct io_uring_sq *sq = &ring->sq; unsigned tail = sq->sqe_tail; + if (ring->flags & IORING_SETUP_SQ_REWIND) { + sq->sqe_tail = 0; + return tail; + } + if (sq->sqe_head != tail) { sq->sqe_head = tail; /* -- 2.52.0