Skip to content

Commit

Permalink
Set IOSQE_ASYNC for some operations
Browse files Browse the repository at this point in the history
For operations which we don't expect to complete the first time the
submission event is processed we let the kernel know not to attempt do
non-blocking operation first, but instead do it in an async manner from
the start.

We do this for:
 * such as receiving process signal,
 * accepting connections, and
 * polling.
  • Loading branch information
Thomasdezeeuw committed Apr 27, 2024
1 parent 6e5466c commit eef3fb3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,7 @@ op_future! {
let (ptr, len) = SocketAddress::as_mut_ptr(&mut address.0);
address.1 = len;
submission.accept(fd.fd(), ptr, &mut address.1, flags);
submission.set_async();
D::create_flags(submission);
},
map_result: |this, (address,), fd| {
Expand All @@ -1049,6 +1050,7 @@ op_async_iter! {
setup_state: flags: libc::c_int,
setup: |submission, this, flags| unsafe {
submission.multishot_accept(this.fd.fd(), flags);
submission.set_async();
D::create_flags(submission);
},
map_result: |this, _flags, fd| {
Expand Down
6 changes: 6 additions & 0 deletions src/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ impl Submission {
self.inner.flags |= libc::IOSQE_CQE_SKIP_SUCCESS;
}

/// Don't attempt to do the operation non-blocking first, always execute it
/// in an async manner.
pub(crate) fn set_async(&mut self) {
self.inner.flags |= libc::IOSQE_ASYNC;
}

/// Set the flag to use direct descriptors.
pub(crate) fn use_direct_fd(&mut self) {
self.inner.flags |= libc::IOSQE_FIXED_FILE;
Expand Down
2 changes: 2 additions & 0 deletions src/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl<'sq> Future for OneshotPoll<'sq> {
ctx,
|submission, (fd, mask)| unsafe {
submission.poll(fd, mask as u32);
submission.set_async();
}
);

Expand Down Expand Up @@ -91,6 +92,7 @@ impl<'sq> Drop for OneshotPoll<'sq> {
if let OpState::Running(op_index) = self.state {
let result = self.sq.cancel_op(op_index, (), |submission| unsafe {
submission.remove_poll(op_index);
submission.set_async();
// We'll get a canceled completion event if we succeeded, which
// is sufficient to cleanup the operation.
submission.no_completion_event();
Expand Down
2 changes: 2 additions & 0 deletions src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ op_future! {
setup: |submission, fd, (info,), _unused| unsafe {
let ptr = (**info).as_mut_ptr().cast();
submission.read_at(fd.fd(), ptr, size_of::<libc::signalfd_siginfo>() as u32, NO_OFFSET);
submission.set_async();
D::use_flags(submission);
},
map_result: |this, (info,), n| {
Expand Down Expand Up @@ -525,6 +526,7 @@ impl<D: Descriptor> ReceiveSignals<D> {
size_of::<libc::signalfd_siginfo>() as u32,
NO_OFFSET,
);
submission.set_async();
D::use_flags(submission);
});
match result {
Expand Down

0 comments on commit eef3fb3

Please sign in to comment.