Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 18 additions & 2 deletions compio-driver/src/iour/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ impl Driver {
if let Some(sqpoll_idle) = builder.sqpoll_idle {
io_uring_builder.setup_sqpoll(sqpoll_idle.as_millis() as _);
}
if builder.coop_taskrun {
io_uring_builder.setup_coop_taskrun();
}
if builder.taskrun_flag {
io_uring_builder.setup_taskrun_flag();
}

let mut inner = io_uring_builder.build(builder.capacity)?;
#[allow(clippy::useless_conversion)]
unsafe {
Expand Down Expand Up @@ -127,14 +134,23 @@ impl Driver {
// Auto means that it choose to wait or not automatically.
fn submit_auto(&mut self, timeout: Option<Duration>) -> io::Result<()> {
instrument!(compio_log::Level::TRACE, "submit_auto", ?timeout);

// when taskrun is true, there are completed cqes wait to handle, no need to
// block the submit
let want_sqe = if self.inner.submission().taskrun() {
0
} else {
1
};

let res = {
// Last part of submission queue, wait till timeout.
if let Some(duration) = timeout {
let timespec = timespec(duration);
let args = SubmitArgs::new().timespec(&timespec);
self.inner.submitter().submit_with_args(1, &args)
self.inner.submitter().submit_with_args(want_sqe, &args)
} else {
self.inner.submit_and_wait(1)
self.inner.submit_and_wait(want_sqe)
}
};
trace!("submit result: {res:?}");
Expand Down
31 changes: 31 additions & 0 deletions compio-driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,8 @@ pub struct ProactorBuilder {
capacity: u32,
pool_builder: ThreadPoolBuilder,
sqpoll_idle: Option<Duration>,
coop_taskrun: bool,
taskrun_flag: bool,
}

impl Default for ProactorBuilder {
Expand All @@ -453,6 +455,8 @@ impl ProactorBuilder {
capacity: 1024,
pool_builder: ThreadPoolBuilder::new(),
sqpoll_idle: None,
coop_taskrun: false,
taskrun_flag: false,
}
}

Expand Down Expand Up @@ -516,6 +520,33 @@ impl ProactorBuilder {
self
}

/// `coop_taskrun` feature has been available since Linux Kernel 5.19. This
/// will optimize performance for most cases, especially compio is a single
/// thread runtime.
///
/// However, it can't run with sqpoll feature.
///
/// # Notes
///
/// - Only effective when the `io-uring` feature is enabled
pub fn coop_taskrun(&mut self, enable: bool) -> &mut Self {
self.coop_taskrun = enable;
self
}

/// `taskrun_flag` feature has been available since Linux Kernel 5.19. This
/// allows io-uring driver can know if any cqes are available when try to
/// push sqe to sq. This should be enabled with
/// [`coop_taskrun`](Self::coop_taskrun)
///
/// # Notes
///
/// - Only effective when the `io-uring` feature is enabled
pub fn taskrun_flag(&mut self, enable: bool) -> &mut Self {
self.taskrun_flag = enable;
self
}

/// Build the [`Proactor`].
pub fn build(&self) -> io::Result<Proactor> {
Proactor::with_builder(self)
Expand Down
Loading