Skip to content

Commit

Permalink
test/sqpoll-sleep: ensure WAKEUP flag is read correctly
Browse files Browse the repository at this point in the history
Rewrite this test to be a bit better:

- Read wakeup properly with IO_URING_READ_ONCE()
- Check if wakeup has been seen
- Check elapsed time before wakeup flag is seen
- Prepare and push a nop request first, to ensure the thread is up
  and running

Hopefully this will fix the quirks with this test.

Link: #1207
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
axboe committed Nov 1, 2024
1 parent 7ef530b commit 8202c46
Showing 1 changed file with 40 additions and 9 deletions.
49 changes: 40 additions & 9 deletions test/sqpoll-sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,63 @@
int main(int argc, char *argv[])
{
struct io_uring_params p = {};
struct io_uring_sqe *sqe;
struct io_uring_cqe *cqe;
struct timeval tv;
struct io_uring ring;
unsigned long elapsed;
bool seen_wakeup;
int ret;

if (argc > 1)
return 0;
return T_EXIT_SKIP;

p.flags = IORING_SETUP_SQPOLL;
p.sq_thread_idle = 10000;
p.sq_thread_idle = 100;

ret = io_uring_queue_init_params(1, &ring, &p);
if (ret) {
if (geteuid()) {
printf("%s: skipped, not root\n", argv[0]);
return 0;
return T_EXIT_SKIP;
}
fprintf(stderr, "queue_init=%d\n", ret);
return 1;
return T_EXIT_FAIL;
}

sqe = io_uring_get_sqe(&ring);
io_uring_prep_nop(sqe);
io_uring_submit(&ring);

ret = io_uring_wait_cqe(&ring, &cqe);
if (ret) {
fprintf(stderr, "wait_cqe: %d\n", ret);
return T_EXIT_FAIL;
}
io_uring_cqe_seen(&ring, cqe);

elapsed = 0;
seen_wakeup = false;
gettimeofday(&tv, NULL);
do {
usleep(100000);
if ((*ring.sq.kflags) & IORING_SQ_NEED_WAKEUP)
return 0;
} while (mtime_since_now(&tv) < 1000);
usleep(100);
if (IO_URING_READ_ONCE(*ring.sq.kflags) & IORING_SQ_NEED_WAKEUP) {
seen_wakeup = true;
break;
}
elapsed = mtime_since_now(&tv);
} while (elapsed < 1000);

if (!seen_wakeup) {
fprintf(stderr, "SQPOLL didn't flag wakeup\n");
return T_EXIT_FAIL;
}

/* should be around 100 msec */
if (elapsed < 90 || elapsed > 110) {
fprintf(stderr, "SQPOLL wakeup timing off %lu\n", elapsed);
return T_EXIT_FAIL;
}

return 1;
return T_EXIT_PASS;
}

0 comments on commit 8202c46

Please sign in to comment.