From 3eab9cea6ee061040008d4a45f455ace75f6f8fe Mon Sep 17 00:00:00 2001 From: Jianfeng Jiang Date: Wed, 14 Jun 2023 10:46:21 +0800 Subject: [PATCH] clock_gettime supports clock_monotonic --- services/libs/jinux-std/src/syscall/clock_gettime.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/services/libs/jinux-std/src/syscall/clock_gettime.rs b/services/libs/jinux-std/src/syscall/clock_gettime.rs index 8005ad034..3c618ee44 100644 --- a/services/libs/jinux-std/src/syscall/clock_gettime.rs +++ b/services/libs/jinux-std/src/syscall/clock_gettime.rs @@ -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 { 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!(