Skip to contentSkip to conversation

introduce time managment in xtf

PATCH In review Paul Semel 2 participants 9 messages Apr 8, 2018 – Apr 9, 2018

lore
Share & tools
lore

Paul Semel

author
#0 lore raw

PATCH v2 1/7 introduce time managment in xtf

From: Paul Semel <[email protected]>

this file is introduce to be able to implement an inter domain communication protocol over xenstore. For synchronization purpose, we do really want to be able to "control" time

common/time.c: since_boot_time gets the time in nanoseconds from the moment the VM has booted

---
 build/files.mk     |  1 +
 common/time.c      | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/xtf/time.h | 31 +++++++++++++++++++++
 3 files changed, 112 insertions(+)
 create mode 100644 common/time.c
 create mode 100644 include/xtf/time.h
build/files.mk +1 -0
index 46b42d6..55ed1ca 100644
@@ -16,6 +16,7 @@ obj-perarch += $(ROOT)/common/libc/vsnprintf.o
 obj-perarch += $(ROOT)/common/report.o
 obj-perarch += $(ROOT)/common/setup.o
 obj-perarch += $(ROOT)/common/xenbus.o
+obj-perarch += $(ROOT)/common/time.o
 
 obj-perenv += $(ROOT)/arch/x86/decode.o
 obj-perenv += $(ROOT)/arch/x86/desc.o
common/time.c new file +80 -0

80 lines not on this page · raw message

include/xtf/time.h new file +31 -0
new file mode 100644
index 0000000..7d46d3a
@@ -0,0 +1,31 @@
+/**
+ * @file include/xtf/time.h
+ *
+ * Time management
+ */
+#ifndef XTF_TIME_H
+# define XTF_TIME_H
+
+#include <xtf/types.h>
+
+#define rdtscp(tsc) {\
+    uint32_t lo, hi;\
+    __asm__ volatile("rdtsc": "=a"(lo), "=d"(hi));\
+    tsc = ((uint64_t)hi << 32) | lo;\
+}
+
+
+/* Time from boot in nanoseconds */
+uint64_t since_boot_time(void);
+
+#endif /* XTF_TIME_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Signature · 7 lines
2.16.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
author
#1 lore raw

PATCH v2 2/7 add current_time function to time manager

From: Paul Semel <[email protected]>

this function returns the "epoch" time

---
 common/time.c      | 18 ++++++++++++++++++
 include/xtf/time.h |  2 ++
 2 files changed, 20 insertions(+)
common/time.c +18 -0
index a0f53bf..3e8e8ce 100644
@@ -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
include/xtf/time.h +2 -0
index 7d46d3a..6195b24 100644
@@ -18,6 +18,8 @@
 /* Time from boot in nanoseconds */
 uint64_t since_boot_time(void);
 
+uint64_t current_time(void);
+
 #endif /* XTF_TIME_H */
 
 /*
Signature · 7 lines
2.16.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
author
#2 lore raw

PATCH v2 3/7 add gettimeofday function to time managment

In reply to Paul Semel

From: Paul Semel <[email protected]>

---
 common/time.c      | 23 +++++++++++++++++++++++
 include/xtf/time.h |  7 +++++++
 2 files changed, 30 insertions(+)
common/time.c +23 -0
index 3e8e8ce..1f0f289 100644
@@ -87,6 +87,29 @@ uint64_t current_time(void)
     return seconds + 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)
+{
+    uint64_t boot_time = since_boot_time();
+    uint32_t mod;
+
+#if defined(__i386__)
+    mod = divmod64(&boot_time, 1000000000);
+#else
+    mod = boot_time % 1000000000;
+#endif
+
+    if (!tp)
+        return -1;
+
+    tp->sec = current_time();
+    tp->nsec = ACCESS_ONCE(shared_info.wc_nsec) + mod;
+    return 0;
+}
+
 /*
  * Local variables:
  * mode: C
include/xtf/time.h +7 -0
index 6195b24..2ff8f42 100644
@@ -8,6 +8,11 @@
 
 #include <xtf/types.h>
 
+struct timeval {
+    uint64_t sec;
+    uint64_t nsec;
+};
+
 #define rdtscp(tsc) {\
     uint32_t lo, hi;\
     __asm__ volatile("rdtsc": "=a"(lo), "=d"(hi));\
@@ -20,6 +25,8 @@ uint64_t since_boot_time(void);
 
 uint64_t current_time(void);
 
+int gettimeofday(struct timeval *tp);
+
 #endif /* XTF_TIME_H */
 
 /*
Signature · 7 lines
2.16.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
author
#3 lore raw

PATCH v2 4/7 add nspin_sleep function to time manager

In reply to Paul Semel

From: Paul Semel <[email protected]>

---
 common/time.c | 9 +++++++++
 1 file changed, 9 insertions(+)
common/time.c +9 -0
index 1f0f289..1d7fef5 100644
@@ -110,6 +110,15 @@ int gettimeofday(struct timeval *tp)
     return 0;
 }
 
+static inline void nspin_sleep(uint64_t t)
+{
+    uint64_t curr = since_boot_time();
+    uint64_t end = curr + t;
+
+    while ( curr < end )
+        curr = since_boot_time();
+}
+
 /*
  * Local variables:
  * mode: C
Signature · 7 lines
2.16.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
author
#4 lore raw

PATCH v2 5/7 add spin_sleep function to time manager

In reply to Paul Semel

From: Paul Semel <[email protected]>

---
 common/time.c | 6 ++++++
 1 file changed, 6 insertions(+)
common/time.c +6 -0
index 1d7fef5..67fe049 100644
@@ -119,6 +119,12 @@ static inline void nspin_sleep(uint64_t t)
         curr = since_boot_time();
 }
 
+static inline void spin_sleep(uint64_t t)
+{
+    uint64_t nsec = t * 1000000000ul;
+    nspin_sleep(nsec);
+}
+
 /*
  * Local variables:
  * mode: C
Signature · 7 lines
2.16.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
author
#5 lore raw

PATCH v2 6/7 add mspin_sleep function to time manager

In reply to Paul Semel

From: Paul Semel <[email protected]>

---
 common/time.c | 6 ++++++
 1 file changed, 6 insertions(+)
common/time.c +6 -0
index 67fe049..f75979a 100644
@@ -125,6 +125,12 @@ static inline void spin_sleep(uint64_t t)
     nspin_sleep(nsec);
 }
 
+static inline void mspin_sleep(uint64_t t)
+{
+    uint64_t nsec = t * 1000000ul;
+    nspin_sleep(nsec);
+}
+
 /*
  * Local variables:
  * mode: C
Signature · 7 lines
2.16.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
author
#6 lore raw

PATCH v2 7/7 add sleep, msleep and NOW() macros to time manager

In reply to Paul Semel

From: Paul Semel <[email protected]>

---
 common/time.c      | 10 ++++++++++
 include/xtf/time.h | 12 ++++++++++++
 2 files changed, 22 insertions(+)
common/time.c +10 -0
index f75979a..246a2dd 100644
@@ -131,6 +131,16 @@ static inline void mspin_sleep(uint64_t t)
     nspin_sleep(nsec);
 }
 
+void sleep(uint64_t t)
+{
+    spin_sleep(t);
+}
+
+void msleep(uint64_t t)
+{
+    mspin_sleep(t);
+}
+
 /*
  * Local variables:
  * mode: C
include/xtf/time.h +12 -0
index 2ff8f42..97f3b5b 100644
@@ -25,8 +25,20 @@ uint64_t since_boot_time(void);
 
 uint64_t current_time(void);
 
+/* This function takes seconds in parameter */
+void sleep(uint64_t f);
+
+/* Be careful, this function takes milliseconds in parameter,
+ * not microseconds !
+ */
+void msleep(uint64_t f);
+
 int gettimeofday(struct timeval *tp);
 
+
+/* This returns the current epoch time */
+#define NOW() current_time()
+
 #endif /* XTF_TIME_H */
 
 /*
Signature · 7 lines
2.16.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
author
#7 lore raw

PATCH v2 1/1 introduce time managment in xtf

In reply to Paul Semel

From: Paul Semel <[email protected]>

this file is introduce to be able to implement an inter domain communication protocol over xenstore. For synchronization purpose, we do really want to be able to "control" time

common/time.c: since_boot_time gets the time in nanoseconds from the moment the VM has booted

---
 build/files.mk     |  1 +
 common/time.c      | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/xtf/time.h | 31 +++++++++++++++++++++
 3 files changed, 113 insertions(+)
 create mode 100644 common/time.c
 create mode 100644 include/xtf/time.h
build/files.mk +1 -0
index 46b42d6..55ed1ca 100644
@@ -16,6 +16,7 @@ obj-perarch += $(ROOT)/common/libc/vsnprintf.o
 obj-perarch += $(ROOT)/common/report.o
 obj-perarch += $(ROOT)/common/setup.o
 obj-perarch += $(ROOT)/common/xenbus.o
+obj-perarch += $(ROOT)/common/time.o
 
 obj-perenv += $(ROOT)/arch/x86/decode.o
 obj-perenv += $(ROOT)/arch/x86/desc.o
common/time.c new file +81 -0

81 lines not on this page · raw message

include/xtf/time.h new file +31 -0
new file mode 100644
index 0000000..7d46d3a
@@ -0,0 +1,31 @@
+/**
+ * @file include/xtf/time.h
+ *
+ * Time management
+ */
+#ifndef XTF_TIME_H
+# define XTF_TIME_H
+
+#include <xtf/types.h>
+
+#define rdtscp(tsc) {\
+    uint32_t lo, hi;\
+    __asm__ volatile("rdtsc": "=a"(lo), "=d"(hi));\
+    tsc = ((uint64_t)hi << 32) | lo;\
+}
+
+
+/* Time from boot in nanoseconds */
+uint64_t since_boot_time(void);
+
+#endif /* XTF_TIME_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Signature · 7 lines
2.16.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#8 lore raw

Comments on v1 (was: [PATCH v2 1/7] introduce time managment in xtf)

In reply to Paul Semel

Hello,

I'm replying to patch 1/7 because there's no cover letter. I've made a bunch of comments on v1 because I didn't realize you had already sent v2. I think a bunch of the comments I've made in v1 also apply to v2, so could you please look at those and fix them up if required?

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel