Use syscall time helper functions

This commit is contained in:
Wildan M
2026-05-30 00:22:21 +07:00
parent a47b3a8d57
commit 973ac667e3
4 changed files with 7 additions and 22 deletions
+1 -1
View File
@@ -44,7 +44,7 @@ pub fn register(
scheme_id,
event_id,
clock,
time: (time.tv_sec as u128 * time::NANOS_PER_SEC) + (time.tv_nsec as u128),
time: time.to_nanos(),
});
}
+1 -4
View File
@@ -157,10 +157,7 @@ impl KernelScheme for TimeScheme {
(CLOCK_MONOTONIC, TimeSchemeKind::ClockGetres) => time::monotonic_resolution(),
_ => return Err(Error::new(EINVAL)),
};
let time = TimeSpec {
tv_sec: (arch_time / time::NANOS_PER_SEC) as i64,
tv_nsec: (arch_time % time::NANOS_PER_SEC) as i32,
};
let time = TimeSpec::from_nanos(arch_time);
current_chunk.copy_exactly(&time)?;
bytes_read += size_of::<TimeSpec>();
+1 -4
View File
@@ -19,7 +19,6 @@ use crate::{
},
memory::{Page, PhysicalAddress, VirtualAddress},
sync::{CleanLockToken, Mutex, L1},
time,
};
use crate::syscall::{
@@ -154,9 +153,7 @@ pub fn futex(
{
let mut context = context_lock.write(token.token());
context.wake = timeout_opt.map(|TimeSpec { tv_sec, tv_nsec }| {
tv_sec as u128 * time::NANOS_PER_SEC + tv_nsec as u128
});
context.wake = timeout_opt.map(|time| time.to_nanos());
if let Some((tctl, pctl, _)) = context.sigcontrol()
&& tctl.currently_pending_unblocked(pctl) != 0
{
+4 -13
View File
@@ -18,10 +18,7 @@ pub fn clock_gettime(clock: usize, buf: UserSliceWo, token: &mut CleanLockToken)
_ => return Err(Error::new(EINVAL)),
};
buf.copy_exactly(&TimeSpec {
tv_sec: (arch_time / time::NANOS_PER_SEC) as i64,
tv_nsec: (arch_time % time::NANOS_PER_SEC) as i32,
})
buf.copy_exactly(&TimeSpec::from_nanos(arch_time))
}
/// Nanosleep will sleep by switching the current context
@@ -37,7 +34,7 @@ pub fn nanosleep(
}
let start = time::monotonic(token);
let end = start + (req.tv_sec as u128 * time::NANOS_PER_SEC) + (req.tv_nsec as u128);
let end = start + req.to_nanos();
let current_context = context::current();
{
@@ -64,15 +61,9 @@ pub fn nanosleep(
rem_buf.copy_exactly(&if current < end {
let diff = end - current;
TimeSpec {
tv_sec: (diff / time::NANOS_PER_SEC) as i64,
tv_nsec: (diff % time::NANOS_PER_SEC) as i32,
}
TimeSpec::from_nanos(diff)
} else {
TimeSpec {
tv_sec: 0,
tv_nsec: 0,
}
TimeSpec::default()
})?;
}