This patch add global time API and implements it in linux-generic.

Signed-off-by: Ivan Khoronzhuk <[email protected]>
---
 include/odp/api/time.h            | 28 ++++++++++++++++++++++++++++
 platform/linux-generic/odp_time.c | 34 +++++++++++++++++++++++++++-------
 2 files changed, 55 insertions(+), 7 deletions(-)

diff --git a/include/odp/api/time.h b/include/odp/api/time.h
index 1f94710..895af75 100644
--- a/include/odp/api/time.h
+++ b/include/odp/api/time.h
@@ -53,6 +53,18 @@ extern "C" {
 odp_time_t odp_time_local(void);
 
 /**
+ * Current global time
+ *
+ * Returns current global time stamp value. The global time source provides 
high
+ * resolution time, it is initialized to zero during ODP startup and will not
+ * wrap around in at least 10 years. The time is global that means it can be
+ * used between threads.
+ *
+ * @return Global time stamp.
+ */
+odp_time_t odp_time_global(void);
+
+/**
  * Time difference
  *
  * @param t2    Second time stamp
@@ -91,6 +103,15 @@ uint64_t odp_time_to_ns(odp_time_t time);
 odp_time_t odp_time_local_from_ns(uint64_t ns);
 
 /**
+ * Convert nanoseconds to global time
+ *
+ * @param ns    Time in nanoseconds
+ *
+ * @return Global time stamp
+ */
+odp_time_t odp_time_global_from_ns(uint64_t ns);
+
+/**
  * Compare two times
  *
  * @param t2    Second time
@@ -108,6 +129,13 @@ int odp_time_cmp(odp_time_t t2, odp_time_t t1);
 uint64_t odp_time_local_res(void);
 
 /**
+ * Global time resolution in hertz
+ *
+ * @return      Global time resolution in hertz
+ */
+uint64_t odp_time_global_res(void);
+
+/**
  * Wait until the specified (wall clock) time has been reached
  *
  * The thread potentially busy loop the entire wait time.
diff --git a/platform/linux-generic/odp_time.c 
b/platform/linux-generic/odp_time.c
index a3ab2e3..2cb84f2 100644
--- a/platform/linux-generic/odp_time.c
+++ b/platform/linux-generic/odp_time.c
@@ -101,11 +101,28 @@ static inline void time_wait_until(odp_time_t time)
        } while (time_cmp(time, cur) > 0);
 }
 
+static inline uint64_t time_local_res(void)
+{
+       int ret;
+       struct timespec tres;
+
+       ret = clock_getres(CLOCK_MONOTONIC_RAW, &tres);
+       if (odp_unlikely(ret != 0))
+               ODP_ABORT("clock_getres failed\n");
+
+       return ODP_TIME_SEC_IN_NS / (uint64_t)tres.tv_nsec;
+}
+
 odp_time_t odp_time_local(void)
 {
        return time_local();
 }
 
+odp_time_t odp_time_global(void)
+{
+       return time_local();
+}
+
 odp_time_t odp_time_diff(odp_time_t t2, odp_time_t t1)
 {
        return time_diff(t2, t1);
@@ -121,6 +138,11 @@ odp_time_t odp_time_local_from_ns(uint64_t ns)
        return time_local_from_ns(ns);
 }
 
+odp_time_t odp_time_global_from_ns(uint64_t ns)
+{
+       return time_local_from_ns(ns);
+}
+
 int odp_time_cmp(odp_time_t t2, odp_time_t t1)
 {
        return time_cmp(t2, t1);
@@ -133,14 +155,12 @@ odp_time_t odp_time_sum(odp_time_t t1, odp_time_t t2)
 
 uint64_t odp_time_local_res(void)
 {
-       int ret;
-       struct timespec tres;
-
-       ret = clock_getres(CLOCK_MONOTONIC_RAW, &tres);
-       if (odp_unlikely(ret != 0))
-               ODP_ABORT("clock_getres failed\n");
+       return time_local_res();
+}
 
-       return ODP_TIME_SEC_IN_NS / (uint64_t)tres.tv_nsec;
+uint64_t odp_time_global_res(void)
+{
+       return time_local_res();
 }
 
 void odp_time_wait_ns(uint64_t ns)
-- 
1.9.1

_______________________________________________
lng-odp mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to