Skip to content

Commit a2032b9

Browse files
committed
rt: add infrastructure code for io_uring
1 parent bdd64cc commit a2032b9

File tree

16 files changed

+605
-39
lines changed

16 files changed

+605
-39
lines changed

.github/workflows/ci.yml

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,40 @@ jobs:
350350
# the unstable cfg to RustDoc
351351
RUSTDOCFLAGS: --cfg tokio_unstable --cfg tokio_taskdump
352352

353+
test-unstable-uring:
354+
name: test tokio full --cfg tokio_unstable_uring
355+
needs: basics
356+
runs-on: ${{ matrix.os }}
357+
strategy:
358+
matrix:
359+
include:
360+
- os: ubuntu-latest
361+
steps:
362+
- uses: actions/checkout@v4
363+
- name: Install Rust ${{ env.rust_stable }}
364+
uses: dtolnay/rust-toolchain@stable
365+
with:
366+
toolchain: ${{ env.rust_stable }}
367+
368+
- name: Install cargo-nextest
369+
uses: taiki-e/install-action@v2
370+
with:
371+
tool: cargo-nextest
372+
373+
- uses: Swatinem/rust-cache@v2
374+
# Run `tokio` with "unstable" and "taskdump" cfg flags.
375+
- name: test tokio full --cfg tokio_unstable_uring
376+
run: |
377+
set -euxo pipefail
378+
cargo nextest run --all-features
379+
cargo test --doc --all-features
380+
working-directory: tokio
381+
env:
382+
RUSTFLAGS: --cfg tokio_unstable_uring -Dwarnings
383+
# in order to run doctests for unstable features, we must also pass
384+
# the unstable cfg to RustDoc
385+
RUSTDOCFLAGS: --cfg tokio_unstable_uring
386+
353387
check-unstable-mt-counters:
354388
name: check tokio full --internal-mt-counters
355389
needs: basics
@@ -664,7 +698,7 @@ jobs:
664698
cargo test --doc -Zbuild-std --target target-specs/i686-unknown-linux-gnu.json -p tokio --all-features
665699
env:
666700
RUST_TEST_THREADS: 1
667-
RUSTFLAGS: --cfg tokio_unstable --cfg tokio_taskdump -Dwarnings --cfg tokio_no_tuning_tests
701+
RUSTFLAGS: --cfg tokio_unstable --cfg tokio_taskdump --cfg=io_uring_skip_arch_check -Dwarnings --cfg tokio_no_tuning_tests
668702

669703
no-atomic-u64-check:
670704
name: Check tokio --feature-powerset --depth 2 on i686-unknown-linux-gnu without AtomicU64
@@ -702,7 +736,7 @@ jobs:
702736
# Try with unstable feature flags
703737
- { name: "--unstable", rustflags: "--cfg tokio_unstable -Dwarnings" }
704738
# Try with unstable and taskdump feature flags
705-
- { name: "--unstable --taskdump", rustflags: "--cfg tokio_unstable -Dwarnings --cfg tokio_taskdump" }
739+
- { name: "--unstable --taskdump", rustflags: "--cfg tokio_unstable -Dwarnings --cfg tokio_taskdump --cfg tokio_unstable_uring" }
706740
steps:
707741
- uses: actions/checkout@v4
708742
- name: Install Rust ${{ env.rust_nightly }}
@@ -765,7 +799,7 @@ jobs:
765799
cargo hack check --all-features --ignore-private
766800
- name: "check --all-features --unstable -Z minimal-versions"
767801
env:
768-
RUSTFLAGS: --cfg tokio_unstable --cfg tokio_taskdump -Dwarnings
802+
RUSTFLAGS: --cfg tokio_unstable --cfg tokio_taskdump --cfg tokio_unstable_uring -Dwarnings
769803
run: |
770804
# Remove dev-dependencies from Cargo.toml to prevent the next `cargo update`
771805
# from determining minimal versions based on dev-dependencies.
@@ -817,8 +851,8 @@ jobs:
817851
run:
818852
- os: windows-latest
819853
- os: ubuntu-latest
820-
RUSTFLAGS: --cfg tokio_taskdump
821-
RUSTDOCFLAGS: --cfg tokio_taskdump
854+
RUSTFLAGS: --cfg tokio_taskdump --cfg tokio_unstable_uring
855+
RUSTDOCFLAGS: --cfg tokio_taskdump --cfg tokio_unstable_uring
822856

823857
steps:
824858
- uses: actions/checkout@v4

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ unexpected_cfgs = { level = "warn", check-cfg = [
2929
'cfg(tokio_no_tuning_tests)',
3030
'cfg(tokio_taskdump)',
3131
'cfg(tokio_unstable)',
32+
'cfg(tokio_unstable_uring)',
3233
] }

spellcheck.dic

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
302
1+
306
22
&
33
+
44
<
@@ -70,6 +70,9 @@ connectionless
7070
coroutines
7171
cpu
7272
cpus
73+
cqe
74+
CQE
75+
cqe's
7376
customizable
7477
Customizable
7578
datagram
@@ -287,6 +290,7 @@ unsets
287290
Unsets
288291
unsynchronized
289292
untrusted
293+
uring
290294
usecases
291295
Valgrind
292296
Varghese

tokio/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ socket2 = { version = "0.5.5", optional = true, features = ["all"] }
103103
[target.'cfg(tokio_unstable)'.dependencies]
104104
tracing = { version = "0.1.29", default-features = false, features = ["std"], optional = true } # Not in full
105105

106+
[target.'cfg(all(tokio_unstable_uring, target_os = "linux"))'.dependencies]
107+
io-uring = { version = "0.7.6", default-features = false }
108+
libc = { version = "0.2.168" }
109+
mio = { version = "1.0.1", default-features = false, features = ["os-poll", "os-ext"] }
110+
slab = "0.4.9"
111+
106112
# Currently unstable. The API exposed by these features may be broken at any time.
107113
# Requires `--cfg tokio_unstable` to enable.
108114
[target.'cfg(tokio_taskdump)'.dependencies]

tokio/src/io/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,11 @@ pub use self::read_buf::ReadBuf;
214214
#[doc(no_inline)]
215215
pub use std::io::{Error, ErrorKind, Result, SeekFrom};
216216

217-
cfg_io_driver_impl! {
217+
cfg_io_driver_impl_or_uring! {
218218
pub(crate) mod interest;
219219
pub(crate) mod ready;
220220

221-
cfg_net! {
221+
cfg_net_or_uring! {
222222
pub use interest::Interest;
223223
pub use ready::Ready;
224224
}

tokio/src/io/poll_evented.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::ops::Deref;
99
use std::panic::{RefUnwindSafe, UnwindSafe};
1010
use std::task::ready;
1111

12-
cfg_io_driver! {
12+
cfg_io_driver_or_uring! {
1313
/// Associates an I/O resource that implements the [`std::io::Read`] and/or
1414
/// [`std::io::Write`] traits with the reactor that drives it.
1515
///

tokio/src/macros/cfg.rs

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,36 @@ macro_rules! cfg_io_driver {
131131
}
132132
}
133133

134+
macro_rules! cfg_io_driver_or_uring {
135+
($($item:item)*) => {
136+
$(
137+
#[cfg(any(
138+
feature = "net",
139+
all(unix, feature = "process"),
140+
all(unix, feature = "signal"),
141+
all(
142+
tokio_unstable_uring,
143+
feature = "rt",
144+
feature = "fs",
145+
target_os = "linux",
146+
)
147+
))]
148+
#[cfg_attr(docsrs, doc(cfg(any(
149+
feature = "net",
150+
all(unix, feature = "process"),
151+
all(unix, feature = "signal"),
152+
all(
153+
tokio_unstable_uring,
154+
feature = "rt",
155+
feature = "fs",
156+
target_os = "linux",
157+
)
158+
))))]
159+
$item
160+
)*
161+
}
162+
}
163+
134164
macro_rules! cfg_io_driver_impl {
135165
( $( $item:item )* ) => {
136166
$(
@@ -157,6 +187,44 @@ macro_rules! cfg_not_io_driver {
157187
}
158188
}
159189

190+
macro_rules! cfg_io_driver_impl_or_uring {
191+
( $( $item:item )* ) => {
192+
$(
193+
#[cfg(any(
194+
feature = "net",
195+
all(unix, feature = "process"),
196+
all(unix, feature = "signal"),
197+
all(
198+
tokio_unstable_uring,
199+
feature = "rt",
200+
feature = "fs",
201+
target_os = "linux",
202+
)
203+
))]
204+
$item
205+
)*
206+
}
207+
}
208+
209+
macro_rules! cfg_not_io_driver_impl_or_uring {
210+
( $( $item:item )* ) => {
211+
$(
212+
#[cfg(not(any(
213+
feature = "net",
214+
all(unix, feature = "process"),
215+
all(unix, feature = "signal"),
216+
all(
217+
tokio_unstable_uring,
218+
feature = "rt",
219+
feature = "fs",
220+
target_os = "linux",
221+
)
222+
)))]
223+
$item
224+
)*
225+
}
226+
}
227+
160228
macro_rules! cfg_io_readiness {
161229
($($item:item)*) => {
162230
$(
@@ -279,6 +347,35 @@ macro_rules! cfg_net {
279347
}
280348
}
281349

350+
macro_rules! cfg_net_or_uring {
351+
($($item:item)*) => {
352+
$(
353+
#[cfg(any(
354+
feature = "net",
355+
all(
356+
tokio_unstable_uring,
357+
feature = "rt",
358+
feature = "fs",
359+
target_os = "linux",
360+
)
361+
))]
362+
#[cfg_attr(
363+
docsrs,
364+
doc(cfg(any(
365+
feature = "net",
366+
all(
367+
tokio_unstable_uring,
368+
feature = "rt",
369+
feature = "fs",
370+
target_os = "linux",
371+
)
372+
)))
373+
)]
374+
$item
375+
)*
376+
}
377+
}
378+
282379
macro_rules! cfg_net_unix {
283380
($($item:item)*) => {
284381
$(
@@ -616,3 +713,17 @@ macro_rules! cfg_metrics_variant {
616713
}
617714
}
618715
}
716+
717+
macro_rules! cfg_tokio_unstable_uring {
718+
($($item:item)*) => {
719+
$(
720+
#[cfg(all(
721+
tokio_unstable_uring,
722+
feature = "rt",
723+
feature = "fs",
724+
target_os = "linux",
725+
))]
726+
$item
727+
)*
728+
};
729+
}

tokio/src/runtime/driver.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl Handle {
8484
self.io.unpark();
8585
}
8686

87-
cfg_io_driver! {
87+
cfg_io_driver_or_uring! {
8888
#[track_caller]
8989
pub(crate) fn io(&self) -> &crate::runtime::io::Handle {
9090
self.io
@@ -121,7 +121,7 @@ impl Handle {
121121

122122
// ===== io driver =====
123123

124-
cfg_io_driver! {
124+
cfg_io_driver_impl_or_uring! {
125125
pub(crate) type IoDriver = crate::runtime::io::Driver;
126126

127127
#[derive(Debug)]
@@ -196,7 +196,7 @@ cfg_io_driver! {
196196
}
197197
}
198198

199-
cfg_not_io_driver! {
199+
cfg_not_io_driver_impl_or_uring! {
200200
pub(crate) type IoHandle = UnparkThread;
201201

202202
#[derive(Debug)]
@@ -226,6 +226,13 @@ cfg_not_io_driver! {
226226
false
227227
}
228228
}
229+
cfg_io_driver_or_uring! {
230+
impl IoHandle {
231+
pub(crate) fn as_ref(&self) -> Option<&crate::runtime::io::Handle> {
232+
todo!()
233+
}
234+
}
235+
}
229236
}
230237

231238
// ===== signal driver =====
@@ -244,7 +251,7 @@ cfg_signal_internal_and_unix! {
244251
cfg_not_signal_internal! {
245252
pub(crate) type SignalHandle = ();
246253

247-
cfg_io_driver! {
254+
cfg_io_driver_impl_or_uring! {
248255
type SignalDriver = IoDriver;
249256

250257
fn create_signal_driver(io_driver: IoDriver, _io_handle: &crate::runtime::io::Handle) -> io::Result<(SignalDriver, SignalHandle)> {
@@ -264,7 +271,7 @@ cfg_process_driver! {
264271
}
265272

266273
cfg_not_process_driver! {
267-
cfg_io_driver! {
274+
cfg_io_driver_impl_or_uring! {
268275
type ProcessDriver = SignalDriver;
269276

270277
fn create_process_driver(signal_driver: SignalDriver) -> ProcessDriver {
@@ -347,3 +354,7 @@ cfg_not_time! {
347354
(io_stack, ())
348355
}
349356
}
357+
358+
cfg_tokio_unstable_uring! {
359+
pub(crate) mod op;
360+
}

0 commit comments

Comments
 (0)