Skip to content

Commit

Permalink
Add benchmark for preparing SQE in place
Browse files Browse the repository at this point in the history
Add benchmark for preparing SQE in place.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
  • Loading branch information
jiangliu committed Jan 3, 2022
1 parent c3869d2 commit 36bbda6
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 5 deletions.
39 changes: 36 additions & 3 deletions io-uring-bench/src/nop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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);
34 changes: 32 additions & 2 deletions io-uring-test/src/tests/queue.rs
Original file line number Diff line number Diff line change
@@ -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<()> {
Expand Down Expand Up @@ -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();
Expand All @@ -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::<Vec<_>>();

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;
Expand Down

0 comments on commit 36bbda6

Please sign in to comment.