diff --git a/compio-driver/src/lib.rs b/compio-driver/src/lib.rs index ffa93508..f6f83761 100644 --- a/compio-driver/src/lib.rs +++ b/compio-driver/src/lib.rs @@ -545,6 +545,7 @@ pub struct ProactorBuilder { capacity: u32, pool_builder: ThreadPoolBuilder, sqpoll_idle: Option, + sqpoll_cpu: Option, cqsize: Option, coop_taskrun: bool, taskrun_flag: bool, @@ -574,6 +575,7 @@ impl ProactorBuilder { capacity: 1024, pool_builder: ThreadPoolBuilder::new(), sqpoll_idle: None, + sqpoll_cpu: None, cqsize: None, coop_taskrun: false, taskrun_flag: false, @@ -660,6 +662,22 @@ impl ProactorBuilder { self } + /// Set CPU affinity for the `io-uring` SQPOLL thread when SQPOLL is + /// enabled. + /// + /// This is only applied when SQPOLL is enabled with + /// [`sqpoll_idle`](Self::sqpoll_idle). + /// + /// # Notes + /// + /// - Only effective when the `io-uring` feature is enabled + /// - `cpu` must be less than the number of cpus in the system, otherwise it + /// will return an error when building the proactor. + pub fn sqpoll_cpu(&mut self, cpu: u32) -> &mut Self { + self.sqpoll_cpu = Some(cpu); + self + } + /// Optimize performance for most cases, especially compio is a single /// thread runtime. /// diff --git a/compio-driver/src/sys/driver/iour/mod.rs b/compio-driver/src/sys/driver/iour/mod.rs index e79431d3..1414f36c 100644 --- a/compio-driver/src/sys/driver/iour/mod.rs +++ b/compio-driver/src/sys/driver/iour/mod.rs @@ -69,6 +69,9 @@ impl Driver { let mut io_uring_builder = IoUring::builder(); if let Some(sqpoll_idle) = builder.sqpoll_idle { io_uring_builder.setup_sqpoll(sqpoll_idle.as_millis() as _); + if let Some(cpu) = builder.sqpoll_cpu { + io_uring_builder.setup_sqpoll_cpu(cpu); + } } if builder.coop_taskrun { io_uring_builder.setup_coop_taskrun();