dope_uring/driver/
handle.rs1use std::io;
2
3use io_uring::IoUring;
4
5use crate::driver::{Driver, FixedBufGuard, ProvidedBuf};
6use crate::sys::Cpu;
7use dope_core::driver as caps;
8
9pub fn new_driver(cfg: crate::DriverConfig) -> io::Result<Driver> {
10 tracing::info!("dope: io-uring driver");
11 if let Some(cpu) = cfg.cpu_id {
12 Cpu::pin(cpu)?;
13 }
14 let uring = open_uring(&cfg)?;
15 if !uring.params().is_feature_ext_arg() {
16 return Err(io::Error::new(
17 io::ErrorKind::Unsupported,
18 "dope: io_uring IORING_FEAT_EXT_ARG is required",
19 ));
20 }
21
22 let ring = crate::driver::Ring::new(uring);
23 let hot_cap = (cfg.ring_entries as usize).saturating_mul(8).max(4096);
24 Driver::new(ring, cfg, hot_cap)
25}
26
27fn open_uring(cfg: &crate::DriverConfig) -> io::Result<IoUring> {
28 let mut builder = IoUring::builder();
29 builder.setup_single_issuer();
30 builder.setup_submit_all();
31 if cfg.defer_taskrun {
32 builder.setup_defer_taskrun();
33 }
34 builder.build(cfg.ring_entries)
35}
36
37impl caps::DriverLifecycle for Driver {
38 #[inline(always)]
39 fn drive(&mut self) -> io::Result<bool> {
40 Self::drive(self)
41 }
42 #[inline(always)]
43 fn has_pending(&mut self) -> bool {
44 Self::has_pending(self)
45 }
46 #[inline(always)]
47 fn park(&mut self) -> io::Result<()> {
48 Self::park(self)
49 }
50 #[inline(always)]
51 fn park_for(&mut self, duration: std::time::Duration) -> io::Result<()> {
52 Self::park_for(self, duration)
53 }
54 #[inline(always)]
55 fn submit_only(&mut self) -> io::Result<()> {
56 Self::submit_only(self)
57 }
58}
59
60impl caps::FixedBuffers for Driver {
61 type Guard = FixedBufGuard;
62
63 #[inline(always)]
64 fn fixed_guard(&mut self) -> Option<Self::Guard> {
65 self.resources.fixed_guard()
66 }
67
68 #[inline(always)]
69 fn register_fixed(&mut self, fd: crate::Fd) -> io::Result<Option<u32>> {
70 self.resources.register_fixed(&self.ring, fd)
71 }
72
73 #[inline(always)]
74 fn unregister_fixed(&mut self, idx: u32) {
75 self.resources.unregister_fixed(&self.ring, idx);
76 }
77}
78
79impl caps::ProvidedBufRing for Driver {
80 type Provided = ProvidedBuf;
81
82 #[inline(always)]
83 fn provided_group(&mut self) -> Option<(u16, u32)> {
84 Some(self.provided.group())
85 }
86
87 #[inline(always)]
88 fn provided(&mut self, bid: u16, len: usize) -> Option<Self::Provided> {
89 Some(self.provided.make_buf(bid, len))
90 }
91}