authorgravatar for oezgurmakkurt@gmail.comÖzgür Akkurt <oezgurmakkurt@gmail.com> 2025-08-16 13:18:49+06:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-08-16 09:18:49+02:00
log99c489055951c09c1a22973078e5d7dbda14bac1
treeab4ba4e2d7da8247ba4236ecd2d17c21443af56f
parent98547713a354efef406ca79731db8984eb26c051
signaturebadge-check Signed by PGP key B5690EEEBB952194

implement registering NAPI on IoUring (#24850)


2 files changed, 44 insertions(+), 2 deletions(-)

lib/std/os/linux.zig+32-2
...@@ -6587,7 +6587,7 @@ pub const IORING_REGISTER = enum(u32) {...@@ -6587,7 +6587,7 @@ pub const IORING_REGISTER = enum(u32) {
65876587
6588 // register/unregister io_uring fd with the ring6588 // register/unregister io_uring fd with the ring
6589 REGISTER_RING_FDS,6589 REGISTER_RING_FDS,
6590 NREGISTER_RING_FDS,6590 UNREGISTER_RING_FDS,
65916591
6592 // register ring based provide buffer group6592 // register ring based provide buffer group
6593 REGISTER_PBUF_RING,6593 REGISTER_PBUF_RING,
...@@ -6599,8 +6599,31 @@ pub const IORING_REGISTER = enum(u32) {...@@ -6599,8 +6599,31 @@ pub const IORING_REGISTER = enum(u32) {
6599 // register a range of fixed file slots for automatic slot allocation6599 // register a range of fixed file slots for automatic slot allocation
6600 REGISTER_FILE_ALLOC_RANGE,6600 REGISTER_FILE_ALLOC_RANGE,
66016601
6602 // return status information for a buffer group
6603 REGISTER_PBUF_STATUS,
6604
6605 // set/clear busy poll settings
6606 REGISTER_NAPI,
6607 UNREGISTER_NAPI,
6608
6609 REGISTER_CLOCK,
6610
6611 // clone registered buffers from source ring to current ring
6612 REGISTER_CLONE_BUFFERS,
6613
6614 // send MSG_RING without having a ring
6615 REGISTER_SEND_MSG_RING,
6616
6617 // register a netdev hw rx queue for zerocopy
6618 REGISTER_ZCRX_IFQ,
6619
6620 // resize CQ ring
6621 REGISTER_RESIZE_RINGS,
6622
6623 REGISTER_MEM_REGION,
6624
6602 // flag added to the opcode to use a registered ring fd6625 // flag added to the opcode to use a registered ring fd
6603 IORING_REGISTER_USE_REGISTERED_RING = 1 << 31,6626 REGISTER_USE_REGISTERED_RING = 1 << 31,
66046627
6605 _,6628 _,
6606};6629};
...@@ -6657,6 +6680,13 @@ pub const io_uring_notification_register = extern struct {...@@ -6657,6 +6680,13 @@ pub const io_uring_notification_register = extern struct {
6657 resv3: u64,6680 resv3: u64,
6658};6681};
66596682
6683pub const io_uring_napi = extern struct {
6684 busy_poll_to: u32,
6685 prefer_busy_poll: u8,
6686 _pad: [3]u8,
6687 resv: u64,
6688};
6689
6660/// Skip updating fd indexes set to this value in the fd table */6690/// Skip updating fd indexes set to this value in the fd table */
6661pub const IORING_REGISTER_FILES_SKIP = -2;6691pub const IORING_REGISTER_FILES_SKIP = -2;
66626692
lib/std/os/linux/IoUring.zig+12
...@@ -1270,6 +1270,18 @@ pub fn unregister_eventfd(self: *IoUring) !void {...@@ -1270,6 +1270,18 @@ pub fn unregister_eventfd(self: *IoUring) !void {
1270 try handle_registration_result(res);1270 try handle_registration_result(res);
1271}1271}
12721272
1273pub fn register_napi(self: *IoUring, napi: *linux.io_uring_napi) !void {
1274 assert(self.fd >= 0);
1275 const res = linux.io_uring_register(self.fd, .REGISTER_NAPI, napi, 1);
1276 try handle_registration_result(res);
1277}
1278
1279pub fn unregister_napi(self: *IoUring, napi: *linux.io_uring_napi) !void {
1280 assert(self.fd >= 0);
1281 const res = linux.io_uring_register(self.fd, .UNREGISTER_NAPI, napi, 1);
1282 try handle_registration_result(res);
1283}
1284
1273/// Registers an array of buffers for use with `read_fixed` and `write_fixed`.1285/// Registers an array of buffers for use with `read_fixed` and `write_fixed`.
1274pub fn register_buffers(self: *IoUring, buffers: []const posix.iovec) !void {1286pub fn register_buffers(self: *IoUring, buffers: []const posix.iovec) !void {
1275 assert(self.fd >= 0);1287 assert(self.fd >= 0);