@@ -79,6 +79,8 @@ int odp_schedule_term_local(void);
int odp_timer_init_global(void);
int odp_timer_disarm_all(void);
+int odp_time_local_init(void);
+
int odp_tm_init_global(void);
void _odp_flush_caches(void);
@@ -586,7 +586,7 @@ static int schedule_loop(odp_queue_t *out_queue, uint64_t wait,
odp_event_t out_ev[],
unsigned int max_num, unsigned int max_deq)
{
- odp_time_t start_time, time, diff, wtime;
+ odp_time_t next, wtime;
int first = 1;
int ret;
@@ -604,15 +604,12 @@ static int schedule_loop(odp_queue_t *out_queue, uint64_t wait,
if (first) {
wtime = odp_time_local_from_ns(wait);
- start_time = odp_time_local();
+ next = odp_time_sum(odp_time_local(), wtime);
first = 0;
continue;
}
- time = odp_time_local();
- diff = odp_time_diff(time, start_time);
-
- if (odp_time_cmp(wtime, diff) < 0)
+ if (odp_time_cmp(next, odp_time_local()) < 0)
break;
}
@@ -11,19 +11,21 @@
#include <odp/hints.h>
#include <odp_debug_internal.h>
-odp_time_t odp_time_local(void)
+static __thread struct timespec start_local;
+
+static inline
+uint64_t _odp_time_to_ns(odp_time_t val)
{
- int ret;
- struct timespec time;
+ uint64_t ns;
- ret = clock_gettime(CLOCK_MONOTONIC_RAW, &time);
- if (odp_unlikely(ret != 0))
- ODP_ABORT("clock_gettime failed\n");
+ ns = val.tv_sec * ODP_TIME_SEC_IN_NS;
+ ns += val.tv_nsec;
- return time;
+ return ns;
}
-odp_time_t odp_time_diff(odp_time_t t2, odp_time_t t1)
+static inline
+odp_time_t _odp_time_diff(odp_time_t t2, odp_time_t t1)
{
struct timespec time;
@@ -38,24 +40,36 @@ odp_time_t odp_time_diff(odp_time_t t2, odp_time_t t1)
return time;
}
-uint64_t odp_time_to_ns(odp_time_t time)
+odp_time_t odp_time_local(void)
{
- uint64_t ns;
+ int ret;
+ struct timespec time;
+
+ ret = clock_gettime(CLOCK_MONOTONIC_RAW, &time);
+ if (odp_unlikely(ret != 0))
+ ODP_ABORT("clock_gettime failed\n");
- ns = time.tv_sec * ODP_TIME_SEC_IN_NS;
- ns += time.tv_nsec;
+ return _odp_time_diff(time, start_local);
+}
- return ns;
+odp_time_t odp_time_diff(odp_time_t t2, odp_time_t t1)
+{
+ return _odp_time_diff(t2, t1);
+}
+
+uint64_t odp_time_to_ns(odp_time_t time)
+{
+ return _odp_time_to_ns(time);
}
odp_time_t odp_time_local_from_ns(uint64_t ns)
{
- struct timespec time;
+ struct timespec val;
- time.tv_sec = ns / ODP_TIME_SEC_IN_NS;
- time.tv_nsec = ns % ODP_TIME_SEC_IN_NS;
+ val.tv_sec = ns / ODP_TIME_SEC_IN_NS;
+ val.tv_nsec = ns % ODP_TIME_SEC_IN_NS;
- return time;
+ return val;
}
int odp_time_cmp(odp_time_t t2, odp_time_t t1)
@@ -96,10 +110,21 @@ uint64_t odp_time_to_u64(odp_time_t time)
resolution = (uint64_t)tres.tv_nsec;
- return odp_time_to_ns(time) / resolution;
+ return _odp_time_to_ns(time) / resolution;
}
odp_time_t odp_time_null(void)
{
return (struct timespec) {0, 0};
}
+
+int odp_time_local_init(void)
+{
+ int ret;
+ struct timespec time;
+
+ ret = clock_gettime(CLOCK_MONOTONIC_RAW, &time);
+ start_local = ret ? odp_time_null() : time;
+
+ return ret;
+}
The local time API supposes the time source is wall time. So correct linux-generic implementation. Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org> --- platform/linux-generic/include/odp_internal.h | 2 + platform/linux-generic/odp_schedule.c | 9 ++-- platform/linux-generic/odp_time.c | 61 +++++++++++++++++++-------- 3 files changed, 48 insertions(+), 24 deletions(-)