Happens pretty rarely, but there were cases when CQE waitinig in test_return_before_timeout() time outs before the SQPOLL thread kicks in and executes submitted requests, give SQPOLL a little bit more time. Signed-off-by: Pavel Begunkov <asml.silence@xxxxxxxxx> --- test/timeout-new.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/test/timeout-new.c b/test/timeout-new.c index 19c5ac3..6efcfb4 100644 --- a/test/timeout-new.c +++ b/test/timeout-new.c @@ -53,14 +53,12 @@ static int test_return_before_timeout(struct io_uring *ring) struct io_uring_cqe *cqe; struct io_uring_sqe *sqe; int ret; + bool retried = false; struct __kernel_timespec ts; - sqe = io_uring_get_sqe(ring); - if (!sqe) { - fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__); - return 1; - } + msec_to_ts(&ts, TIMEOUT_MSEC); + sqe = io_uring_get_sqe(ring); io_uring_prep_nop(sqe); ret = io_uring_submit(ring); @@ -69,13 +67,21 @@ static int test_return_before_timeout(struct io_uring *ring) return 1; } - msec_to_ts(&ts, TIMEOUT_MSEC); +again: ret = io_uring_wait_cqe_timeout(ring, &cqe, &ts); - if (ret < 0) { + if (ret == -ETIME && (ring->flags & IORING_SETUP_SQPOLL) && !retried) { + /* + * there is a small chance SQPOLL hasn't been waked up yet, + * give it one more try. + */ + printf("warning: funky SQPOLL timing\n"); + sleep(1); + retried = true; + goto again; + } else if (ret < 0) { fprintf(stderr, "%s: timeout error: %d\n", __FUNCTION__, ret); return 1; } - io_uring_cqe_seen(ring, cqe); return 0; } -- 2.33.0