diff --git a/rawhammer/src/main.rs b/rawhammer/src/main.rs index 463b2bc..cb2ba5e 100644 --- a/rawhammer/src/main.rs +++ b/rawhammer/src/main.rs @@ -187,16 +187,21 @@ static CH_NTRU: &'static [u8] = b"\ \x00\x2d\x00\x02\x01\x01\x00\x2b\x00\x09\x08\x03\x04\x03\x03\x03\ \x02\x03\x01"; -fn sleep(micros: u64, cmt: &'static str) { +fn sleep(micros: u128, cmt: &'static str) { println!("[START] {}", cmt); sleep_no_comment(micros); println!("[DONE] {}", cmt); } -fn sleep_no_comment(micros: u64) { +fn sleep_no_comment(micros: u128) { if micros > 0 { - let dur_micros = time::Duration::from_micros(micros); - thread::sleep(dur_micros); + if micros > 1000 { + let dur_micros = time::Duration::from_micros(micros as u64); + thread::sleep(dur_micros); + } else { + let t1 = Instant::now(); + while t1.elapsed().as_micros() < micros {} + } } } @@ -258,6 +263,8 @@ fn main() -> std::io::Result<()> { let mut threads = Vec::new(); // report every 1000 msgs sent let msg_nb_report = 1000; + // sleep time in microseconds between each message + let usleep = 1000000/msg_per_sec as u128; for _ in 0..sending_threads { // Condition variables to control threads let t = thread::spawn(move || { @@ -280,7 +287,7 @@ fn main() -> std::io::Result<()> { _ => panic!("Unknown case"), }; s.shutdown(Shutdown::Both).expect("shutdown call failed"); - sleep_no_comment(1000000/msg_per_sec as u64); + sleep_no_comment(usleep); ch_sent += 1; if ch_sent % msg_nb_report == 0 { println!("nb of queries sent: total: {}. {1} msg's in {2} sec. {3} per sec",