From patchwork Wed Apr 1 20:12:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Holmes X-Patchwork-Id: 46658 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f71.google.com (mail-wg0-f71.google.com [74.125.82.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 069A72159A for ; Wed, 1 Apr 2015 20:12:23 +0000 (UTC) Received: by wgua4 with SMTP id a4sf12502932wgu.2 for ; Wed, 01 Apr 2015 13:12:22 -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: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=lTCJBJrX6S+s6EX2S5jBBiQPfpLoYmBD36O4i9IpO2o=; b=iNc1g5rAu5qyiC3iaRMG27G7ix7akR3SeX7+7aYJmWzcBd5LvDyM+gU8DjmwspG5Xn Nzn26xw0WEnANPjslBh4TudXKVEBhOLGlWZfGYT1SoKAFEpfknRUZamu/l8GKHWj70ux FFrltJZBuaxEoDXh/5KRjY0WRzTV0bfDQNiDheKD8adlWz272I09H8KkdA/etjUE/HbI oluHb15SKRtGU6oGoO+qPq0X+Cr/6M8wL2KbkdMS9FGwXEzHfXJUTTctLR2EbwXCJYX/ q0NScRv2DkkGFdFawUHzpdxE8gG7B0R0cbWNG6E39dm8adjV8FBmzhD9IM89eZjAbu8k YM/w== X-Gm-Message-State: ALoCoQmx27cNGcdm1MQU6KisML34VOTTZjBJlOhsWOHp9ZpZYdh2nm33g/y4R/nqX5CDkwWqiYWP X-Received: by 10.194.53.225 with SMTP id e1mr11396921wjp.4.1427919142330; Wed, 01 Apr 2015 13:12:22 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.19.36 with SMTP id b4ls116794lae.46.gmail; Wed, 01 Apr 2015 13:12:22 -0700 (PDT) X-Received: by 10.152.23.70 with SMTP id k6mr8629952laf.76.1427919142163; Wed, 01 Apr 2015 13:12:22 -0700 (PDT) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id qv7si1786425lbb.162.2015.04.01.13.12.21 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Apr 2015 13:12:21 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by labe2 with SMTP id e2so45406373lab.3 for ; Wed, 01 Apr 2015 13:12:21 -0700 (PDT) X-Received: by 10.152.4.104 with SMTP id j8mr17576855laj.72.1427919141852; Wed, 01 Apr 2015 13:12:21 -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.57.201 with SMTP id k9csp892199lbq; Wed, 1 Apr 2015 13:12:21 -0700 (PDT) X-Received: by 10.55.23.83 with SMTP id i80mr94037341qkh.104.1427919140514; Wed, 01 Apr 2015 13:12:20 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id z1si2935975qkz.48.2015.04.01.13.12.19; Wed, 01 Apr 2015 13:12:20 -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: from ip-10-142-244-252.ec2.internal (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 4481C61C6F; Wed, 1 Apr 2015 20:12:19 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: from mail-qg0-f43.google.com (mail-qg0-f43.google.com [209.85.192.43]) by lists.linaro.org (Postfix) with ESMTPS id 8E43B61C6F for ; Wed, 1 Apr 2015 20:12:17 +0000 (UTC) Received: by qgfa8 with SMTP id a8so53005780qgf.0 for ; Wed, 01 Apr 2015 13:12:17 -0700 (PDT) X-Received: by 10.55.51.139 with SMTP id z133mr37856733qkz.38.1427919137344; Wed, 01 Apr 2015 13:12:17 -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 z67sm1999853qgz.10.2015.04.01.13.12.16 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 01 Apr 2015 13:12:16 -0700 (PDT) From: Mike Holmes To: lng-odp@lists.linaro.org Date: Wed, 1 Apr 2015 16:12:06 -0400 Message-Id: <1427919128-30737-1-git-send-email-mike.holmes@linaro.org> X-Mailer: git-send-email 2.1.0 X-Topics: Architecture patch Subject: [lng-odp] [PATCH 1/3] linux-genric: add arch optimised time implementation 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.215.46 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 Precursor to supporting platform specifics at configure time rather than with compile time preprocessor macros Signed-off-by: Mike Holmes --- 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 +#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; +}