On Tuesday call, there were suggestions for another type of wait calls
/* * Wait the specified number of nanoseconds */ void odp_time_wait_ns(uint64_t nsec); /* * Wait until the specified (wall clock) time has been reached */ void odp_time_wait_until(odp_time_t time); These two could replace odp_time_wait(odp_time_t time), since waiting for a number of nsec does not need to define the (local/global) time source. Wait_ns is relative to the current time and wait_until is an absolute time in future. Absolute time wait can be more accurately synchronized, than application calculating relative wait time itself. Wait_until could return immediately if wall time has passed the time specified. -Petri > -----Original Message----- > From: lng-odp [mailto:lng-odp-boun...@lists.linaro.org] On Behalf Of EXT > Ivan Khoronzhuk > Sent: Tuesday, December 15, 2015 2:29 PM > To: lng-odp@lists.linaro.org > Subject: [lng-odp] [API-NEXT PATCH v2 1/6] api: time: add resolution and > wait API calls > > This patch adds odp_time_local_res() and odp_time_wait() APIs. > > Signed-off-by: Ivan Khoronzhuk <ivan.khoronz...@linaro.org> > --- > include/odp/api/time.h | 17 ++++++++++ > platform/linux-generic/odp_time.c | 71 ++++++++++++++++++++++++++++++---- > ----- > 2 files changed, 72 insertions(+), 16 deletions(-) > > diff --git a/include/odp/api/time.h b/include/odp/api/time.h > index 9865d81..0c3b5c8 100644 > --- a/include/odp/api/time.h > +++ b/include/odp/api/time.h > @@ -101,6 +101,23 @@ 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 on for specified length of time > + * > + * It likely causes the thread to busy loop. It's not guaranteed to put > + * this thread into sleep and swap in another thread. > + * > + * @param time time to wait > + */ > +void odp_time_wait(odp_time_t time); > + > +/** > * 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..3a41e2e 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,6 +58,39 @@ odp_time_t odp_time_local(void) > return time_diff(time.ex, start_time); > } > > +static inline > +int time_cmp(odp_time_t t2, odp_time_t 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; > +} > + > +static inline > +odp_time_t time_sum(odp_time_t t1, odp_time_t t2) > +{ > + 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(void) > +{ > + return time_local(); > +} > + > odp_time_t odp_time_diff(odp_time_t t2, odp_time_t t1) > { > return time_diff(t2, t1); > @@ -79,28 +113,33 @@ odp_time_t odp_time_local_from_ns(uint64_t ns) > > int odp_time_cmp(odp_time_t t2, odp_time_t 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; > + 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(odp_time_t time) > +{ > + odp_time_t cur = time_local(); > + odp_time_t end_time = time_sum(cur, time); > + > + while (time_cmp(end_time, cur) > 0) > + cur = time_local(); > } > > uint64_t odp_time_to_u64(odp_time_t time) > -- > 1.9.1 > > _______________________________________________ > lng-odp mailing list > lng-odp@lists.linaro.org > https://lists.linaro.org/mailman/listinfo/lng-odp _______________________________________________ lng-odp mailing list lng-odp@lists.linaro.org https://lists.linaro.org/mailman/listinfo/lng-odp