diff mbox

[API-NEXT,v7,4/6] linux-generic: align implementation with new time API

Message ID 1446737630-2323-5-git-send-email-ivan.khoronzhuk@linaro.org
State New
Headers show

Commit Message

Ivan Khoronzhuk Nov. 5, 2015, 3:33 p.m. UTC
The time API names were changed from odp_time_cycle* to odp_time*.
Also new time API operates with new opaque type - odp_time_t, as
result several new API calls were added. For odp_schdule.c avoid
"cycle" word usage as it was left from old time API names.

This patch is intended to align linux-generic implementation with
new time API.

Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
---
 platform/linux-generic/Makefile.am                 |  1 +
 .../linux-generic/include/odp/plat/time_types.h    | 36 +++++++++++++
 platform/linux-generic/include/odp/time.h          |  1 +
 platform/linux-generic/odp_schedule.c              | 16 +++---
 platform/linux-generic/odp_time.c                  | 62 ++++++++++++++++++----
 platform/linux-generic/odp_timer.c                 |  4 +-
 6 files changed, 99 insertions(+), 21 deletions(-)
 create mode 100644 platform/linux-generic/include/odp/plat/time_types.h
diff mbox

Patch

diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am
index 610c79c..a6b6029 100644
--- a/platform/linux-generic/Makefile.am
+++ b/platform/linux-generic/Makefile.am
@@ -76,6 +76,7 @@  odpplatinclude_HEADERS = \
 		  $(srcdir)/include/odp/plat/strong_types.h \
 		  $(srcdir)/include/odp/plat/thrmask_types.h \
 		  $(srcdir)/include/odp/plat/ticketlock_types.h \
+		  $(srcdir)/include/odp/plat/time_types.h \
 		  $(srcdir)/include/odp/plat/timer_types.h \
 		  $(srcdir)/include/odp/plat/version_types.h
 
diff --git a/platform/linux-generic/include/odp/plat/time_types.h b/platform/linux-generic/include/odp/plat/time_types.h
new file mode 100644
index 0000000..9ba1508
--- /dev/null
+++ b/platform/linux-generic/include/odp/plat/time_types.h
@@ -0,0 +1,36 @@ 
+/* Copyright (c) 2015, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+/**
+ * @file
+ *
+ * ODP time service
+ */
+
+#ifndef ODP_TIME_TYPES_H_
+#define ODP_TIME_TYPES_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** @addtogroup odp_time
+ *  @{
+ **/
+
+typedef uint64_t odp_time_t;
+
+#define ODP_TIME_NULL ((odp_time_t)0)
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/platform/linux-generic/include/odp/time.h b/platform/linux-generic/include/odp/time.h
index 3a3960b..44e0d0d 100644
--- a/platform/linux-generic/include/odp/time.h
+++ b/platform/linux-generic/include/odp/time.h
@@ -21,6 +21,7 @@  extern "C" {
 
 
 
+#include <odp/plat/time_types.h>
 #include <odp/api/time.h>
 
 #ifdef __cplusplus
diff --git a/platform/linux-generic/odp_schedule.c b/platform/linux-generic/odp_schedule.c
index 6df8073..bb7e324 100644
--- a/platform/linux-generic/odp_schedule.c
+++ b/platform/linux-generic/odp_schedule.c
@@ -585,10 +585,10 @@  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)
 {
-	uint64_t start_cycle, cycle, diff;
+	odp_time_t start_time, time, diff;
 	int ret;
 
-	start_cycle = 0;
+	start_time = ODP_TIME_NULL;
 
 	while (1) {
 		ret = schedule(out_queue, out_ev, max_num, max_deq);
@@ -602,15 +602,15 @@  static int schedule_loop(odp_queue_t *out_queue, uint64_t wait,
 		if (wait == ODP_SCHED_NO_WAIT)
 			break;
 
-		if (start_cycle == 0) {
-			start_cycle = odp_time_cycles();
+		if (!odp_time_cmp(ODP_TIME_NULL, start_time)) {
+			start_time = odp_time_local();
 			continue;
 		}
 
-		cycle = odp_time_cycles();
-		diff  = odp_time_diff_cycles(start_cycle, cycle);
+		time = odp_time_local();
+		diff  = odp_time_diff(start_time, time);
 
-		if (wait < diff)
+		if (odp_time_cmp(wait, diff) < 0)
 			break;
 	}
 
@@ -651,7 +651,7 @@  void odp_schedule_resume(void)
 
 uint64_t odp_schedule_wait_time(uint64_t ns)
 {
-	return odp_time_ns_to_cycles(ns);
+	return odp_time_to_u64(odp_time_local_from_ns(ns));
 }
 
 
diff --git a/platform/linux-generic/odp_time.c b/platform/linux-generic/odp_time.c
index abafd12..fdb143f 100644
--- a/platform/linux-generic/odp_time.c
+++ b/platform/linux-generic/odp_time.c
@@ -14,33 +14,73 @@ 
 
 #define GIGA 1000000000
 
-uint64_t odp_time_cycles(void)
+static inline
+uint64_t time_to_tick(odp_time_t time)
 {
-	return odp_cpu_cycles();
+	return (uint64_t)time;
 }
 
-uint64_t odp_time_diff_cycles(uint64_t t1, uint64_t t2)
+static inline
+odp_time_t tick_to_time(uint64_t tick)
 {
-	return _odp_cpu_cycles_diff(t1, t2);
+	return (odp_time_t)tick;
 }
 
-uint64_t odp_time_cycles_to_ns(uint64_t cycles)
+odp_time_t odp_time_local(void)
+{
+	return tick_to_time(odp_cpu_cycles());
+}
+
+odp_time_t odp_time_diff(odp_time_t t1, odp_time_t t2)
+{
+	return tick_to_time(_odp_cpu_cycles_diff(t1, t2));
+}
+
+uint64_t odp_time_to_ns(odp_time_t time)
 {
 	uint64_t hz = odp_cpu_hz_max();
+	uint64_t tick = time_to_tick(time);
 
-	if (cycles > (UINT64_MAX / GIGA))
-		return (cycles/hz)*GIGA;
+	if (tick > (UINT64_MAX / GIGA))
+		return (tick / hz) * GIGA;
 
-	return (cycles*GIGA)/hz;
+	return (tick * GIGA) / hz;
 }
 
 
-uint64_t odp_time_ns_to_cycles(uint64_t ns)
+odp_time_t odp_time_local_from_ns(uint64_t ns)
 {
 	uint64_t hz = odp_cpu_hz_max();
 
 	if (ns > (UINT64_MAX / hz))
-		return (ns/GIGA)*hz;
+		return tick_to_time((ns / GIGA) * hz);
+
+	return tick_to_time((ns * hz) / GIGA);
+}
+
+int odp_time_cmp(odp_time_t t2, odp_time_t t1)
+{
+	uint64_t tick1 = time_to_tick(t1);
+	uint64_t tick2 = time_to_tick(t2);
 
-	return (ns*hz)/GIGA;
+	if (tick1 < tick2)
+		return 1;
+
+	if (tick1 > tick2)
+		return -1;
+
+	return 0;
+}
+
+odp_time_t odp_time_sum(odp_time_t t1, odp_time_t t2)
+{
+	uint64_t tick1 = time_to_tick(t1);
+	uint64_t tick2 = time_to_tick(t2);
+
+	return tick_to_time(tick1 + tick2);
+}
+
+uint64_t odp_time_to_u64(odp_time_t hdl)
+{
+	return time_to_tick(hdl);
 }
diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c
index e8f0267..bb32aa6 100644
--- a/platform/linux-generic/odp_timer.c
+++ b/platform/linux-generic/odp_timer.c
@@ -672,8 +672,8 @@  static void itimer_init(odp_timer_pool *tp)
 			  strerror(errno));
 
 	res  = tp->param.res_ns;
-	sec  = res / ODP_TIME_SEC;
-	nsec = res - sec * ODP_TIME_SEC;
+	sec  = res / ODP_TIME_SEC_IN_NS;
+	nsec = res - sec * ODP_TIME_SEC_IN_NS;
 
 	ispec.it_interval.tv_sec  = (time_t)sec;
 	ispec.it_interval.tv_nsec = (long)nsec;