Skip to content
Draft
Show file tree
Hide file tree
Changes from 201 commits
Commits
Show all changes
204 commits
Select commit Hold shift + click to select a range
44be11a
Add experimental io_uring socket event engine for Linux
benaadams Feb 13, 2026
b12e418
Harden io_uring socket engine: scalable lookups, multishot poll, trac…
benaadams Feb 13, 2026
94baf21
Add tagged user-data encoding, evidence tooling, and expanded docs
benaadams Feb 13, 2026
2110979
Add Phase 2 completion-model scaffolding across native and managed la…
benaadams Feb 13, 2026
0c50760
Add cross-thread SQE staging and Phase 2 completion-mode opt-in gate
benaadams Feb 13, 2026
0ebcefa
Add dual-buffer WaitForSocketEventsAndCompletions and cancellation-sa…
benaadams Feb 13, 2026
d6d6553
Add user_data lifecycle map, fix zero-capacity CQE loss, and add canc…
benaadams Feb 13, 2026
a19ad2b
Add Debug.Fail invariant checks for lifecycle map and close/dispose s…
benaadams Feb 13, 2026
6a765d6
Fix false-positive Debug.Fail in lifecycle map and add teardown drain
benaadams Feb 13, 2026
2fd61bc
Extract TryRemoveTrackedOperationCore helper, add late-CQE diagnostic…
benaadams Feb 13, 2026
c884805
Add SocketsTelemetry late-CQE counter, atomic tracked-map removal, an…
benaadams Feb 13, 2026
64550a9
Add structured counter capture, late-CQE envelope automation, and tel…
benaadams Feb 13, 2026
70ce242
Add operation-level buffer pinning, perf comparison report, and evide…
benaadams Feb 13, 2026
e16deb9
Add non-pinnable prepare fallback telemetry, accept addrlen field, an…
benaadams Feb 13, 2026
0736954
Add non-pinnable prepare fallback envelope evaluation and evidence to…
benaadams Feb 13, 2026
659a27a
Add CQE completion dispatch with per-operation processing, queue remo…
benaadams Feb 13, 2026
58cda5a
Wire native io_uring SQE preparation for send/recv/accept/connect, ad…
benaadams Feb 13, 2026
dc1a1f9
Fix IORING_OP_CONNECT SQE field mapping and add IoUringCompletion lay…
benaadams Feb 13, 2026
ffde294
Add native diagnostics for async-cancel CQEs and wait-buffer saturation
benaadams Feb 13, 2026
28cc036
Add native diagnostics snapshot export to managed telemetry and fix m…
benaadams Feb 13, 2026
992f98f
Add native io_uring vectored message operation support (IORING_OP_SEN…
benaadams Feb 13, 2026
d8126dd
Add recvmsg completion writeback, MessageHeader ABI guards, and Socke…
benaadams Feb 13, 2026
b0997ce
Add runtime per-opcode support gating via IORING_REGISTER_PROBE
benaadams Feb 13, 2026
67f13ec
Add managed interop surface, requeue failure fallback, telemetry coun…
benaadams Feb 13, 2026
b4ef5b8
Add CI archive variants for io_uring enabled/disabled test execution
benaadams Feb 13, 2026
a738588
Update PR evidence template for completion-path counters and current …
benaadams Feb 13, 2026
dd4535a
Suppress unused-macro and unused-parameter warnings when io_uring is …
benaadams Feb 13, 2026
873c1ce
Fix AllocateIoUringUserDataToken zero-skip to loop instead of single …
benaadams Feb 13, 2026
6bf4e51
Add missing sys/mman.h include for io_uring ring mmap/munmap
benaadams Feb 13, 2026
21b234d
Add explicit casts for MAP_FAILED and mmap on io_uring_sqe pointer
benaadams Feb 13, 2026
3f144ab
Fix CS8602 null dereference warning and CA2020 unchecked UIntPtr cast
benaadams Feb 13, 2026
9f26975
Add live cancellation via IORING_OP_ASYNC_CANCEL on TryCancel and fix…
benaadams Feb 13, 2026
ea1bbbc
Mask user_data tokens to 56-bit payload range and increase RemoteExec…
benaadams Feb 13, 2026
7f39970
Raise minimum kernel to 5.13, coalesce cancel submits via worker, de-…
benaadams Feb 13, 2026
49cd8cf
Add buffer-list vectored send/receive for io_uring completion mode vi…
benaadams Feb 13, 2026
5ee2c84
Add ReceiveMessageFrom completion path, extract SocketPal io_uring he…
benaadams Feb 13, 2026
a69f2f9
Add async-cancel probe-disable test hook and accept/connect/cancel-fa…
benaadams Feb 13, 2026
6c8b489
Add per-opcode disable test hook, inline non-Linux stubs, and expand …
benaadams Feb 13, 2026
151bd9f
Add deterministic forced-result test hooks for io_uring completion CQ…
benaadams Feb 13, 2026
98a5d9e
Refactor CreateSocketEngineOptions to use SetOrRemoveEnvironmentVaria…
benaadams Feb 13, 2026
ba61ab5
Add teardown, non-pinnable fallback, mixed-mode, and GC-pressure tests
benaadams Feb 13, 2026
891107e
Add pinning-lifecycle, non-pinnable telemetry, and tracking memory tests
benaadams Feb 13, 2026
40573ab
Add configurable event buffer count, call-site platform guards, and b…
benaadams Feb 13, 2026
1abf3d9
Add cancellation-submit contention, same-socket backlog fairness, and…
benaadams Feb 13, 2026
6554cd6
Add bounded wait-buffer and invalid override scenarios to evidence to…
benaadams Feb 13, 2026
bba97c3
Fix forced-result test races, complete diagnostic snapshot, and refin…
benaadams Feb 14, 2026
4a63427
Harden forced-result follow-up receives and simplify buffer-count test
benaadams Feb 14, 2026
c6b9499
Simplify forced-result tests and reduce invalid buffer-count test to …
benaadams Feb 14, 2026
82e10fe
Split io_uring code into Linux-only partial class files
benaadams Feb 14, 2026
0f17b76
Replace #if TARGET_LINUX blocks with partial method hooks and move co…
benaadams Feb 14, 2026
3b8099c
Move io_uring fields, types, and methods from shared .Unix.cs files t…
benaadams Feb 14, 2026
1cc5c57
Fix Linux build errors, add cold-helper caller guards, extract throw …
benaadams Feb 14, 2026
4771b30
Extract sync precondition helper, add PREPARE_CLEANUP_RETURN macro, c…
benaadams Feb 14, 2026
74f7043
Fix native bugs, harden platform gating, remove dead code, and expand…
benaadams Feb 14, 2026
6ca3ab0
Fix errno bug, hoist connect userData check, add CQ overflow monitori…
benaadams Feb 14, 2026
f664e7c
remove
benaadams Feb 14, 2026
0a6f842
Define TARGET_LINUX in System.Net.Sockets.csproj to fix CS0426 build …
benaadams Feb 14, 2026
c6c7b46
Add canonical mode state machine, centralized env parsing, unified ca…
benaadams Feb 14, 2026
adbafc9
Fix TARGET_LINUX define to exclude Android builds
benaadams Feb 14, 2026
b5694f1
Fix test
benaadams Feb 14, 2026
e02d201
Consolidate io_uring env vars into single DOTNET_SYSTEM_NET_SOCKETS_I…
benaadams Feb 14, 2026
fa82501
Replace #if TARGET_LINUX with partial method hooks and split Interop.…
benaadams Feb 14, 2026
8f89b5a
Fix completion resource use-after-free: defer ClearIoUringUserData un…
benaadams Feb 14, 2026
224a174
Gate test event buffer count env var behind #if DEBUG
benaadams Feb 14, 2026
86e8c5f
Unify io_uring operation registry, lifecycle assertions, and completi…
benaadams Feb 14, 2026
67f7ace
Extract ProcessIoUringCompletionSuccess/Error virtual dispatch from m…
benaadams Feb 14, 2026
1e8f414
Fix TelemetryTest TypeLoadException on non-Linux and consolidate nati…
benaadams Feb 14, 2026
8a8ddd0
Extract generic StartSocketAsyncEventArgsOperation helper and central…
benaadams Feb 14, 2026
cc43b61
Fix disconnect-before-reconnect scoping in IoUringOptIn_DisconnectRec…
benaadams Feb 14, 2026
3e3a2d4
Simplify partial-send theory dispatch and adopt AcceptConnectedTcpPai…
benaadams Feb 14, 2026
208ddef
Make LinuxTryStageIoUringOperation static partial to fix CA1822
benaadams Feb 14, 2026
8ca3046
Extract WithIoUringNativeDiagnosticsSnapshotDeltaAsync wrapper and me…
benaadams Feb 14, 2026
e221f7c
Remove unused using System.Net.Sockets from Interop.SocketEvent.cs
benaadams Feb 14, 2026
3b1f94e
Merge non-pinnable fallback and packet-info IPv4/IPv6 test pairs into…
benaadams Feb 14, 2026
d955796
Fix connect-with-initial-data ErrorCode and callback dispatch on sync…
benaadams Feb 14, 2026
028aef8
Widen _ioUringPrepareSequence to long and make resource release idemp…
benaadams Feb 15, 2026
e2b0190
Add bounded prepare-queue capacity with overflow telemetry
benaadams Feb 15, 2026
7a49552
Add prepare-queue depth gauge and merge ReceiveMessageFrom buffer-lis…
benaadams Feb 15, 2026
11f045a
ArrayPool for buffer-list GCHandle[]/IOVector[] and dynamic hash buck…
benaadams Feb 15, 2026
6a72218
Extract shared SQE initialization helpers for io_uring prep functions
benaadams Feb 15, 2026
e23071a
Pool native completion-operation state and split IoUringTrace into no…
benaadams Feb 15, 2026
0ad41de
Reuse pinned buffers on EAGAIN requeue, consolidate message-op allocs…
benaadams Feb 15, 2026
c7fda12
Add inline fast-path storage for message-op iovec/sockaddr/control bu…
benaadams Feb 15, 2026
c7a1950
Extend pin reuse to buffer-list ops, fix partial-send handle leak, ad…
benaadams Feb 15, 2026
d398073
Add full pin reuse to ReceiveMessageFromOperation with shape-transiti…
benaadams Feb 15, 2026
a55fff3
Defer canceled-op resource release until terminal CQE and gate test e…
benaadams Feb 15, 2026
6774c2d
Fix completion resource use-after-free: defer ClearIoUringUserData un…
benaadams Feb 15, 2026
6dfe23f
Guard ClearIoUringUserData on untrack-mismatch to prevent cross-opera…
benaadams Feb 15, 2026
bd03762
Prune io_uring telemetry to 8 core counters and add SocketEngineBacke…
benaadams Feb 15, 2026
677cda6
Batch CQE drain loop with deferred CqHead publish and fix mid-batch e…
benaadams Feb 15, 2026
9e272d3
Defer poll rearms to post-batch pass after CqHead publish
benaadams Feb 15, 2026
7482d9f
Add IORING_SETUP_CQSIZE for 4x CQ capacity and pre-init SqArray
benaadams Feb 15, 2026
43f82a1
Add IORING_SETUP_SUBMIT_ALL with two-flag peel-based setup probe
benaadams Feb 15, 2026
372887b
O(1) request-ID unlink, skip duplicate lookups on 64-bit hot paths
benaadams Feb 15, 2026
034f174
Dynamic registration bucket sizing and effective-queue-depth pool sca…
benaadams Feb 15, 2026
009726c
Raise completion bucket cap, targeted pool-return reset, fix registra…
benaadams Feb 15, 2026
a1e2385
Merge submit into idle-path io_uring_enter wait call
benaadams Feb 15, 2026
f8ebcdf
Reduce lock hold time: release across submit syscall, defer completio…
benaadams Feb 15, 2026
8bedd8e
Narrow deferred completion to recvmsg-only, revert submit lock releas…
benaadams Feb 15, 2026
1951bbc
Merge PrepareIoUringConnectOperation into shared PrepareIoUringComple…
benaadams Feb 15, 2026
d45cc3e
Hoist canRecordCompletions check, remove dead post-drain branch, drop…
benaadams Feb 15, 2026
638622e
Replace redundant inner-loop bounds checks with asserts guarded by bu…
benaadams Feb 15, 2026
59c7aa5
Remove redundant error-code filter from poll-rearm condition
benaadams Feb 15, 2026
a78b3f2
Fast-gate forced-result test hooks and mark RestoreIoUringForcedCompl…
benaadams Feb 15, 2026
5217ebf
Split FindRegistrationLocked into dedicated by-socket and by-request-…
benaadams Feb 15, 2026
0c6a463
Cache PollEvents at registration time, remove hash mix for monotonic …
benaadams Feb 15, 2026
3640035
Coalesce duplicate poll-rearms within CQE drain batch via generation …
benaadams Feb 15, 2026
8f5e4e0
Skip SubmitIoUringPendingEntriesLocked call when PendingSubmissions i…
benaadams Feb 15, 2026
3724dec
Extract io_uring engine from pal_networking.c into pal_io_uring.c
benaadams Feb 15, 2026
8f21e0a
Decompose CQE drain loop into focused helpers and fix Min macro CI error
benaadams Feb 15, 2026
3511e40
Restore lost socket functions from file split, extract shared socket …
benaadams Feb 15, 2026
d3e4be9
Implement P4.1 single-writer submission queue: route cancellation thr…
benaadams Feb 15, 2026
b0ddf25
Use positive-form preprocessor guards for readability
benaadams Feb 15, 2026
ec530cd
Guard event-loop thread assert macros with HAVE_LINUX_IO_URING_SOCKET…
benaadams Feb 15, 2026
da6a5a2
Replace memset with targeted field init in InitializeIoUringDrainBatc…
benaadams Feb 15, 2026
93dede1
Fix bugs #21-#23 and apply C# null-check style convention
benaadams Feb 15, 2026
aaa6b1e
Skip no-op callback dispatch when connect-with-data callback ownershi…
benaadams Feb 15, 2026
cfdd6f3
Add IORING_SETUP_SINGLE_ISSUER support and clear ConnectOperation Buf…
benaadams Feb 15, 2026
72cb3ae
Add IORING_SETUP_NO_SQARRAY support and fix peel-chain guard bug #25
benaadams Feb 15, 2026
5a138d6
Add COOP_TASKRUN and DEFER_TASKRUN setup flags with local ABI enum
benaadams Feb 15, 2026
69919ae
Add IORING_REGISTER_RING_FD support to eliminate fget/fput on io_urin…
benaadams Feb 15, 2026
0e477e4
Add SYS_io_uring_* fallback for syscall number portability
benaadams Feb 15, 2026
752cd12
Add local opcode/probe definitions and table-driven setup flag peel
benaadams Feb 15, 2026
0eccf7f
Add IORING_ENTER_EXT_ARG bounded wait and fix ETIME handling
benaadams Feb 15, 2026
c2c7bd5
Localize poll multishot and GETEVENTS constants, add DEFER_TASKRUN gate
benaadams Feb 15, 2026
7812833
Add registered file descriptors and fix register return value checks
benaadams Feb 15, 2026
5f2abee
Add registered-file hot cache, teardown skip, and resolve double lookup
benaadams Feb 15, 2026
39c7c25
Fix ARM 32-bit build: move IO_URING_REGISTER_OFFSET_AUTO to #define
benaadams Feb 15, 2026
6488b4f
Token-indexed slot array for O(1) completion lookup and fix rw_flags …
benaadams Feb 15, 2026
c80a6ec
Remove unused HAVE_IO_URING_COMPLETION_OPERATION_STATE macro and reve…
benaadams Feb 15, 2026
4306bb9
Fix rw_flags sign conversion with __typeof__ cast for cross-header co…
benaadams Feb 15, 2026
38343f7
Use local variable for unsafe out-param and ThrowIfNegativeOrZero for…
benaadams Feb 15, 2026
40d3c55
test diverge
benaadams Feb 15, 2026
5af7591
Direct SQE writes from managed via mmap'd ring access and fix IoUring…
benaadams Feb 15, 2026
0a3b551
M0: Native shim + managed interop foundation for io_uring migration
benaadams Feb 15, 2026
054a3ad
M1.1+M1.4: Managed kernel version check and opcode probe support
benaadams Feb 15, 2026
fd5d7f8
M1.2: Managed setup flag peel loop for io_uring initialization
benaadams Feb 15, 2026
633eea8
M1.3: Managed ring mmap and pointer derivation
benaadams Feb 15, 2026
8e0fb13
M1.5: Wire managed io_uring init into engine startup
benaadams Feb 15, 2026
1559615
M2.1: Managed CQE reading helpers
benaadams Feb 15, 2026
85b6763
M2.2: Managed CQE dispatch loop with tag-based routing
benaadams Feb 16, 2026
153be05
M2.3: Replace native wait+drain with managed CQE drain path
benaadams Feb 16, 2026
68dbcc7
M7.1: Managed submit path and wakeup via io_uring_enter
benaadams Feb 16, 2026
bee7632
M3.1: Managed socket registration tracking for poll dispatch
benaadams Feb 16, 2026
c64a3cd
Wire DispatchManagedPollReadinessCqe into CQE drain loop
benaadams Feb 16, 2026
00cad93
M3.2+M3.3: Managed registration change protocol and poll SQE writes
benaadams Feb 16, 2026
e8178d7
M4.1: Managed completion slot array and free-list
benaadams Feb 16, 2026
b530a74
M5.1: Managed registered-file table
benaadams Feb 16, 2026
2522616
Fix build errors: CA2020 checked conversions, IDE0074, CS0649/CA1823
benaadams Feb 16, 2026
ffc66fc
M4.2: Replace native slot allocation P/Invokes with managed alloc in …
benaadams Feb 16, 2026
ee820d4
M4.3+M6.1+M6.2: Test hook forced-result injection and managed message…
benaadams Feb 16, 2026
7cad0e2
M8.1: Managed teardown orchestration for io_uring resources
benaadams Feb 16, 2026
6573618
M9.1+M9.2: Delete thick native io_uring code and remove dead managed …
benaadams Feb 16, 2026
058bef1
Fix IDE0060: remove unused 'origin' parameter from TryQueueIoUringAsy…
benaadams Feb 16, 2026
b35e1b6
Fix IDE0060: remove unused 'origin' parameter from DrainIoUringCancel…
benaadams Feb 16, 2026
47dcf91
Minimize native file changes: restore to main + only shim additions
benaadams Feb 16, 2026
5ebe651
Revert orphaned native changes from earlier io_uring branch work
benaadams Feb 16, 2026
a799f4e
Remove dead WaitForSocketEventsAndCompletions and IoUringCompletion n…
benaadams Feb 16, 2026
a29cb70
Address API design review findings across io_uring managed code
benaadams Feb 16, 2026
c8a0f29
Check completion.UserData == 0 directly instead of casting to UIntPtr…
benaadams Feb 16, 2026
b4f25e1
Replace UIntPtr with ulong for io_uring userData throughout managed code
benaadams Feb 16, 2026
76bb383
Add XML doc summaries to all undocumented io_uring types
benaadams Feb 16, 2026
505a41d
Add XML doc summaries to all io_uring methods, properties, and enums
benaadams Feb 16, 2026
10b58d6
Add missing pal_errno.h include to pal_io_uring_shim.c
benaadams Feb 16, 2026
843446c
Retry eventfd read/write on EINTR in io_uring shim
benaadams Feb 16, 2026
0ad37b0
Eliminate completion buffer and dual dispatch; pure completion mode f…
benaadams Feb 16, 2026
b70c6a1
Rename managed init terminology to io_uring enabled; consolidate env var
benaadams Feb 16, 2026
04f1113
Fix CI failures: emit fallback telemetry, null-safe reflection helper…
benaadams Feb 16, 2026
f2a4ed4
Add SINGLE_ISSUER debug assertions and replace ConcurrentQueue with M…
benaadams Feb 16, 2026
b02b17b
Align MpscQueue padding with runtime PaddingHelpers conventions
benaadams Feb 16, 2026
12a4d1e
Add multishot recv feature detection and kernel version check infrast…
benaadams Feb 16, 2026
eb7d66a
Add multishot recv SQE preparation and completion dispatch infrastruc…
benaadams Feb 16, 2026
3873966
Add provided buffer ring infrastructure and multishot recv operation …
benaadams Feb 16, 2026
face95a
Wire provided buffer completion materialization, one-shot buffer-sele…
benaadams Feb 16, 2026
864163b
Add multishot recv test scenarios for basic iteration, cancellation, …
benaadams Feb 16, 2026
473e4dd
Rework multishot dispatch to inline processing with TryGet and deferr…
benaadams Feb 16, 2026
8560abd
Explicit switch on all multishot completion result variants with Debu…
benaadams Feb 16, 2026
31f4ef5
Rename unused client socket variable to _client in multishot cancella…
benaadams Feb 16, 2026
eb14120
Validate eventfd short reads and writes in io_uring shim
benaadams Feb 16, 2026
fe9dcb8
Fix ProcessCancellation skipping callback for ConnectOperation with p…
benaadams Feb 16, 2026
aab47a8
Fix raw errno to PAL error conversion and lost-wakeup race in io_urin…
benaadams Feb 16, 2026
e4f1af4
Fix completion slot leak, CQ overflow detection, and harden io_uring …
benaadams Feb 16, 2026
c5599d8
Fix CS1656 build error from assigning to using variable in multishot …
benaadams Feb 16, 2026
b06a407
Replace generic Padded<T> with non-generic padding structs in MpscQueue
benaadams Feb 16, 2026
3fe99de
Add readiness fallback and slot exhaustion recovery for io_uring prep…
benaadams Feb 16, 2026
b0198bd
Add adaptive provided-buffer ring sizing for io_uring recv operations
benaadams Feb 16, 2026
2406d48
Assert event-loop thread for adaptive provided-buffer utilization tra…
benaadams Feb 16, 2026
a9d6fca
Add transitional multishot accept for io_uring on kernels >= 5.19
benaadams Feb 16, 2026
eabe14f
Add persistent multishot recv for io_uring with early data buffering
benaadams Feb 16, 2026
179b3f6
Add zero-copy send (SEND_ZC/SENDMSG_ZC) for io_uring on kernels >= 6.0
benaadams Feb 17, 2026
357dfb3
Centralize zero-copy send eligibility policy and extract diagnostic l…
benaadams Feb 17, 2026
bb0d999
Rename using variable discard to named listener in zero-copy send tests
benaadams Feb 17, 2026
1d05b52
Add registered buffers and fixed-buffer receive for io_uring
benaadams Feb 17, 2026
7ff2290
Add missing io_uring telemetry counter names to expected list in Tele…
benaadams Feb 17, 2026
856f5ab
Consolidate buffer registration lifecycle and recycle patterns
benaadams Feb 17, 2026
6c3b555
Merge provided-buffer and fixed-recv materialization into unified path
benaadams Feb 17, 2026
97859ef
Guard io_uring_enter ext arg size on null check
benaadams Feb 17, 2026
e6feb18
Increase multishot accept queue capacity from 64 to 256
benaadams Feb 17, 2026
8fe32a8
Dispose accepted socket in SocketEngineBackendSelected telemetry test
benaadams Feb 17, 2026
41417a0
Add SQPOLL support behind opt-in switch and normalize config to AppCo…
benaadams Feb 17, 2026
5696ead
Address review findings: harden multishot lifecycle, reduce config su…
benaadams Feb 17, 2026
acfe2af
Remove hardcoded ErrnoEAGAIN in favor of PAL conversion and guard Ass…
benaadams Feb 17, 2026
33de3a2
Remove redundant #if DEBUG from AssertSingleThreadAccess; [Conditiona…
benaadams Feb 17, 2026
3bc5822
Skip SQPOLL fallback test gracefully when io_uring port is unavailable
benaadams Feb 17, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.InteropServices;

internal static partial class Interop
{
internal static partial class Sys
{
/// <summary>Wraps io_uring_setup(2): creates an io_uring instance.</summary>
[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_IoUringShimSetup")]
internal static unsafe partial Error IoUringShimSetup(
uint entries, void* parms, int* ringFd);

/// <summary>Wraps io_uring_enter(2): submits SQEs and/or waits for CQEs.</summary>
[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_IoUringShimEnter")]
internal static unsafe partial Error IoUringShimEnter(
int ringFd, uint toSubmit, uint minComplete, uint flags, int* result);

/// <summary>Wraps io_uring_enter2(2) with IORING_ENTER_EXT_ARG for bounded waits.</summary>
[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_IoUringShimEnterExt")]
internal static unsafe partial Error IoUringShimEnterExt(
int ringFd, uint toSubmit, uint minComplete, uint flags, void* arg, int* result);

/// <summary>Wraps io_uring_register(2): registers resources (files, buffers, ring fds).</summary>
[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_IoUringShimRegister")]
internal static unsafe partial Error IoUringShimRegister(
int ringFd, uint opcode, void* arg, uint nrArgs, int* result);

/// <summary>Wraps mmap(2): maps io_uring SQ/CQ ring memory.</summary>
[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_IoUringShimMmap")]
internal static unsafe partial Error IoUringShimMmap(
int ringFd, ulong size, ulong offset, void** mappedPtr);

/// <summary>Wraps munmap(2): unmaps io_uring ring memory.</summary>
[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_IoUringShimMunmap")]
internal static unsafe partial Error IoUringShimMunmap(
void* addr, ulong size);

/// <summary>Creates an eventfd for io_uring wakeup signaling.</summary>
[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_IoUringShimCreateEventFd")]
internal static unsafe partial Error IoUringShimCreateEventFd(
int* eventFd);

/// <summary>Writes to an eventfd to wake the io_uring event loop.</summary>
[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_IoUringShimWriteEventFd")]
internal static partial Error IoUringShimWriteEventFd(int eventFd);

/// <summary>Reads from an eventfd to consume a wakeup signal.</summary>
[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_IoUringShimReadEventFd")]
internal static unsafe partial Error IoUringShimReadEventFd(
int eventFd, ulong* value);

/// <summary>Wraps close(2): closes a file descriptor.</summary>
[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_IoUringShimCloseFd")]
internal static partial Error IoUringShimCloseFd(int fd);

/// <summary>Reads the kernel version via uname(2) for io_uring feature detection.</summary>
[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_IoUringShimGetKernelVersion")]
internal static unsafe partial Error IoUringShimGetKernelVersion(
uint* major, uint* minor);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Net.Sockets;
using System.Runtime.InteropServices;

internal static partial class Interop
{
internal static partial class Sys
{
/// <summary>Derived SQ ring state computed after mmap, used by the managed submission path.</summary>
[StructLayout(LayoutKind.Sequential)]
internal struct IoUringSqRingInfo
{
public IntPtr SqeBase;
public IntPtr SqTailPtr;
public IntPtr SqHeadPtr;
public uint SqMask;
public uint SqEntries;
public uint SqeSize;
public byte UsesNoSqArray;
public int RingFd;
public int RegisteredRingFd;
public byte UsesEnterExtArg;
public byte UsesRegisteredFiles;
}

/// <summary>Mirrors kernel <c>struct io_sqring_offsets</c> (40 bytes). Fields at offset 28+ (resv1, user_addr) are unused.</summary>
[StructLayout(LayoutKind.Explicit, Size = 40)]
internal struct IoUringSqOffsets
{
[FieldOffset(0)] public uint Head;
[FieldOffset(4)] public uint Tail;
[FieldOffset(8)] public uint RingMask;
[FieldOffset(12)] public uint RingEntries;
[FieldOffset(16)] public uint Flags;
[FieldOffset(20)] public uint Dropped;
[FieldOffset(24)] public uint Array;
// resv1 at 28, user_addr at 32 - not needed by managed code
}

/// <summary>Mirrors kernel <c>struct io_cqring_offsets</c> (40 bytes). Fields at offset 28+ (resv1, user_addr) are unused.</summary>
[StructLayout(LayoutKind.Explicit, Size = 40)]
internal struct IoUringCqOffsets
{
[FieldOffset(0)] public uint Head;
[FieldOffset(4)] public uint Tail;
[FieldOffset(8)] public uint RingMask;
[FieldOffset(12)] public uint RingEntries;
[FieldOffset(16)] public uint Overflow;
[FieldOffset(20)] public uint Cqes;
[FieldOffset(24)] public uint Flags;
// resv1 at 28, user_addr at 32 - not needed by managed code
}

/// <summary>Mirrors kernel <c>struct io_uring_params</c> (120 bytes), passed to io_uring_setup.</summary>
[StructLayout(LayoutKind.Explicit, Size = 120)]
internal struct IoUringParams
{
[FieldOffset(0)] public uint SqEntries;
[FieldOffset(4)] public uint CqEntries;
[FieldOffset(8)] public uint Flags;
[FieldOffset(12)] public uint SqThreadCpu;
[FieldOffset(16)] public uint SqThreadIdle;
[FieldOffset(20)] public uint Features;
[FieldOffset(24)] public uint WqFd;
// resv[3] at 28-39
[FieldOffset(40)] public IoUringSqOffsets SqOff;
[FieldOffset(80)] public IoUringCqOffsets CqOff;
}

/// <summary>Mirrors kernel <c>struct io_uring_cqe</c> (16 bytes), read from the CQ ring.</summary>
[StructLayout(LayoutKind.Explicit, Size = 16)]
internal struct IoUringCqe
{
[FieldOffset(0)] public ulong UserData;
[FieldOffset(8)] public int Result;
[FieldOffset(12)] public uint Flags;
}

/// <summary>Mirrors kernel <c>struct io_uring_buf</c> (16 bytes), used by provided-buffer rings.</summary>
[StructLayout(LayoutKind.Explicit, Size = 16)]
internal struct IoUringBuf
{
[FieldOffset(0)] public ulong Address;
[FieldOffset(8)] public uint Length;
[FieldOffset(12)] public ushort BufferId;
[FieldOffset(14)] public ushort Reserved;
}

/// <summary>
/// Mirrors the header overlay of kernel <c>struct io_uring_buf_ring</c> (16 bytes).
/// In UAPI this shares offset 0 with the first <c>io_uring_buf</c> entry via a union.
/// </summary>
[StructLayout(LayoutKind.Explicit, Size = 16)]
internal struct IoUringBufRingHeader
{
[FieldOffset(0)] public ulong Reserved1;
[FieldOffset(8)] public uint Reserved2;
[FieldOffset(12)] public ushort Reserved3;
[FieldOffset(14)] public ushort Tail;
}

/// <summary>Mirrors kernel <c>struct io_uring_buf_reg</c> (40 bytes), used for pbuf ring registration.</summary>
[StructLayout(LayoutKind.Explicit, Size = 40)]
internal struct IoUringBufReg
{
[FieldOffset(0)] public ulong RingAddress;
[FieldOffset(8)] public uint RingEntries;
[FieldOffset(12)] public ushort BufferGroupId;
[FieldOffset(14)] public ushort Padding;
[FieldOffset(16)] public ulong Reserved0;
[FieldOffset(24)] public ulong Reserved1;
[FieldOffset(32)] public ulong Reserved2;
}

/// <summary>Derived CQ ring state computed after mmap, used by the managed completion drain path.</summary>
[StructLayout(LayoutKind.Sequential)]
internal struct IoUringCqRingInfo
{
public IntPtr CqeBase; // io_uring_cqe* base of CQE array
public IntPtr CqTailPtr; // uint32_t* kernel writes CQ tail
public IntPtr CqHeadPtr; // uint32_t* managed advances CQ head
public uint CqMask; // CqEntries - 1
public uint CqEntries; // number of CQ slots
public uint CqeSize; // sizeof(io_uring_cqe) = 16
public IntPtr CqOverflowPtr; // uint32_t* kernel CQ overflow counter
}

/// <summary>Mirrors kernel <c>struct io_uring_getevents_arg</c>, used with IORING_ENTER_EXT_ARG.</summary>
[StructLayout(LayoutKind.Sequential)]
internal struct IoUringGeteventsArg
{
public ulong Sigmask;
public uint SigmaskSize;
public uint MinWaitUsec;
public ulong Ts;
}

/// <summary>Mirrors kernel <c>struct __kernel_timespec</c>, used for io_uring timeout arguments.</summary>
[StructLayout(LayoutKind.Sequential)]
internal struct IoUringKernelTimespec
{
public long TvSec;
public long TvNsec;
}

}
}
11 changes: 11 additions & 0 deletions src/libraries/System.Net.Sockets/src/System.Net.Sockets.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,20 @@

<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'unix' or '$(TargetPlatformIdentifier)' == 'osx' or '$(TargetPlatformIdentifier)' == 'ios' or '$(TargetPlatformIdentifier)' == 'tvos'">
<Compile Include="System\Net\Sockets\UnixDomainSocketEndPoint.Unix.cs"/>
<Compile Include="System\Net\Sockets\SocketAsyncEngine.Linux.cs" Condition="'$(TargetPlatformIdentifier)' == 'unix' and '$(TargetOS)' == 'linux'" />
<Compile Include="System\Net\Sockets\MpscQueue.cs" Condition="'$(TargetPlatformIdentifier)' == 'unix' and '$(TargetOS)' == 'linux'" />
<Compile Include="System\Net\Sockets\IoUringProvidedBufferRing.Linux.cs" Condition="'$(TargetPlatformIdentifier)' == 'unix' and '$(TargetOS)' == 'linux'" />
<Compile Include="System\Net\Sockets\SocketPal.IoUring.Linux.cs" Condition="'$(TargetPlatformIdentifier)' == 'unix' and '$(TargetOS)' == 'linux'" />
<Compile Include="System\Net\Sockets\SocketAsyncContext.IoUring.Linux.cs" Condition="'$(TargetPlatformIdentifier)' == 'unix' and '$(TargetOS)' == 'linux'" />
<Compile Include="System\Net\Sockets\SocketAsyncEngine.Unix.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.SocketEvent.cs"
Link="Common\Interop\Unix\System.Native\Interop.SocketEvent.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.SocketEvent.Linux.cs"
Link="Common\Interop\Unix\System.Native\Interop.SocketEvent.Linux.cs"
Condition="'$(TargetPlatformIdentifier)' == 'unix' and '$(TargetOS)' == 'linux'" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.IoUringShim.cs"
Link="Common\Interop\Unix\System.Native\Interop.IoUringShim.cs"
Condition="'$(TargetPlatformIdentifier)' == 'unix' and '$(TargetOS)' == 'linux'" />
</ItemGroup>

<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'unix' or '$(TargetPlatformIdentifier)' == 'wasi' or '$(TargetPlatformIdentifier)' == 'osx' or '$(TargetPlatformIdentifier)' == 'ios' or '$(TargetPlatformIdentifier)' == 'tvos'">
Expand Down
Loading
Loading