From 085766d3e3f6be2c8a54de01633bb8d977b3e2a7 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Sat, 21 Jan 2023 10:04:37 -0700 Subject: [PATCH 1/2] test/read-before-exit: handle IOPOLL failure on older kernels Signed-off-by: Jens Axboe Signed-off-by: Ferry Meng --- test/read-before-exit.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/test/read-before-exit.c b/test/read-before-exit.c index be36bd41..f7af5502 100644 --- a/test/read-before-exit.c +++ b/test/read-before-exit.c @@ -14,6 +14,8 @@ #include "liburing.h" #include "helpers.h" +static int no_iopoll; + struct data { struct io_uring *ring; int timer_fd1; @@ -35,8 +37,21 @@ void *submit(void *data) io_uring_prep_read(sqe, d->timer_fd2, &d->buf2, sizeof(d->buf2), 0); ret = io_uring_submit(d->ring); - if (ret != 2) + if (ret != 2) { + struct io_uring_cqe *cqe; + + /* + * Kernels without submit-all-on-error behavior will + * fail submitting all, check if that's the case and + * don't error + */ + ret = io_uring_peek_cqe(d->ring, &cqe); + if (!ret && cqe->res == -EOPNOTSUPP) { + no_iopoll = 1; + return NULL; + } return (void *) (uintptr_t) 1; + } /* Exit suddenly. */ return NULL; @@ -95,9 +110,11 @@ int main(int argc, char *argv[]) for (i = 0; i < 1000; i++) { ret = test(IORING_SETUP_IOPOLL); if (ret) { - fprintf(stderr, "Test IOPOLL failed\n"); + fprintf(stderr, "Test IOPOLL failed loop %d\n", ret); return ret; } + if (no_iopoll) + break; } for (i = 0; i < 100; i++) { -- Gitee From 672653880347d22bc783da6f16228f248ef09df0 Mon Sep 17 00:00:00 2001 From: Ferry Meng Date: Sun, 8 Oct 2023 17:02:40 +0800 Subject: [PATCH 2/2] test/sqpoll-idle-us: add SQ_AFF flag When we use SQTHREAD_PERCPU, we should specify the CPU it runs on. The flag is missing in sqpoll-idle-us test, now we add it. Signed-off-by: Ferry Meng --- test/sqpoll-idle-us.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/sqpoll-idle-us.c b/test/sqpoll-idle-us.c index 957ea7ce..2da3b54e 100644 --- a/test/sqpoll-idle-us.c +++ b/test/sqpoll-idle-us.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "liburing.h" #define DEFAULT_IDLE_US 50 @@ -59,8 +60,10 @@ static int test_sqpoll_idle_us(int nr) int ret, count = nr; srand((unsigned)time(NULL)); - p.flags = (IORING_SETUP_SQPOLL | IORING_SETUP_SQPOLL_PERCPU | IORING_SETUP_IDLE_US); + p.flags = (IORING_SETUP_SQPOLL | IORING_SETUP_SQPOLL_PERCPU | + IORING_SETUP_SQ_AFF | IORING_SETUP_IDLE_US); p.sq_thread_idle = DEFAULT_IDLE_US; + p.sq_thread_cpu = get_nprocs_conf() - 1; ret = io_uring_queue_init_params(nr + 10, &ring, &p); if (ret) { -- Gitee