All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH liburing 0/2] timeout tests
@ 2021-10-03 11:10 Pavel Begunkov
  2021-10-03 11:10 ` [PATCH liburing 1/2] io_uring: test IORING_TIMEOUT_ETIME_SUCCESS Pavel Begunkov
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Pavel Begunkov @ 2021-10-03 11:10 UTC (permalink / raw)
  To: io-uring; +Cc: Jens Axboe, asml.silence

1/2 tests IORING_TIMEOUT_ETIME_SUCCESS,
2/2 works around a pretty rare test timeout false failures

Pavel Begunkov (2):
  io_uring: test IORING_TIMEOUT_ETIME_SUCCESS
  io_uring: fix SQPOLL timeout-new test

 src/include/liburing/io_uring.h |  1 +
 test/timeout-new.c              | 22 +++++++----
 test/timeout.c                  | 67 +++++++++++++++++++++++++++++++++
 3 files changed, 82 insertions(+), 8 deletions(-)

-- 
2.33.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH liburing 1/2] io_uring: test IORING_TIMEOUT_ETIME_SUCCESS
  2021-10-03 11:10 [PATCH liburing 0/2] timeout tests Pavel Begunkov
@ 2021-10-03 11:10 ` Pavel Begunkov
  2021-10-03 11:11 ` [PATCH liburing 2/2] io_uring: fix SQPOLL timeout-new test Pavel Begunkov
  2021-10-03 13:07 ` [PATCH liburing 0/2] timeout tests Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Pavel Begunkov @ 2021-10-03 11:10 UTC (permalink / raw)
  To: io-uring; +Cc: Jens Axboe, asml.silence

Make sure we don't fail links on ETIME when IORING_TIMEOUT_ETIME_SUCCESS
is set.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 src/include/liburing/io_uring.h |  1 +
 test/timeout.c                  | 67 +++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+)

diff --git a/src/include/liburing/io_uring.h b/src/include/liburing/io_uring.h
index 7aa43fc..61683bd 100644
--- a/src/include/liburing/io_uring.h
+++ b/src/include/liburing/io_uring.h
@@ -162,6 +162,7 @@ enum {
 #define IORING_TIMEOUT_BOOTTIME		(1U << 2)
 #define IORING_TIMEOUT_REALTIME		(1U << 3)
 #define IORING_LINK_TIMEOUT_UPDATE	(1U << 4)
+#define IORING_TIMEOUT_ETIME_SUCCESS	(1U << 5)
 #define IORING_TIMEOUT_CLOCK_MASK	(IORING_TIMEOUT_BOOTTIME | IORING_TIMEOUT_REALTIME)
 #define IORING_TIMEOUT_UPDATE_MASK	(IORING_TIMEOUT_UPDATE | IORING_LINK_TIMEOUT_UPDATE)
 /*
diff --git a/test/timeout.c b/test/timeout.c
index 775063f..f8ba973 100644
--- a/test/timeout.c
+++ b/test/timeout.c
@@ -1267,6 +1267,67 @@ static int test_timeout_link_cancel(void)
 	return 0;
 }
 
+
+static int test_not_failing_links(void)
+{
+	struct io_uring ring;
+	struct io_uring_sqe *sqe;
+	struct io_uring_cqe *cqe;
+	struct __kernel_timespec ts;
+	int ret;
+
+	ret = io_uring_queue_init(8, &ring, 0);
+	if (ret) {
+		fprintf(stderr, "ring create failed: %d\n", ret);
+		return 1;
+	}
+
+	msec_to_ts(&ts, 1);
+	sqe = io_uring_get_sqe(&ring);
+	io_uring_prep_timeout(sqe, &ts, 0, IORING_TIMEOUT_ETIME_SUCCESS);
+	sqe->user_data = 1;
+	sqe->flags |= IOSQE_IO_LINK;
+
+	sqe = io_uring_get_sqe(&ring);
+	io_uring_prep_nop(sqe);
+	sqe->user_data = 2;
+
+	ret = io_uring_submit(&ring);
+	if (ret != 2) {
+		fprintf(stderr, "%s: sqe submit failed: %d\n", __FUNCTION__, ret);
+		return 1;
+	}
+
+	ret = io_uring_wait_cqe(&ring, &cqe);
+	if (ret < 0) {
+		fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret);
+		return 1;
+	} else if (cqe->user_data == 1 && cqe->res == -EINVAL) {
+		fprintf(stderr, "ETIME_SUCCESS is not supported, skip\n");
+		goto done;
+	} else if (cqe->res != -ETIME || cqe->user_data != 1) {
+		fprintf(stderr, "timeout failed %i %i\n", cqe->res,
+				(int)cqe->user_data);
+		return 1;
+	}
+	io_uring_cqe_seen(&ring, cqe);
+
+	ret = io_uring_wait_cqe(&ring, &cqe);
+	if (ret < 0) {
+		fprintf(stderr, "%s: wait completion %d\n", __FUNCTION__, ret);
+		return 1;
+	} else if (cqe->res || cqe->user_data != 2) {
+		fprintf(stderr, "nop failed %i %i\n", cqe->res,
+				(int)cqe->user_data);
+		return 1;
+	}
+done:
+	io_uring_cqe_seen(&ring, cqe);
+	io_uring_queue_exit(&ring);
+	return 0;
+}
+
+
 int main(int argc, char *argv[])
 {
 	struct io_uring ring, sqpoll_ring;
@@ -1450,6 +1511,12 @@ int main(int argc, char *argv[])
 		return ret;
 	}
 
+	ret = test_not_failing_links();
+	if (ret) {
+		fprintf(stderr, "test_not_failing_links failed\n");
+		return ret;
+	}
+
 	if (sqpoll)
 		io_uring_queue_exit(&sqpoll_ring);
 	return 0;
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH liburing 2/2] io_uring: fix SQPOLL timeout-new test
  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
  2021-10-03 13:07 ` [PATCH liburing 0/2] timeout tests Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Pavel Begunkov @ 2021-10-03 11:11 UTC (permalink / raw)
  To: io-uring; +Cc: Jens Axboe, asml.silence

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@gmail.com>
---
 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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH liburing 0/2] timeout tests
  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 ` [PATCH liburing 2/2] io_uring: fix SQPOLL timeout-new test Pavel Begunkov
@ 2021-10-03 13:07 ` Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2021-10-03 13:07 UTC (permalink / raw)
  To: Pavel Begunkov, io-uring

On 10/3/21 5:10 AM, Pavel Begunkov wrote:
> 1/2 tests IORING_TIMEOUT_ETIME_SUCCESS,
> 2/2 works around a pretty rare test timeout false failures

Applied, thanks.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-10-03 13:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH liburing 2/2] io_uring: fix SQPOLL timeout-new test Pavel Begunkov
2021-10-03 13:07 ` [PATCH liburing 0/2] timeout tests Jens Axboe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.