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

[Xen-devel] [PATCH v3 3/7] add gettimeofday function to time managment



From: Paul Semel <phentex@xxxxxxxxx>

this function acts as the POSIX gettimeofday function

Signed-off-by: Paul Semel <phentex@xxxxxxxxx>
---
 common/time.c      | 30 ++++++++++++++++++++++++++++++
 include/xtf/time.h |  7 +++++++
 2 files changed, 37 insertions(+)

diff --git a/common/time.c b/common/time.c
index 29b38ca..d0c9ed2 100644
--- a/common/time.c
+++ b/common/time.c
@@ -1,6 +1,7 @@
 #include <xtf/types.h>
 #include <xtf/traps.h>
 #include <xtf/time.h>
+#include <xen/errno.h>
 
 #include <arch/barrier.h>
 #include <arch/div.h>
@@ -109,6 +110,35 @@ uint64_t current_time(void)
     return sec + 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, void *restrict tzp)
+{
+    uint64_t boot_time, sec;
+    uint32_t mod, nsec;
+
+    if ( tzp != NULL )
+        return -EOPNOTSUPP;
+
+    if ( tp == NULL )
+        return -EINVAL;
+
+    get_time_info(&boot_time, &sec, &nsec);
+
+#if defined(__i386__)
+    mod = divmod64(&boot_time, SEC_TO_NSEC(1));
+#else
+    mod = boot_time % SEC_TO_NSEC(1);
+    boot_time /= SEC_TO_NSEC(1);
+#endif
+
+    tp->sec = sec + boot_time;
+    tp->nsec = nsec + mod;
+    return 0;
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/include/xtf/time.h b/include/xtf/time.h
index 4d94958..5ed88ad 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 rdtsc(tsc) {\
     uint32_t lo, hi;\
     __asm__ volatile("rdtsc": "=a"(lo), "=d"(hi));\
@@ -22,6 +27,8 @@ uint64_t since_boot_time(void);
 
 uint64_t current_time(void);
 
+int gettimeofday(struct timeval *tp, void *restrict tzp);
+
 #endif /* XTF_TIME_H */
 
 /*
-- 
2.16.1


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

 


Rackspace

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