diff mbox

[API-NEXT,1/2] api: time: add global time API

Message ID 1450440867-5891-2-git-send-email-ivan.khoronzhuk@linaro.org
State Superseded
Headers show

Commit Message

Ivan Khoronzhuk Dec. 18, 2015, 12:14 p.m. UTC
This patch add global time API and implements it in linux-generic.

Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
---
 include/odp/api/time.h            | 28 ++++++++++++++++++++++++++++
 platform/linux-generic/odp_time.c | 34 +++++++++++++++++++++++++++-------
 2 files changed, 55 insertions(+), 7 deletions(-)

Comments

Ivan Khoronzhuk Dec. 21, 2015, 10:56 a.m. UTC | #1
On 21.12.15 10:39, Savolainen, Petri (Nokia - FI/Espoo) wrote:
>
> Otherwise OK, but I'd highlight that ability to *share* time stamps is the main difference of global vs. local. See below.
>
>
>> -----Original Message-----
>> From: EXT Ivan Khoronzhuk [mailto:ivan.khoronzhuk@linaro.org]
>> Sent: Friday, December 18, 2015 2:14 PM
>> To: lng-odp@lists.linaro.org
>> Cc: Savolainen, Petri (Nokia - FI/Espoo); Ivan Khoronzhuk
>> Subject: [lng-odp] [API-NEXT PATCH 1/2] api: time: add global time API
>>
>> This patch add global time API and implements it in linux-generic.
>>
>> Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
>> ---
>>   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.
>
>
> This last sentence could be on its own line an simply state:
>
> "Global time stamps can be shared between threads"
>
>
>
> This patch could also add the same definition to odp_time_local() documentation:
>
> /**
>   * Current local time
>   *
>   * 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);
>
>
>
> odp_time_t typedef documents this already, but better to highlight it also on the time stamp calls.
>
>
> -Petri
>
>
Will correct in v2.

>
>
>> + *
>> + * @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
>
diff mbox

Patch

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)