From patchwork Mon Oct 9 14: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: 115246 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp2598797qgn; Mon, 9 Oct 2017 07:07:18 -0700 (PDT) X-Google-Smtp-Source: AOwi7QDEr4+wUzafSsfUajKX9QZSGGa67ptmaNeWaFlMw3QFgQ19gAKyPJ/TjNuKyjcJE4bnVx5I X-Received: by 10.36.44.200 with SMTP id i191mr14526063iti.136.1507558038121; Mon, 09 Oct 2017 07:07:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507558038; cv=none; d=google.com; s=arc-20160816; b=ptfznXZagfIMlYFYrVmscAbbnV0JYLNQAWR94kf1sSUcVKiOotWYKDtcEuYZ7NWa+U H8S0H4ohRrXsqB7yX2JR9gJmo2PiMhHo09E9/Cq3ilVw7/H8z7bpU+SXisExADj1qpuE uXjhmo6IR8v+BI/K9ffmQ+ZOPdzQcGiI8rP5reiYV01V1ryEDcZ3D+hlnd76yakQcUE6 nenScOQNjSBbLvTYaTb0J6yvqZHbRNmsyCLAKQuTCUPnPYEo1sCtB/C9de28p9xbx9mJ aauG/a6gaETD5zrVvElZMCNvfo+nCbXY/GjTj9cZGPZ1580eXk/BZv4rzZ/357+r4CP7 MWYA== 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=OyumqxBV0Y/cgnQW3hNzTt85DNixR4zcaSSXzqOaLfg=; b=N7QQ1D+w/dOhSA9UlMKN5WjWAqoSL/DgMlV0G5dOKNGiQQy8Kkq6aP1t4anxjNvjoM miSkevP4WOxXEV68XP6UcOdwErRLJZk7s4Zyp7gUaNlPpsF1f5ntdyoT/3MhgH3iJ/24 +7mp7OnVCC3BeZlAwY5tln+nZqbH3Dx9qyIoMlBhZ4e3WKrf/b+JIqegkXqbEt02BreF 3kOnVewHTD/2N8lx/+IRarOsRjyElvxU9Vjot10cqJhiKwGqv9WR11XcTcr8+hwMdLnZ pvbNU5BB4CsHETK5QsTZZUUibQGPKSJ+ujy9ZRR3ejy1gYPbxIqbVrl7Q/LWekLLwtUC Fr1w== 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 y66si7188047itf.66.2017.10.09.07.07.17; Mon, 09 Oct 2017 07:07:18 -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 A577960C40; Mon, 9 Oct 2017 14:07:17 +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,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 6559A60C18; Mon, 9 Oct 2017 14:01:28 +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 E9C6760BEB; Mon, 9 Oct 2017 14:01:00 +0000 (UTC) Received: from forward101o.mail.yandex.net (forward101o.mail.yandex.net [37.140.190.181]) by lists.linaro.org (Postfix) with ESMTPS id E06AA60AC8 for ; Mon, 9 Oct 2017 14:00:48 +0000 (UTC) Received: from mxback2j.mail.yandex.net (mxback2j.mail.yandex.net [IPv6:2a02:6b8:0:1619::10b]) by forward101o.mail.yandex.net (Yandex) with ESMTP id BEEE41341A7B for ; Mon, 9 Oct 2017 17:00:45 +0300 (MSK) Received: from smtp4o.mail.yandex.net (smtp4o.mail.yandex.net [2a02:6b8:0:1a2d::28]) by mxback2j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id Pe0OY5ti72-0jd4VMRQ; Mon, 09 Oct 2017 17:00:45 +0300 Received: by smtp4o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id wSTIYzb9Br-0id8N5kn; Mon, 09 Oct 2017 17:00:44 +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: Mon, 9 Oct 2017 17:00:09 +0300 Message-Id: <1507557617-32018-6-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1507557617-32018-1-git-send-email-odpbot@yandex.ru> References: <1507557617-32018-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 188 Subject: [lng-odp] [PATCH v3 5/13] 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 Reviewed-by: Bill Fischofer Signed-off-by: Maxim Uvarov --- /** Email created from pull request 188 (WonderfulVoid:master) ** https://github.com/Linaro/odp/pull/188 ** Patch: https://github.com/Linaro/odp/pull/188.patch ** Base sha: c16af6486eea240609f334b1bdc81a11404275de ** Merge commit sha: 4ad1d0615a4dcd74d4e9703090149eec1a58d7d2 **/ platform/Makefile.inc | 22 ------ platform/linux-generic/Makefile.am | 46 +++++++------ .../aarch64/{odp_cpu_arch.c => odp_global_time.c} | 37 ---------- .../linux-generic/arch/aarch64/odp_sysinfo_parse.c | 28 -------- platform/linux-generic/arch/arm/odp_cpu_arch.c | 79 ---------------------- .../linux-generic/arch/arm/odp_sysinfo_parse.c | 28 -------- 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, 169 insertions(+), 365 deletions(-) rename platform/linux-generic/arch/aarch64/{odp_cpu_arch.c => odp_global_time.c} (68%) delete mode 100644 platform/linux-generic/arch/aarch64/odp_sysinfo_parse.c delete mode 100644 platform/linux-generic/arch/arm/odp_cpu_arch.c 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/platform/Makefile.inc b/platform/Makefile.inc index bb5da187b..f3161abd4 100644 --- a/platform/Makefile.inc +++ b/platform/Makefile.inc @@ -81,25 +81,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/aarch64/odp/api/cpu_arch.h \ - arch/aarch64/odp_cpu_arch.c \ - arch/aarch64/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 7257a60f5..0ebb6f76c 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -68,22 +68,6 @@ odpapiinclude_HEADERS = \ $(srcdir)/include/odp/api/traffic_mngr.h \ $(srcdir)/include/odp/api/version.h -if ARCH_IS_ARM -odpapiinclude_HEADERS += $(srcdir)/arch/arm/odp/api/cpu_arch.h -endif -if ARCH_IS_AARCH64 -odpapiinclude_HEADERS += $(srcdir)/arch/aarch64/odp/api/cpu_arch.h -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 odpapiplatinclude_HEADERS = \ $(builddir)/include/odp/api/plat/static_inline.h \ @@ -238,27 +222,47 @@ __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 +__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 endif if ARCH_IS_AARCH64 -__LIB__libodp_linux_la_SOURCES += arch/aarch64/odp_cpu_arch.c \ - arch/aarch64/odp_sysinfo_parse.c +__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 endif 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 +arch_odp_headers = $(srcdir)/arch/mips64/odp/api/cpu_arch.h endif 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 +arch_odp_headers = $(srcdir)/arch/powerpc/odp/api/cpu_arch.h endif 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 +noinst_HEADERS += $(srcdir)/arch/x86/cpu_flags.h endif +noinst_HEADERS += $(srcdir)/arch/default/odp/api/cpu_arch.h + +odpapiinclude_HEADERS += $(arch_odp_headers) + if HAVE_PCAP __LIB__libodp_linux_la_SOURCES += pktio/pcap.c endif diff --git a/platform/linux-generic/arch/aarch64/odp_cpu_arch.c b/platform/linux-generic/arch/aarch64/odp_global_time.c similarity index 68% rename from platform/linux-generic/arch/aarch64/odp_cpu_arch.c rename to platform/linux-generic/arch/aarch64/odp_global_time.c index b87d1c102..97444f7e9 100644 --- a/platform/linux-generic/arch/aarch64/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(); diff --git a/platform/linux-generic/arch/aarch64/odp_sysinfo_parse.c b/platform/linux-generic/arch/aarch64/odp_sysinfo_parse.c deleted file mode 100644 index 1e2c729a7..000000000 --- a/platform/linux-generic/arch/aarch64/odp_sysinfo_parse.c +++ /dev/null @@ -1,28 +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; -} - -void sys_info_print_arch(void) -{ -} diff --git a/platform/linux-generic/arch/arm/odp_cpu_arch.c b/platform/linux-generic/arch/arm/odp_cpu_arch.c deleted file mode 100644 index fc49ce371..000000000 --- a/platform/linux-generic/arch/arm/odp_cpu_arch.c +++ /dev/null @@ -1,79 +0,0 @@ -/* 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 - -#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(); - - /* - * The system counter portion of the architected timer must - * provide a uniform view of system time to all processing - * elements in the system. This should hold true even for - * heterogeneous SoCs. - * - * Determine whether the system has 'global time' by checking - * whether a read of the architected timer frequency sys reg - * returns a sane value. Sane is considered to be within - * 1MHz and 6GHz (1us and .1667ns period). - */ - return hz >= 1000000 && hz <= 6000000000; -} - -uint64_t cpu_global_time(void) -{ - return 0; -} - -uint64_t cpu_global_time_freq(void) -{ - return 0; -} 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 1e2c729a7..000000000 --- a/platform/linux-generic/arch/arm/odp_sysinfo_parse.c +++ /dev/null @@ -1,28 +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; -} - -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 fab351feb..8a8da7445 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 000000000..ccc588825 --- /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 000000000..89cce1cfb --- /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 143867ea0..620a01044 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 fab351feb..6a16f13a2 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 000000000..d54ba6bc8 --- /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 50fbbac66..a20d91734 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 000000000..3ed243cc6 --- /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); +}