Precursor to supporting platform specifics at configure time rather than with compile time preprocessor macros
Signed-off-by: Mike Holmes <[email protected]> --- 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 ++++++++++++++++ 3 files changed, 82 insertions(+) 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 --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; +} -- 2.1.0 _______________________________________________ lng-odp mailing list [email protected] https://lists.linaro.org/mailman/listinfo/lng-odp
