Skip to content

Commit 4c38ff5

Browse files
authored
Merge pull request #193 from Berrysoft/io-uring-large-qe
feat(driver,iour): add large sqe & cqe support
2 parents 4a0b6b7 + 2027b96 commit 4c38ff5

File tree

4 files changed

+67
-21
lines changed

4 files changed

+67
-21
lines changed

azure-pipelines.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,24 @@ jobs:
3636
matrix:
3737
focal:
3838
image: ubuntu-20.04
39+
features:
3940
jammy:
4041
image: ubuntu-22.04
42+
features: io-uring-sqe128,io-uring-cqe32
4143
pool:
4244
vmImage: $(image)
4345

4446
steps:
4547
- script: |
4648
rustup toolchain install nightly
47-
cargo +nightly test --workspace --features all,nightly
49+
cargo +nightly test --workspace --features all,nightly,$(features)
4850
displayName: TestNightly
4951
- script: |
5052
rustup toolchain install beta
51-
cargo +beta test --workspace --features all
53+
cargo +beta test --workspace --features all,$(features)
5254
displayName: TestBeta
5355
# - script: |
54-
# cargo test --workspace --features all
56+
# cargo test --workspace --features all,$(features)
5557
# displayName: TestStable
5658

5759
- script: |

compio-driver/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ compio-buf = { workspace = true, features = ["arrayvec"] }
7878
default = ["io-uring"]
7979
polling = ["dep:polling"]
8080

81+
io-uring-sqe128 = []
82+
io-uring-cqe32 = []
83+
8184
# Nightly features
8285
once_cell_try = []
8386
nightly = ["once_cell_try"]

compio-driver/src/fusion/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ mod driver_type {
8585
OpenAt::CODE,
8686
Close::CODE,
8787
Shutdown::CODE,
88+
// Linux kernel 5.19
89+
#[cfg(any(feature = "io-uring-seq128", feature = "io-uring-cqe32"))]
90+
Socket::CODE,
8891
];
8992

9093
Ok(())

compio-driver/src/iour/mod.rs

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,22 @@ use std::{
88

99
use compio_log::{instrument, trace};
1010
use crossbeam_queue::SegQueue;
11+
cfg_if::cfg_if! {
12+
if #[cfg(feature = "io-uring-cqe32")] {
13+
use io_uring::cqueue::Entry32 as CEntry;
14+
} else {
15+
use io_uring::cqueue::Entry as CEntry;
16+
}
17+
}
18+
cfg_if::cfg_if! {
19+
if #[cfg(feature = "io-uring-sqe128")] {
20+
use io_uring::squeue::Entry128 as SEntry;
21+
} else {
22+
use io_uring::squeue::Entry as SEntry;
23+
}
24+
}
1125
use io_uring::{
12-
cqueue,
1326
opcode::{AsyncCancel, Read},
14-
squeue,
1527
types::{Fd, SubmitArgs, Timespec},
1628
IoUring,
1729
};
@@ -26,17 +38,27 @@ pub(crate) use crate::unix::RawOp;
2638
/// The created entry of [`OpCode`].
2739
pub enum OpEntry {
2840
/// This operation creates an io-uring submission entry.
29-
Submission(squeue::Entry),
41+
Submission(io_uring::squeue::Entry),
42+
#[cfg(feature = "io-uring-sqe128")]
43+
/// This operation creates an 128-bit io-uring submission entry.
44+
Submission128(io_uring::squeue::Entry128),
3045
/// This operation is a blocking one.
3146
Blocking,
3247
}
3348

34-
impl From<squeue::Entry> for OpEntry {
35-
fn from(value: squeue::Entry) -> Self {
49+
impl From<io_uring::squeue::Entry> for OpEntry {
50+
fn from(value: io_uring::squeue::Entry) -> Self {
3651
Self::Submission(value)
3752
}
3853
}
3954

55+
#[cfg(feature = "io-uring-sqe128")]
56+
impl From<io_uring::squeue::Entry128> for OpEntry {
57+
fn from(value: io_uring::squeue::Entry128) -> Self {
58+
Self::Submission128(value)
59+
}
60+
}
61+
4062
/// Abstraction of io-uring operations.
4163
pub trait OpCode {
4264
/// Create submission entry.
@@ -51,8 +73,8 @@ pub trait OpCode {
5173

5274
/// Low-level driver of io-uring.
5375
pub(crate) struct Driver {
54-
inner: IoUring,
55-
squeue: VecDeque<squeue::Entry>,
76+
inner: IoUring<SEntry, CEntry>,
77+
squeue: VecDeque<SEntry>,
5678
notifier: Notifier,
5779
notifier_registered: bool,
5880
pool: AsyncifyPool,
@@ -67,7 +89,7 @@ impl Driver {
6789
instrument!(compio_log::Level::TRACE, "new", ?builder);
6890
trace!("new iour driver");
6991
Ok(Self {
70-
inner: IoUring::new(builder.capacity)?,
92+
inner: IoUring::builder().build(builder.capacity)?,
7193
squeue: VecDeque::with_capacity(builder.capacity as usize),
7294
notifier: Notifier::new()?,
7395
notifier_registered: false,
@@ -170,24 +192,38 @@ impl Driver {
170192
pub fn cancel(&mut self, user_data: usize, _registry: &mut Slab<RawOp>) {
171193
instrument!(compio_log::Level::TRACE, "cancel", user_data);
172194
trace!("cancel RawOp");
195+
#[allow(clippy::useless_conversion)]
173196
self.squeue.push_back(
174197
AsyncCancel::new(user_data as _)
175198
.build()
176-
.user_data(Self::CANCEL),
199+
.user_data(Self::CANCEL)
200+
.into(),
177201
);
178202
}
179203

180204
pub fn push(&mut self, user_data: usize, op: &mut RawOp) -> Poll<io::Result<usize>> {
181205
instrument!(compio_log::Level::TRACE, "push", user_data);
182206
let op_pin = op.as_pin();
183207
trace!("push RawOp");
184-
if let OpEntry::Submission(entry) = op_pin.create_entry() {
185-
self.squeue.push_back(entry.user_data(user_data as _));
186-
Poll::Pending
187-
} else if self.push_blocking(user_data, op)? {
188-
Poll::Pending
189-
} else {
190-
Poll::Ready(Err(io::Error::from_raw_os_error(libc::EBUSY)))
208+
match op_pin.create_entry() {
209+
OpEntry::Submission(entry) => {
210+
#[allow(clippy::useless_conversion)]
211+
self.squeue
212+
.push_back(entry.user_data(user_data as _).into());
213+
Poll::Pending
214+
}
215+
#[cfg(feature = "io-uring-sqe128")]
216+
OpEntry::Submission128(_entry) => {
217+
self.squeue.push_back(_entry.user_data(user_data as _));
218+
Poll::Pending
219+
}
220+
OpEntry::Blocking => {
221+
if self.push_blocking(user_data, op)? {
222+
Poll::Pending
223+
} else {
224+
Poll::Ready(Err(io::Error::from_raw_os_error(libc::EBUSY)))
225+
}
226+
}
191227
}
192228
}
193229

@@ -223,10 +259,12 @@ impl Driver {
223259
if !self.notifier_registered {
224260
let fd = self.notifier.as_raw_fd();
225261
let dst = self.notifier.dst();
262+
#[allow(clippy::useless_conversion)]
226263
self.squeue.push_back(
227264
Read::new(Fd(fd), dst.as_mut_ptr(), dst.len() as _)
228265
.build()
229-
.user_data(Self::NOTIFY),
266+
.user_data(Self::NOTIFY)
267+
.into(),
230268
);
231269
trace!("registered notifier");
232270
self.notifier_registered = true
@@ -259,7 +297,7 @@ impl AsRawFd for Driver {
259297
}
260298
}
261299

262-
fn create_entry(entry: cqueue::Entry) -> Entry {
300+
fn create_entry(entry: CEntry) -> Entry {
263301
let result = entry.result();
264302
let result = if result < 0 {
265303
let result = if result == -libc::ECANCELED {

0 commit comments

Comments
 (0)