iouring: Fix min_timeout behaviour
PATCH 1/1 iouring: Fix min_timeout behaviour
The wakeup condition if a min timeout is present and has expired is that at least _one_ CQE was posted. Thus set the cq_tail target to ->cq_min_tail + 1. Without this commit a spurious wakeup can result in a premature wakeup because io_should_wake() will return true even if _no_ CQE was posted at all.
Tested by running the liburing testsuite with no regressions.
Additionally, tested by turning all calls to schedule() in io_uring/wait.c into calls to schedule_timeout(1) to force the spurious wakeups. With these spurious wakeups the min-timeout.t test fails before and passes after this commit.
--- io_uring/wait.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
io_uring/wait.c +1 -1
@@ -103,7 +103,7 @@ static enum hrtimer_restart io_cqring_min_timer_wakeup(struct hrtimer *timer) }/* any generated CQE posted past this time should wake us up */ - iowq->cq_tail = iowq->cq_min_tail; + iowq->cq_tail = iowq->cq_min_tail +1 ;hrtimer_update_function (&iowq->t, io_cqring_timer_wakeup);hrtimer_set_expires (timer, iowq->timeout);
Signature · 1 line
2.43.0
Jens Axboe
maintainerQuoted 7 lines · Christian A. Ehrhardt
The wakeup condition if a min timeout is present and has expired is that at least _one_ CQE was posted. Thus set the
cq_tailtarget to ->cq_min_tail + 1. Without this commit a spurious wakeup can result in a premature wakeup becauseio_should_wake()will return true even if _no_ CQE was posted at all.
Quoted 6 lines
Tested by running the liburing testsuite with no regressions.
Additionally, tested by turning all calls to
schedule()inio_uring/wait.cinto calls toschedule_timeout(1)to force the spurious wakeups. With these spurious wakeups the min-timeout.t test fails before and passes after this commit.
Either this or the test case is broken, with or without the change you sent for the test case. I'll take a look, but it's definitely not passing as-is.
Signature · 1 line
Jens Axboe
Quoted 10 lines · Jens Axboe
Quoted 9 lines · Christian A. Ehrhardt
The wakeup condition if a min timeout is present and has expired is that at least _one_ CQE was posted. Thus set the
cq_tailtarget to ->cq_min_tail + 1. Without this commit a spurious wakeup can result in a premature wakeup becauseio_should_wake()will return true even if _no_ CQE was posted at all.Tested by running the liburing testsuite with no regressions.
Quoted 8 lines
Quoted 4 lines
Additionally, tested by turning all calls to
schedule()inio_uring/wait.cinto calls toschedule_timeout(1)to force the spurious wakeups. With these spurious wakeups the min-timeout.t test fails before and passes after this commit.Either this or the test case is broken, with or without the change you sent for the test case. I'll take a look, but it's definitely not passing as-is.
I also tested with the zig reproducer from
https://github.com/axboe/liburing/issues/1477
and with the spurious wakeups the reproducer shows the premature wakeup without any CQE posted, too. It seems that the missing "+1" is an oversight that got introduced between v1 and v2 of the commit that fixed the above issue.
Best regards,
Christian
Quoted 8 lines · Christian A. Ehrhardt
The wakeup condition if a min timeout is present and has expired is that at least _one_ CQE was posted. Thus set the
cq_tailtarget to ->cq_min_tail + 1. Without this commit a spurious wakeup can result in a premature wakeup becauseio_should_wake()will return true even if _no_ CQE was posted at all.[...]
Applied, thanks!
[1/1] iouring: Fix min_timeout behaviour
commit: 29fe1bd01b99714f3136f922230a643c2742cda9
Best regards,
Signature · 1 line
Jens Axboe