-
Notifications
You must be signed in to change notification settings - Fork 28
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
2ba7eb3
commit 53867a6
Showing
4 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,44 @@ | ||
mod common; | ||
|
||
use byte_unit::{Byte, Unit}; | ||
use common::{build_hermit_bin, check_result}; | ||
use regex::Regex; | ||
use uhyvelib::{ | ||
params::{Output, Params}, | ||
vm::UhyveVm, | ||
}; | ||
|
||
#[test] | ||
fn multicore_test() { | ||
env_logger::try_init().ok(); | ||
let bin_path = build_hermit_bin("multi-thread"); | ||
|
||
let re = Regex::new(r"Speedup: [\d]+us / \d+us =\s*([\d.]+)").unwrap(); | ||
|
||
for nr_cpus in [2, 4] { | ||
println!("Launching kernel {}", bin_path.display()); | ||
let params = Params { | ||
cpu_count: nr_cpus.try_into().unwrap(), | ||
memory_size: Byte::from_u64_with_unit(64, Unit::MiB) | ||
.unwrap() | ||
.try_into() | ||
.unwrap(), | ||
output: Output::Buffer, | ||
..Default::default() | ||
}; | ||
let vm = UhyveVm::new(bin_path.clone(), params).unwrap(); | ||
let res = vm.run(None); | ||
check_result(&res); | ||
|
||
let outp = res.output.unwrap(); | ||
let caps = re | ||
.captures(outp.as_str()) | ||
.expect("Speedup not present in test output"); | ||
dbg!(&caps); | ||
let speedup = caps.get(1).unwrap().as_str().parse::<f64>().unwrap(); | ||
dbg!(&speedup); | ||
if speedup < nr_cpus as f64 * 0.66 { | ||
panic!("Speedup of {speedup} is not enough for a CPU count of {nr_cpus}"); | ||
} | ||
} | ||
} |
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,47 @@ | ||
use std::{hint::black_box, thread, time::Instant}; | ||
|
||
#[cfg(target_os = "hermit")] | ||
use hermit as _; | ||
|
||
fn gauss_sum(n: u64) -> u64 { | ||
if n == 0 { | ||
return 0; | ||
} | ||
n + gauss_sum(n - 1) | ||
} | ||
|
||
fn main() { | ||
println!("Multi threading test"); | ||
|
||
const CNT: usize = 50000; | ||
const NR_THREADS: usize = 4; | ||
|
||
let start = Instant::now(); | ||
for _ in 0..CNT { | ||
let _result = black_box(gauss_sum(black_box(10000))); | ||
} | ||
let duration_single_thread = start.elapsed(); // Calculate elapsed time | ||
println!("Duration single thread: {duration_single_thread:?}"); | ||
|
||
let mut threads = Vec::with_capacity(NR_THREADS); | ||
let start = Instant::now(); | ||
for _ in 0..NR_THREADS { | ||
threads.push(thread::spawn(|| { | ||
for _ in 0..(CNT / NR_THREADS) { | ||
let _result = black_box(gauss_sum(black_box(10000))); | ||
} | ||
})); | ||
} | ||
for t in threads { | ||
t.join().unwrap(); | ||
} | ||
|
||
let duration_multi_thread = start.elapsed(); // Calculate elapsed time | ||
println!("Duration mutli thread: {duration_multi_thread:?}"); | ||
println!( | ||
"Speedup: {}us / {}us = {:.3}", | ||
duration_single_thread.as_micros(), | ||
duration_multi_thread.as_micros(), | ||
duration_single_thread.as_micros() as f64 / duration_multi_thread.as_micros() as f64 | ||
); | ||
} |