From 2a82e3bdbea8315d1d10135fcec8fd971004b898 Mon Sep 17 00:00:00 2001 From: Ozgur Akkurt Date: Thu, 14 Aug 2025 22:39:38 +0600 Subject: [PATCH 1/4] implement registering NAPI on IoUring --- lib/std/os/linux.zig | 30 ++++++++++++++++++++++++++++++ lib/std/os/linux/IoUring.zig | 13 ++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index 9242c33ecefd..377436f2b576 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -6547,6 +6547,29 @@ pub const IORING_REGISTER = enum(u32) { // register a range of fixed file slots for automatic slot allocation REGISTER_FILE_ALLOC_RANGE, + // return status information for a buffer group + IORING_REGISTER_PBUF_STATUS, + + // set/clear busy poll settings + IORING_REGISTER_NAPI, + IORING_UNREGISTER_NAPI, + + IORING_REGISTER_CLOCK, + + // clone registered buffers from source ring to current ring + IORING_REGISTER_CLONE_BUFFERS, + + // send MSG_RING without having a ring + IORING_REGISTER_SEND_MSG_RING, + + // register a netdev hw rx queue for zerocopy + IORING_REGISTER_ZCRX_IFQ, + + // resize CQ ring + IORING_REGISTER_RESIZE_RINGS, + + IORING_REGISTER_MEM_REGION, + // flag added to the opcode to use a registered ring fd IORING_REGISTER_USE_REGISTERED_RING = 1 << 31, @@ -6605,6 +6628,13 @@ pub const io_uring_notification_register = extern struct { resv3: u64, }; +pub const io_uring_napi = extern struct { + busy_poll_to: u32, + prefer_busy_poll: u8, + pad: [3]u8, + resv: u64, +}; + /// Skip updating fd indexes set to this value in the fd table */ pub const IORING_REGISTER_FILES_SKIP = -2; diff --git a/lib/std/os/linux/IoUring.zig b/lib/std/os/linux/IoUring.zig index 62a87ac10341..8c15a892c3bb 100644 --- a/lib/std/os/linux/IoUring.zig +++ b/lib/std/os/linux/IoUring.zig @@ -1270,7 +1270,18 @@ pub fn unregister_eventfd(self: *IoUring) !void { try handle_registration_result(res); } -/// Registers an array of buffers for use with `read_fixed` and `write_fixed`. +pub fn register_napi(self: *IoUring, napi: *linux.io_uring_napi) !void { + assert(self.fd >= 0); + const res = linux.io_uring_register(self.fd, .REGISTER_NAPI, napi, 1); + try handle_registration_result(res); +} + +pub fn unregister_napi(self: *IoUring, napi: *linux.io_uring_napi) !void { + assert(self.fd >= 0); + const res = linux.io_uring_register(self.fd, .UNREGISTER_NAPI, napi, 1); + try handle_registration_result(res); +} + pub fn register_buffers(self: *IoUring, buffers: []const posix.iovec) !void { assert(self.fd >= 0); const res = linux.io_uring_register( From 5ec55fbce47a2fbd9e29aae287735ab960626758 Mon Sep 17 00:00:00 2001 From: Ozgur Akkurt Date: Thu, 14 Aug 2025 22:48:20 +0600 Subject: [PATCH 2/4] remove prefixes and fix old typo in IORING_REGISTER --- lib/std/os/linux.zig | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index 377436f2b576..6bf852a44388 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -6535,7 +6535,7 @@ pub const IORING_REGISTER = enum(u32) { // register/unregister io_uring fd with the ring REGISTER_RING_FDS, - NREGISTER_RING_FDS, + UNREGISTER_RING_FDS, // register ring based provide buffer group REGISTER_PBUF_RING, @@ -6548,30 +6548,30 @@ pub const IORING_REGISTER = enum(u32) { REGISTER_FILE_ALLOC_RANGE, // return status information for a buffer group - IORING_REGISTER_PBUF_STATUS, + REGISTER_PBUF_STATUS, // set/clear busy poll settings - IORING_REGISTER_NAPI, - IORING_UNREGISTER_NAPI, + REGISTER_NAPI, + UNREGISTER_NAPI, - IORING_REGISTER_CLOCK, + REGISTER_CLOCK, // clone registered buffers from source ring to current ring - IORING_REGISTER_CLONE_BUFFERS, + REGISTER_CLONE_BUFFERS, // send MSG_RING without having a ring - IORING_REGISTER_SEND_MSG_RING, + REGISTER_SEND_MSG_RING, // register a netdev hw rx queue for zerocopy - IORING_REGISTER_ZCRX_IFQ, + REGISTER_ZCRX_IFQ, // resize CQ ring - IORING_REGISTER_RESIZE_RINGS, + REGISTER_RESIZE_RINGS, - IORING_REGISTER_MEM_REGION, + REGISTER_MEM_REGION, // flag added to the opcode to use a registered ring fd - IORING_REGISTER_USE_REGISTERED_RING = 1 << 31, + REGISTER_USE_REGISTERED_RING = 1 << 31, _, }; From 3942c0c62280c01ba669086e92b7a5fc53076608 Mon Sep 17 00:00:00 2001 From: Ozgur Akkurt Date: Thu, 14 Aug 2025 23:02:41 +0600 Subject: [PATCH 3/4] restore deleted comment --- lib/std/os/linux/IoUring.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/std/os/linux/IoUring.zig b/lib/std/os/linux/IoUring.zig index 8c15a892c3bb..25d4d88fd02f 100644 --- a/lib/std/os/linux/IoUring.zig +++ b/lib/std/os/linux/IoUring.zig @@ -1282,6 +1282,7 @@ pub fn unregister_napi(self: *IoUring, napi: *linux.io_uring_napi) !void { try handle_registration_result(res); } +/// Registers an array of buffers for use with `read_fixed` and `write_fixed`. pub fn register_buffers(self: *IoUring, buffers: []const posix.iovec) !void { assert(self.fd >= 0); const res = linux.io_uring_register( From 6a9799618301e77472547c685ef0b5ef181e988e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96zg=C3=BCr=20Akkurt?= Date: Sat, 16 Aug 2025 05:25:38 +0600 Subject: [PATCH 4/4] Update lib/std/os/linux.zig MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Alex Rønne Petersen --- lib/std/os/linux.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index 6bf852a44388..7b5a7303a6bf 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -6631,7 +6631,7 @@ pub const io_uring_notification_register = extern struct { pub const io_uring_napi = extern struct { busy_poll_to: u32, prefer_busy_poll: u8, - pad: [3]u8, + _pad: [3]u8, resv: u64, };