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;...@@ -1284,6 +1284,9 @@ pub const IORING_SETUP_CLAMP = 1 << 4;
1284/// attach to existing wq1284/// attach to existing wq
1285pub const IORING_SETUP_ATTACH_WQ = 1 << 5;1285pub const IORING_SETUP_ATTACH_WQ = 1 << 5;
12861286
1287/// start with ring disabled
1288pub const IORING_SETUP_R_DISABLED = 1 << 6;
1289
1287pub const io_sqring_offsets = extern struct {1290pub const io_sqring_offsets = extern struct {
1288 /// offset of ring head1291 /// offset of ring head
1289 head: u32,1292 head: u32,
...@@ -1430,6 +1433,11 @@ pub const io_uring_cqe = extern struct {...@@ -1430,6 +1433,11 @@ pub const io_uring_cqe = extern struct {
1430 flags: u32,1433 flags: u32,
1431};1434};
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
1433pub const IORING_OFF_SQ_RING = 0;1441pub const IORING_OFF_SQ_RING = 0;
1434pub const IORING_OFF_CQ_RING = 0x8000000;1442pub const IORING_OFF_CQ_RING = 0x8000000;
1435pub const IORING_OFF_SQES = 0x10000000;1443pub const IORING_OFF_SQES = 0x10000000;
...@@ -1439,7 +1447,7 @@ pub const IORING_ENTER_GETEVENTS = 1 << 0;...@@ -1439,7 +1447,7 @@ pub const IORING_ENTER_GETEVENTS = 1 << 0;
1439pub const IORING_ENTER_SQ_WAKEUP = 1 << 1;1447pub const IORING_ENTER_SQ_WAKEUP = 1 << 1;
14401448
1441// io_uring_register opcodes and arguments1449// io_uring_register opcodes and arguments
1442pub const IORING_REGISTER = extern enum(u32) {1450pub const IORING_REGISTER = extern enum(u8) {
1443 REGISTER_BUFFERS,1451 REGISTER_BUFFERS,
1444 UNREGISTER_BUFFERS,1452 UNREGISTER_BUFFERS,
1445 REGISTER_FILES,1453 REGISTER_FILES,
...@@ -1451,11 +1459,13 @@ pub const IORING_REGISTER = extern enum(u32) {...@@ -1451,11 +1459,13 @@ pub const IORING_REGISTER = extern enum(u32) {
1451 REGISTER_PROBE,1459 REGISTER_PROBE,
1452 REGISTER_PERSONALITY,1460 REGISTER_PERSONALITY,
1453 UNREGISTER_PERSONALITY,1461 UNREGISTER_PERSONALITY,
1462 REGISTER_RESTRICTIONS,
1463 REGISTER_ENABLE_RINGS,
14541464
1455 _,1465 _,
1456};1466};
14571467
1458pub const io_uring_files_update = struct {1468pub const io_uring_files_update = extern struct {
1459 offset: u32,1469 offset: u32,
1460 resv: u32,1470 resv: u32,
1461 fds: u64,1471 fds: u64,
...@@ -1463,7 +1473,7 @@ pub const io_uring_files_update = struct {...@@ -1463,7 +1473,7 @@ pub const io_uring_files_update = struct {
14631473
1464pub const IO_URING_OP_SUPPORTED = 1 << 0;1474pub const IO_URING_OP_SUPPORTED = 1 << 0;
14651475
1466pub const io_uring_probe_op = struct {1476pub const io_uring_probe_op = extern struct {
1467 op: IORING_OP,1477 op: IORING_OP,
14681478
1469 resv: u8,1479 resv: u8,
...@@ -1474,7 +1484,7 @@ pub const io_uring_probe_op = struct {...@@ -1474,7 +1484,7 @@ pub const io_uring_probe_op = struct {
1474 resv2: u32,1484 resv2: u32,
1475};1485};
14761486
1477pub const io_uring_probe = struct {1487pub const io_uring_probe = extern struct {
1478 /// last opcode supported1488 /// last opcode supported
1479 last_op: IORING_OP,1489 last_op: IORING_OP,
14801490
...@@ -1487,6 +1497,39 @@ pub const io_uring_probe = struct {...@@ -1487,6 +1497,39 @@ pub const io_uring_probe = struct {
1487 // Followed by up to `ops_len` io_uring_probe_op structures1497 // Followed by up to `ops_len` io_uring_probe_op structures
1488};1498};
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
1490pub const utsname = extern struct {1533pub const utsname = extern struct {
1491 sysname: [64:0]u8,1534 sysname: [64:0]u8,
1492 nodename: [64:0]u8,1535 nodename: [64:0]u8,
lib/std/os/linux/io_uring.zig+4-6
...@@ -28,7 +28,7 @@ pub const IO_Uring = struct {...@@ -28,7 +28,7 @@ pub const IO_Uring = struct {
28 /// call on how many entries the submission and completion queues will ultimately have,28 /// call on how many entries the submission and completion queues will ultimately have,
29 /// see https://github.com/torvalds/linux/blob/v5.8/fs/io_uring.c#L8027-L8050.29 /// see https://github.com/torvalds/linux/blob/v5.8/fs/io_uring.c#L8027-L8050.
30 /// Matches the interface of io_uring_queue_init() in liburing.30 /// 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 {
32 var params = mem.zeroInit(io_uring_params, .{32 var params = mem.zeroInit(io_uring_params, .{
33 .flags = flags,33 .flags = flags,
34 .sq_thread_idle = 1000,34 .sq_thread_idle = 1000,
...@@ -39,17 +39,15 @@ pub const IO_Uring = struct {...@@ -39,17 +39,15 @@ pub const IO_Uring = struct {
39 /// A powerful way to setup an io_uring, if you want to tweak io_uring_params such as submission39 /// A powerful way to setup an io_uring, if you want to tweak io_uring_params such as submission
40 /// queue thread cpu affinity or thread idle timeout (the kernel and our default is 1 second).40 /// queue thread cpu affinity or thread idle timeout (the kernel and our default is 1 second).
41 /// `params` is passed by reference because the kernel needs to modify the parameters.41 /// `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.
44 /// Matches the interface of io_uring_queue_init_params() in liburing.42 /// 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 {
46 if (entries == 0) return error.EntriesZero;44 if (entries == 0) return error.EntriesZero;
47 if (!std.math.isPowerOfTwo(entries)) return error.EntriesNotPowerOfTwo;45 if (!std.math.isPowerOfTwo(entries)) return error.EntriesNotPowerOfTwo;
4846
49 assert(p.sq_entries == 0);47 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);
51 assert(p.features == 0);49 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);
53 assert(p.resv[0] == 0);51 assert(p.resv[0] == 0);
54 assert(p.resv[1] == 0);52 assert(p.resv[1] == 0);
55 assert(p.resv[2] == 0);53 assert(p.resv[2] == 0);