authorgravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2021-01-04 01:27:35+11:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-01-03 19:52:20-08:00
loge4c4a0a5f6374d6c1b2daabc52395bfc58583b2f
treec58917dcffde5846d0f6be33fd3e1c278a599c3e
parent53a0b7997d1ee51f1c93cb44e6ee967e244b0c7d

Improve uring definitions


2 files changed, 51 insertions(+), 10 deletions(-)

lib/std/os/bits/linux.zig+47-4
......@@ -1284,6 +1284,9 @@ pub const IORING_SETUP_CLAMP = 1 << 4;
12841284/// attach to existing wq
12851285pub const IORING_SETUP_ATTACH_WQ = 1 << 5;
12861286
1287/// start with ring disabled
1288pub const IORING_SETUP_R_DISABLED = 1 << 6;
1289
12871290pub const io_sqring_offsets = extern struct {
12881291 /// offset of ring head
12891292 head: u32,
......@@ -1430,6 +1433,11 @@ pub const io_uring_cqe = extern struct {
14301433 flags: u32,
14311434};
14321435
1436// io_uring_cqe.flags
1437
1438/// If set, the upper 16 bits are the buffer ID
1439pub const IORING_CQE_F_BUFFER = 1 << 0;
1440
14331441pub const IORING_OFF_SQ_RING = 0;
14341442pub const IORING_OFF_CQ_RING = 0x8000000;
14351443pub const IORING_OFF_SQES = 0x10000000;
......@@ -1439,7 +1447,7 @@ pub const IORING_ENTER_GETEVENTS = 1 << 0;
14391447pub const IORING_ENTER_SQ_WAKEUP = 1 << 1;
14401448
14411449// io_uring_register opcodes and arguments
1442pub const IORING_REGISTER = extern enum(u32) {
1450pub const IORING_REGISTER = extern enum(u8) {
14431451 REGISTER_BUFFERS,
14441452 UNREGISTER_BUFFERS,
14451453 REGISTER_FILES,
......@@ -1451,11 +1459,13 @@ pub const IORING_REGISTER = extern enum(u32) {
14511459 REGISTER_PROBE,
14521460 REGISTER_PERSONALITY,
14531461 UNREGISTER_PERSONALITY,
1462 REGISTER_RESTRICTIONS,
1463 REGISTER_ENABLE_RINGS,
14541464
14551465 _,
14561466};
14571467
1458pub const io_uring_files_update = struct {
1468pub const io_uring_files_update = extern struct {
14591469 offset: u32,
14601470 resv: u32,
14611471 fds: u64,
......@@ -1463,7 +1473,7 @@ pub const io_uring_files_update = struct {
14631473
14641474pub const IO_URING_OP_SUPPORTED = 1 << 0;
14651475
1466pub const io_uring_probe_op = struct {
1476pub const io_uring_probe_op = extern struct {
14671477 op: IORING_OP,
14681478
14691479 resv: u8,
......@@ -1474,7 +1484,7 @@ pub const io_uring_probe_op = struct {
14741484 resv2: u32,
14751485};
14761486
1477pub const io_uring_probe = struct {
1487pub const io_uring_probe = extern struct {
14781488 /// last opcode supported
14791489 last_op: IORING_OP,
14801490
......@@ -1487,6 +1497,39 @@ pub const io_uring_probe = struct {
14871497 // Followed by up to `ops_len` io_uring_probe_op structures
14881498};
14891499
1500pub const io_uring_restriction = extern struct {
1501 opcode: u16,
1502 arg: extern union {
1503 /// IORING_RESTRICTION_REGISTER_OP
1504 register_op: IORING_REGISTER,
1505
1506 /// IORING_RESTRICTION_SQE_OP
1507 sqe_op: IORING_OP,
1508
1509 /// IORING_RESTRICTION_SQE_FLAGS_*
1510 sqe_flags: u8,
1511 },
1512 resv: u8,
1513 resv2: u32[3],
1514};
1515
1516/// io_uring_restriction->opcode values
1517pub const IORING_RESTRICTION = extern enum(u8) {
1518 /// Allow an io_uring_register(2) opcode
1519 REGISTER_OP = 0,
1520
1521 /// Allow an sqe opcode
1522 SQE_OP = 1,
1523
1524 /// Allow sqe flags
1525 SQE_FLAGS_ALLOWED = 2,
1526
1527 /// Require sqe flags (these flags must be set on each submission)
1528 SQE_FLAGS_REQUIRED = 3,
1529
1530 _,
1531};
1532
14901533pub const utsname = extern struct {
14911534 sysname: [64:0]u8,
14921535 nodename: [64:0]u8,
lib/std/os/linux/io_uring.zig+4-6
......@@ -28,7 +28,7 @@ pub const IO_Uring = struct {
2828 /// call on how many entries the submission and completion queues will ultimately have,
2929 /// see https://github.com/torvalds/linux/blob/v5.8/fs/io_uring.c#L8027-L8050.
3030 /// Matches the interface of io_uring_queue_init() in liburing.
31 pub fn init(entries: u12, flags: u32) !IO_Uring {
31 pub fn init(entries: u13, flags: u32) !IO_Uring {
3232 var params = mem.zeroInit(io_uring_params, .{
3333 .flags = flags,
3434 .sq_thread_idle = 1000,
......@@ -39,17 +39,15 @@ pub const IO_Uring = struct {
3939 /// A powerful way to setup an io_uring, if you want to tweak io_uring_params such as submission
4040 /// queue thread cpu affinity or thread idle timeout (the kernel and our default is 1 second).
4141 /// `params` is passed by reference because the kernel needs to modify the parameters.
42 /// You may only set the `flags`, `sq_thread_cpu` and `sq_thread_idle` parameters.
43 /// Every other parameter belongs to the kernel and must be zeroed.
4442 /// Matches the interface of io_uring_queue_init_params() in liburing.
45 pub fn init_params(entries: u12, p: *io_uring_params) !IO_Uring {
43 pub fn init_params(entries: u13, p: *io_uring_params) !IO_Uring {
4644 if (entries == 0) return error.EntriesZero;
4745 if (!std.math.isPowerOfTwo(entries)) return error.EntriesNotPowerOfTwo;
4846
4947 assert(p.sq_entries == 0);
50 assert(p.cq_entries == 0);
48 assert(p.cq_entries == 0 or p.flags & linux.IORING_SETUP_CQSIZE != 0);
5149 assert(p.features == 0);
52 assert(p.wq_fd == 0);
50 assert(p.wq_fd == 0 or p.flags & linux.IORING_SETUP_ATTACH_WQ != 0);
5351 assert(p.resv[0] == 0);
5452 assert(p.resv[1] == 0);
5553 assert(p.resv[2] == 0);