diff mbox series

[XTF,2/6] time: add current_time() function to time management

Message ID 20200417070528.48329-3-wipawel@amazon.de (mailing list archive)
State New, archived
Headers show
Series Add time management functionality | expand

Commit Message

Wieczorkiewicz, Pawel April 17, 2020, 7:05 a.m. UTC
From: Paul Semel <phentex@amazon.de>

This function returns the "epoch" time.

Signed-off-by: Paul Semel <phentex@amazon.de>
---
 common/time.c      | 16 ++++++++++++++++
 include/xtf/time.h |  4 ++++
 2 files changed, 20 insertions(+)
diff mbox series

Patch

diff --git a/common/time.c b/common/time.c
index b9a6531..7decd07 100644
--- a/common/time.c
+++ b/common/time.c
@@ -74,6 +74,22 @@  uint64_t since_boot_time(void)
     return system_time;
 }
 
+/* This function return the epoch time (number of seconds elapsed
+ * since Juanary 1, 1970) */
+#if defined(__i386__)
+uint32_t current_time(void)
+#else
+uint64_t current_time(void)
+#endif
+{
+#if defined(__i386__)
+    uint32_t seconds = shared_info.wc_sec;
+#else
+    uint64_t seconds = ((uint64_t)shared_info.wc_sec_hi << 32) | shared_info.wc_sec;
+#endif
+    return seconds + (since_boot_time() / 1000000000);
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/include/xtf/time.h b/include/xtf/time.h
index e30d109..52da27a 100644
--- a/include/xtf/time.h
+++ b/include/xtf/time.h
@@ -11,8 +11,12 @@ 
 #if defined(__i386__)
 /* Time from boot in nanoseconds */
 uint32_t since_boot_time(void);
+
+uint32_t current_time(void);
 #else
 uint64_t since_boot_time(void);
+
+uint64_t current_time(void);
 #endif
 
 #endif /* XTF_TIME_H */