Skip to content

Commit

Permalink
Merge pull request #6356 from jorangreef/io_uring
Browse files Browse the repository at this point in the history
std: add io_uring library
  • Loading branch information
andrewrk authored Oct 29, 2020
2 parents f51ccf0 + e9ba12f commit a41c0b6
Show file tree
Hide file tree
Showing 4 changed files with 1,243 additions and 37 deletions.
58 changes: 21 additions & 37 deletions lib/std/os/bits/linux.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,8 @@ pub const IORING_FEAT_NODROP = 1 << 1;
pub const IORING_FEAT_SUBMIT_STABLE = 1 << 2;
pub const IORING_FEAT_RW_CUR_POS = 1 << 3;
pub const IORING_FEAT_CUR_PERSONALITY = 1 << 4;
pub const IORING_FEAT_FAST_POLL = 1 << 5;
pub const IORING_FEAT_POLL_32BITS = 1 << 6;

// io_uring_params.flags

Expand Down Expand Up @@ -1252,6 +1254,9 @@ pub const io_sqring_offsets = extern struct {
/// needs io_uring_enter wakeup
pub const IORING_SQ_NEED_WAKEUP = 1 << 0;

/// kernel has cqes waiting beyond the cq ring
pub const IORING_SQ_CQ_OVERFLOW = 1 << 1;

pub const io_cqring_offsets = extern struct {
head: u32,
tail: u32,
Expand All @@ -1263,48 +1268,19 @@ pub const io_cqring_offsets = extern struct {
};

pub const io_uring_sqe = extern struct {
pub const union1 = extern union {
off: u64,
addr2: u64,
};

pub const union2 = extern union {
rw_flags: kernel_rwf,
fsync_flags: u32,
poll_events: u16,
sync_range_flags: u32,
msg_flags: u32,
timeout_flags: u32,
accept_flags: u32,
cancel_flags: u32,
open_flags: u32,
statx_flags: u32,
fadvise_flags: u32,
};

pub const union3 = extern union {
struct1: extern struct {
/// index into fixed buffers, if used
buf_index: u16,

/// personality to use, if used
personality: u16,
},
__pad2: [3]u64,
};
opcode: IORING_OP,
flags: u8,
ioprio: u16,
fd: i32,

union1: union1,
off: u64,
addr: u64,
len: u32,

union2: union2,
rw_flags: u32,
user_data: u64,

union3: union3,
buf_index: u16,
personality: u16,
splice_fd_in: i32,
__pad2: [2]u64
};

pub const IOSQE_BIT = extern enum(u8) {
Expand All @@ -1313,7 +1289,8 @@ pub const IOSQE_BIT = extern enum(u8) {
IO_LINK,
IO_HARDLINK,
ASYNC,

BUFFER_SELECT,

_,
};

Expand All @@ -1332,7 +1309,10 @@ pub const IOSQE_IO_LINK = 1 << @enumToInt(IOSQE_BIT.IO_LINK);
pub const IOSQE_IO_HARDLINK = 1 << @enumToInt(IOSQE_BIT.IO_HARDLINK);

/// always go async
pub const IOSQE_ASYNC = 1 << IOSQE_BIT.ASYNC;
pub const IOSQE_ASYNC = 1 << @enumToInt(IOSQE_BIT.ASYNC);

/// select buffer from buf_group
pub const IOSQE_BUFFER_SELECT = 1 << @enumToInt(IOSQE_BIT.BUFFER_SELECT);

pub const IORING_OP = extern enum(u8) {
NOP,
Expand Down Expand Up @@ -1365,6 +1345,10 @@ pub const IORING_OP = extern enum(u8) {
RECV,
OPENAT2,
EPOLL_CTL,
SPLICE,
PROVIDE_BUFFERS,
REMOVE_BUFFERS,
TEE,

_,
};
Expand Down
3 changes: 3 additions & 0 deletions lib/std/os/bits/linux/mips.zig
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,9 @@ pub const SYS = extern enum(usize) {
statx = Linux + 366,
rseq = Linux + 367,
io_pgetevents = Linux + 368,
io_uring_setup = Linux + 425,
io_uring_enter = Linux + 426,
io_uring_register = Linux + 427,
openat2 = Linux + 437,
pidfd_getfd = Linux + 438,

Expand Down
1 change: 1 addition & 0 deletions lib/std/os/linux.zig
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub usingnamespace switch (builtin.arch) {
pub usingnamespace @import("bits.zig");
pub const tls = @import("linux/tls.zig");
pub const BPF = @import("linux/bpf.zig");
pub usingnamespace @import("linux/io_uring.zig");

/// Set by startup code, used by `getauxval`.
pub var elf_aux_maybe: ?[*]std.elf.Auxv = null;
Expand Down
Loading

0 comments on commit a41c0b6

Please sign in to comment.