* [PATCH liburing 1/3] tests: refactor poll-many.c
2023-01-16 16:46 [PATCH liburing 0/3] test lazy poll wq activation Pavel Begunkov
@ 2023-01-16 16:46 ` Pavel Begunkov
2023-01-16 16:46 ` [PATCH liburing 2/3] tests: test DEFER_TASKRUN in poll-many Pavel Begunkov
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Pavel Begunkov @ 2023-01-16 16:46 UTC (permalink / raw)
To: io-uring; +Cc: Jens Axboe, asml.silence
Use right return codes and extract the testing into a function
Signed-off-by: Pavel Begunkov <[email protected]>
---
test/poll-many.c | 46 +++++++++++++++++++++++++++-------------------
1 file changed, 27 insertions(+), 19 deletions(-)
diff --git a/test/poll-many.c b/test/poll-many.c
index dfbeeab..ebf22e8 100644
--- a/test/poll-many.c
+++ b/test/poll-many.c
@@ -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, ¶ms);
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");
--
2.38.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH liburing 2/3] tests: test DEFER_TASKRUN in poll-many
2023-01-16 16:46 [PATCH liburing 0/3] test lazy poll wq activation Pavel Begunkov
2023-01-16 16:46 ` [PATCH liburing 1/3] tests: refactor poll-many.c Pavel Begunkov
@ 2023-01-16 16:46 ` Pavel Begunkov
2023-01-16 16:46 ` [PATCH liburing 3/3] tests: lazy pollwq activation for disabled rings Pavel Begunkov
2023-01-16 17:49 ` [PATCH liburing 0/3] test lazy poll wq activation Jens Axboe
3 siblings, 0 replies; 5+ messages in thread
From: Pavel Begunkov @ 2023-01-16 16:46 UTC (permalink / raw)
To: io-uring; +Cc: Jens Axboe, asml.silence
We want to extend DEFER_TASKRUN test coverage for polling, so
make poll-many.c to test it.
Signed-off-by: Pavel Begunkov <[email protected]>
---
test/poll-many.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/test/poll-many.c b/test/poll-many.c
index ebf22e8..da3da21 100644
--- a/test/poll-many.c
+++ b/test/poll-many.c
@@ -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, ¶ms);
+ 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), "
--
2.38.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH liburing 3/3] tests: lazy pollwq activation for disabled rings
2023-01-16 16:46 [PATCH liburing 0/3] test lazy poll wq activation Pavel Begunkov
2023-01-16 16:46 ` [PATCH liburing 1/3] tests: refactor poll-many.c Pavel Begunkov
2023-01-16 16:46 ` [PATCH liburing 2/3] tests: test DEFER_TASKRUN in poll-many Pavel Begunkov
@ 2023-01-16 16:46 ` Pavel Begunkov
2023-01-16 17:49 ` [PATCH liburing 0/3] test lazy poll wq activation Jens Axboe
3 siblings, 0 replies; 5+ messages in thread
From: Pavel Begunkov @ 2023-01-16 16:46 UTC (permalink / raw)
To: io-uring; +Cc: Jens Axboe, asml.silence
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.
Signed-off-by: Pavel Begunkov <[email protected]>
---
test/poll.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 89 insertions(+), 7 deletions(-)
diff --git a/test/poll.c b/test/poll.c
index a7db7dc..7b90f3d 100644
--- a/test/poll.c
+++ b/test/poll.c
@@ -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;
--
2.38.1
^ permalink raw reply related [flat|nested] 5+ messages in thread