-
Notifications
You must be signed in to change notification settings - Fork 109
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
Catfish-Man
wants to merge
49
commits into
main
Choose a base branch
from
david/ioring
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,441
−20
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 6338029
stage 2: IORequest enum
oxy 996e940
initial AsyncFileDescriptor work
oxy 1f821a8
AsyncSequence draft implementation
oxy 0762f57
migrate CSystem to systemLibrary
oxy d099546
fix access control
oxy b584504
fix off-by-one in IORequest.openat
oxy b596783
implement closing
oxy 6b4084c
introduce IORing unit tests
oxy baab9b2
Starting to move to noncopyable structs, and away from swift-atomics
Catfish-Man 6029936
One more noncopyable struct
Catfish-Man 10c070a
WIP, more ~Copyable adoption
Catfish-Man 32966f9
It builds again! With some horrible hacks
Catfish-Man 822e481
Adopt isolation parameters
Catfish-Man fcb0b69
Merge branch 'main' into david/ioring
Catfish-Man 6f793cf
Merge branch 'main' into david/ioring
Catfish-Man a9f92a6
Delete stray Package.resolved changes
Catfish-Man 1a3e37d
Fix mismerge
Catfish-Man f369347
Fix mismerge
Catfish-Man ef94a37
Refactoring, and give up on resources being noncopyable structs
Catfish-Man 7ea32ae
More refactoring, and working timeout support on ManagedIORing
Catfish-Man 55fd6e7
Add support for timeout-on-wait to IORing, don't have tests yet
Catfish-Man e5fdf9e
Remove managed abstractions for now
Catfish-Man fdbceca
Eliminate internal locking and add multiple consume support
Catfish-Man 7107a57
Fix import visibility
Catfish-Man 02481e0
More import fixes
Catfish-Man bb03f0f
Redesign registered resources API
Catfish-Man a396967
More registration tweaks
Catfish-Man d4ca412
Some renaming, and implement linked requests
Catfish-Man 5bfed03
Switch to static methods for constructing requests
Catfish-Man 74366c3
Improve submit API
Catfish-Man 7f6e673
Adjust registered resources API
Catfish-Man 0c6ef16
Fix type
Catfish-Man a22e5f6
Add a version of registerBuffers that isn't varargs
Catfish-Man 6983196
Add unlinkAt support
Catfish-Man 5ba1377
Dubious approach to this, but I want to try it out a bit
Catfish-Man 0064649
Turn on single issuer as an experiment
Catfish-Man 901f4c8
Revert "Turn on single issuer as an experiment"
Catfish-Man 283e8d6
Reapply "Turn on single issuer as an experiment"
Catfish-Man d895f2a
Revert "Reapply "Turn on single issuer as an experiment""
Catfish-Man f3b8cc4
Actually consume events we waited for
Catfish-Man d338de1
Only get one completion if we asked for one completion
Catfish-Man 5e24673
Switch from unsafe pointers to FilePaths, using hacks
Catfish-Man 49dd797
Add a combined "submit and consume" operation
Catfish-Man 91155fd
Plumb error handling through completion consumers
Catfish-Man 9ad16c0
Plumb through userData
Catfish-Man 880ec90
Add a pointer convenience for getting the user data
Catfish-Man 48455a9
Fix plumbing
Catfish-Man 72c316b
Make completions noncopyable again
Catfish-Man File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
WIP, more ~Copyable adoption
commit 10c070abd648bb66da947c77b5a5c645ef1d53fd
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
case nop // nothing here | ||
case openat( | ||
atDirectory: FileDescriptor, | ||
atDirectory: FileDescriptor, | ||
path: UnsafePointer<CChar>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.