From c4e86bfffd08e6ea7788ea2193499c898e00a48e Mon Sep 17 00:00:00 2001 From: Wildan M Date: Tue, 10 Mar 2026 05:58:26 +0700 Subject: [PATCH] Change time offset to RwLock --- src/arch/aarch64/device/generic_timer.rs | 2 +- src/arch/x86_shared/interrupt/irq.rs | 2 +- src/arch/x86_shared/time.rs | 3 ++- src/time.rs | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/arch/aarch64/device/generic_timer.rs b/src/arch/aarch64/device/generic_timer.rs index 0bbb9346c2..b090a37b58 100644 --- a/src/arch/aarch64/device/generic_timer.rs +++ b/src/arch/aarch64/device/generic_timer.rs @@ -128,7 +128,7 @@ impl InterruptHandler for GenericTimer { fn irq_handler(&mut self, irq: u32, token: &mut CleanLockToken) { self.clear_irq(); { - *time::OFFSET.lock(token.token()) += self.clk_freq as u128; + *time::OFFSET.write(token.token()) += self.clk_freq as u128; } timeout::trigger(token); diff --git a/src/arch/x86_shared/interrupt/irq.rs b/src/arch/x86_shared/interrupt/irq.rs index 3853a47cfe..1b3f455d30 100644 --- a/src/arch/x86_shared/interrupt/irq.rs +++ b/src/arch/x86_shared/interrupt/irq.rs @@ -169,7 +169,7 @@ interrupt_stack!(pit_stack, |_stack| { let mut token = unsafe { CleanLockToken::new() }; { - *time::OFFSET.lock(token.token()) += pit::RATE; + *time::OFFSET.write(token.token()) += pit::RATE; } unsafe { eoi(0) }; diff --git a/src/arch/x86_shared/time.rs b/src/arch/x86_shared/time.rs index a08c786226..0fef35e00d 100644 --- a/src/arch/x86_shared/time.rs +++ b/src/arch/x86_shared/time.rs @@ -12,7 +12,8 @@ pub fn monotonic_absolute(token: &mut CleanLockToken) -> u128 { return ns; } - *crate::time::OFFSET.lock(token.token()) + hpet_or_pit() + let offset = { *crate::time::OFFSET.read(token.token()) }; + offset + hpet_or_pit() } fn hpet_or_pit() -> u128 { #[cfg(feature = "acpi")] diff --git a/src/time.rs b/src/time.rs index 406ccc2411..72992f1d42 100644 --- a/src/time.rs +++ b/src/time.rs @@ -1,5 +1,5 @@ use crate::{ - sync::{CleanLockToken, Mutex, L1}, + sync::{CleanLockToken, Mutex, RwLock, L1}, syscall::error::{Error, Result, EINVAL}, }; @@ -9,7 +9,7 @@ pub const NANOS_PER_SEC: u128 = 1_000_000_000; /// Kernel start time, measured in nanoseconds since Unix epoch pub static START: Mutex = Mutex::new(0); /// Kernel up time, measured in nanoseconds since `START_TIME` -pub static OFFSET: Mutex = Mutex::new(0); +pub static OFFSET: RwLock = RwLock::new(0); pub fn monotonic(token: &mut CleanLockToken) -> u128 { crate::arch::time::monotonic_absolute(token)