diff mbox

[API-NEXT,1/6] api: time: add rate and delay API calls

Message ID 1450119496-21604-2-git-send-email-ivan.khoronzhuk@linaro.org
State New
Headers show

Commit Message

Ivan Khoronzhuk Dec. 14, 2015, 6:58 p.m. UTC
This patch adds odp_time_local_rate() and odp_time_delay() APIs.

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

Comments

Ivan Khoronzhuk Dec. 15, 2015, 9:13 a.m. UTC | #1
On 15.12.15 10:49, Savolainen, Petri (Nokia - FI/Espoo) wrote:
>
>
>> -----Original Message-----
>> From: lng-odp [mailto:lng-odp-bounces@lists.linaro.org] On Behalf Of EXT
>> Ivan Khoronzhuk
>> Sent: Monday, December 14, 2015 8:58 PM
>> To: lng-odp@lists.linaro.org
>> Subject: [lng-odp] [API-NEXT PATCH 1/6] api: time: add rate and delay API
>> calls
>>
>> This patch adds odp_time_local_rate() and odp_time_delay() APIs.
>>
>> Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
>> ---
>>   include/odp/api/time.h            | 12 ++++++++++++
>>   platform/linux-generic/odp_time.c | 21 +++++++++++++++++++++
>>   2 files changed, 33 insertions(+)
>>
>> diff --git a/include/odp/api/time.h b/include/odp/api/time.h
>> index 9865d81..75644ca 100644
>> --- a/include/odp/api/time.h
>> +++ b/include/odp/api/time.h
>> @@ -101,6 +101,18 @@ odp_time_t odp_time_local_from_ns(uint64_t ns);
>>   int odp_time_cmp(odp_time_t t2, odp_time_t t1);
>>
>>   /**
>> + * Get local time rate
>> + */
>> +uint64_t odp_time_local_rate(void);
>
> Documentation needs to be improved. Better description and @return tag is missing. When modifying API spec, you should run 'make doxygen-html' and
>  check that no new doxygen warnings are generated. Last time API patches did introduce new warnings:
Ok.

>
> odp/platform/linux-generic/include/odp/plat/time_types.h:26: warning: Member odp_time_null(void) (function) of group odp_time is not documented.
> odp/platform/linux-generic/include/odp/plat/time_types.h:26: warning: Member odp_time_null(void) (function) of group odp_time is not documented.
>
>
> I think resolution is better term than rate for this. Posix time API and our timer API use "res" for the same thing.
>
>
>   /**
>    * Local timestamp resolution in hertz
>    *
>    * @return Local timestamp resolution in hertz
>    */
> uint64_t odp_time_local_res(void);
Ok. Will correct in v2

>
>> +
>> +/**
>> + * Wait on for specified length of time
>> + *
>> + * @param delay    time to wait
>> + */
>> +void odp_time_delay(odp_time_t delay);
>
>
> I think odp_time_wait() is better name for the function. We wait for a specified amount of time, we do not delay time for a specified amount...
>
> It's good to mention that this likely causes the thread to busy loop. It's not guaranteed to put this thread into sleep and swap in another thread...
>
> -Petri
>
>
>
>
>> +
>> +/**
>>    * Get printable value for an odp_time_t
>>    *
>>    * @param time time to be printed
>> diff --git a/platform/linux-generic/odp_time.c b/platform/linux-
>> generic/odp_time.c
>> index 1c7c214..182522d 100644
>> --- a/platform/linux-generic/odp_time.c
>> +++ b/platform/linux-generic/odp_time.c
>> @@ -98,6 +98,27 @@ odp_time_t odp_time_sum(odp_time_t t1, odp_time_t t2)
>>   	return time;
>>   }
>>
>> +uint64_t odp_time_local_rate(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;
>> +}
>> +
>> +void odp_time_delay(odp_time_t delay)
>> +{
>> +	odp_time_t cur = odp_time_local();
>> +	odp_time_t end_time = odp_time_sum(cur, delay);
>> +
>> +	while (odp_time_cmp(end_time, cur) > 0)
>> +		cur = odp_time_local();
>> +}
>> +
>>   uint64_t odp_time_to_u64(odp_time_t time)
>>   {
>>   	int ret;
>> --
>> 1.9.1
>>
>> _______________________________________________
>> lng-odp mailing list
>> lng-odp@lists.linaro.org
>> https://lists.linaro.org/mailman/listinfo/lng-odp
diff mbox

Patch

diff --git a/include/odp/api/time.h b/include/odp/api/time.h
index 9865d81..75644ca 100644
--- a/include/odp/api/time.h
+++ b/include/odp/api/time.h
@@ -101,6 +101,18 @@  odp_time_t odp_time_local_from_ns(uint64_t ns);
 int odp_time_cmp(odp_time_t t2, odp_time_t t1);
 
 /**
+ * Get local time rate
+ */
+uint64_t odp_time_local_rate(void);
+
+/**
+ * Wait on for specified length of time
+ *
+ * @param delay    time to wait
+ */
+void odp_time_delay(odp_time_t delay);
+
+/**
  * Get printable value for an odp_time_t
  *
  * @param time time to be printed
diff --git a/platform/linux-generic/odp_time.c b/platform/linux-generic/odp_time.c
index 1c7c214..182522d 100644
--- a/platform/linux-generic/odp_time.c
+++ b/platform/linux-generic/odp_time.c
@@ -98,6 +98,27 @@  odp_time_t odp_time_sum(odp_time_t t1, odp_time_t t2)
 	return time;
 }
 
+uint64_t odp_time_local_rate(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;
+}
+
+void odp_time_delay(odp_time_t delay)
+{
+	odp_time_t cur = odp_time_local();
+	odp_time_t end_time = odp_time_sum(cur, delay);
+
+	while (odp_time_cmp(end_time, cur) > 0)
+		cur = odp_time_local();
+}
+
 uint64_t odp_time_to_u64(odp_time_t time)
 {
 	int ret;