RustForge

foundry

Foundry OS: the operating system built on the Rustbelt kernel

foundry / spin.rs
542 bytes ยท raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//! A CPU hog: busy-loops without ever making a syscall in between. The timer
//! interrupt still preempts it, so everything else keeps running.
#![no_std]
#![no_main]

#[macro_use]
#[path = "ulib.rs"]
mod ulib;

fn main() -> i64 {
    println!("[spin] pid {}: spinning without syscalls...", ulib::getpid());
    let mut count: u64 = 0;
    for round in 1..=3 {
        for _ in 0..30_000_000 {
            count = core::hint::black_box(count + 1);
        }
        println!("[spin] round {} done (count = {})", round, count);
    }
    0
}