|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v2 3/7] add gettimeofday function to time managment
From: Paul Semel <phentex@xxxxxxxxx>
Signed-off-by: Paul Semel <phentex@xxxxxxxxx>
---
common/time.c | 23 +++++++++++++++++++++++
include/xtf/time.h | 7 +++++++
2 files changed, 30 insertions(+)
diff --git a/common/time.c b/common/time.c
index 3e8e8ce..1f0f289 100644
--- a/common/time.c
+++ b/common/time.c
@@ -87,6 +87,29 @@ uint64_t current_time(void)
return seconds + boot_time;
}
+/* The POSIX gettimeofday syscall normally takes a second argument, which is
+ * the timezone (struct timezone). However, it sould be NULL because linux
+ * doesn't use it anymore. So we need for us to add it in this function
+ */
+int gettimeofday(struct timeval *tp)
+{
+ uint64_t boot_time = since_boot_time();
+ uint32_t mod;
+
+#if defined(__i386__)
+ mod = divmod64(&boot_time, 1000000000);
+#else
+ mod = boot_time % 1000000000;
+#endif
+
+ if (!tp)
+ return -1;
+
+ tp->sec = current_time();
+ tp->nsec = ACCESS_ONCE(shared_info.wc_nsec) + mod;
+ return 0;
+}
+
/*
* Local variables:
* mode: C
diff --git a/include/xtf/time.h b/include/xtf/time.h
index 6195b24..2ff8f42 100644
--- a/include/xtf/time.h
+++ b/include/xtf/time.h
@@ -8,6 +8,11 @@
#include <xtf/types.h>
+struct timeval {
+ uint64_t sec;
+ uint64_t nsec;
+};
+
#define rdtscp(tsc) {\
uint32_t lo, hi;\
__asm__ volatile("rdtsc": "=a"(lo), "=d"(hi));\
@@ -20,6 +25,8 @@ uint64_t since_boot_time(void);
uint64_t current_time(void);
+int gettimeofday(struct timeval *tp);
+
#endif /* XTF_TIME_H */
/*
--
2.16.1
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |