From patchwork Wed Apr 1 20:02:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Holmes X-Patchwork-Id: 47087 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 57B5F21416 for ; Sat, 11 Apr 2015 10:03:46 +0000 (UTC) Received: by widjs5 with SMTP id js5sf3943710wid.3 for ; Sat, 11 Apr 2015 03:03:45 -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=SeY1l33yshxwIyW9HtA0eOwS3qIkZDsT8636xlGaAskeywKRTrHo7odsGlZd68s7GW 9HefCWq6+GgF0rGmSeJ5O3FW1+5safAMwGslX6O2Ge54F4gTBe1pPJ+5bmgZnIB8ZZiH qGp8YjxQVc/TN6+uBYGz+v1z+MBrLQP8fyTW7pr6TC08nTFGlouoU3YelOswNqjqEHk8 XE62hAKG3sMIVGQJg3iGbpUyfdP3DLYAdRUPKdy8B+IM4Jep/d6q1MH3QV3EiMXcDaM5 nfeylFB3tLVqD0PLzJoq54OTBL/P8OzdkKWj3exSg1r5naLfSOrChQzdmVSsFXuJYXX2 8bqg== X-Gm-Message-State: ALoCoQkfRf/foLdzzgN77oooHB7t6F+J5+GSCRIDONS2GA0bwvBvIXtvL8LY52Ad7+o5ohCaVJDJ X-Received: by 10.194.161.194 with SMTP id xu2mr938565wjb.1.1428746625608; Sat, 11 Apr 2015 03:03:45 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.38 with SMTP id p6ls454156lap.17.gmail; Sat, 11 Apr 2015 03:03:45 -0700 (PDT) X-Received: by 10.112.200.230 with SMTP id jv6mr5020202lbc.21.1428746625352; Sat, 11 Apr 2015 03:03:45 -0700 (PDT) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com. [209.85.217.170]) by mx.google.com with ESMTPS id s5si3489365laa.137.2015.04.11.03.03.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 11 Apr 2015 03:03:45 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by lbbuc2 with SMTP id uc2so29200774lbb.2 for ; Sat, 11 Apr 2015 03:03:45 -0700 (PDT) X-Received: by 10.112.163.168 with SMTP id yj8mr4600588lbb.36.1428746625217; Sat, 11 Apr 2015 03:03:45 -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 l1csp233989lbt; Sat, 11 Apr 2015 03:03:44 -0700 (PDT) X-Received: by 10.140.98.245 with SMTP id o108mr6490845qge.36.1428746624021; Sat, 11 Apr 2015 03:03:44 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id i91si4402592qgi.6.2015.04.11.03.03.43; Sat, 11 Apr 2015 03:03: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; Received: by lists.linaro.org (Postfix, from userid 109) id 4C7E561C7D; Sat, 11 Apr 2015 10:03:43 +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_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=unavailable 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 A9F1565161; Sat, 11 Apr 2015 09:52:23 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: from mail-qc0-f175.google.com (mail-qc0-f175.google.com [209.85.216.175]) by lists.linaro.org (Postfix) with ESMTPS id BEBE864FF3 for ; Wed, 1 Apr 2015 20:03:01 +0000 (UTC) Received: by qcay5 with SMTP id y5so50894768qca.1 for ; Wed, 01 Apr 2015 13:03:01 -0700 (PDT) X-Received: by 10.55.19.79 with SMTP id d76mr57748941qkh.92.1427918581536; Wed, 01 Apr 2015 13:03:01 -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 186sm1974503qhd.11.2015.04.01.13.03.00 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 01 Apr 2015 13:03:01 -0700 (PDT) From: Mike Holmes To: lng-odp@lists.linaro.org Date: Wed, 1 Apr 2015 16:02:51 -0400 Message-Id: <1427918573-30596-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.217.170 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; +}