//! A CPU hog: busy-loops without ever making a syscall in between. The timer //! interrupt still preempts it, so everything else keeps running. //! `spin` does 3 rounds of 30 million additions; `spin ` does n rounds. #![no_std] #![no_main] #[macro_use] #[path = "ulib.rs"] mod ulib; fn main() -> i64 { println!("[spin] pid {}: spinning without syscalls...", ulib::getpid()); let rounds: u64 = ulib::arg(1).and_then(|a| a.parse().ok()).unwrap_or(3); let mut count: u64 = 0; for round in 1..=rounds { for _ in 0..30_000_000 { count = core::hint::black_box(count + 1); } println!("[spin] round {} done (count = {})", round, count); } 0 }