Skip to content

Commit 145e007

Browse files
isilenceaxboe
authored andcommitted
selftests/io_uring: support NO_SQARRAY in miniliburing
Add support for IORING_SETUP_NO_SQARRAY in miniliburing. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 73061db commit 145e007

1 file changed

Lines changed: 27 additions & 7 deletions

File tree

tools/include/io_uring/mini_liburing.h

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <stdio.h>
77
#include <string.h>
88
#include <unistd.h>
9+
#include <sys/uio.h>
910

1011
struct io_sq_ring {
1112
unsigned int *head;
@@ -55,6 +56,7 @@ struct io_uring {
5556
struct io_uring_sq sq;
5657
struct io_uring_cq cq;
5758
int ring_fd;
59+
unsigned flags;
5860
};
5961

6062
#if defined(__x86_64) || defined(__i386__)
@@ -72,7 +74,14 @@ static inline int io_uring_mmap(int fd, struct io_uring_params *p,
7274
void *ptr;
7375
int ret;
7476

75-
sq->ring_sz = p->sq_off.array + p->sq_entries * sizeof(unsigned int);
77+
if (p->flags & IORING_SETUP_NO_SQARRAY) {
78+
sq->ring_sz = p->cq_off.cqes;
79+
sq->ring_sz += p->cq_entries * sizeof(struct io_uring_cqe);
80+
} else {
81+
sq->ring_sz = p->sq_off.array;
82+
sq->ring_sz += p->sq_entries * sizeof(unsigned int);
83+
}
84+
7685
ptr = mmap(0, sq->ring_sz, PROT_READ | PROT_WRITE,
7786
MAP_SHARED | MAP_POPULATE, fd, IORING_OFF_SQ_RING);
7887
if (ptr == MAP_FAILED)
@@ -83,7 +92,8 @@ static inline int io_uring_mmap(int fd, struct io_uring_params *p,
8392
sq->kring_entries = ptr + p->sq_off.ring_entries;
8493
sq->kflags = ptr + p->sq_off.flags;
8594
sq->kdropped = ptr + p->sq_off.dropped;
86-
sq->array = ptr + p->sq_off.array;
95+
if (!(p->flags & IORING_SETUP_NO_SQARRAY))
96+
sq->array = ptr + p->sq_off.array;
8797

8898
size = p->sq_entries * sizeof(struct io_uring_sqe);
8999
sq->sqes = mmap(0, size, PROT_READ | PROT_WRITE,
@@ -138,10 +148,12 @@ static inline int io_uring_queue_init_params(unsigned int entries,
138148
if (fd < 0)
139149
return fd;
140150
ret = io_uring_mmap(fd, p, &ring->sq, &ring->cq);
141-
if (!ret)
151+
if (!ret) {
142152
ring->ring_fd = fd;
143-
else
153+
ring->flags = p->flags;
154+
} else {
144155
close(fd);
156+
}
145157
return ret;
146158
}
147159

@@ -208,10 +220,18 @@ static inline int io_uring_submit(struct io_uring *ring)
208220

209221
ktail = *sq->ktail;
210222
to_submit = sq->sqe_tail - sq->sqe_head;
211-
for (submitted = 0; submitted < to_submit; submitted++) {
212-
read_barrier();
213-
sq->array[ktail++ & mask] = sq->sqe_head++ & mask;
223+
224+
if (!(ring->flags & IORING_SETUP_NO_SQARRAY)) {
225+
for (submitted = 0; submitted < to_submit; submitted++) {
226+
read_barrier();
227+
sq->array[ktail++ & mask] = sq->sqe_head++ & mask;
228+
}
229+
} else {
230+
ktail += to_submit;
231+
sq->sqe_head += to_submit;
232+
submitted = to_submit;
214233
}
234+
215235
if (!submitted)
216236
return 0;
217237

0 commit comments

Comments
 (0)