Skip to content

feat: add SQPOLL support for io_uring#7960

Open
SidongYang wants to merge 1 commit intotokio-rs:masterfrom
SidongYang:uring-sqpoll
Open

feat: add SQPOLL support for io_uring#7960
SidongYang wants to merge 1 commit intotokio-rs:masterfrom
SidongYang:uring-sqpoll

Conversation

@SidongYang
Copy link

This adds uring_setup_sqpoll to the Runtime Builder, allowing the io_uring driver
to be configured with SQPOLL enabled. This offloads submission queue polling to a
kernel thread, which can significantly reduce syscall overhead.

  • Added uring_setup_sqpoll to tokio::runtime::Builder.
  • Updated UringContext to sync the submission queue and check need_wakeup.
  • Added tests to verify sqpoll in both single-thread and multi-thread runtimes.

/// .unwrap();
/// ```
#[cfg_attr(docsrs, doc(cfg(feature = "io-uring")))]
pub fn uring_setup_sqpoll(&mut self, idle: u32) -> &mut Self {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn uring_setup_sqpoll(&mut self, idle: u32) -> &mut Self {
pub fn uring_setup_sqpoll(&mut self, idle_timeout: u32) -> &mut Self {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Applied.

/// ```
#[cfg_attr(docsrs, doc(cfg(feature = "io-uring")))]
pub fn uring_setup_sqpoll(&mut self, idle: u32) -> &mut Self {
self.uring_setup_sqpoll = Some(idle);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.uring_setup_sqpoll = Some(idle);
self.uring_setup_sqpoll = Some(idle_timeout);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Applied.

self
}

/// Enables SQPOLL for the io_uring driver and sets the idle timeout.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Enables SQPOLL for the io_uring driver and sets the idle timeout.
/// Enables SQPOLL for the io_uring driver and sets the idle timeout (in milliseconds).

if the timeout is in millis. Otherwise, please mention the correct time unit.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Applied.

@Darksonn Darksonn added A-tokio Area: The main tokio crate T-io-uring Topic: Linux io_uring labels Mar 9, 2026
@SidongYang
Copy link
Author

I have updated the PR to address the remaining review comments:

  • Naming: Renamed the idle parameter to idle_timeout in uring_setup_sqpoll and its internal implementation for better clarity.
  • Documentation:
    • Explicitly specified that the idle_timeout unit is in milliseconds.
    • Added prerequisites regarding required Linux kernel versions (5.1+) and CAP_SYS_ADMIN privileges (required before Linux 5.11).
    • Clarified that the first I/O operation will fail if SQPOLL is enabled but not supported by the system.
  • Feature Flags: Standardized cfg attributes for io-uring to consistently include rt, fs, and target_os = "linux" to match workspace conventions and prevent compilation failures.
  • Validation: Verified that the changes compile and that the fs_uring_sqpoll tests pass successfully under tokio_unstable.

@martin-g
Copy link
Member

Please fix the formatting issues and update to master to fix the FreeBSD build

@SidongYang
Copy link
Author

@martin-g Thanks, I've fixed formatting and rebased this branch.

@SidongYang SidongYang requested review from Darksonn and martin-g March 10, 2026 08:56
@martin-g
Copy link
Member

Now the spellchecker is complaining.
Please add SQPOLL to https://github.com/tokio-rs/tokio/blob/master/spellcheck.dic and increment the number on the first line in this file.

@SidongYang
Copy link
Author

Thanks, @martin-g . I've added SQPOLL to the spellcheck file and incremented the number on the first line.

feature = "rt",
feature = "fs",
target_os = "linux"
))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some rustdoc here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I've added a line for rustdoc above. Thanks.

This adds `uring_setup_sqpoll` to the Runtime `Builder`, allowing the io_uring driver
to be configured with SQPOLL enabled. This offloads submission queue polling to a
kernel thread, which can significantly reduce syscall overhead.

- Added `uring_setup_sqpoll` to `tokio::runtime::Builder`.
- Updated `UringContext` to sync the submission queue and check `need_wakeup`.
- Added tests to verify `sqpoll` in both single-thread and multi-thread runtimes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-tokio Area: The main tokio crate T-io-uring Topic: Linux io_uring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants