mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 06:44:00 -04:00
The io_uring_enter() has a fixed order of execution: it submits requests, waits for completions, and returns to the user. Allow to optionally replace it with a custom loop driven by a callback called loop_step. The basic requirements to the callback is that it should be able to submit requests, wait for completions, parse them and repeat. Most of the communication including parameter passing can be implemented via shared memory. The callback should return IOU_LOOP_CONTINUE to continue execution or IOU_LOOP_STOP to return to the user space. Note that the kernel may decide to prematurely terminate it as well, e.g. in case the process was signalled or killed. The hook takes a structure with parameters. It can be used to ask the kernel to wait for CQEs by setting cq_wait_idx to the CQE index it wants to wait for. Spurious wake ups are possible and even likely, the callback is expected to handle it. There will be more parameters in the future like timeout. It can be used with kernel callbacks, for example, as a slow path deprecation mechanism overwiting SQEs and emulating the wanted behaviour, however it's more useful together with BPF programs implemented in following patches. Note that keeping it separately from the normal io_uring wait loop makes things much simpler and cleaner. It keeps it in one place instead of spreading a bunch of checks in different places including disabling the submission path. It holds the lock by default, which is a better fit for BPF synchronisation and the loop execution model. It nicely avoids existing quirks like forced wake ups on timeout request completion. And it should be easier to implement new features. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://patch.msgid.link/a2d369aa1c9dd23ad7edac9220cffc563abcaed6.1772109579.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
28 lines
463 B
C
28 lines
463 B
C
// SPDX-License-Identifier: GPL-2.0
|
|
#ifndef IOU_LOOP_H
|
|
#define IOU_LOOP_H
|
|
|
|
#include <linux/io_uring_types.h>
|
|
|
|
struct iou_loop_params {
|
|
/*
|
|
* The CQE index to wait for. Only serves as a hint and can still be
|
|
* woken up earlier.
|
|
*/
|
|
__u32 cq_wait_idx;
|
|
};
|
|
|
|
enum {
|
|
IOU_LOOP_CONTINUE = 0,
|
|
IOU_LOOP_STOP,
|
|
};
|
|
|
|
static inline bool io_has_loop_ops(struct io_ring_ctx *ctx)
|
|
{
|
|
return data_race(ctx->loop_step);
|
|
}
|
|
|
|
int io_run_loop(struct io_ring_ctx *ctx);
|
|
|
|
#endif
|