-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c0e4e78
commit ffea19f
Showing
1 changed file
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
use mempipe::{SendPipe, RecvPipe}; | ||
|
||
/// Benchmark was run on a custom init, thus no other processes or threads | ||
/// running on the Linux system | ||
fn main() { | ||
fn pin_core(core: usize) { | ||
unsafe { | ||
let mut cpuset = [0u8; 64]; | ||
cpuset[core / 8] |= 1 << (core % 8) as u8; | ||
assert!(libc::sched_setaffinity( | ||
0, cpuset.len(), cpuset.as_ptr() as *const _) != -1); | ||
} | ||
} | ||
|
||
// Create `/proc` | ||
std::fs::create_dir_all("/proc").unwrap(); | ||
|
||
// Mount procfs | ||
unsafe { | ||
while libc::umount(c"/proc".as_ptr()) != -1 {} | ||
|
||
if libc::mount(c"proc".as_ptr(), c"/proc".as_ptr(), | ||
c"proc".as_ptr(), | ||
0, std::ptr::null_mut()) == -1 { | ||
panic!("{:?}", std::io::Error::last_os_error()); | ||
} | ||
} | ||
|
||
std::fs::create_dir_all("/dev/shm").unwrap(); | ||
|
||
println!("{}", std::fs::read_to_string("/proc/cpuinfo").unwrap()); | ||
|
||
/* | ||
for file in std::fs::read_dir("/proc").unwrap() { | ||
let file = file.unwrap(); | ||
if let Ok(pid) = file.path().file_name().unwrap().to_str().unwrap().parse::<i32>() { | ||
println!("{}", std::fs::read_to_string(format!("/proc/{pid}/stat")).unwrap()); | ||
} | ||
}*/ | ||
|
||
for core in 0..192 { | ||
for core2 in 0..192 { | ||
pin_core(core); | ||
|
||
let iters = if core == core2 { | ||
100 | ||
} else { | ||
1000000 | ||
}; | ||
|
||
// We should fail to make a pipe with a mismatched size | ||
let mut tx = SendPipe::<1, 4>::create().unwrap(); | ||
let id = tx.uid(); | ||
|
||
let thr = std::thread::spawn(move || { | ||
pin_core(core2); | ||
|
||
let rx = RecvPipe::<1, 4>::open(id).unwrap(); | ||
let mut ticket = rx.request_ticket(); | ||
let mut foop = 0; | ||
while foop < iters { | ||
let (new_ticket, res) = rx.try_recv(ticket, |_| -> Result<(), ()> { | ||
Ok(()) | ||
}); | ||
|
||
if res.is_some() { | ||
foop += 1; | ||
} | ||
|
||
ticket = new_ticket; | ||
} | ||
}); | ||
|
||
let it = rdtsc(); | ||
for _ in 0..iters { | ||
tx.alloc_buffer(false); | ||
} | ||
|
||
let _ = thr.join().unwrap(); | ||
let elapsed = rdtsc() - it; | ||
|
||
println!("{core:3} {core2:3} {:14.3}", | ||
elapsed as f64 / iters as f64); | ||
} | ||
} | ||
} | ||
|