authorgravatar for vincent@rischmann.frVincent Rischmann <vincent@rischmann.fr> 2022-07-23 16:21:17+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-07-23 17:21:17+03:00
logd99c32c2e193847d9d2cd1bbbef8e6ca157dde14
tree0f95ecb96fab4306bc3efaa95ab8c88dee1528a8
parent72c60acd5dd9172c648cb3c5a4b51224ebea33f2
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

io_uring: add new flags and opcodes


1 files changed, 111 insertions(+), 3 deletions(-)

lib/std/os/linux.zig+111-3
......@@ -3496,6 +3496,12 @@ pub const IORING_FEAT_RW_CUR_POS = 1 << 3;
34963496pub const IORING_FEAT_CUR_PERSONALITY = 1 << 4;
34973497pub const IORING_FEAT_FAST_POLL = 1 << 5;
34983498pub const IORING_FEAT_POLL_32BITS = 1 << 6;
3499pub const IORING_FEAT_SQPOLL_NONFIXED = 1 << 7;
3500pub const IORING_FEAT_EXT_ARG = 1 << 8;
3501pub const IORING_FEAT_NATIVE_WORKERS = 1 << 9;
3502pub const IORING_FEAT_RSRC_TAGS = 1 << 10;
3503pub const IORING_FEAT_CQE_SKIP = 1 << 11;
3504pub const IORING_FEAT_LINKED_FILE = 1 << 12;
34993505
35003506// io_uring_params.flags
35013507
......@@ -3520,6 +3526,26 @@ pub const IORING_SETUP_ATTACH_WQ = 1 << 5;
35203526/// start with ring disabled
35213527pub const IORING_SETUP_R_DISABLED = 1 << 6;
35223528
3529/// continue submit on error
3530pub const IORING_SETUP_SUBMIT_ALL = 1 << 7;
3531
3532/// Cooperative task running. When requests complete, they often require
3533/// forcing the submitter to transition to the kernel to complete. If this
3534/// flag is set, work will be done when the task transitions anyway, rather
3535/// than force an inter-processor interrupt reschedule. This avoids interrupting
3536/// a task running in userspace, and saves an IPI.
3537pub const IORING_SETUP_COOP_TASKRUN = 1 << 8;
3538
3539/// If COOP_TASKRUN is set, get notified if task work is available for
3540/// running and a kernel transition would be needed to run it. This sets
3541/// IORING_SQ_TASKRUN in the sq ring flags. Not valid with COOP_TASKRUN.
3542pub const IORING_SETUP_TASKRUN_FLAG = 1 << 9;
3543
3544/// SQEs are 128 byte
3545pub const IORING_SETUP_SQE128 = 1 << 10;
3546/// CQEs are 32 byte
3547pub const IORING_SETUP_CQE32 = 1 << 11;
3548
35233549pub const io_sqring_offsets = extern struct {
35243550 /// offset of ring head
35253551 head: u32,
......@@ -3550,9 +3576,10 @@ pub const io_sqring_offsets = extern struct {
35503576
35513577/// needs io_uring_enter wakeup
35523578pub const IORING_SQ_NEED_WAKEUP = 1 << 0;
3553
35543579/// kernel has cqes waiting beyond the cq ring
35553580pub const IORING_SQ_CQ_OVERFLOW = 1 << 1;
3581/// task should enter the kernel
3582pub const IORING_SQ_TASKRUN = 1 << 2;
35563583
35573584pub const io_cqring_offsets = extern struct {
35583585 head: u32,
......@@ -3587,6 +3614,7 @@ pub const IOSQE_BIT = enum(u8) {
35873614 IO_HARDLINK,
35883615 ASYNC,
35893616 BUFFER_SELECT,
3617 CQE_SKIP_SUCCESS,
35903618
35913619 _,
35923620};
......@@ -3611,6 +3639,10 @@ pub const IOSQE_ASYNC = 1 << @enumToInt(IOSQE_BIT.ASYNC);
36113639/// select buffer from buf_group
36123640pub const IOSQE_BUFFER_SELECT = 1 << @enumToInt(IOSQE_BIT.BUFFER_SELECT);
36133641
3642/// don't post CQE if request succeeded
3643/// Available since Linux 5.17
3644pub const IOSQE_CQE_SKIP_SUCCESS = 1 << @enumToInt(IOSQE_BIT.CQE_SKIP_SUCCESS);
3645
36143646pub const IORING_OP = enum(u8) {
36153647 NOP,
36163648 READV,
......@@ -3656,11 +3688,51 @@ pub const IORING_OP = enum(u8) {
36563688 _,
36573689};
36583690
3659// io_uring_sqe.fsync_flags
3691// io_uring_sqe.fsync_flags (rw_flags in the Zig struct)
36603692pub const IORING_FSYNC_DATASYNC = 1 << 0;
36613693
3662// io_uring_sqe.timeout_flags
3694// io_uring_sqe.timeout_flags (rw_flags in the Zig struct)
36633695pub const IORING_TIMEOUT_ABS = 1 << 0;
3696pub const IORING_TIMEOUT_UPDATE = 1 << 1; // Available since Linux 5.11
3697pub const IORING_TIMEOUT_BOOTTIME = 1 << 2; // Available since Linux 5.15
3698pub const IORING_TIMEOUT_REALTIME = 1 << 3; // Available since Linux 5.15
3699pub const IORING_LINK_TIMEOUT_UPDATE = 1 << 4; // Available since Linux 5.15
3700pub const IORING_TIMEOUT_ETIME_SUCCESS = 1 << 5; // Available since Linux 5.16
3701pub const IORING_TIMEOUT_CLOCK_MASK = IORING_TIMEOUT_BOOTTIME | IORING_TIMEOUT_REALTIME;
3702pub const IORING_TIMEOUT_UPDATE_MASK = IORING_TIMEOUT_UPDATE | IORING_LINK_TIMEOUT_UPDATE;
3703
3704// io_uring_sqe.splice_flags (rw_flags in the Zig struct)
3705// extends splice(2) flags
3706pub const IORING_SPLICE_F_FD_IN_FIXED = 1 << 31;
3707
3708// POLL_ADD flags.
3709// Note that since sqe->poll_events (rw_flags in the Zig struct) is the flag space, the command flags for POLL_ADD are stored in sqe->len.
3710
3711/// Multishot poll. Sets IORING_CQE_F_MORE if the poll handler will continue to report CQEs on behalf of the same SQE.
3712pub const IORING_POLL_ADD_MULTI = 1 << 0;
3713/// Update existing poll request, matching sqe->addr as the old user_data field.
3714pub const IORING_POLL_UPDATE_EVENTS = 1 << 1;
3715pub const IORING_POLL_UPDATE_USER_DATA = 1 << 2;
3716
3717// ASYNC_CANCEL flags.
3718
3719/// Cancel all requests that match the given key
3720pub const IORING_ASYNC_CANCEL_ALL = 1 << 0;
3721/// Key off 'fd' for cancelation rather than the request 'user_data'.
3722pub const IORING_ASYNC_CANCEL_FD = 1 << 1;
3723/// Match any request
3724pub const IORING_ASYNC_CANCEL_ANY = 1 << 2;
3725
3726// send/sendmsg and recv/recvmsg flags (sqe->ioprio)
3727
3728/// If set, instead of first attempting to send or receive and arm poll if that yields an -EAGAIN result,
3729/// arm poll upfront and skip the initial transfer attempt.
3730pub const IORING_RECVSEND_POLL_FIRST = 1 << 0;
3731/// Multishot recv. Sets IORING_CQE_F_MORE if the handler will continue to report CQEs on behalf of the same SQE.
3732pub const IORING_RECV_MULTISHOT = 1 << 1;
3733
3734/// accept flags stored in sqe->ioprio
3735pub const IORING_ACCEPT_MULTISHOT = 1 << 0;
36643736
36653737// IO completion data structure (Completion Queue Entry)
36663738pub const io_uring_cqe = extern struct {
......@@ -3683,7 +3755,13 @@ pub const io_uring_cqe = extern struct {
36833755
36843756/// If set, the upper 16 bits are the buffer ID
36853757pub const IORING_CQE_F_BUFFER = 1 << 0;
3758/// If set, parent SQE will generate more CQE entries.
3759/// Avaiable since Linux 5.13.
3760pub const IORING_CQE_F_MORE = 1 << 1;
3761/// If set, more data to read after socket recv
3762pub const IORING_CQE_F_SOCK_NONEMPTY = 1 << 2;
36863763
3764/// Magic offsets for the application to mmap the data it needs
36873765pub const IORING_OFF_SQ_RING = 0;
36883766pub const IORING_OFF_CQ_RING = 0x8000000;
36893767pub const IORING_OFF_SQES = 0x10000000;
......@@ -3691,6 +3769,9 @@ pub const IORING_OFF_SQES = 0x10000000;
36913769// io_uring_enter flags
36923770pub const IORING_ENTER_GETEVENTS = 1 << 0;
36933771pub const IORING_ENTER_SQ_WAKEUP = 1 << 1;
3772pub const IORING_ENTER_SQ_WAIT = 1 << 2;
3773pub const IORING_ENTER_EXT_ARG = 1 << 3;
3774pub const IORING_ENTER_REGISTERED_RING = 1 << 4;
36943775
36953776// io_uring_register opcodes and arguments
36963777pub const IORING_REGISTER = enum(u8) {
......@@ -3708,6 +3789,33 @@ pub const IORING_REGISTER = enum(u8) {
37083789 REGISTER_RESTRICTIONS,
37093790 REGISTER_ENABLE_RINGS,
37103791
3792 // extended with tagging
3793 IORING_REGISTER_FILES2,
3794 IORING_REGISTER_FILES_UPDATE2,
3795 IORING_REGISTER_BUFFERS2,
3796 IORING_REGISTER_BUFFERS_UPDATE,
3797
3798 // set/clear io-wq thread affinities
3799 IORING_REGISTER_IOWQ_AFF,
3800 IORING_UNREGISTER_IOWQ_AFF,
3801
3802 // set/get max number of io-wq workers
3803 IORING_REGISTER_IOWQ_MAX_WORKERS,
3804
3805 // register/unregister io_uring fd with the ring
3806 IORING_REGISTER_RING_FDS,
3807 IORING_UNREGISTER_RING_FDS,
3808
3809 // register ring based provide buffer group
3810 IORING_REGISTER_PBUF_RING,
3811 IORING_UNREGISTER_PBUF_RING,
3812
3813 // sync cancelation API
3814 IORING_REGISTER_SYNC_CANCEL,
3815
3816 // register a range of fixed file slots for automatic slot allocation
3817 IORING_REGISTER_FILE_ALLOC_RANGE,
3818
37113819 _,
37123820};
37133821