mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-22 17:03:23 +00:00
clock_gettime supports clock_monotonic
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
db489f09a8
commit
3eab9cea6e
@ -1,3 +1,7 @@
|
||||
use core::time::Duration;
|
||||
|
||||
use jinux_frame::timer::read_monotonic_milli_seconds;
|
||||
|
||||
use super::SyscallReturn;
|
||||
use super::SYS_CLOCK_GETTIME;
|
||||
use crate::{
|
||||
@ -17,6 +21,12 @@ pub fn sys_clock_gettime(clockid: clockid_t, timespec_addr: Vaddr) -> Result<Sys
|
||||
ClockID::CLOCK_REALTIME | ClockID::CLOCK_REALTIME_COARSE => {
|
||||
now.duration_since(&SystemTime::UNIX_EPOCH)?
|
||||
}
|
||||
ClockID::CLOCK_MONOTONIC => {
|
||||
let time_ms = read_monotonic_milli_seconds();
|
||||
let secs = time_ms / 1000;
|
||||
let nanos = (time_ms % 1000) * 1000;
|
||||
Duration::new(secs, nanos as u32)
|
||||
}
|
||||
// TODO: Respect other type of clock_id
|
||||
_ => {
|
||||
warn!(
|
||||
|
Reference in New Issue
Block a user