aboutsummaryrefslogtreecommitdiff
path: root/platform/linux-generic/odp_time.c
diff options
context:
space:
mode:
authorIvan Khoronzhuk <ivan.khoronzhuk@linaro.org>2015-11-06 15:08:55 +0200
committerMaxim Uvarov <maxim.uvarov@linaro.org>2015-11-25 16:28:54 +0300
commit44dde8a5c19a8dcdf6fb993fd47f6c7f208b1ba4 (patch)
tree374ae9a56c2736b92ac9730c2c7c3b63302192c2 /platform/linux-generic/odp_time.c
parent9ba0ff81a33077472eea84670b45e85a8457ea23 (diff)
api: time: unbind CPU cycles from time API
Current time API supposes that frequency of counter is equal to CPU frequency. But that's not always true, for instance, in case if no access to CPU cycle counter, another hi-resolution timer can be used, and it`s rate can be different from CPU rate. There is no big difference in which cycles to measure time, the better hi-resolution timer the better measurements. So, unbind CPU cycle counter from time API by eliminating word "cycle" as it's believed to be used with CPU. Also add new opaque type for time odp_time_t, as it asks user to use API and abstracts time from units. New odp_time_t requires several additional API functions to be added: odp_time_t odp_time_sum(odp_time_t t1, odp_time_t t2); int odp_time_cmp(odp_time_t t1, odp_time_t t2); uint64_t odp_time_to_u64(odp_time_t hdl); Also added new definition that represents 0 ticks for time - ODP_TIME_NULL. It can be used instead of odp_time_from_ns(0) for comparison and initialization. This patch changes only used time API, it doesn't change used var names for simplicity. This time API can be implemented with local timer counter, so shouldn't be used between threads. Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org> Reviewed-by: Petri Savolainen <petri.savolainen@nokia.com> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org> Conflicts: platform/linux-generic/odp_time.c
Diffstat (limited to 'platform/linux-generic/odp_time.c')
-rw-r--r--platform/linux-generic/odp_time.c62
1 files changed, 51 insertions, 11 deletions
diff --git a/platform/linux-generic/odp_time.c b/platform/linux-generic/odp_time.c
index 74f802b83..a1494d76c 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_sys_cpu_hz();
+ 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_sys_cpu_hz();
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);
}