| ... | ... | @@ -28,21 +28,11 @@ pub const IO_Uring = struct { |
| 28 | 28 | /// call on how many entries the submission and completion queues will ultimately have, |
| 29 | 29 | /// see https://github.com/torvalds/linux/blob/v5.8/fs/io_uring.c#L8027-L8050. |
| 30 | 30 | /// Matches the interface of io_uring_queue_init() in liburing. |
| 31 | | pub fn init(entries: u32, flags: u32) !IO_Uring { |
| 32 | | var params = io_uring_params { |
| 33 | | .sq_entries = 0, |
| 34 | | .cq_entries = 0, |
| 31 | pub fn init(entries: u12, flags: u32) !IO_Uring { |
| 32 | var params = mem.zeroInit(io_uring_params, .{ |
| 35 | 33 | .flags = flags, |
| 36 | | .sq_thread_cpu = 0, |
| 37 | | .sq_thread_idle = 1000, |
| 38 | | .features = 0, |
| 39 | | .wq_fd = 0, |
| 40 | | .resv = [_]u32{0} ** 3, |
| 41 | | .sq_off = undefined, |
| 42 | | .cq_off = undefined, |
| 43 | | }; |
| 44 | | // The kernel will zero the memory of the sq_off and cq_off structs in io_uring_create(), |
| 45 | | // see https://github.com/torvalds/linux/blob/v5.8/fs/io_uring.c#L7986-L8002. |
| 34 | .sq_thread_idle = 1000 |
| 35 | }); |
| 46 | 36 | return try IO_Uring.init_params(entries, &params); |
| 47 | 37 | } |
| 48 | 38 | |
| ... | ... | @@ -52,8 +42,10 @@ pub const IO_Uring = struct { |
| 52 | 42 | /// You may only set the `flags`, `sq_thread_cpu` and `sq_thread_idle` parameters. |
| 53 | 43 | /// Every other parameter belongs to the kernel and must be zeroed. |
| 54 | 44 | /// Matches the interface of io_uring_queue_init_params() in liburing. |
| 55 | | pub fn init_params(entries: u32, p: *io_uring_params) !IO_Uring { |
| 56 | | assert(entries >= 1 and entries <= 4096 and std.math.isPowerOfTwo(entries)); |
| 45 | pub fn init_params(entries: u12, p: *io_uring_params) !IO_Uring { |
| 46 | if (entries == 0) return error.EntriesZero; |
| 47 | if (!std.math.isPowerOfTwo(entries)) return error.EntriesNotPowerOfTwo; |
| 48 | |
| 57 | 49 | assert(p.sq_entries == 0); |
| 58 | 50 | assert(p.cq_entries == 0); |
| 59 | 51 | assert(p.features == 0); |
| ... | ... | @@ -684,6 +676,9 @@ test "structs and offsets" { |
| 684 | 676 | testing.expectEqual(0, linux.IORING_OFF_SQ_RING); |
| 685 | 677 | testing.expectEqual(0x8000000, linux.IORING_OFF_CQ_RING); |
| 686 | 678 | testing.expectEqual(0x10000000, linux.IORING_OFF_SQES); |
| 679 | |
| 680 | testing.expectError(error.EntriesZero, IO_Uring.init(0, 0)); |
| 681 | testing.expectError(error.EntriesNotPowerOfTwo, IO_Uring.init(3, 0)); |
| 687 | 682 | } |
| 688 | 683 | |
| 689 | 684 | test "queue_nop" { |