From patchwork Fri Sep 8 00:00:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 111996 Delivered-To: patch@linaro.org Received: by 10.140.94.239 with SMTP id g102csp787488qge; Thu, 7 Sep 2017 17:01:44 -0700 (PDT) X-Google-Smtp-Source: AOwi7QDGgbHsD71kGvQJT2hNQoRsBQGZv3cRTtHsj9sGzDA3mzAGxs8RmpGgR9M8m7EOz85D0+VX X-Received: by 10.55.136.7 with SMTP id k7mr1518368qkd.302.1504828904352; Thu, 07 Sep 2017 17:01:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504828904; cv=none; d=google.com; s=arc-20160816; b=birud2QXlyE6gP9eKr6Nr3U0xWxINICa/uoMLjmjrm2qC5KkIa8iywzJoMkCABB02k Bgk7wKk5r4wSGH6q2hVAlK9r9k1HeSCzRoDDAUU4qTokmQ3Lmv1gboRZQuDwor8iKDdT UB3kOOS8suEWfhJo7bD5AyAPnDI7vPuidVklhLkqdFWDcMfClNRqRilVVfWiTEw5P/lj w150f7N3xs7JXCsPIAQ654/38u3esVvXp9HwMd0RoAvOw1Zj44iKIKhLKCVp9ooUpJEc 5gTG2d0x8xgie4o+plxEVD9UadQdoN0F1M9uuw+qLxOvsCUOfhSjsXk9WSvJH4mv0NZU lwCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=qmFm/23XITD4cldcIFCrx5b7X1SZcYMy1oZ5P7rf2sA=; b=ErrCBnkONTxaz4aPuEOXvSfoNxA4Pxf8ewDGbQJKEfG/aWWN51Bi58AQB8omBL4A7s BU8S+SaA15xMiJ9ZOYosNgaybsS0U+QXuSL3sYzDd7Mz2+bR0kyIEKJV4yRcBox9oV4w b3kPSJJUV+pY5+8NNEIb65Ul78Vj2R+B7PnWWYrtMelK1auRLgy0Kdw02dq9HVMf6frc RdE13BPQ0NHLjgQwE7BymJqGl+NkBHdWIyxar7GuYdsr5PTdSItZ9xyJ8VVm/Wnm9Qub rFf8ThEJmwB9I8PPjOmQJZuNMslJFY3jZzwCC2+1xPoi30Hb8ZSEaXZ0iVShbWpbSjmL 2/jg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id d24si662896qtf.414.2017.09.07.17.01.44; Thu, 07 Sep 2017 17:01:44 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 0A8F9644CC; Fri, 8 Sep 2017 00:01:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id E3306644C7; Fri, 8 Sep 2017 00:00:40 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 414DB644C2; Fri, 8 Sep 2017 00:00:26 +0000 (UTC) Received: from forward100o.mail.yandex.net (forward100o.mail.yandex.net [37.140.190.180]) by lists.linaro.org (Postfix) with ESMTPS id B29ED644B7 for ; Fri, 8 Sep 2017 00:00:13 +0000 (UTC) Received: from mxback6j.mail.yandex.net (mxback6j.mail.yandex.net [IPv6:2a02:6b8:0:1619::10f]) by forward100o.mail.yandex.net (Yandex) with ESMTP id 010F22A201A4 for ; Fri, 8 Sep 2017 03:00:12 +0300 (MSK) Received: from smtp3p.mail.yandex.net (smtp3p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:8]) by mxback6j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id cziiaCYxLx-0BHCOewT; Fri, 08 Sep 2017 03:00:11 +0300 Received: by smtp3p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id 7RlSQsaFqo-0B8Cd4wK; Fri, 08 Sep 2017 03:00:11 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Fri, 8 Sep 2017 03:00:09 +0300 Message-Id: <1504828809-10552-2-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1504828809-10552-1-git-send-email-odpbot@yandex.ru> References: <1504828809-10552-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 163 Subject: [lng-odp] [PATCH v4 1/1] linux-gen: deduplicate arch-specific files X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Dmitry Eremin-Solenikov Rewrite ARCH-specific files so that there is no significant code duplication between different arch files and default files set. Signed-off-by: Dmitry Eremin-Solenikov --- /** Email created from pull request 163 (lumag:improve-build-4) ** https://github.com/Linaro/odp/pull/163 ** Patch: https://github.com/Linaro/odp/pull/163.patch ** Base sha: 360c1d34b52a2356619b9290811862b9de41de00 ** Merge commit sha: 7a7b0b0efb3d98a9737c8f39c5786ca8cd814c0a **/ configure.ac | 3 +- platform/Makefile.inc | 19 ------ platform/linux-generic/Makefile.am | 50 +++++++++++--- .../linux-generic/arch/aarch64/odp/api/cpu_arch.h | 30 +++++++++ .../odp_cpu_arch.c => aarch64/odp_global_time.c} | 45 ------------- .../linux-generic/arch/arm/odp_sysinfo_parse.c | 33 ---------- platform/linux-generic/arch/default/odp_cpu_arch.c | 28 -------- .../linux-generic/arch/default/odp_cpu_cycles.c | 19 ++++++ .../linux-generic/arch/default/odp_global_time.c | 33 ++++++++++ platform/linux-generic/arch/mips64/odp_cpu_arch.c | 25 ------- platform/linux-generic/arch/powerpc/odp_cpu_arch.c | 25 ------- .../linux-generic/arch/powerpc/odp_global_time.c | 15 +++++ platform/linux-generic/arch/x86/odp_cpu_arch.c | 72 -------------------- platform/linux-generic/arch/x86/odp_global_time.c | 77 ++++++++++++++++++++++ 14 files changed, 216 insertions(+), 258 deletions(-) create mode 100644 platform/linux-generic/arch/aarch64/odp/api/cpu_arch.h rename platform/linux-generic/arch/{arm/odp_cpu_arch.c => aarch64/odp_global_time.c} (65%) delete mode 100644 platform/linux-generic/arch/arm/odp_sysinfo_parse.c create mode 100644 platform/linux-generic/arch/default/odp_cpu_cycles.c create mode 100644 platform/linux-generic/arch/default/odp_global_time.c create mode 100644 platform/linux-generic/arch/powerpc/odp_global_time.c create mode 100644 platform/linux-generic/arch/x86/odp_global_time.c diff --git a/configure.ac b/configure.ac index df0a0f61..5ff85d55 100644 --- a/configure.ac +++ b/configure.ac @@ -107,7 +107,7 @@ AS_CASE([$host], [i686*], [ARCH_DIR=x86], [mips64*], [ARCH_DIR=mips64], [powerpc*], [ARCH_DIR=powerpc], - [aarch64*], [ARCH_DIR=arm], + [aarch64*], [ARCH_DIR=aarch64], [arm*], [ARCH_DIR=arm], [ARCH_DIR=undefined] ) @@ -218,6 +218,7 @@ AM_CONDITIONAL([user_guide], [test "x${user_guides}" = "xyes" ]) AM_CONDITIONAL([HAVE_MSCGEN], [test "x${MSCGEN}" = "xmscgen"]) AM_CONDITIONAL([helper_linux], [test x$helper_linux = xyes ]) AM_CONDITIONAL([ARCH_IS_ARM], [test "x${ARCH_DIR}" = "xarm"]) +AM_CONDITIONAL([ARCH_IS_AARCH64], [test "x${ARCH_DIR}" = "xaarch64"]) AM_CONDITIONAL([ARCH_IS_MIPS64], [test "x${ARCH_DIR}" = "xmips64"]) AM_CONDITIONAL([ARCH_IS_POWERPC], [test "x${ARCH_DIR}" = "xpowerpc"]) AM_CONDITIONAL([ARCH_IS_X86], [test "x${ARCH_DIR}" = "xx86"]) diff --git a/platform/Makefile.inc b/platform/Makefile.inc index 738f0f9a..bcd06c44 100644 --- a/platform/Makefile.inc +++ b/platform/Makefile.inc @@ -84,22 +84,3 @@ odpapiabiarchinclude_HEADERS = \ $(top_srcdir)/include/odp/arch/@ARCH_ABI@/odp/api/abi/pool.h \ $(top_srcdir)/include/odp/arch/@ARCH_ABI@/odp/api/abi/queue.h \ $(top_srcdir)/include/odp/arch/@ARCH_ABI@/odp/api/abi/shared_memory.h - -EXTRA_DIST = \ - arch/arm/odp/api/cpu_arch.h \ - arch/arm/odp_cpu_arch.c \ - arch/arm/odp_sysinfo_parse.c \ - arch/default/odp/api/cpu_arch.h \ - arch/default/odp_cpu_arch.c \ - arch/default/odp_sysinfo_parse.c \ - arch/mips64/odp/api/cpu_arch.h \ - arch/mips64/odp_cpu_arch.c \ - arch/mips64/odp_sysinfo_parse.c \ - arch/powerpc/odp/api/cpu_arch.h \ - arch/powerpc/odp_cpu_arch.c \ - arch/powerpc/odp_sysinfo_parse.c \ - arch/x86/odp/api/cpu_arch.h \ - arch/x86/odp_cpu_arch.c \ - arch/x86/odp_sysinfo_parse.c \ - arch/x86/cpu_flags.c \ - arch/x86/cpu_flags.h diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 8f0618f4..9fde4dcb 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -68,17 +68,16 @@ odpapiinclude_HEADERS = \ $(srcdir)/include/odp/api/traffic_mngr.h \ $(srcdir)/include/odp/api/version.h +odpapiinclude_HEADERS += $(arch_odp_headers) if ARCH_IS_ARM -odpapiinclude_HEADERS += $(srcdir)/arch/arm/odp/api/cpu_arch.h +endif +if ARCH_IS_AARCH64 endif if ARCH_IS_MIPS64 -odpapiinclude_HEADERS += $(srcdir)/arch/mips64/odp/api/cpu_arch.h endif if ARCH_IS_POWERPC -odpapiinclude_HEADERS += $(srcdir)/arch/powerpc/odp/api/cpu_arch.h endif if ARCH_IS_X86 -odpapiinclude_HEADERS += $(srcdir)/arch/x86/odp/api/cpu_arch.h endif odpapiplatincludedir= $(includedir)/odp/api/plat @@ -236,21 +235,52 @@ __LIB__libodp_linux_la_SOURCES = \ odp_weak.c if ARCH_IS_ARM -__LIB__libodp_linux_la_SOURCES += arch/arm/odp_cpu_arch.c \ - arch/arm/odp_sysinfo_parse.c -endif +__LIB__libodp_linux_la_SOURCES += arch/default/odp_cpu_arch.c \ + arch/default/odp_cpu_cycles.c \ + arch/default/odp_global_time.c \ + arch/default/odp_sysinfo_parse.c +arch_odp_headers = $(srcdir)/arch/arm/odp/api/cpu_arch.h +else +if ARCH_IS_AARCH64 +__LIB__libodp_linux_la_SOURCES += arch/default/odp_cpu_arch.c \ + arch/default/odp_cpu_cycles.c \ + arch/aarch64/odp_global_time.c \ + arch/default/odp_sysinfo_parse.c +arch_odp_headers = $(srcdir)/arch/aarch64/odp/api/cpu_arch.h +else if ARCH_IS_MIPS64 __LIB__libodp_linux_la_SOURCES += arch/mips64/odp_cpu_arch.c \ + arch/default/odp_cpu_cycles.c \ + arch/default/odp_global_time.c \ arch/mips64/odp_sysinfo_parse.c -endif +arch_odp_headers = $(srcdir)/arch/mips64/odp/api/cpu_arch.h +else if ARCH_IS_POWERPC -__LIB__libodp_linux_la_SOURCES += arch/powerpc/odp_cpu_arch.c \ +__LIB__libodp_linux_la_SOURCES += arch/default/odp_cpu_arch.c \ + arch/default/odp_cpu_cycles.c \ + arch/default/odp_global_time.c \ arch/powerpc/odp_sysinfo_parse.c -endif +arch_odp_headers = $(srcdir)/arch/powerpc/odp/api/cpu_arch.h +else if ARCH_IS_X86 __LIB__libodp_linux_la_SOURCES += arch/x86/cpu_flags.c \ arch/x86/odp_cpu_arch.c \ + arch/default/odp_cpu_cycles.c \ + arch/x86/odp_global_time.c \ arch/x86/odp_sysinfo_parse.c +arch_odp_headers = $(srcdir)/arch/x86/odp/api/cpu_arch.h \ + $(srcdir)/arch/x86/cpu_flags.h + +else +__LIB__libodp_linux_la_SOURCES += arch/default/odp_cpu_arch.c \ + arch/default/odp_cpu_cycles.c \ + arch/default/odp_global_time.c \ + arch/default/odp_sysinfo_parse.c +arch_odp_headers = $(srcdir)/arch/default/odp/api/cpu_arch.h +endif +endif +endif +endif endif if HAVE_PCAP diff --git a/platform/linux-generic/arch/aarch64/odp/api/cpu_arch.h b/platform/linux-generic/arch/aarch64/odp/api/cpu_arch.h new file mode 100644 index 00000000..7c75a690 --- /dev/null +++ b/platform/linux-generic/arch/aarch64/odp/api/cpu_arch.h @@ -0,0 +1,30 @@ +/* Copyright (c) 2016, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef ODP_PLAT_CPU_ARCH_H_ +#define ODP_PLAT_CPU_ARCH_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#define _ODP_CACHE_LINE_SIZE 64 + +static inline void odp_cpu_pause(void) +{ + /* YIELD hints the CPU to switch to another thread if possible + * and executes as a NOP otherwise. + * ISB flushes the pipeline, then restarts. This is guaranteed to + * stall the CPU a number of cycles. + */ + __asm volatile("isb" ::: "memory"); +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/platform/linux-generic/arch/arm/odp_cpu_arch.c b/platform/linux-generic/arch/aarch64/odp_global_time.c similarity index 65% rename from platform/linux-generic/arch/arm/odp_cpu_arch.c rename to platform/linux-generic/arch/aarch64/odp_global_time.c index 6622e619..97444f7e 100644 --- a/platform/linux-generic/arch/arm/odp_cpu_arch.c +++ b/platform/linux-generic/arch/aarch64/odp_global_time.c @@ -8,48 +8,11 @@ #include -#include #include -#include -#include -#include #include #include -#define GIGA 1000000000 - -uint64_t odp_cpu_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_cpu_hz_max(); - sec = (uint64_t)time.tv_sec; - ns = (uint64_t)time.tv_nsec; - - cycles = sec * hz; - cycles += (ns * hz) / GIGA; - - return cycles; -} - -uint64_t odp_cpu_cycles_max(void) -{ - return UINT64_MAX; -} - -uint64_t odp_cpu_cycles_resolution(void) -{ - return 1; -} - int cpu_has_global_time(void) { uint64_t hz = cpu_global_time_freq(); @@ -70,7 +33,6 @@ int cpu_has_global_time(void) uint64_t cpu_global_time(void) { -#ifdef __aarch64__ uint64_t cntvct; /* @@ -83,20 +45,13 @@ uint64_t cpu_global_time(void) __asm__ volatile("mrs %0, cntvct_el0" : "=r"(cntvct) : : "memory"); return cntvct; -#else - return 0; -#endif } uint64_t cpu_global_time_freq(void) { -#ifdef __aarch64__ uint64_t cntfrq; __asm__ volatile("mrs %0, cntfrq_el0" : "=r"(cntfrq) : : ); return cntfrq; -#else - return 0; -#endif } diff --git a/platform/linux-generic/arch/arm/odp_sysinfo_parse.c b/platform/linux-generic/arch/arm/odp_sysinfo_parse.c deleted file mode 100644 index 1e9db418..00000000 --- a/platform/linux-generic/arch/arm/odp_sysinfo_parse.c +++ /dev/null @@ -1,33 +0,0 @@ -/* Copyright (c) 2016, Linaro Limited - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include "config.h" - -#include -#include -#include - -int cpuinfo_parser(FILE *file ODP_UNUSED, system_info_t *sysinfo) -{ - int i; - - ODP_DBG("Warning: use dummy values for freq and model string\n"); - for (i = 0; i < MAX_CPU_NUMBER; i++) { - sysinfo->cpu_hz_max[i] = 1400000000; - strcpy(sysinfo->model_str[i], "UNKNOWN"); - } - - return 0; -} - -uint64_t odp_cpu_hz_current(int id ODP_UNUSED) -{ - return 0; -} - -void sys_info_print_arch(void) -{ -} diff --git a/platform/linux-generic/arch/default/odp_cpu_arch.c b/platform/linux-generic/arch/default/odp_cpu_arch.c index fab351fe..8a8da744 100644 --- a/platform/linux-generic/arch/default/odp_cpu_arch.c +++ b/platform/linux-generic/arch/default/odp_cpu_arch.c @@ -12,10 +12,7 @@ #include #include -#include -#include #include -#include #define GIGA 1000000000 @@ -39,28 +36,3 @@ uint64_t odp_cpu_cycles(void) return cycles; } - -uint64_t odp_cpu_cycles_max(void) -{ - return UINT64_MAX; -} - -uint64_t odp_cpu_cycles_resolution(void) -{ - return 1; -} - -int cpu_has_global_time(void) -{ - return 0; -} - -uint64_t cpu_global_time(void) -{ - return 0; -} - -uint64_t cpu_global_time_freq(void) -{ - return 0; -} diff --git a/platform/linux-generic/arch/default/odp_cpu_cycles.c b/platform/linux-generic/arch/default/odp_cpu_cycles.c new file mode 100644 index 00000000..ccc58882 --- /dev/null +++ b/platform/linux-generic/arch/default/odp_cpu_cycles.c @@ -0,0 +1,19 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "config.h" + +#include + +uint64_t odp_cpu_cycles_max(void) +{ + return UINT64_MAX; +} + +uint64_t odp_cpu_cycles_resolution(void) +{ + return 1; +} diff --git a/platform/linux-generic/arch/default/odp_global_time.c b/platform/linux-generic/arch/default/odp_global_time.c new file mode 100644 index 00000000..89cce1cf --- /dev/null +++ b/platform/linux-generic/arch/default/odp_global_time.c @@ -0,0 +1,33 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "config.h" + +#include + +#include +#include + +#include +#include +#include +#include +#include + +int cpu_has_global_time(void) +{ + return 0; +} + +uint64_t cpu_global_time(void) +{ + return 0; +} + +uint64_t cpu_global_time_freq(void) +{ + return 0; +} diff --git a/platform/linux-generic/arch/mips64/odp_cpu_arch.c b/platform/linux-generic/arch/mips64/odp_cpu_arch.c index 143867ea..620a0104 100644 --- a/platform/linux-generic/arch/mips64/odp_cpu_arch.c +++ b/platform/linux-generic/arch/mips64/odp_cpu_arch.c @@ -22,28 +22,3 @@ uint64_t odp_cpu_cycles(void) return cycle; } - -uint64_t odp_cpu_cycles_max(void) -{ - return UINT64_MAX; -} - -uint64_t odp_cpu_cycles_resolution(void) -{ - return 1; -} - -int cpu_has_global_time(void) -{ - return 0; -} - -uint64_t cpu_global_time(void) -{ - return 0; -} - -uint64_t cpu_global_time_freq(void) -{ - return 0; -} diff --git a/platform/linux-generic/arch/powerpc/odp_cpu_arch.c b/platform/linux-generic/arch/powerpc/odp_cpu_arch.c index fab351fe..6a16f13a 100644 --- a/platform/linux-generic/arch/powerpc/odp_cpu_arch.c +++ b/platform/linux-generic/arch/powerpc/odp_cpu_arch.c @@ -39,28 +39,3 @@ uint64_t odp_cpu_cycles(void) return cycles; } - -uint64_t odp_cpu_cycles_max(void) -{ - return UINT64_MAX; -} - -uint64_t odp_cpu_cycles_resolution(void) -{ - return 1; -} - -int cpu_has_global_time(void) -{ - return 0; -} - -uint64_t cpu_global_time(void) -{ - return 0; -} - -uint64_t cpu_global_time_freq(void) -{ - return 0; -} diff --git a/platform/linux-generic/arch/powerpc/odp_global_time.c b/platform/linux-generic/arch/powerpc/odp_global_time.c new file mode 100644 index 00000000..d54ba6bc --- /dev/null +++ b/platform/linux-generic/arch/powerpc/odp_global_time.c @@ -0,0 +1,15 @@ + +int cpu_has_global_time(void) +{ + return 0; +} + +uint64_t cpu_global_time(void) +{ + return 0; +} + +uint64_t cpu_global_time_freq(void) +{ + return 0; +} diff --git a/platform/linux-generic/arch/x86/odp_cpu_arch.c b/platform/linux-generic/arch/x86/odp_cpu_arch.c index 50fbbac6..a20d9173 100644 --- a/platform/linux-generic/arch/x86/odp_cpu_arch.c +++ b/platform/linux-generic/arch/x86/odp_cpu_arch.c @@ -9,7 +9,6 @@ #include #include -#include #include #include @@ -30,74 +29,3 @@ uint64_t odp_cpu_cycles(void) return tsc.tsc_64; } - -uint64_t odp_cpu_cycles_max(void) -{ - return UINT64_MAX; -} - -uint64_t odp_cpu_cycles_resolution(void) -{ - return 1; -} - -uint64_t cpu_global_time(void) -{ - return odp_cpu_cycles(); -} - -#define SEC_IN_NS 1000000000ULL - -/* Measure TSC frequency. Frequency information registers are defined for x86, - * but those are often not enumerated. */ -uint64_t cpu_global_time_freq(void) -{ - struct timespec sleep, ts1, ts2; - uint64_t t1, t2, ts_nsec, cycles, hz; - int i; - uint64_t avg = 0; - int rounds = 3; - int warm_up = 1; - - for (i = 0; i < rounds; i++) { - sleep.tv_sec = 0; - - if (warm_up) - sleep.tv_nsec = SEC_IN_NS / 1000; - else - sleep.tv_nsec = SEC_IN_NS / 4; - - if (clock_gettime(CLOCK_MONOTONIC_RAW, &ts1)) { - ODP_DBG("clock_gettime failed\n"); - return 0; - } - - t1 = cpu_global_time(); - - if (nanosleep(&sleep, NULL) < 0) { - ODP_DBG("nanosleep failed\n"); - return 0; - } - - if (clock_gettime(CLOCK_MONOTONIC_RAW, &ts2)) { - ODP_DBG("clock_gettime failed\n"); - return 0; - } - - t2 = cpu_global_time(); - - ts_nsec = (ts2.tv_sec - ts1.tv_sec) * SEC_IN_NS; - ts_nsec += ts2.tv_nsec - ts1.tv_nsec; - - cycles = t2 - t1; - - hz = (cycles * SEC_IN_NS) / ts_nsec; - - if (warm_up) - warm_up = 0; - else - avg += hz; - } - - return avg / (rounds - 1); -} diff --git a/platform/linux-generic/arch/x86/odp_global_time.c b/platform/linux-generic/arch/x86/odp_global_time.c new file mode 100644 index 00000000..3ed243cc --- /dev/null +++ b/platform/linux-generic/arch/x86/odp_global_time.c @@ -0,0 +1,77 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "config.h" + +#include + +#include + +#include +#include +#include +#include + +uint64_t cpu_global_time(void) +{ + return odp_cpu_cycles(); +} + +#define SEC_IN_NS 1000000000ULL + +/* Measure TSC frequency. Frequency information registers are defined for x86, + * but those are often not enumerated. */ +uint64_t cpu_global_time_freq(void) +{ + struct timespec sleep, ts1, ts2; + uint64_t t1, t2, ts_nsec, cycles, hz; + int i; + uint64_t avg = 0; + int rounds = 3; + int warm_up = 1; + + for (i = 0; i < rounds; i++) { + sleep.tv_sec = 0; + + if (warm_up) + sleep.tv_nsec = SEC_IN_NS / 1000; + else + sleep.tv_nsec = SEC_IN_NS / 4; + + if (clock_gettime(CLOCK_MONOTONIC_RAW, &ts1)) { + ODP_DBG("clock_gettime failed\n"); + return 0; + } + + t1 = cpu_global_time(); + + if (nanosleep(&sleep, NULL) < 0) { + ODP_DBG("nanosleep failed\n"); + return 0; + } + + if (clock_gettime(CLOCK_MONOTONIC_RAW, &ts2)) { + ODP_DBG("clock_gettime failed\n"); + return 0; + } + + t2 = cpu_global_time(); + + ts_nsec = (ts2.tv_sec - ts1.tv_sec) * SEC_IN_NS; + ts_nsec += ts2.tv_nsec - ts1.tv_nsec; + + cycles = t2 - t1; + + hz = (cycles * SEC_IN_NS) / ts_nsec; + + if (warm_up) + warm_up = 0; + else + avg += hz; + } + + return avg / (rounds - 1); +}