clock_gettime supports clock_monotonic

This commit is contained in:
Jianfeng Jiang
2023-06-14 10:46:21 +08:00
committed by Tate, Hongliang Tian
parent db489f09a8
commit 3eab9cea6e

View File

@ -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!(