Skip to contentSkip to conversation

test lazy poll wq activation

PATCH Applied Pavel Begunkov 2 participants 5 messages Jan 16, 2023 io_uring

lore
Share & tools
lore
#0 lore raw

cover test lazy poll wq activation

Some tests around DEFER_TASKRUN and lazy poll activation, with 3/3 specifically testing the feature with disabled.

Pavel Begunkov (3):
tests: refactor poll-many.c
tests: test DEFER_TASKRUN in poll-many
tests: lazy pollwq activation for disabled rings

 test/poll-many.c | 60 ++++++++++++++++++++----------
 test/poll.c      | 96 ++++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 130 insertions(+), 26 deletions(-)
Signature · 1 line
2.38.1
#1 lore raw

PATCH 1/3 tests: refactor poll-many.c

Use right return codes and extract the testing into a function

---
 test/poll-many.c | 46 +++++++++++++++++++++++++++-------------------
 1 file changed, 27 insertions(+), 19 deletions(-)
test/poll-many.c +27 -19
index dfbeeab..ebf22e8 100644
@@ -14,6 +14,7 @@
 #include <fcntl.h>
 
 #include "liburing.h"
+#include "helpers.h"
 
 #define	NFILES	5000
 #define BATCH	500
@@ -137,6 +138,21 @@ static int arm_polls(struct io_uring *ring)
 	return 0;
 }
 
+static int do_test(struct io_uring *ring)
+{
+	int i;
+
+	if (arm_polls(ring))
+		return 1;
+
+	for (i = 0; i < NLOOPS; i++) {
+		trigger_polls();
+		if (reap_polls(ring))
+			return 1;
+	}
+	return 0;
+}
+
 int main(int argc, char *argv[])
 {
 	struct io_uring ring;
@@ -149,7 +165,7 @@ int main(int argc, char *argv[])
 
 	if (getrlimit(RLIMIT_NOFILE, &rlim) < 0) {
 		perror("getrlimit");
-		goto err_noring;
+		return T_EXIT_FAIL;
 	}
 
 	if (rlim.rlim_cur < (2 * NFILES + 5)) {
@@ -159,14 +175,14 @@ int main(int argc, char *argv[])
 			if (errno == EPERM)
 				goto err_nofail;
 			perror("setrlimit");
-			goto err_noring;
+			return T_EXIT_FAIL;
 		}
 	}
 
 	for (i = 0; i < NFILES; i++) {
 		if (pipe(p[i].fd) < 0) {
 			perror("pipe");
-			goto err_noring;
+			return T_EXIT_FAIL;
 		}
 	}
 
@@ -176,31 +192,23 @@ int main(int argc, char *argv[])
 	if (ret) {
 		if (ret == -EINVAL) {
 			fprintf(stdout, "No CQSIZE, trying without\n");
-			ret = io_uring_queue_init(RING_SIZE, &ring, 0);
+
+			params.flags &= ~IORING_SETUP_CQSIZE;
+			params.cq_entries = 0;
+			ret = io_uring_queue_init_params(RING_SIZE, &ring, &params);
 			if (ret) {
 				fprintf(stderr, "ring setup failed: %d\n", ret);
-				return 1;
+				return T_EXIT_FAIL;
 			}
 		}
 	}
 
-	if (arm_polls(&ring))
-		goto err;
-
-	for (i = 0; i < NLOOPS; i++) {
-		trigger_polls();
-		ret = reap_polls(&ring);
-		if (ret)
-			goto err;
+	if (do_test(&ring)) {
+		fprintf(stderr, "test (normal) failed\n");
+		return T_EXIT_FAIL;
 	}
-
 	io_uring_queue_exit(&ring);
 	return 0;
-err:
-	io_uring_queue_exit(&ring);
-err_noring:
-	fprintf(stderr, "poll-many failed\n");
-	return 1;
 err_nofail:
 	fprintf(stderr, "poll-many: not enough files available (and not root), "
 			"skipped\n");
Signature · 1 line
2.38.1
#2 lore raw

PATCH 2/3 tests: test DEFER_TASKRUN in poll-many

In reply to Pavel Begunkov

We want to extend DEFER_TASKRUN test coverage for polling, so make poll-many.c to test it.

---
 test/poll-many.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
test/poll-many.c +14 -0
index ebf22e8..da3da21 100644
@@ -208,6 +208,20 @@ int main(int argc, char *argv[])
 		return T_EXIT_FAIL;
 	}
 	io_uring_queue_exit(&ring);
+
+	if (t_probe_defer_taskrun()) {
+		params.flags |= IORING_SETUP_SINGLE_ISSUER | IORING_SETUP_DEFER_TASKRUN;
+		ret = io_uring_queue_init_params(RING_SIZE, &ring, &params);
+		if (ret) {
+			fprintf(stderr, "ring DEFER setup failed: %d\n", ret);
+			return T_EXIT_FAIL;
+		}
+		if (do_test(&ring)) {
+			fprintf(stderr, "test (DEFER) failed\n");
+			return T_EXIT_FAIL;
+		}
+		io_uring_queue_exit(&ring);
+	}
 	return 0;
 err_nofail:
 	fprintf(stderr, "poll-many: not enough files available (and not root), "
Signature · 1 line
2.38.1
#3 lore raw

PATCH 3/3 tests: lazy pollwq activation for disabled rings

In reply to Pavel Begunkov

We have some internal changes in how ring polling is done, i.e. lazy pollwq activation, test it when we start polling a disabled ring and so before the task has been assigned.

---
 test/poll.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 89 insertions(+), 7 deletions(-)
test/poll.c +89 -7
index a7db7dc..7b90f3d 100644
@@ -12,6 +12,7 @@
 #include <poll.h>
 #include <sys/wait.h>
 #include <error.h>
+#include <assert.h>
 
 #include "helpers.h"
 #include "liburing.h"
@@ -22,6 +23,15 @@ static void do_setsockopt(int fd, int level, int optname, int val)
 		error(1, errno, "setsockopt %d.%d: %d", level, optname, val);
 }
 
+static bool check_cq_empty(struct io_uring *ring)
+{
+	struct io_uring_cqe *cqe = NULL;
+	int ret;
+
+	ret = io_uring_peek_cqe(ring, &cqe); /* nothing should be there */
+	return ret == -EAGAIN;
+}
+
 static int test_basic(void)
 {
 	struct io_uring_cqe *cqe;
@@ -110,9 +120,6 @@ static int test_missing_events(void)
 	char buf[2] = {};
 	int res_mask = 0;
 
-	if (!t_probe_defer_taskrun())
-		return 0;
-
 	ret = io_uring_queue_init(8, &ring, IORING_SETUP_SINGLE_ISSUER |
 					    IORING_SETUP_DEFER_TASKRUN);
 	if (ret) {
@@ -180,6 +187,66 @@ static int test_missing_events(void)
 	return 0;
 }
 
+static int test_disabled_ring_lazy_polling(int early_poll)
+{
+	struct io_uring_cqe *cqe;
+	struct io_uring_sqe *sqe;
+	struct io_uring ring, ring2;
+	unsigned head;
+	int ret, i = 0;
+
+	ret = io_uring_queue_init(8, &ring, IORING_SETUP_SINGLE_ISSUER |
+					     IORING_SETUP_DEFER_TASKRUN |
+					     IORING_SETUP_R_DISABLED);
+	if (ret) {
+		fprintf(stderr, "ring setup failed: %d\n", ret);
+		return 1;
+	}
+	ret = io_uring_queue_init(8, &ring2, 0);
+	if (ret) {
+		fprintf(stderr, "ring2 setup failed: %d\n", ret);
+		return 1;
+	}
+
+	if (early_poll) {
+		/* start polling disabled DEFER_TASKRUN ring */
+		sqe = io_uring_get_sqe(&ring2);
+		io_uring_prep_poll_add(sqe, ring.ring_fd, POLLIN);
+		ret = io_uring_submit(&ring2);
+		assert(ret == 1);
+		assert(check_cq_empty(&ring2));
+	}
+
+	/* enable rings, which should also activate pollwq */
+	ret = io_uring_enable_rings(&ring);
+	assert(ret >= 0);
+
+	if (!early_poll) {
+		/* start polling enabled DEFER_TASKRUN ring */
+		sqe = io_uring_get_sqe(&ring2);
+		io_uring_prep_poll_add(sqe, ring.ring_fd, POLLIN);
+		ret = io_uring_submit(&ring2);
+		assert(ret == 1);
+		assert(check_cq_empty(&ring2));
+	}
+
+	sqe = io_uring_get_sqe(&ring);
+	io_uring_prep_nop(sqe);
+	ret = io_uring_submit(&ring);
+	assert(ret == 1);
+
+	io_uring_for_each_cqe(&ring2, head, cqe) {
+		i++;
+	}
+	if (i !=  1) {
+		fprintf(stderr, "fail, polling stuck\n");
+		return 1;
+	}
+	io_uring_queue_exit(&ring);
+	io_uring_queue_exit(&ring2);
+	return 0;
+}
+
 int main(int argc, char *argv[])
 {
 	int ret;
@@ -193,10 +260,25 @@ int main(int argc, char *argv[])
 		return T_EXIT_FAIL;
 	}
 
-	ret = test_missing_events();
-	if (ret) {
-		fprintf(stderr, "test_missing_events() failed %i\n", ret);
-		return T_EXIT_FAIL;
+
+	if (t_probe_defer_taskrun()) {
+		ret = test_missing_events();
+		if (ret) {
+			fprintf(stderr, "test_missing_events() failed %i\n", ret);
+			return T_EXIT_FAIL;
+		}
+
+		ret = test_disabled_ring_lazy_polling(false);
+		if (ret) {
+			fprintf(stderr, "test_disabled_ring_lazy_polling(false) failed %i\n", ret);
+			return T_EXIT_FAIL;
+		}
+
+		ret = test_disabled_ring_lazy_polling(true);
+		if (ret) {
+			fprintf(stderr, "test_disabled_ring_lazy_polling(true) failed %i\n", ret);
+			return T_EXIT_FAIL;
+		}
 	}
 
 	return 0;
Signature · 1 line
2.38.1
maintainer Applied
#4 lore raw
In reply to Pavel Begunkov
Quoted 9 lines · Pavel Begunkov

Some tests around DEFER_TASKRUN and lazy poll activation, with 3/3 specifically testing the feature with disabled.

Pavel Begunkov (3):
tests: refactor poll-many.c
tests: test DEFER_TASKRUN in poll-many
tests: lazy pollwq activation for disabled rings

[...]

Applied, thanks!

[1/3] tests: refactor poll-many.c

      commit: cfd00c3bfe18452a06792b7269a59d269f62d637
[2/3] tests: test DEFER_TASKRUN in poll-many
      commit: a2ab37070b9453e43a94b88878ec3a4d780a4ba6
[3/3] tests: lazy pollwq activation for disabled rings
      commit: 849f5ba89b0d1ccf9d825160bf8560ad9901c48b

Best regards,

Signature · 1 line
Jens Axboe