io_uring: add support for vectored futex waits
authorJens Axboe <axboe@kernel.dk>
Tue, 13 Jun 2023 01:04:32 +0000 (19:04 -0600)
committerJens Axboe <axboe@kernel.dk>
Mon, 11 Sep 2023 15:41:32 +0000 (09:41 -0600)
commitdf137dff93fc8f7d8fdef049531adb2f1fdc51bd
tree090f507bb5546b4d6026ed9c9c5409ca59b08141
parent4d71956ede24d7e63b01891d3029d5bebbdfaba1
io_uring: add support for vectored futex waits

This adds support for IORING_OP_FUTEX_WAITV, which allows registering a
notification for a number of futexes at once. If one of the futexes are
woken, then the request will complete with the index of the futex that got
woken as the result. This is identical to what the normal vectored futex
waitv operation does.

Use like IORING_OP_FUTEX_WAIT, except sqe->addr must now contain the a
pointer to a struct futex_waitv array, and sqe->off must now contain the
number of elements in that array.

For cancelations, FUTEX_WAITV does not rely on the futex_unqueue()
return value as we're dealing with multiple futexes. Instead, a separate
per io_uring request atomic is used to claim ownership of the request.

Waiting on N futexes could be done with IORING_OP_FUTEX_WAIT as well,
but that punts a lot of the work to the application:

1) Application would need to submit N IORING_OP_FUTEX_WAIT requests,
   rather than just a single IORING_OP_FUTEX_WAITV.

2) When one futex is woken, application would need to cancel the
   remaining N-1 requests that didn't trigger.

While this is of course doable, having a single vectored futex wait
makes for much simpler application code.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
include/uapi/linux/io_uring.h
io_uring/futex.c
io_uring/futex.h
io_uring/opdef.c