|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v2 2/7] add current_time function to time manager
From: Paul Semel <phentex@xxxxxxxxx>
this function returns the "epoch" time
Signed-off-by: Paul Semel <phentex@xxxxxxxxx>
---
common/time.c | 18 ++++++++++++++++++
include/xtf/time.h | 2 ++
2 files changed, 20 insertions(+)
diff --git a/common/time.c b/common/time.c
index a0f53bf..3e8e8ce 100644
--- a/common/time.c
+++ b/common/time.c
@@ -3,6 +3,7 @@
#include <xtf/time.h>
#include <arch/barrier.h>
+#include <arch/div.h>
/* This function was taken from mini-os source code */
/* It returns ((delta << shift) * mul_frac) >> 32 */
@@ -69,6 +70,23 @@ uint64_t since_boot_time(void)
return system_time;
}
+/* This function return the epoch time (number of seconds elapsed
+ * since Juanary 1, 1970) */
+uint64_t current_time(void)
+{
+ uint64_t seconds;
+ uint64_t boot_time = since_boot_time();
+#if defined(__i386__)
+ seconds = (uint64_t)ACCESS_ONCE(shared_info.wc_sec);
+ divmod64(&boot_time, 1000000000);
+#else
+ seconds = ((uint64_t)ACCESS_ONCE(shared_info.wc_sec_hi) << 32)
+ | ACCESS_ONCE(shared_info.wc_sec);
+ boot_time /= 1000000000;
+#endif
+ return seconds + boot_time;
+}
+
/*
* Local variables:
* mode: C
diff --git a/include/xtf/time.h b/include/xtf/time.h
index 7d46d3a..6195b24 100644
--- a/include/xtf/time.h
+++ b/include/xtf/time.h
@@ -18,6 +18,8 @@
/* Time from boot in nanoseconds */
uint64_t since_boot_time(void);
+uint64_t current_time(void);
+
#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 |