Skip to content

Commit

Permalink
Add Config::defer_task_run
Browse files Browse the repository at this point in the history
Sets IORING_SETUP_DEFER_TASKRUN.
  • Loading branch information
Thomasdezeeuw committed Apr 5, 2024
1 parent 01056eb commit 0f4d484
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct Config<'r> {
completion_entries: Option<u32>,
disabled: bool,
single_issuer: bool,
defer_taskrun: bool,
clamp: bool,
kernel_thread: bool,
cpu_affinity: Option<u32>,
Expand Down Expand Up @@ -61,6 +62,7 @@ impl<'r> Config<'r> {
completion_entries: None,
disabled: false,
single_issuer: false,
defer_taskrun: false,
clamp: false,
kernel_thread: true,
cpu_affinity: None,
Expand Down Expand Up @@ -100,6 +102,24 @@ impl<'r> Config<'r> {
self
}

/// Defer task running.
///
/// By default, kernel will process all outstanding work at the end of any
/// system call or thread interrupt. This can delay the application from
/// making other progress.
///
/// Enabling this option will hint to kernel that it should defer work until
/// [`Ring::poll`] is called. This way the work is done in the
/// [`Ring::poll`].
///
/// This options required [`Config::single_issuer`] to be set. This option
/// does not work with [`Config::with_kernel_thread`] set.
#[doc(alias = "IORING_SETUP_DEFER_TASKRUN")]
pub const fn defer_task_run(mut self) -> Config<'r> {
self.defer_taskrun = true;
self
}

/// Set the size of the completion queue.
///
/// By default the kernel will use a completion queue twice as large as the
Expand Down Expand Up @@ -213,6 +233,9 @@ impl<'r> Config<'r> {
// Only allow access from a single thread.
parameters.flags |= libc::IORING_SETUP_SINGLE_ISSUER;
}
if self.defer_taskrun {
parameters.flags |= libc::IORING_SETUP_DEFER_TASKRUN;
}
if let Some(completion_entries) = self.completion_entries {
parameters.cq_entries = completion_entries;
parameters.flags |= libc::IORING_SETUP_CQSIZE;
Expand Down
15 changes: 15 additions & 0 deletions tests/ring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,21 @@ fn config_single_issuer_disabled_ring() {
.unwrap();
}

#[test]
fn config_defer_task_run() {
require_kernel!(6, 1);
init();

let mut ring = Ring::config(1)
.single_issuer()
.defer_task_run()
.with_kernel_thread(false)
.build()
.unwrap();

ring.poll(Some(Duration::ZERO)).unwrap();
}

#[test]
fn wake_ring() {
init();
Expand Down

0 comments on commit 0f4d484

Please sign in to comment.