From patchwork Mon Dec 14 18:58:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 58364 Delivered-To: patch@linaro.org Received: by 10.112.73.68 with SMTP id j4csp1670341lbv; Mon, 14 Dec 2015 11:06:20 -0800 (PST) X-Received: by 10.55.72.3 with SMTP id v3mr44765597qka.107.1450119543262; Mon, 14 Dec 2015 10:59:03 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id t90si36089418qgd.108.2015.12.14.10.59.02; Mon, 14 Dec 2015 10:59:03 -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 AA57261D31; Mon, 14 Dec 2015 18:59:02 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=Z4kltNqJ; 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_H2,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 14F4C61D13; Mon, 14 Dec 2015 18:58:33 +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 95BAD61D08; Mon, 14 Dec 2015 18:58:27 +0000 (UTC) Received: from mail-lb0-f175.google.com (mail-lb0-f175.google.com [209.85.217.175]) by lists.linaro.org (Postfix) with ESMTPS id C679F61C9E for ; Mon, 14 Dec 2015 18:58:25 +0000 (UTC) Received: by lbbkw15 with SMTP id kw15so112603638lbb.0 for ; Mon, 14 Dec 2015 10:58:24 -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=l+XhrHwPiFZ282U5lGW3bD0k7KsB94BzNueRMqz68Hk=; b=Z4kltNqJ4jfon+19L5KIMFx04jccLUFgcPqQzrc9yIuHQ7LgFdbI4zRKWipfBfWid3 L+2rS0HWTPZSKQmge+ENNvGPb56ZgNf8mRIz0JpKVNYgELvuZDD+TMRnu08+E48KBuiT HLXlgMCGdKt0EOYCXHl5ZkiwPF9nhxIbSZTGI= 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=l+XhrHwPiFZ282U5lGW3bD0k7KsB94BzNueRMqz68Hk=; b=CVsfENXzgqvlNoRt/TbD/xF8iTvvSTnPTab7Z5Gx9ofR7BQGnqTaBrsozF94MpoyRl HmxX/8Ojh2V19PEbANRPQrpcfO6nVdVZ4i0aJdtrcStUA1ujJs/JaqT+3Py4qxuSz20B kJw2YXe1tgzz7C3nMHJ+/9biJXb8fKojMB6G5ZyYirCaqF40n2zJLd8y26z7S+oa1ei/ SejzpJRvj7v3hWKfgRYlsHKzkDEbpCE6BWMWTQMvn90ggHbaWCGWuwq4yCwruaBYKLPO mL7yyqWqSsDpz4zwcZZ1wVRtWN+CD8e6XeQcmBGn3AQqnJS02CoGCrB8wU1wmaf0L7q9 4Yig== X-Gm-Message-State: ALoCoQkmmeIF/5Rq8XmRH9R8qmSbUdkE1NX3LU2yoOSISNknmF5MRiu6gCVRVRy34GLuDikJFmB7yBwXcad2jRUR/qyf0JdLkQ== X-Received: by 10.112.201.132 with SMTP id ka4mr13654662lbc.71.1450119504620; Mon, 14 Dec 2015 10:58:24 -0800 (PST) Received: from localhost.localdomain ([212.90.60.8]) by smtp.gmail.com with ESMTPSA id o5sm5609246lbw.16.2015.12.14.10.58.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 14 Dec 2015 10:58:23 -0800 (PST) From: Ivan Khoronzhuk To: lng-odp@lists.linaro.org Date: Mon, 14 Dec 2015 20:58:11 +0200 Message-Id: <1450119496-21604-2-git-send-email-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1450119496-21604-1-git-send-email-ivan.khoronzhuk@linaro.org> References: <1450119496-21604-1-git-send-email-ivan.khoronzhuk@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCH 1/6] api: time: add rate and delay 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_rate() and odp_time_delay() APIs. Signed-off-by: Ivan Khoronzhuk --- include/odp/api/time.h | 12 ++++++++++++ platform/linux-generic/odp_time.c | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/include/odp/api/time.h b/include/odp/api/time.h index 9865d81..75644ca 100644 --- a/include/odp/api/time.h +++ b/include/odp/api/time.h @@ -101,6 +101,18 @@ odp_time_t odp_time_local_from_ns(uint64_t ns); int odp_time_cmp(odp_time_t t2, odp_time_t t1); /** + * Get local time rate + */ +uint64_t odp_time_local_rate(void); + +/** + * Wait on for specified length of time + * + * @param delay time to wait + */ +void odp_time_delay(odp_time_t delay); + +/** * 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 1c7c214..182522d 100644 --- a/platform/linux-generic/odp_time.c +++ b/platform/linux-generic/odp_time.c @@ -98,6 +98,27 @@ odp_time_t odp_time_sum(odp_time_t t1, odp_time_t t2) return time; } +uint64_t odp_time_local_rate(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; +} + +void odp_time_delay(odp_time_t delay) +{ + odp_time_t cur = odp_time_local(); + odp_time_t end_time = odp_time_sum(cur, delay); + + while (odp_time_cmp(end_time, cur) > 0) + cur = odp_time_local(); +} + uint64_t odp_time_to_u64(odp_time_t time) { int ret;