From patchwork Mon Dec 21 12:17:52 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 58812 Delivered-To: patch@linaro.org Received: by 10.112.89.199 with SMTP id bq7csp2560604lbb; Mon, 21 Dec 2015 04:18:42 -0800 (PST) X-Received: by 10.107.33.203 with SMTP id h194mr17152795ioh.108.1450700321895; Mon, 21 Dec 2015 04:18:41 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id c8si5732778ioj.142.2015.12.21.04.18.41; Mon, 21 Dec 2015 04:18:41 -0800 (PST) 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; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 45E33616C1; Mon, 21 Dec 2015 12:18:41 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=ZwM29fuf; dkim-adsp=none (unprotected policy); dkim-atps=neutral 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.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID, 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 6DC0F61737; Mon, 21 Dec 2015 12:18:14 +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 66CA3610B1; Mon, 21 Dec 2015 12:18:07 +0000 (UTC) Received: from mail-lf0-f47.google.com (mail-lf0-f47.google.com [209.85.215.47]) by lists.linaro.org (Postfix) with ESMTPS id B27D3610B1 for ; Mon, 21 Dec 2015 12:18:04 +0000 (UTC) Received: by mail-lf0-f47.google.com with SMTP id l133so109369210lfd.2 for ; Mon, 21 Dec 2015 04:18:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LJbhIl9uEnZ/jsjN9tnxJL36GKVa/h6Bcb+VlunOBu0=; b=ZwM29fufQX9pArWVB2l2xo4L0nQfo2lndFieZqap6uawzRXtUK6t4ccWzfBMauS4UW IvmGJbpprDX3707VRsRytX75yCSO5udCZUcDfV1xHBHe87VJ4urKYo6gfEVIdIWEczrs RemmBpXyzx0ktH3KWeDmTnKNZI8zbKZ3AO8Xw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LJbhIl9uEnZ/jsjN9tnxJL36GKVa/h6Bcb+VlunOBu0=; b=B8siDxhnNnSO+/e1TeVitDx7SSxMDht6FJ+vCXRSCknxy7iU14AzhAnqUsljMUNlGI pBcGuSfDMBwnRgusQdjrKaYa2uApXQSs4Hrj9nMytRLkKzIiXpBHCW3fE0l/Mnqx2mRW Noi9AVnebOOks5YWh3SqUeN9ueQ0mMGjX8Osvrb6OXMID55tp+neVhfrh7p2CddeFhg1 cFgsRenM8BRWbanwYgRgmbBmHW3fgWU8z1ewCA8TTJU3xWgq2wUu4zmfgfk/fsSLNg41 EgbyK3Yc0e9dPcR0quk36LEhJbBLUga9vXcoZTEIOVHYzsaMXpYj7SIeoUkf2lajmh+M VqFw== X-Gm-Message-State: ALoCoQkSuQMXVjyv1Km9ld/58Gkxtyx6Uqi5D4KIj4VEct73ZDYljblF4gTLPINqBw+yKvmSLg8V/UPCtiZ4lDUBPrDudupjKg== X-Received: by 10.25.44.210 with SMTP id s201mr6395535lfs.117.1450700283451; Mon, 21 Dec 2015 04:18:03 -0800 (PST) Received: from localhost.localdomain ([195.238.92.128]) by smtp.gmail.com with ESMTPSA id 99sm680093lfp.30.2015.12.21.04.18.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 21 Dec 2015 04:18:02 -0800 (PST) From: Ivan Khoronzhuk To: lng-odp@lists.linaro.org Date: Mon, 21 Dec 2015 14:17:52 +0200 Message-Id: <1450700273-20473-2-git-send-email-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1450700273-20473-1-git-send-email-ivan.khoronzhuk@linaro.org> References: <1450700273-20473-1-git-send-email-ivan.khoronzhuk@linaro.org> X-Topics: patch Cc: petri.savolainen@nokia.com Subject: [lng-odp] [API-NEXT PATCH v2 1/2] api: time: add global time API 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: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" This patch adds global time API and implements it in linux-generic. Signed-off-by: Ivan Khoronzhuk --- include/odp/api/time.h | 30 ++++++++++++++++++++++++++++++ platform/linux-generic/odp_time.c | 34 +++++++++++++++++++++++++++------- 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/include/odp/api/time.h b/include/odp/api/time.h index 1f94710..efc5478 100644 --- a/include/odp/api/time.h +++ b/include/odp/api/time.h @@ -47,12 +47,26 @@ extern "C" { * Returns current local time stamp value. The local time source provides high * resolution time, it is initialized to zero during ODP startup and will not * wrap around in at least 10 years. + * Local time stamps are local to the calling thread and must not be shared + * with other threads. * * @return Local time stamp. */ odp_time_t odp_time_local(void); /** + * Current global time + * + * Returns current global time stamp value. The global time source provides high + * resolution time, it is initialized to zero during ODP startup and will not + * wrap around in at least 10 years. + * Global time stamps can be shared between threads. + * + * @return Global time stamp. + */ +odp_time_t odp_time_global(void); + +/** * Time difference * * @param t2 Second time stamp @@ -91,6 +105,15 @@ uint64_t odp_time_to_ns(odp_time_t time); odp_time_t odp_time_local_from_ns(uint64_t ns); /** + * Convert nanoseconds to global time + * + * @param ns Time in nanoseconds + * + * @return Global time stamp + */ +odp_time_t odp_time_global_from_ns(uint64_t ns); + +/** * Compare two times * * @param t2 Second time @@ -108,6 +131,13 @@ int odp_time_cmp(odp_time_t t2, odp_time_t t1); uint64_t odp_time_local_res(void); /** + * Global time resolution in hertz + * + * @return Global time resolution in hertz + */ +uint64_t odp_time_global_res(void); + +/** * Wait until the specified (wall clock) time has been reached * * The thread potentially busy loop the entire wait time. diff --git a/platform/linux-generic/odp_time.c b/platform/linux-generic/odp_time.c index a3ab2e3..2cb84f2 100644 --- a/platform/linux-generic/odp_time.c +++ b/platform/linux-generic/odp_time.c @@ -101,11 +101,28 @@ static inline void time_wait_until(odp_time_t time) } while (time_cmp(time, cur) > 0); } +static inline uint64_t time_local_res(void) +{ + int ret; + struct timespec tres; + + ret = clock_getres(CLOCK_MONOTONIC_RAW, &tres); + if (odp_unlikely(ret != 0)) + ODP_ABORT("clock_getres failed\n"); + + return ODP_TIME_SEC_IN_NS / (uint64_t)tres.tv_nsec; +} + odp_time_t odp_time_local(void) { return time_local(); } +odp_time_t odp_time_global(void) +{ + return time_local(); +} + odp_time_t odp_time_diff(odp_time_t t2, odp_time_t t1) { return time_diff(t2, t1); @@ -121,6 +138,11 @@ odp_time_t odp_time_local_from_ns(uint64_t ns) return time_local_from_ns(ns); } +odp_time_t odp_time_global_from_ns(uint64_t ns) +{ + return time_local_from_ns(ns); +} + int odp_time_cmp(odp_time_t t2, odp_time_t t1) { return time_cmp(t2, t1); @@ -133,14 +155,12 @@ odp_time_t odp_time_sum(odp_time_t t1, odp_time_t t2) uint64_t odp_time_local_res(void) { - int ret; - struct timespec tres; - - ret = clock_getres(CLOCK_MONOTONIC_RAW, &tres); - if (odp_unlikely(ret != 0)) - ODP_ABORT("clock_getres failed\n"); + return time_local_res(); +} - return ODP_TIME_SEC_IN_NS / (uint64_t)tres.tv_nsec; +uint64_t odp_time_global_res(void) +{ + return time_local_res(); } void odp_time_wait_ns(uint64_t ns)