diff mbox

[API-NEXT,1/2] linux-generic: use cycles_diff for time API also

Message ID 1444049893-28349-2-git-send-email-ivan.khoronzhuk@linaro.org
State Accepted
Commit fe67c25f71a1c327eecf852f33e4abb78fd47ec7
Headers show

Commit Message

Ivan Khoronzhuk Oct. 5, 2015, 12:58 p.m. UTC
Currently, time API reuses cpu API to get ticks, but uses it's own
function to count diff but it can differ from cpu diff function.
So, better to use the same function in order to eliminate possible
difference in counting.

Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
---
 platform/linux-generic/Makefile.am                |  1 +
 platform/linux-generic/include/odp_cpu_internal.h | 29 +++++++++++++++++++++++
 platform/linux-generic/odp_cpu.c                  |  6 ++---
 platform/linux-generic/odp_time.c                 |  6 ++---
 4 files changed, 34 insertions(+), 8 deletions(-)
 create mode 100644 platform/linux-generic/include/odp_cpu_internal.h
diff mbox

Patch

diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am
index 202ec6a..2b4a277 100644
--- a/platform/linux-generic/Makefile.am
+++ b/platform/linux-generic/Makefile.am
@@ -140,6 +140,7 @@  noinst_HEADERS = \
 		  ${srcdir}/include/odp_schedule_internal.h \
 		  ${srcdir}/include/odp_spin_internal.h \
 		  ${srcdir}/include/odp_timer_internal.h \
+		  ${srcdir}/include/odp_cpu_internal.h \
 		  ${srcdir}/Makefile.inc
 
 __LIB__libodp_la_SOURCES = \
diff --git a/platform/linux-generic/include/odp_cpu_internal.h b/platform/linux-generic/include/odp_cpu_internal.h
new file mode 100644
index 0000000..28a0a84
--- /dev/null
+++ b/platform/linux-generic/include/odp_cpu_internal.h
@@ -0,0 +1,29 @@ 
+/* Copyright (c) 2015, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+#ifndef ODP_CPU_INTERNAL_H_
+#define ODP_CPU_INTERNAL_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <odp/cpu.h>
+
+static inline
+uint64_t _odp_cpu_cycles_diff(uint64_t c1, uint64_t c2)
+{
+	if (odp_likely(c2 >= c1))
+		return c2 - c1;
+
+	return c2 + (odp_cpu_cycles_max() - c1);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/platform/linux-generic/odp_cpu.c b/platform/linux-generic/odp_cpu.c
index 45a79db..e5ec4f0 100644
--- a/platform/linux-generic/odp_cpu.c
+++ b/platform/linux-generic/odp_cpu.c
@@ -6,11 +6,9 @@ 
 
 #include <odp/cpu.h>
 #include <odp/hints.h>
+#include <odp_cpu_internal.h>
 
 uint64_t odp_cpu_cycles_diff(uint64_t c1, uint64_t c2)
 {
-	if (odp_likely(c2 >= c1))
-		return c2 - c1;
-
-	return c2 + (odp_cpu_cycles_max() - c1);
+	return _odp_cpu_cycles_diff(c1, c2);
 }
diff --git a/platform/linux-generic/odp_time.c b/platform/linux-generic/odp_time.c
index b378c35..74f802b 100644
--- a/platform/linux-generic/odp_time.c
+++ b/platform/linux-generic/odp_time.c
@@ -10,6 +10,7 @@ 
 #include <odp/hints.h>
 #include <odp/system_info.h>
 #include <odp/cpu.h>
+#include <odp_cpu_internal.h>
 
 #define GIGA 1000000000
 
@@ -20,10 +21,7 @@  uint64_t odp_time_cycles(void)
 
 uint64_t odp_time_diff_cycles(uint64_t t1, uint64_t t2)
 {
-	if (odp_likely(t2 >= t1))
-		return t2 - t1;
-
-	return t2 + (UINT64_MAX - t1);
+	return _odp_cpu_cycles_diff(t1, t2);
 }
 
 uint64_t odp_time_cycles_to_ns(uint64_t cycles)