diff mbox

[v2,2/2] linux-generic: use arch optimisations for time

Message ID 1428348899-22253-2-git-send-email-mike.holmes@linaro.org
State Accepted
Commit be57a997211c1cef9a3c10cb2e9dd9754aa9dc6b
Headers show

Commit Message

Mike Holmes April 6, 2015, 7:34 p.m. UTC
Switch to using configure time optimizations from compile time

Signed-off-by: Mike Holmes <mike.holmes@linaro.org>
---
 platform/linux-generic/Makefile.am            |  3 +-
 platform/linux-generic/arch/linux/odp_time.c  | 38 ++++++++++++++++
 platform/linux-generic/arch/mips64/odp_time.c | 21 +++++++++
 platform/linux-generic/arch/x86/odp_time.c    | 23 ++++++++++
 platform/linux-generic/odp_time.c             | 64 ---------------------------
 5 files changed, 84 insertions(+), 65 deletions(-)
 create mode 100644 platform/linux-generic/arch/linux/odp_time.c
 create mode 100644 platform/linux-generic/arch/mips64/odp_time.c
 create mode 100644 platform/linux-generic/arch/x86/odp_time.c
diff mbox

Patch

diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am
index e5558ac..06d5998 100644
--- a/platform/linux-generic/Makefile.am
+++ b/platform/linux-generic/Makefile.am
@@ -167,4 +167,5 @@  __LIB__libodp_la_SOURCES = \
 			   odp_time.c \
 			   odp_timer.c \
 			   odp_version.c \
-			   odp_weak.c
+			   odp_weak.c \
+			   arch/@ARCH@/odp_time.c
diff --git a/platform/linux-generic/arch/linux/odp_time.c b/platform/linux-generic/arch/linux/odp_time.c
new file mode 100644
index 0000000..4dc0764
--- /dev/null
+++ b/platform/linux-generic/arch/linux/odp_time.c
@@ -0,0 +1,38 @@ 
+/* Copyright (c) 2015, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+#define _POSIX_C_SOURCE 199309L
+
+#include <stdlib.h>
+#include <time.h>
+
+#include <odp/time.h>
+#include <odp/hints.h>
+#include <odp/system_info.h>
+#include <odp_debug_internal.h>
+
+#define GIGA 1000000000
+
+uint64_t odp_time_cycles(void)
+{
+	struct timespec time;
+	uint64_t sec, ns, hz, cycles;
+	int ret;
+
+	ret = clock_gettime(CLOCK_MONOTONIC_RAW, &time);
+
+	if (ret != 0)
+		ODP_ABORT("clock_gettime failed\n");
+
+	hz  = odp_sys_cpu_hz();
+	sec = (uint64_t) time.tv_sec;
+	ns  = (uint64_t) time.tv_nsec;
+
+	cycles  = sec * hz;
+	cycles += (ns * hz) / GIGA;
+
+	return cycles;
+}
diff --git a/platform/linux-generic/arch/mips64/odp_time.c b/platform/linux-generic/arch/mips64/odp_time.c
new file mode 100644
index 0000000..4fb790b
--- /dev/null
+++ b/platform/linux-generic/arch/mips64/odp_time.c
@@ -0,0 +1,21 @@ 
+/* Copyright (c) 2015, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+#include <odp/time.h>
+#include <odp/hints.h>
+#include <odp/system_info.h>
+
+uint64_t odp_time_cycles(void)
+{
+	#define CVMX_TMP_STR(x) CVMX_TMP_STR2(x)
+	#define CVMX_TMP_STR2(x) #x
+	uint64_t cycle;
+
+	__asm__ __volatile__ ("rdhwr %[rt],$" CVMX_TMP_STR(31) :
+			   [rt] "=d" (cycle) : : "memory");
+
+	return cycle;
+}
diff --git a/platform/linux-generic/arch/x86/odp_time.c b/platform/linux-generic/arch/x86/odp_time.c
new file mode 100644
index 0000000..a111561
--- /dev/null
+++ b/platform/linux-generic/arch/x86/odp_time.c
@@ -0,0 +1,23 @@ 
+/* Copyright (c) 2015, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+#include <odp/time.h>
+
+uint64_t odp_time_cycles(void)
+{
+	union {
+		uint64_t tsc_64;
+		struct {
+			uint32_t lo_32;
+			uint32_t hi_32;
+		};
+	} tsc;
+
+	__asm__ __volatile__ ("rdtsc" :
+		     "=a" (tsc.lo_32),
+		     "=d" (tsc.hi_32) : : "memory");
+
+	return tsc.tsc_64;
+}
diff --git a/platform/linux-generic/odp_time.c b/platform/linux-generic/odp_time.c
index 31d6656..a08833d 100644
--- a/platform/linux-generic/odp_time.c
+++ b/platform/linux-generic/odp_time.c
@@ -12,70 +12,6 @@ 
 
 #define GIGA 1000000000
 
-#if defined __x86_64__ || defined __i386__
-
-uint64_t odp_time_cycles(void)
-{
-	union {
-		uint64_t tsc_64;
-		struct {
-			uint32_t lo_32;
-			uint32_t hi_32;
-		};
-	} tsc;
-
-	__asm__ __volatile__ ("rdtsc" :
-		     "=a" (tsc.lo_32),
-		     "=d" (tsc.hi_32) : : "memory");
-
-	return tsc.tsc_64;
-}
-
-
-#elif defined __OCTEON__
-
-uint64_t odp_time_cycles(void)
-{
-	#define CVMX_TMP_STR(x) CVMX_TMP_STR2(x)
-	#define CVMX_TMP_STR2(x) #x
-	uint64_t cycle;
-
-	__asm__ __volatile__ ("rdhwr %[rt],$" CVMX_TMP_STR(31) :
-			   [rt] "=d" (cycle) : : "memory");
-
-	return cycle;
-}
-
-#else
-
-#include <time.h>
-#include <stdlib.h>
-#include <odp_debug_internal.h>
-
-uint64_t odp_time_cycles(void)
-{
-	struct timespec time;
-	uint64_t sec, ns, hz, cycles;
-	int ret;
-
-	ret = clock_gettime(CLOCK_MONOTONIC_RAW, &time);
-
-	if (ret != 0) {
-		ODP_ABORT("clock_gettime failed\n");
-	}
-
-	hz  = odp_sys_cpu_hz();
-	sec = (uint64_t) time.tv_sec;
-	ns  = (uint64_t) time.tv_nsec;
-
-	cycles  = sec * hz;
-	cycles += (ns * hz) / GIGA;
-
-	return cycles;
-}
-
-#endif
-
 uint64_t odp_time_diff_cycles(uint64_t t1, uint64_t t2)
 {
 	if (odp_likely(t2 > t1))