authorgravatar for joran@ronomon.comJoran Dirk Greef <joran@ronomon.com> 2020-09-20 15:54:31+02:00
committergravatar for joran@ronomon.comJoran Dirk Greef <joran@ronomon.com> 2020-09-20 15:54:31+02:00
loge51728a1b4b68cbfbd5aae47330a7a43563fce0e
treeb41d5aad18683ef5e713416dc0f4d94add516fd1
parent40293a0643419b7b52438861215c57b32669656f

Make enter(), flush_sq(), sq_ring_needs_enter(), cq_ring_needs_flush() public

These will also be needed by any custom helpers

1 files changed, 13 insertions(+), 14 deletions(-)

lib/std/os/linux/io_uring.zig+13-14
......@@ -18,7 +18,7 @@ comptime {
1818 assert(@sizeOf(io_uring_params) == 120);
1919 assert(@sizeOf(io_uring_sqe) == 64);
2020 assert(@sizeOf(io_uring_cqe) == 16);
21
21
2222 assert(linux.IORING_OFF_SQ_RING == 0);
2323 assert(linux.IORING_OFF_CQ_RING == 0x8000000);
2424 assert(linux.IORING_OFF_SQES == 0x10000000);
......@@ -192,9 +192,9 @@ pub const IO_Uring = struct {
192192 return submitted;
193193 }
194194
195 // Tell the kernel we have submitted SQEs and/or want to wait for CQEs.
196 // Returns the number of SQEs submitted.
197 fn enter(self: *IO_Uring, to_submit: u32, min_complete: u32, flags: u32) !u32 {
195 /// Tell the kernel we have submitted SQEs and/or want to wait for CQEs.
196 /// Returns the number of SQEs submitted.
197 pub fn enter(self: *IO_Uring, to_submit: u32, min_complete: u32, flags: u32) !u32 {
198198 assert(self.fd >= 0);
199199 const res = linux.io_uring_enter(self.fd, to_submit, min_complete, flags, null);
200200 switch (linux.getErrno(res)) {
......@@ -225,12 +225,12 @@ pub const IO_Uring = struct {
225225 return @truncate(u32, res);
226226 }
227227
228 // Sync internal state with kernel ring state on the SQ side.
229 // Returns the number of all pending events in the SQ ring, for the shared ring.
230 // This return value includes previously flushed SQEs, as per liburing.
231 // The reasoning for this is to suggest that an io_uring_enter() call is needed rather than not.
232 // Matches the implementation of __io_uring_flush_sq() in liburing.
233 fn flush_sq(self: *IO_Uring) u32 {
228 /// Sync internal state with kernel ring state on the SQ side.
229 /// Returns the number of all pending events in the SQ ring, for the shared ring.
230 /// This return value includes previously flushed SQEs, as per liburing.
231 /// The rationale is to suggest that an io_uring_enter() call is needed rather than not.
232 /// Matches the implementation of __io_uring_flush_sq() in liburing.
233 pub fn flush_sq(self: *IO_Uring) u32 {
234234 if (self.sq.sqe_head != self.sq.sqe_tail) {
235235 // Fill in SQEs that we have queued up, adding them to the kernel ring.
236236 const to_submit = self.sq.sqe_tail -% self.sq.sqe_head;
......@@ -252,7 +252,7 @@ pub const IO_Uring = struct {
252252 /// or if IORING_SQ_NEED_WAKEUP is set and the SQ thread must be explicitly awakened.
253253 /// For the latter case, we set the SQ thread wakeup flag.
254254 /// Matches the implementation of sq_ring_needs_enter() in liburing.
255 fn sq_ring_needs_enter(self: *IO_Uring, submitted: u32, flags: *u32) bool {
255 pub fn sq_ring_needs_enter(self: *IO_Uring, submitted: u32, flags: *u32) bool {
256256 assert(flags.* == 0);
257257 if ((self.flags & linux.IORING_SETUP_SQPOLL) == 0 and submitted > 0) return true;
258258 if ((@atomicLoad(u32, self.sq.flags, .Unordered) & linux.IORING_SQ_NEED_WAKEUP) != 0) {
......@@ -326,8 +326,8 @@ pub const IO_Uring = struct {
326326 return cqes[0];
327327 }
328328
329 // Matches the implementation of cq_ring_needs_flush() in liburing.
330 fn cq_ring_needs_flush(self: *IO_Uring) bool {
329 /// Matches the implementation of cq_ring_needs_flush() in liburing.
330 pub fn cq_ring_needs_flush(self: *IO_Uring) bool {
331331 return (@atomicLoad(u32, self.sq.flags, .Unordered) & linux.IORING_SQ_CQ_OVERFLOW) != 0;
332332 }
333333
......@@ -567,7 +567,6 @@ pub const IO_Uring = struct {
567567 }
568568};
569569
570
571570pub const SubmissionQueue = struct {
572571 head: *u32,
573572 tail: *u32,