Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft changes to the io_uring prototype #208

Draft
wants to merge 49 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
15794f5
ioring pitch: first steps
oxy Jul 19, 2023
6338029
stage 2: IORequest enum
oxy Aug 1, 2023
996e940
initial AsyncFileDescriptor work
oxy Aug 1, 2023
1f821a8
AsyncSequence draft implementation
oxy Aug 8, 2023
0762f57
migrate CSystem to systemLibrary
oxy Aug 10, 2023
d099546
fix access control
oxy Aug 11, 2023
b584504
fix off-by-one in IORequest.openat
oxy Aug 11, 2023
b596783
implement closing
oxy Aug 11, 2023
6b4084c
introduce IORing unit tests
oxy Aug 11, 2023
baab9b2
Starting to move to noncopyable structs, and away from swift-atomics
Catfish-Man Oct 24, 2024
6029936
One more noncopyable struct
Catfish-Man Oct 24, 2024
10c070a
WIP, more ~Copyable adoption
Catfish-Man Oct 28, 2024
32966f9
It builds again! With some horrible hacks
Catfish-Man Oct 28, 2024
822e481
Adopt isolation parameters
Catfish-Man Oct 28, 2024
fcb0b69
Merge branch 'main' into david/ioring
Catfish-Man Oct 29, 2024
6f793cf
Merge branch 'main' into david/ioring
Catfish-Man Oct 29, 2024
a9f92a6
Delete stray Package.resolved changes
Catfish-Man Oct 29, 2024
1a3e37d
Fix mismerge
Catfish-Man Oct 29, 2024
f369347
Fix mismerge
Catfish-Man Oct 29, 2024
ef94a37
Refactoring, and give up on resources being noncopyable structs
Catfish-Man Dec 5, 2024
7ea32ae
More refactoring, and working timeout support on ManagedIORing
Catfish-Man Dec 11, 2024
55fd6e7
Add support for timeout-on-wait to IORing, don't have tests yet
Catfish-Man Dec 12, 2024
e5fdf9e
Remove managed abstractions for now
Catfish-Man Feb 6, 2025
fdbceca
Eliminate internal locking and add multiple consume support
Catfish-Man Feb 6, 2025
7107a57
Fix import visibility
Catfish-Man Feb 11, 2025
02481e0
More import fixes
Catfish-Man Feb 11, 2025
bb03f0f
Redesign registered resources API
Catfish-Man Feb 11, 2025
a396967
More registration tweaks
Catfish-Man Feb 11, 2025
d4ca412
Some renaming, and implement linked requests
Catfish-Man Feb 11, 2025
5bfed03
Switch to static methods for constructing requests
Catfish-Man Feb 11, 2025
74366c3
Improve submit API
Catfish-Man Feb 12, 2025
7f6e673
Adjust registered resources API
Catfish-Man Feb 12, 2025
0c6ef16
Fix type
Catfish-Man Feb 12, 2025
a22e5f6
Add a version of registerBuffers that isn't varargs
Catfish-Man Feb 13, 2025
6983196
Add unlinkAt support
Catfish-Man Feb 13, 2025
5ba1377
Dubious approach to this, but I want to try it out a bit
Catfish-Man Feb 13, 2025
0064649
Turn on single issuer as an experiment
Catfish-Man Feb 14, 2025
901f4c8
Revert "Turn on single issuer as an experiment"
Catfish-Man Feb 14, 2025
283e8d6
Reapply "Turn on single issuer as an experiment"
Catfish-Man Feb 14, 2025
d895f2a
Revert "Reapply "Turn on single issuer as an experiment""
Catfish-Man Feb 14, 2025
f3b8cc4
Actually consume events we waited for
Catfish-Man Feb 28, 2025
d338de1
Only get one completion if we asked for one completion
Catfish-Man Feb 28, 2025
5e24673
Switch from unsafe pointers to FilePaths, using hacks
Catfish-Man Mar 3, 2025
49dd797
Add a combined "submit and consume" operation
Catfish-Man Mar 3, 2025
91155fd
Plumb error handling through completion consumers
Catfish-Man Mar 3, 2025
9ad16c0
Plumb through userData
Catfish-Man Mar 3, 2025
880ec90
Add a pointer convenience for getting the user data
Catfish-Man Mar 3, 2025
48455a9
Fix plumbing
Catfish-Man Mar 3, 2025
72c316b
Make completions noncopyable again
Catfish-Man Mar 3, 2025
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
Prev Previous commit
Next Next commit
WIP, more ~Copyable adoption
Catfish-Man committed Oct 28, 2024
commit 10c070abd648bb66da947c77b5a5c645ef1d53fd
145 changes: 90 additions & 55 deletions Sources/System/IORequest.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import struct CSystem.io_uring_sqe

public enum IORequest {
public enum IORequest: ~Copyable {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unclear to me how we want to structure this. An enum is… kinda elegant, but I haven't figured out how to express "this enum's associated values are all borrows scoped to some other thing's lifetime" yet.

case nop // nothing here
case openat(
atDirectory: FileDescriptor,
atDirectory: FileDescriptor,
path: UnsafePointer<CChar>,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path should probably be a FilePath?

FileDescriptor.AccessMode,
options: FileDescriptor.OpenOptions = FileDescriptor.OpenOptions(),
@@ -22,71 +22,106 @@ public enum IORequest {
)
case close(File)

public enum Buffer {
public enum Buffer: ~Copyable {
case registered(IORingBuffer)
case unregistered(UnsafeMutableRawBufferPointer)
}

public enum File {
public enum File: ~Copyable {
case registered(IORingFileSlot)
case unregistered(FileDescriptor)
}
}

@inlinable @inline(__always)
internal func makeRawRequest_readWrite_registered(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Workaround for "can't mix ~Copyable and fallthrough", courtesy of @jckarter <3

file: consuming IORequest.File,
buffer: consuming IORingBuffer,
offset: UInt64,
request: consuming RawIORequest
) -> RawIORequest {
switch file {
case .registered(let regFile):
request.rawValue.fd = Int32(exactly: regFile.index)!
request.flags = .fixedFile
case .unregistered(let fd):
request.fileDescriptor = fd
}
request.buffer = buffer.unsafeBuffer
request.rawValue.buf_index = UInt16(exactly: buffer.index)!
request.offset = offset
return request
}

@inlinable @inline(__always)
internal func makeRawRequest_readWrite_unregistered(
file: consuming IORequest.File,
buffer: UnsafeMutableRawBufferPointer,
offset: UInt64,
request: consuming RawIORequest
) -> RawIORequest {
switch file {
case .registered(let regFile):
request.rawValue.fd = Int32(exactly: regFile.index)!
request.flags = .fixedFile
case .unregistered(let fd):
request.fileDescriptor = fd
}
request.buffer = buffer
request.offset = offset
return request
}

extension IORequest {
@inlinable @inline(__always)
public func makeRawRequest() -> RawIORequest {
public consuming func makeRawRequest() -> RawIORequest {
var request = RawIORequest()
switch self {
case .nop:
request.operation = .nop
case .openat(let atDirectory, let path, let mode, let options, let permissions, let slot):
// TODO: use rawValue less
request.operation = .openAt
request.fileDescriptor = atDirectory
request.rawValue.addr = unsafeBitCast(path, to: UInt64.self)
request.rawValue.open_flags = UInt32(bitPattern: options.rawValue | mode.rawValue)
request.rawValue.len = permissions?.rawValue ?? 0
if let fileSlot = slot {
request.rawValue.file_index = UInt32(fileSlot.index + 1)
}
case .read(let file, let buffer, let offset), .write(let file, let buffer, let offset):
if case .read = self {
if case .registered = buffer {
request.operation = .readFixed
} else {
request.operation = .read
}
} else {
if case .registered = buffer {
request.operation = .writeFixed
} else {
request.operation = .write
}
}
switch file {
case .registered(let regFile):
request.rawValue.fd = Int32(exactly: regFile.index)!
request.flags = .fixedFile
case .unregistered(let fd):
request.fileDescriptor = fd
}
switch buffer {
case .registered(let regBuf):
request.buffer = regBuf.unsafeBuffer
request.rawValue.buf_index = UInt16(exactly: regBuf.index)!
case .unregistered(let buf):
request.buffer = buf
}
request.offset = offset
case .close(let file):
request.operation = .close
switch file {
case .registered(let regFile):
request.rawValue.file_index = UInt32(regFile.index + 1)
case .unregistered(let normalFile):
request.fileDescriptor = normalFile
}
switch consume self {
case .nop:
request.operation = .nop
case .openat(let atDirectory, let path, let mode, let options, let permissions, let slot):
// TODO: use rawValue less
request.operation = .openAt
request.fileDescriptor = atDirectory
request.rawValue.addr = unsafeBitCast(path, to: UInt64.self)
request.rawValue.open_flags = UInt32(bitPattern: options.rawValue | mode.rawValue)
request.rawValue.len = permissions?.rawValue ?? 0
if let fileSlot = slot {
request.rawValue.file_index = UInt32(fileSlot.index + 1)
}
case .write(let file, let buffer, let offset):
switch consume buffer {
case .registered(let buffer):
request.operation = .writeFixed
return makeRawRequest_readWrite_registered(
file: file, buffer: buffer, offset: offset, request: request)

case .unregistered(let buffer):
request.operation = .write
return makeRawRequest_readWrite_unregistered(
file: file, buffer: buffer, offset: offset, request: request)
}
case .read(let file, let buffer, let offset):

switch consume buffer {
case .registered(let buffer):
request.operation = .readFixed
return makeRawRequest_readWrite_registered(
file: file, buffer: buffer, offset: offset, request: request)

case .unregistered(let buffer):
request.operation = .read
return makeRawRequest_readWrite_unregistered(
file: file, buffer: buffer, offset: offset, request: request)
}
case .close(let file):
request.operation = .close
switch file {
case .registered(let regFile):
request.rawValue.file_index = UInt32(regFile.index + 1)
case .unregistered(let normalFile):
request.fileDescriptor = normalFile
}
}
return request
}
Loading