@@ -47,12 +47,26 @@ extern "C" {
* Returns current local time stamp value. The local time source provides high
* resolution time, it is initialized to zero during ODP startup and will not
* wrap around in at least 10 years.
+ * Local time stamps are local to the calling thread and must not be shared
+ * with other threads.
*
* @return Local time stamp.
*/
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.
+ * Global time stamps can be shared between threads.
+ *
+ * @return Global time stamp.
+ */
+odp_time_t odp_time_global(void);
+
+/**
* Time difference
*
* @param t2 Second time stamp
@@ -91,6 +105,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 +131,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.
@@ -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)
This patch adds global time API and implements it in linux-generic. Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org> --- include/odp/api/time.h | 30 ++++++++++++++++++++++++++++++ platform/linux-generic/odp_time.c | 34 +++++++++++++++++++++++++++------- 2 files changed, 57 insertions(+), 7 deletions(-)