Don't account idle time

This commit is contained in:
Wildan M
2026-04-23 16:33:15 +07:00
parent 2ca610193b
commit 8262fa7da9
2 changed files with 10 additions and 6 deletions
+5 -3
View File
@@ -78,20 +78,22 @@ impl CpuStats {
self.state.store(new_state as u8, Ordering::Relaxed);
}
/// Increments time statistics of a CPU
/// Increments time statistics of a CPU, return the state is was accounting to.
///
/// Which statistic is incremented depends on the [`State`] of the CPU.
///
/// # Parameters
/// * `nanos` - Number of nanoseconds to add.
#[inline]
pub fn add_time(&self, nanos: u64) {
match self.state.load(Ordering::Relaxed) {
pub fn add_time(&self, nanos: u64) -> u8 {
let state = self.state.load(Ordering::Relaxed);
match state {
val if val == CpuState::Idle as u8 => self.idle.fetch_add(nanos, Ordering::Relaxed),
val if val == CpuState::User as u8 => self.user.fetch_add(nanos, Ordering::Relaxed),
val if val == CpuState::Kernel as u8 => self.kernel.fetch_add(nanos, Ordering::Relaxed),
_ => unreachable!("all possible values are covered"),
};
state
}
/// Add an IRQ event to both the global count and the CPU that handled it.