From 99c489055951c09c1a22973078e5d7dbda14bac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96zg=C3=BCr=20Akkurt?= Date: Sat, 16 Aug 2025 13:18:49 +0600 Subject: [PATCH] implement registering NAPI on IoUring (#24850) --- lib/std/os/linux.zig | 34 ++++++++++++++++++++++++++++++++-- lib/std/os/linux/IoUring.zig | 12 ++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index eb9b98e6c5..0ec059dc87 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -6587,7 +6587,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, @@ -6599,8 +6599,31 @@ 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 + REGISTER_PBUF_STATUS, + + // set/clear busy poll settings + REGISTER_NAPI, + UNREGISTER_NAPI, + + REGISTER_CLOCK, + + // clone registered buffers from source ring to current ring + REGISTER_CLONE_BUFFERS, + + // send MSG_RING without having a ring + REGISTER_SEND_MSG_RING, + + // register a netdev hw rx queue for zerocopy + REGISTER_ZCRX_IFQ, + + // resize CQ ring + REGISTER_RESIZE_RINGS, + + 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, _, }; @@ -6657,6 +6680,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 62a87ac103..25d4d88fd0 100644 --- a/lib/std/os/linux/IoUring.zig +++ b/lib/std/os/linux/IoUring.zig @@ -1270,6 +1270,18 @@ pub fn unregister_eventfd(self: *IoUring) !void { try handle_registration_result(res); } +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); +} + /// 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);