diff options
| author | ihc童鞋@提不起劲 <[email protected]> | 2023-07-11 20:09:21 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-07-11 20:09:21 +0800 |
| commit | d1e80e2c98e168a271803e313a8697d7cf30aaf4 (patch) | |
| tree | 3263890e3b0ecbdacbb63d3de54072bfce1db360 | |
| parent | 0624bea6b71189037acc68b62f9e263ba6c89c50 (diff) | |
refactor: detect feature instead of enable feature (#191)
| -rw-r--r-- | examples/Cargo.toml | 1 | ||||
| -rw-r--r-- | monoio/Cargo.toml | 4 | ||||
| -rw-r--r-- | monoio/src/driver/uring/mod.rs | 50 |
3 files changed, 26 insertions, 29 deletions
diff --git a/examples/Cargo.toml b/examples/Cargo.toml index cb5b94b..577a00f 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -17,7 +17,6 @@ monoio = { path = "../monoio", default-features = false, features = [ "legacy", "macros", "utils", - "enter-args", ] } # Enable tracing and tracing-subscriber for print out runtime debug diff --git a/monoio/Cargo.toml b/monoio/Cargo.toml index 04262d2..8451f93 100644 --- a/monoio/Cargo.toml +++ b/monoio/Cargo.toml @@ -57,10 +57,6 @@ async-cancel = [] # enanle zero copy(enable SOCK_ZEROCOPY + MSG_ZEROCOPY flag) # WARNING: this feature may cause performance degradation zero-copy = [] -# will use enter+args to park with timeout on uring driver -# better performance but requires 5.11+ -# has no effect on legacy driver -enter-args = [] # splice op(requires kernel 5.7+) splice = [] # enable `async main` macros support diff --git a/monoio/src/driver/uring/mod.rs b/monoio/src/driver/uring/mod.rs index f93e13e..024b409 100644 --- a/monoio/src/driver/uring/mod.rs +++ b/monoio/src/driver/uring/mod.rs @@ -10,7 +10,7 @@ use std::{ time::Duration, }; -use io_uring::{cqueue, types::Timespec, IoUring}; +use io_uring::{cqueue, opcode, types::Timespec, IoUring}; use lifecycle::Lifecycle; use super::{ @@ -28,7 +28,6 @@ pub(crate) use waker::UnparkHandle; #[allow(unused)] pub(crate) const CANCEL_USERDATA: u64 = u64::MAX; -#[cfg(not(feature = "enter-args"))] pub(crate) const TIMEOUT_USERDATA: u64 = u64::MAX - 1; #[allow(unused)] pub(crate) const EVENTFD_USERDATA: u64 = u64::MAX - 2; @@ -69,6 +68,9 @@ pub(crate) struct UringInner { // Waker receiver #[cfg(feature = "sync")] waker_receiver: flume::Receiver<std::task::Waker>, + + // Uring support ext_arg + ext_arg: bool, } // When dropping the driver, all in-flight operations must have completed. This @@ -93,6 +95,7 @@ impl IoUringDriver { let inner = Rc::new(UnsafeCell::new(UringInner { ops: Ops::new(), + ext_arg: uring.params().is_feature_ext_arg(), uring, })); @@ -122,6 +125,7 @@ impl IoUringDriver { let inner = Rc::new(UnsafeCell::new(UringInner { ops: Ops::new(), + ext_arg: uring.params().is_feature_ext_arg(), uring, shared_waker: std::sync::Arc::new(waker::EventWaker::new(waker)), eventfd_installed: false, @@ -161,7 +165,7 @@ impl IoUringDriver { #[cfg(feature = "sync")] fn install_eventfd(&self, inner: &mut UringInner, fd: RawFd) { - let entry = io_uring::opcode::Read::new(io_uring::types::Fd(fd), self.eventfd_read_dst, 8) + let entry = opcode::Read::new(io_uring::types::Fd(fd), self.eventfd_read_dst, 8) .build() .user_data(EVENTFD_USERDATA); @@ -170,13 +174,12 @@ impl IoUringDriver { inner.eventfd_installed = true; } - #[cfg(not(feature = "enter-args"))] fn install_timeout(&self, inner: &mut UringInner, duration: Duration) { let timespec = timespec(duration); unsafe { std::ptr::replace(self.timespec, timespec); } - let entry = io_uring::opcode::Timeout::new(self.timespec as *const Timespec) + let entry = opcode::Timeout::new(self.timespec as *const Timespec) .build() .user_data(TIMEOUT_USERDATA); @@ -235,23 +238,22 @@ impl IoUringDriver { self.install_eventfd(inner, inner.shared_waker.as_raw_fd()); } if let Some(duration) = timeout { - // Submit and Wait with timeout in an TimeoutOp way. - // Better compatibility(5.4+). - #[cfg(not(feature = "enter-args"))] - { - self.install_timeout(inner, duration); - inner.uring.submit_and_wait(1)?; - } - - // Submit and Wait with enter args. - // Better performance(5.11+). - #[cfg(feature = "enter-args")] - { - let timespec = timespec(duration); - let args = io_uring::types::SubmitArgs::new().timespec(×pec); - if let Err(e) = inner.uring.submitter().submit_with_args(1, &args) { - if e.raw_os_error() != Some(libc::ETIME) { - return Err(e); + match inner.ext_arg { + // Submit and Wait with timeout in an TimeoutOp way. + // Better compatibility(5.4+). + false => { + self.install_timeout(inner, duration); + inner.uring.submit_and_wait(1)?; + } + // Submit and Wait with enter args. + // Better performance(5.11+). + true => { + let timespec = timespec(duration); + let args = io_uring::types::SubmitArgs::new().timespec(×pec); + if let Err(e) = inner.uring.submitter().submit_with_args(1, &args) { + if e.raw_os_error() != Some(libc::ETIME) { + return Err(e); + } } } } @@ -422,7 +424,7 @@ impl UringInner { #[cfg(feature = "async-cancel")] if !_must_finished { unsafe { - let cancel = io_uring::opcode::AsyncCancel::new(index as u64) + let cancel = opcode::AsyncCancel::new(index as u64) .build() .user_data(u64::MAX); @@ -438,7 +440,7 @@ impl UringInner { pub(crate) unsafe fn cancel_op(this: &Rc<UnsafeCell<UringInner>>, index: usize) { let inner = &mut *this.get(); - let cancel = io_uring::opcode::AsyncCancel::new(index as u64) + let cancel = opcode::AsyncCancel::new(index as u64) .build() .user_data(u64::MAX); if inner.uring.submission().push(&cancel).is_err() { |
