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

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



From: Paul Semel <phentex@xxxxxxxxx>

Signed-off-by: Paul Semel <phentex@xxxxxxxxx>

cr https://code.amazon.com/reviews/CR-786225
---
 common/time.c      | 14 ++++++++++++++
 include/xtf/time.h | 12 ++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/common/time.c b/common/time.c
index 37a9faf..c80bc11 100644
--- a/common/time.c
+++ b/common/time.c
@@ -92,6 +92,20 @@ uint64_t current_time(void)
     return seconds + (since_boot_time() / 1000000000);
 }
 
+/* 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)
+{
+    if (!tp)
+        return -1;
+
+    tp->sec = current_time();
+    tp->nsec = shared_info.wc_nsec + (since_boot_time() % 1000000000);
+    return 0;
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/include/xtf/time.h b/include/xtf/time.h
index a8c10eb..16356eb 100644
--- a/include/xtf/time.h
+++ b/include/xtf/time.h
@@ -8,6 +8,16 @@
 
 #include <xtf/types.h>
 
+struct timeval {
+#if !defined(__i386__)
+    uint64_t sec;
+    uint64_t nsec;
+#else
+    uint32_t sec;
+    uint32_t nsec;
+#endif
+};
+
 #define rdtscp(tsc) {\
     uint32_t lo, hi;\
     __asm__ volatile("rdtsc": "=a"(lo), "=d"(hi));\
@@ -26,6 +36,8 @@ uint64_t since_boot_time(void);
 uint64_t current_time(void);
 #endif
 
+int gettimeofday(struct timeval *tp);
+
 #endif /* XTF_TIME_H */
 
 /*
-- 
2.16.2

Amazon Development Center Germany GmbH
Berlin - Dresden - Aachen
main office: Krausenstr. 38, 10117 Berlin
Geschaeftsfuehrer: Dr. Ralf Herbrich, Christian Schlaeger
Ust-ID: DE289237879
Eingetragen am Amtsgericht Charlottenburg HRB 149173 B


_______________________________________________
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®.