Skip to content

Commit 4b70ffe

Browse files
committed
Fix short submits and also fix the registration ops enum, which somehow stopped compiling overnight
1 parent d2b78f8 commit 4b70ffe

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

Sources/CSystem/include/io_uring.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,6 @@ struct swift_io_uring_getevents_arg {
3333
__u64 ts;
3434
};
3535

36-
//This was #defines in older headers, so we redeclare it to get a consistent import
37-
typedef enum : __u32 {
38-
SWIFT_IORING_REGISTER_BUFFERS = 0,
39-
SWIFT_IORING_UNREGISTER_BUFFERS = 1,
40-
SWIFT_IORING_REGISTER_FILES = 2,
41-
SWIFT_IORING_UNREGISTER_FILES = 3,
42-
SWIFT_IORING_REGISTER_EVENTFD = 4,
43-
SWIFT_IORING_UNREGISTER_EVENTFD = 5,
44-
SWIFT_IORING_REGISTER_FILES_UPDATE = 6,
45-
SWIFT_IORING_REGISTER_EVENTFD_ASYNC = 7,
46-
SWIFT_IORING_REGISTER_PROBE = 8,
47-
SWIFT_IORING_REGISTER_PERSONALITY = 9,
48-
SWIFT_IORING_UNREGISTER_PERSONALITY = 10,
49-
50-
/* this goes last */
51-
SWIFT_IORING_REGISTER_LAST
52-
} SWIFT_IORING_REGISTER_OPS;
53-
5436
static inline int io_uring_register(int fd, unsigned int opcode, void *arg,
5537
unsigned int nr_args)
5638
{

Sources/System/IORing.swift

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@ import Musl
88
#endif
99
import Synchronization
1010

11+
//This was #defines in older headers, so we redeclare it to get a consistent import
12+
internal enum RegistrationOps: UInt32 {
13+
case registerBuffers = 0
14+
case unregisterBuffers = 1
15+
case registerFiles = 2
16+
case unregisterFiles = 3
17+
case registerEventFD = 4
18+
case unregisterEventFD = 5
19+
case registerFilesUpdate = 6
20+
case registerEventFDAsync = 7
21+
case registerProbe = 8
22+
case registerPersonality = 9
23+
case unregisterPersonality = 10
24+
}
25+
1126
extension UnsafeMutableRawPointer {
1227
func advanced(by offset: UInt32) -> UnsafeMutableRawPointer {
1328
return advanced(by: Int(offset))
@@ -71,6 +86,7 @@ internal func _tryWriteRequest(
7186
//Tell the kernel that we've submitted requests and/or are waiting for completions
7287
@inlinable
7388
internal func _enter(
89+
ring: borrowing SQRing,
7490
ringDescriptor: Int32,
7591
numEvents: UInt32,
7692
minCompletions: UInt32,
@@ -91,6 +107,9 @@ internal func _enter(
91107
continue
92108
} else if ret < 0 {
93109
throw(Errno(rawValue: -ret))
110+
} else if _getSubmissionQueueCount(ring: ring) > 0 {
111+
// See https://github.com/axboe/liburing/issues/309, in some cases not all pending requests are submitted
112+
continue
94113
} else {
95114
return ret
96115
}
@@ -101,7 +120,7 @@ internal func _enter(
101120
internal func _submitRequests(ring: borrowing SQRing, ringDescriptor: Int32) throws(Errno) {
102121
let flushedEvents = _flushQueue(ring: ring)
103122
_ = try _enter(
104-
ringDescriptor: ringDescriptor, numEvents: flushedEvents, minCompletions: 0, flags: 0)
123+
ring: ring, ringDescriptor: ringDescriptor, numEvents: flushedEvents, minCompletions: 0, flags: 0)
105124
}
106125

107126
@inlinable
@@ -536,7 +555,7 @@ public struct IORing: ~Copyable {
536555
let result = withUnsafePointer(to: &rawfd) { fdptr in
537556
let result = io_uring_register(
538557
ringDescriptor,
539-
SWIFT_IORING_REGISTER_EVENTFD.rawValue,
558+
RegistrationOps.registerEventFD.rawValue,
540559
UnsafeMutableRawPointer(mutating: fdptr),
541560
1
542561
)
@@ -551,7 +570,7 @@ public struct IORing: ~Copyable {
551570
public mutating func unregisterEventFD() throws(Errno) {
552571
let result = io_uring_register(
553572
ringDescriptor,
554-
IORING_UNREGISTER_EVENTFD.rawValue,
573+
RegistrationOps.unregisterEventFD.rawValue,
555574
nil,
556575
0
557576
)
@@ -569,7 +588,7 @@ public struct IORing: ~Copyable {
569588
let regResult = files.withUnsafeBufferPointer { bPtr in
570589
let result = io_uring_register(
571590
self.ringDescriptor,
572-
IORING_REGISTER_FILES.rawValue,
591+
RegistrationOps.registerFiles.rawValue,
573592
UnsafeMutableRawPointer(mutating: bPtr.baseAddress!),
574593
UInt32(truncatingIfNeeded: count)
575594
)
@@ -588,7 +607,7 @@ public struct IORing: ~Copyable {
588607
public func unregisterFiles() throws {
589608
let result = io_uring_register(
590609
ringDescriptor,
591-
IORING_UNREGISTER_FILES.rawValue,
610+
RegistrationOps.unregisterFiles.rawValue,
592611
nil,
593612
0
594613
)
@@ -613,7 +632,7 @@ public struct IORing: ~Copyable {
613632
let regResult = iovecs.withUnsafeBufferPointer { bPtr in
614633
let result = io_uring_register(
615634
self.ringDescriptor,
616-
IORING_REGISTER_BUFFERS.rawValue,
635+
RegistrationOps.registerBuffers.rawValue,
617636
UnsafeMutableRawPointer(mutating: bPtr.baseAddress!),
618637
UInt32(truncatingIfNeeded: buffers.count)
619638
)
@@ -662,7 +681,7 @@ public struct IORing: ~Copyable {
662681
public func unregisterBuffers() throws {
663682
let result = io_uring_register(
664683
self.ringDescriptor,
665-
IORING_UNREGISTER_BUFFERS.rawValue,
684+
RegistrationOps.unregisterBuffers.rawValue,
666685
nil,
667686
0
668687
)

0 commit comments

Comments
 (0)