From patchwork Tue Dec 15 12:29:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 58433 Delivered-To: patch@linaro.org Received: by 10.112.89.199 with SMTP id bq7csp3040lbb; Tue, 15 Dec 2015 04:31:15 -0800 (PST) X-Received: by 10.140.140.8 with SMTP id 8mr28791000qhm.60.1450182667607; Tue, 15 Dec 2015 04:31:07 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id x83si937778qhc.114.2015.12.15.04.31.07; Tue, 15 Dec 2015 04:31:07 -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 269DD61A0A; Tue, 15 Dec 2015 12:31:07 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=gSvPuP7R; 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 04391619E7; Tue, 15 Dec 2015 12:30:05 +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 01963619B8; Tue, 15 Dec 2015 12:29:43 +0000 (UTC) Received: from mail-lf0-f50.google.com (mail-lf0-f50.google.com [209.85.215.50]) by lists.linaro.org (Postfix) with ESMTPS id 96B60610E1 for ; Tue, 15 Dec 2015 12:29:37 +0000 (UTC) Received: by mail-lf0-f50.google.com with SMTP id p203so5268237lfa.0 for ; Tue, 15 Dec 2015 04:29:37 -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=vwrqaD2NFDk0Z4xwjVVyjxXrRgKDGtb07BNpmV3G5Tg=; b=gSvPuP7RdMcrjvHsTpQ51SuL9i7sSjshs7OHyO86umdGh8DK+Nk9eTZWgmIVavw4/q LWfUow2QbtUMKde6IKZeessvhWgTrbjixrfK9dL41MHs3iEf1qLMzqGhJVcqVAEgsGJL 1oB3GYZzL6lEzLDIxc+4lJMBXCiyI/9s2Qguw= 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=vwrqaD2NFDk0Z4xwjVVyjxXrRgKDGtb07BNpmV3G5Tg=; b=WFELwvEfBFDXr5qs6SQezEB69gg2bX42p/tWrvMuTCDPjDozbVErum8PZ/QI3cAxFN MMoO3IkEFLHMoM5fiyyO43wRazAQ7IiIBhAq0u82pR0pBUf9vNH9WdhtZjHBs9pkuq4k b7pYnY7q4XPzx0Tf6IerZVAsraqnYftv+gt764KLwNbFbrfVklQfx98oU7wU79V2qF7a 9NLo/1uo7hkucXx/QL+RgoHhh7ajjHPsZzUi1cqX+Cy7sqf9YSoSrZ4PSolVOY6N/Mly qF2QTSOyHaXSe7w8k7C9u9E/1NwujMoXVjBE4/NtoPQWxoQcb6XW6LzM7uemF2wa6V61 VNQw== X-Gm-Message-State: ALoCoQlVKNNwqcD2mQXaw1jcicg/AEA/jWXzv2VsQJ21INhsXnkyB342UfBwyKAWB9WKysy8b3G0e7hm4tjwxYg4sWsi+OtMeA== X-Received: by 10.25.21.106 with SMTP id l103mr3470205lfi.92.1450182576470; Tue, 15 Dec 2015 04:29:36 -0800 (PST) Received: from localhost.localdomain ([195.238.92.128]) by smtp.gmail.com with ESMTPSA id h8sm15103lbd.5.2015.12.15.04.29.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 15 Dec 2015 04:29:35 -0800 (PST) From: Ivan Khoronzhuk To: lng-odp@lists.linaro.org Date: Tue, 15 Dec 2015 14:29:22 +0200 Message-Id: <1450182567-7646-2-git-send-email-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1450182567-7646-1-git-send-email-ivan.khoronzhuk@linaro.org> References: <1450182567-7646-1-git-send-email-ivan.khoronzhuk@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCH v2 1/6] api: time: add resolution and wait API calls 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 odp_time_local_res() and odp_time_wait() APIs. Signed-off-by: Ivan Khoronzhuk --- include/odp/api/time.h | 17 ++++++++++ platform/linux-generic/odp_time.c | 71 ++++++++++++++++++++++++++++++--------- 2 files changed, 72 insertions(+), 16 deletions(-) diff --git a/include/odp/api/time.h b/include/odp/api/time.h index 9865d81..0c3b5c8 100644 --- a/include/odp/api/time.h +++ b/include/odp/api/time.h @@ -101,6 +101,23 @@ odp_time_t odp_time_local_from_ns(uint64_t ns); int odp_time_cmp(odp_time_t t2, odp_time_t t1); /** + * Local time resolution in hertz + * + * @return Local time resolution in hertz + */ +uint64_t odp_time_local_res(void); + +/** + * Wait on for specified length of time + * + * It likely causes the thread to busy loop. It's not guaranteed to put + * this thread into sleep and swap in another thread. + * + * @param time time to wait + */ +void odp_time_wait(odp_time_t time); + +/** * Get printable value for an odp_time_t * * @param time time to be printed diff --git a/platform/linux-generic/odp_time.c b/platform/linux-generic/odp_time.c index 9b64b37..3a41e2e 100644 --- a/platform/linux-generic/odp_time.c +++ b/platform/linux-generic/odp_time.c @@ -45,7 +45,8 @@ odp_time_t time_diff(odp_time_t t2, odp_time_t t1) return time; } -odp_time_t odp_time_local(void) +static inline +odp_time_t time_local(void) { int ret; _odp_time_t time; @@ -57,6 +58,39 @@ odp_time_t odp_time_local(void) return time_diff(time.ex, start_time); } +static inline +int time_cmp(odp_time_t t2, odp_time_t t1) +{ + if (t2.tv_sec < t1.tv_sec) + return -1; + + if (t2.tv_sec > t1.tv_sec) + return 1; + + return t2.tv_nsec - t1.tv_nsec; +} + +static inline +odp_time_t time_sum(odp_time_t t1, odp_time_t t2) +{ + odp_time_t time; + + time.tv_sec = t2.tv_sec + t1.tv_sec; + time.tv_nsec = t2.tv_nsec + t1.tv_nsec; + + if (time.tv_nsec >= (long)ODP_TIME_SEC_IN_NS) { + time.tv_nsec -= ODP_TIME_SEC_IN_NS; + ++time.tv_sec; + } + + return time; +} + +odp_time_t odp_time_local(void) +{ + return time_local(); +} + odp_time_t odp_time_diff(odp_time_t t2, odp_time_t t1) { return time_diff(t2, t1); @@ -79,28 +113,33 @@ odp_time_t odp_time_local_from_ns(uint64_t ns) int odp_time_cmp(odp_time_t t2, odp_time_t t1) { - if (t2.tv_sec < t1.tv_sec) - return -1; - - if (t2.tv_sec > t1.tv_sec) - return 1; - - return t2.tv_nsec - t1.tv_nsec; + return time_cmp(t2, t1); } odp_time_t odp_time_sum(odp_time_t t1, odp_time_t t2) { - odp_time_t time; + return time_sum(t1, t2); +} - time.tv_sec = t2.tv_sec + t1.tv_sec; - time.tv_nsec = t2.tv_nsec + t1.tv_nsec; +uint64_t odp_time_local_res(void) +{ + int ret; + struct timespec tres; - if (time.tv_nsec >= (long)ODP_TIME_SEC_IN_NS) { - time.tv_nsec -= ODP_TIME_SEC_IN_NS; - ++time.tv_sec; - } + ret = clock_getres(CLOCK_MONOTONIC_RAW, &tres); + if (odp_unlikely(ret != 0)) + ODP_ABORT("clock_getres failed\n"); - return time; + return ODP_TIME_SEC_IN_NS / (uint64_t)tres.tv_nsec; +} + +void odp_time_wait(odp_time_t time) +{ + odp_time_t cur = time_local(); + odp_time_t end_time = time_sum(cur, time); + + while (time_cmp(end_time, cur) > 0) + cur = time_local(); } uint64_t odp_time_to_u64(odp_time_t time)