diff options
author | Mike Holmes <mike.holmes@linaro.org> | 2015-04-06 15:34:59 -0400 |
---|---|---|
committer | Maxim Uvarov <maxim.uvarov@linaro.org> | 2015-04-10 19:00:19 +0300 |
commit | be57a997211c1cef9a3c10cb2e9dd9754aa9dc6b (patch) | |
tree | 4a6d00e6d25849f32b84eecfce24e6c96c5966d4 /platform/linux-generic/arch | |
parent | a2383e6d72e9fc498986658a17bdbcd7c2ca46fe (diff) |
linux-generic: use arch optimisations for time
Switch to using configure time optimizations from compile time
Signed-off-by: Mike Holmes <mike.holmes@linaro.org>
Reviewed-by: Anders Roxell <anders.roxell@linaro.org>
Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Diffstat (limited to 'platform/linux-generic/arch')
-rw-r--r-- | platform/linux-generic/arch/linux/odp_time.c | 38 | ||||
-rw-r--r-- | platform/linux-generic/arch/mips64/odp_time.c | 21 | ||||
-rw-r--r-- | platform/linux-generic/arch/x86/odp_time.c | 23 |
3 files changed, 82 insertions, 0 deletions
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 000000000..4dc0764ed --- /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 000000000..4fb790b19 --- /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 000000000..a11156184 --- /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; +} |