Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: check if monoio is using io uring (#84) #188

Merged
merged 3 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 0 additions & 47 deletions crates/server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,18 +196,6 @@ impl Game {
info!("Starting hyperion");
Lazy::force(&config::CONFIG);

// if linux
#[cfg(target_os = "linux")]
{
info!("Running on linux");

if let Err(e) = try_io_uring() {
warn!("io_uring not supported: {e}");
} else {
info!("io_uring supported");
}
}

let current_threads = rayon::current_num_threads();
let max_threads = rayon::max_num_threads();

Expand Down Expand Up @@ -455,38 +443,3 @@ impl EntityReaction {
unsafe impl Send for EntityReaction {}

unsafe impl Sync for EntityReaction {}

#[cfg(target_os = "linux")]
fn try_io_uring() -> anyhow::Result<()> {
use std::{fs, os::unix::io::AsRawFd};

use io_uring::{opcode, types, IoUring};

let mut ring = IoUring::new(8)?;

let fd = fs::File::open("/dev/urandom")?;
let mut buf = vec![0; 1024];

let read_e = opcode::Read::new(
types::Fd(fd.as_raw_fd()),
buf.as_mut_ptr(),
buf.len().try_into()?,
)
.build()
.user_data(0x42);

unsafe {
ring.submission()
.push(&read_e)
.expect("submission queue is full");
}

ring.submit_and_wait(1)?;

let cqe = ring.completion().next().expect("completion queue is empty");

assert_eq!(cqe.user_data(), 0x42);
assert!(cqe.result() >= 0, "read error: {}", cqe.result());

Ok(())
}
13 changes: 12 additions & 1 deletion crates/server/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ use evenio::prelude::Component;
use monoio::{
io::{AsyncReadRent, AsyncWriteRentExt, OwnedReadHalf, OwnedWriteHalf, Splitable},
net::{TcpListener, TcpStream},
FusionRuntime,
};
use serde_json::json;
use sha2::Digest;
use tracing::{debug, error, instrument, trace, warn};
use tracing::{debug, error, info, instrument, trace, warn};
use valence_protocol::{
decode::PacketFrame,
nbt::{compound, Compound, List},
Expand Down Expand Up @@ -628,6 +629,16 @@ pub fn init_io_thread(
.build()
.unwrap();

match &runtime {
#[cfg(target_os = "linux")]
FusionRuntime::Uring(_) => {
info!("monoio is using io_uring runtime");
}
FusionRuntime::Legacy(_) => {
info!("monoio is using legacy runtime");
}
}

runtime.block_on(async move {
let run = main_loop(connection_tx, address, shared);
let shutdown = shutdown.recv_async();
Expand Down