public inbox for [email protected]
 help / color / mirror / Atom feed
From: Pavel Begunkov <[email protected]>
To: [email protected]
Cc: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH liburing 2/2] io_uring: fix SQPOLL timeout-new test
Date: Sun,  3 Oct 2021 12:11:00 +0100	[thread overview]
Message-ID: <5faf8ade7e161931d76a47b809650e68a1b361ba.1633259449.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>

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 <[email protected]>
---
 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


  parent reply	other threads:[~2021-10-03 11:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-03 11:10 [PATCH liburing 0/2] timeout tests Pavel Begunkov
2021-10-03 11:10 ` [PATCH liburing 1/2] io_uring: test IORING_TIMEOUT_ETIME_SUCCESS Pavel Begunkov
2021-10-03 11:11 ` Pavel Begunkov [this message]
2021-10-03 13:07 ` [PATCH liburing 0/2] timeout tests Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5faf8ade7e161931d76a47b809650e68a1b361ba.1633259449.git.asml.silence@gmail.com \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox