summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Rouzier <rouzier@gmail.com>2019-09-21 12:32:47 -0400
committerJames Rouzier <rouzier@gmail.com>2019-09-21 16:15:34 -0400
commit59df60ecfb64776841afa9091994e4ecf7890807 (patch)
treeb7abf7d21f54aaea3d2ef471037cd9f858f8164d
parent7485e31f855d8646e6c59cd048f6803a4137e1f7 (diff)
downloadliburing-59df60ecfb64776841afa9091994e4ecf7890807.tar.gz
liburing-59df60ecfb64776841afa9091994e4ecf7890807.tar.bz2
Add io_uring_sq_space_left()
io_uring_sq_space_left(), returns the amount of space left in the submission queue. test/sq-space_left.c tests io_uring_sq_space_left Signed-off-by: James Rouzier <rouzier@gmail.com>
-rw-r--r--src/include/liburing.h5
-rw-r--r--test/Makefile7
-rw-r--r--test/sq-space_left.c51
3 files changed, 61 insertions, 2 deletions
diff --git a/src/include/liburing.h b/src/include/liburing.h
index 7c6731f..1cae1cd 100644
--- a/src/include/liburing.h
+++ b/src/include/liburing.h
@@ -241,6 +241,11 @@ static inline void io_uring_prep_timeout(struct io_uring_sqe *sqe,
io_uring_prep_rw(IORING_OP_TIMEOUT, sqe, 0, ts, 1, count);
}
+static inline unsigned io_uring_sq_space_left(struct io_uring *ring)
+{
+ return *ring->sq.kring_entries - (ring->sq.sqe_tail - ring->sq.sqe_head);
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/test/Makefile b/test/Makefile
index 8bd96c1..a5898a2 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -4,7 +4,8 @@ override CFLAGS += -Wall -D_GNU_SOURCE -L../src/ -I../src/include/
all_targets += poll poll-cancel ring-leak fsync io_uring_setup io_uring_register \
io_uring_enter nop sq-full cq-full 35fa71a030ca-test \
917257daa0fe-test b19062a56726-test eeed8b54e0df-test link \
- send_recvmsg a4c0b3decb33-test 500f9fbadef8-test timeout
+ send_recvmsg a4c0b3decb33-test 500f9fbadef8-test timeout \
+ sq-space_left
all: $(all_targets)
@@ -12,7 +13,7 @@ test_srcs := poll.c poll-cancel.c ring-leak.c fsync.c io_uring_setup.c \
io_uring_register.c io_uring_enter.c nop.c sq-full.c cq-full.c \
35fa71a030ca-test.c 917257daa0fe-test.c b19062a56726-test.c \
eeed8b54e0df-test.c link.c send_recvmsg.c a4c0b3decb33-test.c \
- 500f9fbadef8-test.c timeout.c
+ 500f9fbadef8-test.c timeout.c sq-space_left.c
test_objs := $(patsubst %.c,%.ol,$(test_srcs))
@@ -34,6 +35,8 @@ nop: nop.c
$(CC) $(CFLAGS) -o $@ nop.c -luring
sq-full: sq-full.c
$(CC) $(CFLAGS) -o $@ sq-full.c -luring
+sq-space_left: sq-space_left.c
+ $(CC) $(CFLAGS) -o $@ sq-space_left.c -luring
cq-full: cq-full.c
$(CC) $(CFLAGS) -o $@ cq-full.c -luring
35fa71a030ca-test: 35fa71a030ca-test.c
diff --git a/test/sq-space_left.c b/test/sq-space_left.c
new file mode 100644
index 0000000..71fc871
--- /dev/null
+++ b/test/sq-space_left.c
@@ -0,0 +1,51 @@
+/*
+ * Description: test SQ queue space left
+ *
+ */
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+
+#include "liburing.h"
+
+int main(int argc, char *argv[])
+{
+ struct io_uring_sqe *sqe;
+ struct io_uring ring;
+ int ret, i = 0, s;
+
+ ret = io_uring_queue_init(8, &ring, 0);
+ if (ret) {
+ printf("ring setup failed\n");
+ return 1;
+
+ }
+
+ if ((s = io_uring_sq_space_left(&ring)) != 8) {
+ printf("Got %d SQEs left, expected %d\n", s, 8);
+ goto err;
+ }
+
+ i = 0;
+ while ((sqe = io_uring_get_sqe(&ring)) != NULL) {
+ i++;
+ if ((s = io_uring_sq_space_left(&ring)) != 8 - i) {
+ printf("Got %d SQEs left, expected %d\n", s, 8 - i);
+ goto err;
+ }
+ }
+
+ if (i != 8) {
+ printf("Got %d SQEs, expected %d\n", i, 8);
+ goto err;
+ }
+
+ io_uring_queue_exit(&ring);
+ return 0;
+err:
+ io_uring_queue_exit(&ring);
+ return 1;
+}