diff --git a/io-uring-bench/src/nop.rs b/io-uring-bench/src/nop.rs index 8a4ff4e5..198f1622 100644 --- a/io-uring-bench/src/nop.rs +++ b/io-uring-bench/src/nop.rs @@ -47,14 +47,13 @@ fn bench_prepare(c: &mut Criterion) { c.bench_function("prepare", |b| { b.iter(|| { let mut queue = TaskQueue(128); - let nop = black_box(opcode::Nop::new()); while queue.want() { { let mut sq = io_uring.submission(); while queue.want() { unsafe { - match sq.push_command(&nop, None) { + match sq.push_command(&black_box(opcode::Nop::new()), None) { Ok(_) => queue.pop(), Err(_) => break, } @@ -69,5 +68,39 @@ fn bench_prepare(c: &mut Criterion) { }); }); } -criterion_group!(squeue, bench_normal, bench_prepare); + +fn bench_prepare_sqe(c: &mut Criterion) { + let mut io_uring = IoUring::new(16).unwrap(); + + c.bench_function("prepare_sqe", |b| { + b.iter(|| { + let mut queue = TaskQueue(128); + + while queue.want() { + { + let mut sq = io_uring.submission(); + while queue.want() { + unsafe { + match sq.get_available_sqe(0) { + Ok(sqe) => { + let nop_sqe: &mut opcode::NopSqe = black_box(sqe.into()); + nop_sqe.prepare(); + sq.move_forward(1); + queue.pop(); + } + Err(_) => break, + }; + } + } + } + + io_uring.submit_and_wait(16).unwrap(); + + io_uring.completion().map(black_box).for_each(drop); + } + }); + }); +} + +criterion_group!(squeue, bench_normal, bench_prepare, bench_prepare_sqe); criterion_main!(squeue); diff --git a/io-uring-test/src/tests/queue.rs b/io-uring-test/src/tests/queue.rs index 439ee7a1..9a556c12 100644 --- a/io-uring-test/src/tests/queue.rs +++ b/io-uring-test/src/tests/queue.rs @@ -1,5 +1,5 @@ use crate::Test; -use io_uring::squeue::OptionValues; +use io_uring::squeue::SqeCommonOptions; use io_uring::{opcode, IoUring}; pub fn test_nop(ring: &mut IoUring, test: &Test) -> anyhow::Result<()> { @@ -35,7 +35,7 @@ pub fn test_nop_prepare(ring: &mut IoUring, test: &Test) -> anyhow::Result<()> { println!("test nop with prepare"); let nop = opcode::Nop::new(); - let opt = OptionValues::default().user_data(0x42); + let opt = SqeCommonOptions::default().user_data(0x42); unsafe { let mut queue = ring.submission(); @@ -53,6 +53,36 @@ pub fn test_nop_prepare(ring: &mut IoUring, test: &Test) -> anyhow::Result<()> { Ok(()) } +#[cfg(feature = "unstable")] +pub fn test_nop_prepare_sqe(ring: &mut IoUring, test: &Test) -> anyhow::Result<()> { + require! { + test; + } + + println!("test nop with prepare"); + + let opt = SqeCommonOptions::default().user_data(0x42); + + unsafe { + let mut queue = ring.submission(); + let sqe = queue.get_available_sqe(0).unwrap(); + let nop_sqe: &mut crate::opcode::NopSqe = sqe.into(); + nop_sqe.prepare(); + opt.set(nop_sqe.get_mut_sqe()); + queue.move_forward(1); + } + + ring.submit_and_wait(1)?; + + let cqes = ring.completion().collect::>(); + + assert_eq!(cqes.len(), 1); + assert_eq!(cqes[0].user_data(), 0x42); + assert_eq!(cqes[0].result(), 0); + + Ok(()) +} + #[cfg(feature = "unstable")] pub fn test_batch(ring: &mut IoUring, test: &Test) -> anyhow::Result<()> { use std::mem::MaybeUninit;