From patchwork Mon Apr 6 19:34:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Holmes X-Patchwork-Id: 46789 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4B3EB214BA for ; Mon, 6 Apr 2015 19:35:38 +0000 (UTC) Received: by wibgr10 with SMTP id gr10sf8008758wib.2 for ; Mon, 06 Apr 2015 12:35:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:delivered-to:from:to:date :message-id:in-reply-to:references:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :mime-version:content-type:content-transfer-encoding:errors-to :sender:x-original-sender:x-original-authentication-results :mailing-list; bh=U3MtfyrKKOi/0I3uZI+/w02LodN61QepM74GrGh3dEs=; b=SmbR7NttAGy/FXLkvO6z2jsjyCM97E+0u4hEnaJEheLrqheLIPkwoxWggC40PstmuX XLjeZ5DGEBMIoWKlJYgbk6ZABm2L3/fLI8v+mgSdMoxGKhDYCUqPqxusrTmBFVAMmu7V GbyRg2MsrAcXxySMJ3xWLmkKP1coD87K7iGyJQz8qOSYh17uzmkreXOmNabp2aB6koxY LiHP7n1ZfUK62LLXkX9CVjSxVJjyIQ96HwNYNvlw0hbKPxbyfPs9BATYBPIyp5sKjecP QPlHRE2eWXS0fSK1HeNWxJMW2jN7scaBqaBITncMr3+He8qfEh75Zp7l+/HYNJBfRvRw ddkw== X-Gm-Message-State: ALoCoQkj8ImuFouo7+Q+k2OrGNMJJ+LWBXlH7wp4YTnasTJYIvZhKXWhWgPGp9i0Jqlzti2/WrZ3 X-Received: by 10.112.125.67 with SMTP id mo3mr3388254lbb.6.1428348937498; Mon, 06 Apr 2015 12:35:37 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.19.36 with SMTP id b4ls548424lae.46.gmail; Mon, 06 Apr 2015 12:35:37 -0700 (PDT) X-Received: by 10.112.138.195 with SMTP id qs3mr5158096lbb.47.1428348937345; Mon, 06 Apr 2015 12:35:37 -0700 (PDT) Received: from mail-lb0-f174.google.com (mail-lb0-f174.google.com. [209.85.217.174]) by mx.google.com with ESMTPS id dg6si4241084lac.105.2015.04.06.12.35.37 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Apr 2015 12:35:37 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) client-ip=209.85.217.174; Received: by lbbqq2 with SMTP id qq2so18261534lbb.3 for ; Mon, 06 Apr 2015 12:35:37 -0700 (PDT) X-Received: by 10.112.141.202 with SMTP id rq10mr14990237lbb.88.1428348937097; Mon, 06 Apr 2015 12:35:37 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.67.65 with SMTP id l1csp11885lbt; Mon, 6 Apr 2015 12:35:36 -0700 (PDT) X-Received: by 10.55.31.85 with SMTP id f82mr31350204qkf.6.1428348935015; Mon, 06 Apr 2015 12:35:35 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id b136si5099642qka.31.2015.04.06.12.35.33; Mon, 06 Apr 2015 12:35:35 -0700 (PDT) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: by lists.linaro.org (Postfix, from userid 109) id B692064E16; Mon, 6 Apr 2015 19:35:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from ip-10-142-244-252.ec2.internal (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 036CC64DF6; Mon, 6 Apr 2015 19:35:30 +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 BEAB564E03; Mon, 6 Apr 2015 19:35:27 +0000 (UTC) Received: from mail-qk0-f172.google.com (mail-qk0-f172.google.com [209.85.220.172]) by lists.linaro.org (Postfix) with ESMTPS id 3EF0864E37 for ; Mon, 6 Apr 2015 19:35:18 +0000 (UTC) Received: by qkx62 with SMTP id 62so30659141qkx.0 for ; Mon, 06 Apr 2015 12:35:18 -0700 (PDT) X-Received: by 10.55.25.34 with SMTP id k34mr31511468qkh.12.1428348918037; Mon, 06 Apr 2015 12:35:18 -0700 (PDT) Received: from mike-desktop.?.holmesfamily.ws (c-98-221-136-245.hsd1.nj.comcast.net. [98.221.136.245]) by mx.google.com with ESMTPSA id m49sm3850734qgd.44.2015.04.06.12.35.17 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 06 Apr 2015 12:35:17 -0700 (PDT) From: Mike Holmes To: lng-odp@lists.linaro.org Date: Mon, 6 Apr 2015 15:34:59 -0400 Message-Id: <1428348899-22253-2-git-send-email-mike.holmes@linaro.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1428348899-22253-1-git-send-email-mike.holmes@linaro.org> References: <1428348899-22253-1-git-send-email-mike.holmes@linaro.org> X-Topics: Architecture patch Subject: [lng-odp] [PATCH v2 2/2] linux-generic: use arch optimisations for time X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: mike.holmes@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Switch to using configure time optimizations from compile time Signed-off-by: Mike Holmes --- 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 --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 +#include + +#include +#include +#include +#include + +#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 +#include +#include + +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 + +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 -#include -#include - -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))