From: Pavel Begunkov <[email protected]>
To: [email protected]
Cc: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH liburing 3/3] tests: lazy pollwq activation for disabled rings
Date: Mon, 16 Jan 2023 16:46:09 +0000 [thread overview]
Message-ID: <befc85abe49e87880de9575327a73ff634362bcc.1673886955.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>
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
next prev parent reply other threads:[~2023-01-16 17:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2023-01-16 17:49 ` [PATCH liburing 0/3] test lazy poll wq activation 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=befc85abe49e87880de9575327a73ff634362bcc.1673886955.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