From patchwork Wed Apr 1 16:50:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Holmes X-Patchwork-Id: 47083 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 200AE21416 for ; Sat, 11 Apr 2015 10:03:02 +0000 (UTC) Received: by wghm4 with SMTP id m4sf8924054wgh.2 for ; Sat, 11 Apr 2015 03:03:01 -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=AoTMUc/cjCj5fTXjpD7bN/BK0+hTZu0g8eB6izTo1I2n0M0kTuZdfpo/yz7Kyxu5EO 550iLfkzvHW+Tt5T4a77iAqOH0A0lkhEGOL6NMVApoPYSNG5TPRezAXhI/8NsgXRH90f ZmvN1FiFrt7P+NWYBr1cR2sUiPlZ7WPXO3ajC6WIDJsSooxfrVnhKXkv1w2MG+pg1s2T DeREDdAC3VOTD2RAm4I7ZGv1Mttpr16mHa1wrZYrTSVi8MPT9T9tQQFrN6TzJWy+zdDv fzI5Ruuv5GbAnHqNR3O9xf3nmKApKR91QzOfHEOhxiJ+YSyx/Z0ilQk7HBPC/gZgi2br hnQQ== X-Gm-Message-State: ALoCoQl+H1Xxi++4/PEnYyIVXsPXRWr5wlngY7TdySU8yt46Ugl6WpJGxrIp1y9f1XzZorOy9jps X-Received: by 10.112.26.5 with SMTP id h5mr949969lbg.4.1428746581411; Sat, 11 Apr 2015 03:03:01 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.28.100 with SMTP id a4ls533943lah.23.gmail; Sat, 11 Apr 2015 03:03:01 -0700 (PDT) X-Received: by 10.152.19.199 with SMTP id h7mr5164150lae.32.1428746581128; Sat, 11 Apr 2015 03:03:01 -0700 (PDT) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com. [209.85.217.171]) by mx.google.com with ESMTPS id aq10si3508227lbc.58.2015.04.11.03.03.01 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 11 Apr 2015 03:03:01 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by lbcga7 with SMTP id ga7so29272510lbc.1 for ; Sat, 11 Apr 2015 03:03:01 -0700 (PDT) X-Received: by 10.152.19.199 with SMTP id h7mr5164147lae.32.1428746581038; Sat, 11 Apr 2015 03:03:01 -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 l1csp233711lbt; Sat, 11 Apr 2015 03:03:00 -0700 (PDT) X-Received: by 10.55.33.142 with SMTP id f14mr11035255qki.1.1428746577947; Sat, 11 Apr 2015 03:02:57 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id e188si4359103qhc.102.2015.04.11.03.02.57; Sat, 11 Apr 2015 03:02:57 -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 6B59761C6A; Sat, 11 Apr 2015 10:02:53 +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=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 C03E765159; Sat, 11 Apr 2015 09:52:22 +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 26E4E64FDA; Wed, 1 Apr 2015 16:50:47 +0000 (UTC) Received: from mail-qg0-f52.google.com (mail-qg0-f52.google.com [209.85.192.52]) by lists.linaro.org (Postfix) with ESMTPS id AF30D64FD3 for ; Wed, 1 Apr 2015 16:50:46 +0000 (UTC) Received: by qgep97 with SMTP id p97so47763302qge.1 for ; Wed, 01 Apr 2015 09:50:46 -0700 (PDT) X-Received: by 10.55.23.34 with SMTP id i34mr91270793qkh.6.1427907046443; Wed, 01 Apr 2015 09:50:46 -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 f37sm1619236qkf.14.2015.04.01.09.50.45 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 01 Apr 2015 09:50:45 -0700 (PDT) From: Mike Holmes To: lng-odp@lists.linaro.org Date: Wed, 1 Apr 2015 12:50:36 -0400 Message-Id: <1427907038-12230-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.171 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; +}