[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCH v3 7/8] plat/linuxu: Add monotonic clock
Implement ukplat_monotonic_clock() with clock_gettime() system call. Signed-off-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx> --- plat/linuxu/include/linuxu/syscall-arm_32.h | 2 ++ plat/linuxu/include/linuxu/syscall-x86_64.h | 2 ++ plat/linuxu/include/linuxu/syscall.h | 8 ++++++++ plat/linuxu/include/linuxu/time.h | 1 + plat/linuxu/time.c | 15 +++++++++++++-- 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/plat/linuxu/include/linuxu/syscall-arm_32.h b/plat/linuxu/include/linuxu/syscall-arm_32.h index 2f0980a..3cdd32b 100644 --- a/plat/linuxu/include/linuxu/syscall-arm_32.h +++ b/plat/linuxu/include/linuxu/syscall-arm_32.h @@ -47,6 +47,8 @@ #define __SC_EXIT 1 #define __SC_IOCTL 54 +#define __SC_CLOCK_GETTIME 263 + #define __SC_RT_SIGACTION 43 #define __SC_RT_SIGPROCMASK 126 diff --git a/plat/linuxu/include/linuxu/syscall-x86_64.h b/plat/linuxu/include/linuxu/syscall-x86_64.h index e58f260..5406ddf 100644 --- a/plat/linuxu/include/linuxu/syscall-x86_64.h +++ b/plat/linuxu/include/linuxu/syscall-x86_64.h @@ -47,6 +47,8 @@ #define __SC_IOCTL 16 #define __SC_EXIT 60 +#define __SC_CLOCK_GETTIME 228 + #define __SC_RT_SIGACTION 13 #define __SC_RT_SIGPROCMASK 14 diff --git a/plat/linuxu/include/linuxu/syscall.h b/plat/linuxu/include/linuxu/syscall.h index 8411f39..577c0bd 100644 --- a/plat/linuxu/include/linuxu/syscall.h +++ b/plat/linuxu/include/linuxu/syscall.h @@ -37,6 +37,7 @@ #define __SYSCALL_H__ #include <sys/types.h> +#include <sys/time.h> #include <linuxu/signal.h> #if defined __X86_64__ @@ -69,6 +70,13 @@ static inline int sys_exit(int status) (long) (status)); } +static inline int sys_clock_gettime(clockid_t clk_id, struct timespec *tp) +{ + return (int) syscall2(__SC_CLOCK_GETTIME, + (long) clk_id, + (long) tp); +} + /* * Please note that on failure sys_mmap() is returning -errno */ diff --git a/plat/linuxu/include/linuxu/time.h b/plat/linuxu/include/linuxu/time.h index c4c97e1..94bf91b 100644 --- a/plat/linuxu/include/linuxu/time.h +++ b/plat/linuxu/include/linuxu/time.h @@ -41,5 +41,6 @@ /* POSIX definitions */ #define CLOCK_REALTIME 0 +#define CLOCK_MONOTONIC 1 #endif /* __LINUXU_TIME_H__ */ diff --git a/plat/linuxu/time.c b/plat/linuxu/time.c index b79a821..c9ff452 100644 --- a/plat/linuxu/time.c +++ b/plat/linuxu/time.c @@ -39,6 +39,7 @@ #include <uk/assert.h> #include <linuxu/syscall.h> #include <linuxu/time.h> +#include <sys/time.h> #define TIMER_INTVAL_NSEC ukarch_time_msec_to_nsec(TIMER_INTVAL_MSEC) @@ -47,8 +48,18 @@ static timer_t timerid; __nsec ukplat_monotonic_clock(void) { - /* TODO */ - return 0; + struct timespec tp; + __nsec ret; + int rc; + + rc = sys_clock_gettime(CLOCK_MONOTONIC, &tp); + if (unlikely(rc != 0)) + return 0; + + ret = ukarch_time_sec_to_nsec((__nsec) tp.tv_sec); + ret += (__nsec) tp.tv_nsec; + + return ret; } static int timer_handler(void *arg __unused) -- 2.7.4 _______________________________________________ Minios-devel mailing list Minios-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/minios-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |