Message ID | 1450369889-4310-2-git-send-email-ivan.khoronzhuk@linaro.org |
---|---|
State | Superseded |
Headers | show |
On 18.12.15 11:13, Savolainen, Petri (Nokia - FI/Espoo) wrote: > > For APIs changes are OK otherwise but, wait functions could have warning that the thread potentially busy loop the entire wait time. Ok, I will add to description for both functions: The thread potentially busy loop the entire wait time. The inline I'll align. > > Don’t break function prototypes into multiple lines. See under. > > >> -----Original Message----- >> From: lng-odp [mailto:lng-odp-bounces@lists.linaro.org] On Behalf Of EXT >> Ivan Khoronzhuk >> Sent: Thursday, December 17, 2015 6:31 PM >> To: lng-odp@lists.linaro.org >> Subject: [lng-odp] [API-NEXT PATCH v4 1/6] api: time: add resolution and >> wait API calls >> >> This patch adds odp_time_local_res() and odp_time_wait_until(), >> odp_time_wait_ns() APIs. >> >> Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org> >> --- >> include/odp/api/time.h | 21 ++++++++ >> platform/linux-generic/odp_time.c | 100 ++++++++++++++++++++++++++++++--- >> ----- >> 2 files changed, 101 insertions(+), 20 deletions(-) >> >> diff --git a/include/odp/api/time.h b/include/odp/api/time.h >> index 9865d81..3319c27 100644 >> --- a/include/odp/api/time.h >> +++ b/include/odp/api/time.h >> @@ -101,6 +101,27 @@ odp_time_t odp_time_local_from_ns(uint64_t ns); >> int odp_time_cmp(odp_time_t t2, odp_time_t t1); >> >> /** >> + * Local time resolution in hertz >> + * >> + * @return Local time resolution in hertz >> + */ >> +uint64_t odp_time_local_res(void); >> + >> +/** >> + * Wait until the specified (wall clock) time has been reached >> + * >> + * @param time Time to reach before continue >> + */ >> +void odp_time_wait_until(odp_time_t time); >> + >> +/** >> + * Wait the specified number of nanoseconds >> + * >> + * @param ns Time in nanoseconds to wait >> + */ >> +void odp_time_wait_ns(uint64_t ns); >> + >> +/** >> * 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 9b64b37..d86f5ed 100644 >> --- a/platform/linux-generic/odp_time.c >> +++ b/platform/linux-generic/odp_time.c >> @@ -45,7 +45,8 @@ odp_time_t time_diff(odp_time_t t2, odp_time_t t1) >> return time; >> } >> >> -odp_time_t odp_time_local(void) >> +static inline >> +odp_time_t time_local(void) >> { >> int ret; >> _odp_time_t time; >> @@ -57,17 +58,36 @@ odp_time_t odp_time_local(void) >> return time_diff(time.ex, start_time); >> } >> >> -odp_time_t odp_time_diff(odp_time_t t2, odp_time_t t1) >> +static inline >> +int time_cmp(odp_time_t t2, odp_time_t t1) > > > "static inline" should be on the same line. If 80 char limit is the problem, break parameters into next line(s). > > Not all of our static inlines are on the same line, but ~95% are and I think all of those should be. > > -Petri > > >
v5 is sent On 18.12.15 11:13, Savolainen, Petri (Nokia - FI/Espoo) wrote: > > For APIs changes are OK otherwise but, wait functions could have warning that the thread potentially busy loop the entire wait time. > > Don’t break function prototypes into multiple lines. See under. > > >> -----Original Message----- >> From: lng-odp [mailto:lng-odp-bounces@lists.linaro.org] On Behalf Of EXT >> Ivan Khoronzhuk >> Sent: Thursday, December 17, 2015 6:31 PM >> To: lng-odp@lists.linaro.org >> Subject: [lng-odp] [API-NEXT PATCH v4 1/6] api: time: add resolution and >> wait API calls >> >> This patch adds odp_time_local_res() and odp_time_wait_until(), >> odp_time_wait_ns() APIs. >> >> Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org> >> --- >> include/odp/api/time.h | 21 ++++++++ >> platform/linux-generic/odp_time.c | 100 ++++++++++++++++++++++++++++++--- >> ----- >> 2 files changed, 101 insertions(+), 20 deletions(-) >> >> diff --git a/include/odp/api/time.h b/include/odp/api/time.h >> index 9865d81..3319c27 100644 >> --- a/include/odp/api/time.h >> +++ b/include/odp/api/time.h >> @@ -101,6 +101,27 @@ odp_time_t odp_time_local_from_ns(uint64_t ns); >> int odp_time_cmp(odp_time_t t2, odp_time_t t1); >> >> /** >> + * Local time resolution in hertz >> + * >> + * @return Local time resolution in hertz >> + */ >> +uint64_t odp_time_local_res(void); >> + >> +/** >> + * Wait until the specified (wall clock) time has been reached >> + * >> + * @param time Time to reach before continue >> + */ >> +void odp_time_wait_until(odp_time_t time); >> + >> +/** >> + * Wait the specified number of nanoseconds >> + * >> + * @param ns Time in nanoseconds to wait >> + */ >> +void odp_time_wait_ns(uint64_t ns); >> + >> +/** >> * 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 9b64b37..d86f5ed 100644 >> --- a/platform/linux-generic/odp_time.c >> +++ b/platform/linux-generic/odp_time.c >> @@ -45,7 +45,8 @@ odp_time_t time_diff(odp_time_t t2, odp_time_t t1) >> return time; >> } >> >> -odp_time_t odp_time_local(void) >> +static inline >> +odp_time_t time_local(void) >> { >> int ret; >> _odp_time_t time; >> @@ -57,17 +58,36 @@ odp_time_t odp_time_local(void) >> return time_diff(time.ex, start_time); >> } >> >> -odp_time_t odp_time_diff(odp_time_t t2, odp_time_t t1) >> +static inline >> +int time_cmp(odp_time_t t2, odp_time_t t1) > > > "static inline" should be on the same line. If 80 char limit is the problem, break parameters into next line(s). > > Not all of our static inlines are on the same line, but ~95% are and I think all of those should be. > > -Petri > > >
diff --git a/include/odp/api/time.h b/include/odp/api/time.h index 9865d81..3319c27 100644 --- a/include/odp/api/time.h +++ b/include/odp/api/time.h @@ -101,6 +101,27 @@ odp_time_t odp_time_local_from_ns(uint64_t ns); int odp_time_cmp(odp_time_t t2, odp_time_t t1); /** + * Local time resolution in hertz + * + * @return Local time resolution in hertz + */ +uint64_t odp_time_local_res(void); + +/** + * Wait until the specified (wall clock) time has been reached + * + * @param time Time to reach before continue + */ +void odp_time_wait_until(odp_time_t time); + +/** + * Wait the specified number of nanoseconds + * + * @param ns Time in nanoseconds to wait + */ +void odp_time_wait_ns(uint64_t ns); + +/** * 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 9b64b37..d86f5ed 100644 --- a/platform/linux-generic/odp_time.c +++ b/platform/linux-generic/odp_time.c @@ -45,7 +45,8 @@ odp_time_t time_diff(odp_time_t t2, odp_time_t t1) return time; } -odp_time_t odp_time_local(void) +static inline +odp_time_t time_local(void) { int ret; _odp_time_t time; @@ -57,17 +58,36 @@ odp_time_t odp_time_local(void) return time_diff(time.ex, start_time); } -odp_time_t odp_time_diff(odp_time_t t2, odp_time_t t1) +static inline +int time_cmp(odp_time_t t2, odp_time_t t1) { - return time_diff(t2, t1); + if (t2.tv_sec < t1.tv_sec) + return -1; + + if (t2.tv_sec > t1.tv_sec) + return 1; + + return t2.tv_nsec - t1.tv_nsec; } -uint64_t odp_time_to_ns(odp_time_t time) +static inline +odp_time_t time_sum(odp_time_t t1, odp_time_t t2) { - return time_to_ns(time); + odp_time_t time; + + time.tv_sec = t2.tv_sec + t1.tv_sec; + time.tv_nsec = t2.tv_nsec + t1.tv_nsec; + + if (time.tv_nsec >= (long)ODP_TIME_SEC_IN_NS) { + time.tv_nsec -= ODP_TIME_SEC_IN_NS; + ++time.tv_sec; + } + + return time; } -odp_time_t odp_time_local_from_ns(uint64_t ns) +static inline +odp_time_t time_local_from_ns(uint64_t ns) { odp_time_t time; @@ -77,30 +97,70 @@ odp_time_t odp_time_local_from_ns(uint64_t ns) return time; } -int odp_time_cmp(odp_time_t t2, odp_time_t t1) +static inline +void time_wait_until(odp_time_t time) { - if (t2.tv_sec < t1.tv_sec) - return -1; + odp_time_t cur; - if (t2.tv_sec > t1.tv_sec) - return 1; + do { + cur = time_local(); + } while (time_cmp(time, cur) > 0); +} - return t2.tv_nsec - t1.tv_nsec; +odp_time_t odp_time_local(void) +{ + return time_local(); +} + +odp_time_t odp_time_diff(odp_time_t t2, odp_time_t t1) +{ + return time_diff(t2, t1); +} + +uint64_t odp_time_to_ns(odp_time_t time) +{ + return time_to_ns(time); +} + +odp_time_t odp_time_local_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); } odp_time_t odp_time_sum(odp_time_t t1, odp_time_t t2) { - odp_time_t time; + return time_sum(t1, t2); +} - time.tv_sec = t2.tv_sec + t1.tv_sec; - time.tv_nsec = t2.tv_nsec + t1.tv_nsec; +uint64_t odp_time_local_res(void) +{ + int ret; + struct timespec tres; - if (time.tv_nsec >= (long)ODP_TIME_SEC_IN_NS) { - time.tv_nsec -= ODP_TIME_SEC_IN_NS; - ++time.tv_sec; - } + ret = clock_getres(CLOCK_MONOTONIC_RAW, &tres); + if (odp_unlikely(ret != 0)) + ODP_ABORT("clock_getres failed\n"); - return time; + return ODP_TIME_SEC_IN_NS / (uint64_t)tres.tv_nsec; +} + +void odp_time_wait_ns(uint64_t ns) +{ + odp_time_t cur = time_local(); + odp_time_t wait = time_local_from_ns(ns); + odp_time_t end_time = time_sum(cur, wait); + + time_wait_until(end_time); +} + +void odp_time_wait_until(odp_time_t time) +{ + return time_wait_until(time); } uint64_t odp_time_to_u64(odp_time_t time)
This patch adds odp_time_local_res() and odp_time_wait_until(), odp_time_wait_ns() APIs. Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org> --- include/odp/api/time.h | 21 ++++++++ platform/linux-generic/odp_time.c | 100 ++++++++++++++++++++++++++++++-------- 2 files changed, 101 insertions(+), 20 deletions(-)