|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v4 3/7] add gettimeofday function to time managment
this function acts as the POSIX gettimeofday function
Signed-off-by: Paul Semel <phentex@xxxxxxxxx>
---
Notes:
v4:
- new patch version
common/time.c | 30 ++++++++++++++++++++++++++++++
include/xtf/time.h | 8 ++++++++
2 files changed, 38 insertions(+)
diff --git a/common/time.c b/common/time.c
index c1b7cd1..8489f3b 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/lib.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 e33dc8a..ce4d6db 100644
--- a/include/xtf/time.h
+++ b/include/xtf/time.h
@@ -8,6 +8,12 @@
#include <xtf/types.h>
+struct timeval {
+ uint64_t sec;
+ uint64_t nsec;
+};
+
+
#define SEC_TO_NSEC(x) ((x) * 1000000000ul)
@@ -16,6 +22,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
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |