summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2019-11-14 17:24:19 -0700
committerJens Axboe <axboe@kernel.dk>2019-11-14 17:24:19 -0700
commitda869dc3eb101b5d8fcb193b3a4361109d8946dd (patch)
tree09630aac6e66526874c705baabf7687fa9082d1a
parent624333413172787ca7d18b1d0cc18c9196ca68d3 (diff)
downloadliburing-da869dc3eb101b5d8fcb193b3a4361109d8946dd.tar.gz
liburing-da869dc3eb101b5d8fcb193b3a4361109d8946dd.tar.bz2
Add test/poll-cancel-ton
Just tests a lot of polls waiting, then cancelling them. Should be nearly instant on a good kernel, takes 5-10s on a slow kernel. Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--test/Makefile4
-rw-r--r--test/poll-cancel-ton.c120
2 files changed, 122 insertions, 2 deletions
diff --git a/test/Makefile b/test/Makefile
index 988e249..6305d95 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -10,7 +10,7 @@ all_targets += poll poll-cancel ring-leak fsync io_uring_setup io_uring_register
cq-size 8a9973408177-test a0908ae19763-test 232c93d07b74-test \
socket-rw accept timeout-overflow defer read-write io-cancel \
link-timeout cq-overflow link_drain fc2a85cb02ef-test \
- poll-link accept-link fixed-link
+ poll-link accept-link fixed-link poll-cancel-ton
include ../Makefile.quiet
@@ -28,7 +28,7 @@ test_srcs := poll.c poll-cancel.c ring-leak.c fsync.c io_uring_setup.c \
a0908ae19763-test.c 232c93d07b74-test.c socket-rw.c accept.c \
timeout-overflow.c defer.c read-write.c io-cancel.c link-timeout.c \
cq-overflow.c link_drain.c fc2a85cb02ef-test.c poll-link.c \
- accept-link.c fixed-link.c
+ accept-link.c fixed-link.c poll-cancel-ton.c
test_objs := $(patsubst %.c,%.ol,$(test_srcs))
diff --git a/test/poll-cancel-ton.c b/test/poll-cancel-ton.c
new file mode 100644
index 0000000..8ddce7e
--- /dev/null
+++ b/test/poll-cancel-ton.c
@@ -0,0 +1,120 @@
+/*
+ * Description: test massive amounts of poll with cancel
+ *
+ */
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include <sys/poll.h>
+#include <sys/wait.h>
+#include <sys/signal.h>
+
+#include "liburing.h"
+
+static int reap_events(struct io_uring *ring, unsigned nr_events)
+{
+ struct io_uring_cqe *cqe;
+ int i, ret = 0;
+
+ for (i = 0; i < nr_events; i++) {
+ if (!i)
+ ret = io_uring_wait_cqe(ring, &cqe);
+ else
+ ret = io_uring_peek_cqe(ring, &cqe);
+ if (ret) {
+ if (ret != -EAGAIN)
+ fprintf(stderr, "cqe peek failed: %d\n", ret);
+ break;
+ }
+ io_uring_cqe_seen(ring, cqe);
+ }
+
+ return i ? i : ret;
+}
+
+static int del_polls(struct io_uring *ring, int fd, int nr)
+{
+ int pending, batch, i, ret;
+ struct io_uring_sqe *sqe;
+
+ while (nr) {
+ batch = 1024;
+ if (batch > nr)
+ batch = nr;
+
+ for (i = 0; i < batch; i++) {
+ unsigned data;
+ sqe = io_uring_get_sqe(ring);
+ data = rand() % 10001;
+ io_uring_prep_poll_remove(sqe, (void *) (unsigned long) data);
+ }
+
+ ret = io_uring_submit(ring);
+ if (ret != batch) {
+ fprintf(stderr, "%s: failed submit, %d\n", __FUNCTION__, ret);
+ return 1;
+ }
+ nr -= batch;
+ pending += batch;
+ ret = reap_events(ring, 2 * batch);
+ }
+ return 0;
+}
+
+static int add_polls(struct io_uring *ring, int fd, int nr)
+{
+ int pending, batch, i, count, ret;
+ struct io_uring_sqe *sqe;
+
+ pending = count = 0;
+ while (nr) {
+ batch = 1024;
+ if (batch > nr)
+ batch = nr;
+
+ for (i = 0; i < batch; i++) {
+ sqe = io_uring_get_sqe(ring);
+ io_uring_prep_poll_add(sqe, fd, POLLIN);
+ sqe->user_data = ++count;
+ }
+
+ ret = io_uring_submit(ring);
+ if (ret != batch) {
+ fprintf(stderr, "%s: failed submit, %d\n", __FUNCTION__, ret);
+ return 1;
+ }
+ nr -= batch;
+ pending += batch;
+ }
+ return 0;
+}
+
+int main(int argc, char *argv[])
+{
+ struct io_uring ring;
+ int pipe1[2];
+ int ret;
+
+ if (pipe(pipe1) != 0) {
+ printf("pipe failed\n");
+ return 1;
+ }
+
+ ret = io_uring_queue_init(1024, &ring, 0);
+ if (ret) {
+ printf("child: ring setup failed\n");
+ return 1;
+ }
+
+ add_polls(&ring, pipe1[0], 30000);
+#if 0
+ usleep(1000);
+#endif
+ del_polls(&ring, pipe1[0], 30000);
+
+ io_uring_queue_exit(&ring);
+ return 0;
+}