[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH 7/7] lib/nolibc: Implement clock_gettime()



Signed-off-by: Florian Schmidt <florian.schmidt@xxxxxxxxx>
---
 lib/nolibc/exportsyms.uk                      |  1 +
 .../include/nolibc-internal/shareddefs.h      |  5 ++++
 lib/nolibc/include/sys/types.h                |  1 +
 lib/nolibc/include/time.h                     |  7 +++++
 lib/nolibc/time.c                             | 26 +++++++++++++++++++
 5 files changed, 40 insertions(+)

diff --git a/lib/nolibc/exportsyms.uk b/lib/nolibc/exportsyms.uk
index a26440c9..ddc73bf1 100644
--- a/lib/nolibc/exportsyms.uk
+++ b/lib/nolibc/exportsyms.uk
@@ -71,6 +71,7 @@ strlcat
 
 # time
 nanosleep
+clock_gettime
 
 # sys/time
 gettimeofday
diff --git a/lib/nolibc/include/nolibc-internal/shareddefs.h 
b/lib/nolibc/include/nolibc-internal/shareddefs.h
index 7572e2d3..fb7d95b2 100644
--- a/lib/nolibc/include/nolibc-internal/shareddefs.h
+++ b/lib/nolibc/include/nolibc-internal/shareddefs.h
@@ -91,6 +91,11 @@ struct timespec {
 #define __DEFINED_struct_timespec
 #endif
 
+#if (defined __NEED_clockid_t && !defined __DEFINED_clockid_t)
+typedef int clockid_t;
+#define __DEFINED_clockid_t
+#endif
+
 #if (defined __NEED_mode_t && !defined __DEFINED_mode_t)
 typedef unsigned mode_t;
 #define __DEFINED_mode_t
diff --git a/lib/nolibc/include/sys/types.h b/lib/nolibc/include/sys/types.h
index 7c43ef3f..20a3c97d 100644
--- a/lib/nolibc/include/sys/types.h
+++ b/lib/nolibc/include/sys/types.h
@@ -48,6 +48,7 @@ extern "C" {
 #define __NEED_off_t
 #define __NEED_time_t
 #define __NEED_suseconds_t
+#define __NEED_clockid_t
 #define __NEED_mode_t
 #define __NEED_uid_t
 #define __NEED_gid_t
diff --git a/lib/nolibc/include/time.h b/lib/nolibc/include/time.h
index a6b9585b..5223914a 100644
--- a/lib/nolibc/include/time.h
+++ b/lib/nolibc/include/time.h
@@ -44,14 +44,21 @@ extern "C" {
 #define __NEED_NULL
 #define __NEED_time_t
 #define __NEED_struct_timespec
+#define __NEED_clockid_t
 #include <nolibc-internal/shareddefs.h>
 
+#define CLOCK_REALTIME  0
+#define CLOCK_MONOTONIC 1
+
+#define TIMER_ABSTIME 1
+
 struct itimerspec {
        struct timespec it_interval;
        struct timespec it_value;
 };
 
 int nanosleep(const struct timespec *req, struct timespec *rem);
+int clock_gettime(clockid_t clk, struct timespec *tp);
 
 #ifdef __cplusplus
 }
diff --git a/lib/nolibc/time.c b/lib/nolibc/time.c
index b15d7e0d..69f29300 100644
--- a/lib/nolibc/time.c
+++ b/lib/nolibc/time.c
@@ -105,3 +105,29 @@ int gettimeofday(struct timeval *tv, void *tz __unused)
        tv->tv_usec = ukarch_time_nsec_to_usec(ukarch_time_subsec(now));
        return 0;
 }
+
+int clock_gettime(clockid_t clk_id, struct timespec *tp)
+{
+       __nsec now;
+
+       if (!tp) {
+               errno = EFAULT;
+               return -1;
+       }
+
+       switch (clk_id) {
+       case CLOCK_MONOTONIC:
+               now = ukplat_monotonic_clock();
+               break;
+       case CLOCK_REALTIME:
+               now = ukplat_wall_clock();
+               break;
+       default:
+               errno = EINVAL;
+               return -1;
+       }
+
+       tp->tv_sec = ukarch_time_nsec_to_sec(now);
+       tp->tv_nsec = ukarch_time_subsec(now);
+       return 0;
+}
-- 
2.20.1


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.