|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT/NEWLIB PATCH] Implement gettimeofday, clock_gettime, sleep
The implementations are taken from nolibc.
Signed-off-by: Florian Schmidt <florian.schmidt@xxxxxxxxx>
---
include/time.h | 1 +
time.c | 43 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 44 insertions(+)
diff --git a/include/time.h b/include/time.h
index dd2eef2..2718515 100644
--- a/include/time.h
+++ b/include/time.h
@@ -59,6 +59,7 @@
#endif /* __DYNAMIC_REENT__ */
#endif /* __rtems__ */
+#define _POSIX_MONOTONIC_CLOCK 1
#include_next <time.h>
/* cleanup __rtems__ */
diff --git a/time.c b/time.c
index fa887ba..dccf8a1 100644
--- a/time.c
+++ b/time.c
@@ -36,6 +36,7 @@
*/
#include <errno.h>
+#include <time.h>
#include <sys/time.h>
#include <utime.h>
#include <uk/plat/time.h>
@@ -49,6 +50,15 @@
int
gettimeofday(struct timeval *tv __unused, void *tz __unused)
{
+ __nsec now = ukplat_wall_clock();
+
+ if (!tv) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ tv->tv_sec = ukarch_time_nsec_to_sec(now);
+ tv->tv_usec = ukarch_time_nsec_to_usec(ukarch_time_subsec(now));
return 0;
}
@@ -103,7 +113,40 @@ int nanosleep(const struct timespec *req, struct timespec
*rem)
return 0;
}
+unsigned int sleep(unsigned int seconds)
+{
+ struct timespec ts;
+
+ ts.tv_sec = seconds;
+ ts.tv_nsec = 0;
+ if (nanosleep(&ts, &ts))
+ return ts.tv_sec;
+
+ return 0;
+}
+
int clock_gettime(clockid_t clk_id __unused, struct timespec *tp __unused)
{
+ __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.21.0
_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |