From patchwork Thu Oct 15 13:02:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 55001 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by patches.linaro.org (Postfix) with ESMTPS id 608CF2301F for ; Thu, 15 Oct 2015 13:05:32 +0000 (UTC) Received: by wijq8 with SMTP id q8sf9717789wij.1 for ; Thu, 15 Oct 2015 06:05:31 -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:in-reply-to:references: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=K+8/UuKltzfJH+N3PFbpW24d9fS7lI7YDGJSdsqK+bU=; b=iemgxq6v9FkpY1P6ajaCZNsjCSxD26wzRajZDC4awINbRi8t/0Du+rMan9+rcYsy9b 9rFlCWzqXPcpgOAWaGqqNuG7cWiYD17O09aJdiNN846/4xhfIiC3HKTfT4o0H+5EQId3 zTK9Vh0I8c43RlzSbXjLq3/NcCClhzcDKP+V/tL2/wcIlET+V4DPpAsdfFz+1j3+06xa /sdLvaazru6SEA7ThL0qyTAksGUuS/I6Jv3ftKHBwAqlTpNXlUL4Nod8jsFcc+9EAUYJ 7B9cx+koEZVmXe3p2RxsWqQoj4pdDHvQgGEX8jjvpt7D3M+qJDIosHgSNX4vKEmdWBJU TRvQ== X-Gm-Message-State: ALoCoQnC/OcXyfI1vwYjP1u3nNmJ7tsHB+Yx4KfRv/Fim8UeR/dZ0VgWSoKl9vnPzAg96ADNvixu X-Received: by 10.180.35.132 with SMTP id h4mr6898870wij.5.1444914331724; Thu, 15 Oct 2015 06:05:31 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.210.198 with SMTP id j189ls139248lfg.86.gmail; Thu, 15 Oct 2015 06:05:31 -0700 (PDT) X-Received: by 10.25.147.76 with SMTP id v73mr2973417lfd.102.1444914331567; Thu, 15 Oct 2015 06:05:31 -0700 (PDT) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com. [209.85.217.178]) by mx.google.com with ESMTPS id sw10si9070596lbb.124.2015.10.15.06.05.31 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Oct 2015 06:05:31 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) client-ip=209.85.217.178; Received: by lbbwb3 with SMTP id wb3so6265582lbb.1 for ; Thu, 15 Oct 2015 06:05:31 -0700 (PDT) X-Received: by 10.112.202.35 with SMTP id kf3mr4504393lbc.19.1444914331400; Thu, 15 Oct 2015 06:05:31 -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.59.35 with SMTP id w3csp621467lbq; Thu, 15 Oct 2015 06:05:30 -0700 (PDT) X-Received: by 10.141.28.21 with SMTP id f21mr12171547qhe.13.1444914330397; Thu, 15 Oct 2015 06:05:30 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id b41si9471880qge.98.2015.10.15.06.05.30; Thu, 15 Oct 2015 06:05:30 -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 E4FDC61FAE; Thu, 15 Oct 2015 13:05:29 +0000 (UTC) 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.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 B63ED61FDA; Thu, 15 Oct 2015 13:02:55 +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 6FB8361FD9; Thu, 15 Oct 2015 13:02:42 +0000 (UTC) Received: from mail-wi0-f176.google.com (mail-wi0-f176.google.com [209.85.212.176]) by lists.linaro.org (Postfix) with ESMTPS id 08D4A61E6E for ; Thu, 15 Oct 2015 13:02:38 +0000 (UTC) Received: by wijp11 with SMTP id p11so28656271wij.0 for ; Thu, 15 Oct 2015 06:02:37 -0700 (PDT) X-Received: by 10.195.11.232 with SMTP id el8mr10562835wjd.138.1444914157048; Thu, 15 Oct 2015 06:02:37 -0700 (PDT) Received: from localhost.localdomain ([195.238.92.128]) by smtp.gmail.com with ESMTPSA id z4sm11886602wjz.29.2015.10.15.06.02.35 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 15 Oct 2015 06:02:36 -0700 (PDT) From: Ivan Khoronzhuk To: lng-odp@lists.linaro.org, petri.savolainen@nokia.com Date: Thu, 15 Oct 2015 16:02:21 +0300 Message-Id: <1444914142-20587-5-git-send-email-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1444914142-20587-1-git-send-email-ivan.khoronzhuk@linaro.org> References: <1444914142-20587-1-git-send-email-ivan.khoronzhuk@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCH v4 4/5] linux-generic: align implementation with new time API 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: ivan.khoronzhuk@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.178 as permitted sender) smtp.mailfrom=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 The time API names were changed from odp_time_cycle* to odp_time*. Also new time API operates with new opaque type - odp_time_t, as result several new API calls were added. For odp_schdule.c avoid "cycle" word usage as it was left from old time API names. This patch is intended to align linux-generic implementation with new time API. Signed-off-by: Ivan Khoronzhuk --- platform/linux-generic/Makefile.am | 1 + .../linux-generic/include/odp/plat/time_types.h | 36 +++++++++++++ platform/linux-generic/include/odp/time.h | 1 + platform/linux-generic/odp_schedule.c | 16 +++--- platform/linux-generic/odp_time.c | 62 ++++++++++++++++++---- 5 files changed, 97 insertions(+), 19 deletions(-) create mode 100644 platform/linux-generic/include/odp/plat/time_types.h diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 85c976d..b0842c5 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -74,6 +74,7 @@ odpplatinclude_HEADERS = \ $(srcdir)/include/odp/plat/strong_types.h \ $(srcdir)/include/odp/plat/thrmask_types.h \ $(srcdir)/include/odp/plat/ticketlock_types.h \ + $(srcdir)/include/odp/plat/time_types.h \ $(srcdir)/include/odp/plat/timer_types.h \ $(srcdir)/include/odp/plat/version_types.h diff --git a/platform/linux-generic/include/odp/plat/time_types.h b/platform/linux-generic/include/odp/plat/time_types.h new file mode 100644 index 0000000..9ba1508 --- /dev/null +++ b/platform/linux-generic/include/odp/plat/time_types.h @@ -0,0 +1,36 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODP time service + */ + +#ifndef ODP_TIME_TYPES_H_ +#define ODP_TIME_TYPES_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/** @addtogroup odp_time + * @{ + **/ + +typedef uint64_t odp_time_t; + +#define ODP_TIME_NULL ((odp_time_t)0) + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/platform/linux-generic/include/odp/time.h b/platform/linux-generic/include/odp/time.h index 3a3960b..44e0d0d 100644 --- a/platform/linux-generic/include/odp/time.h +++ b/platform/linux-generic/include/odp/time.h @@ -21,6 +21,7 @@ extern "C" { +#include #include #ifdef __cplusplus diff --git a/platform/linux-generic/odp_schedule.c b/platform/linux-generic/odp_schedule.c index 6df8073..e88f3f2 100644 --- a/platform/linux-generic/odp_schedule.c +++ b/platform/linux-generic/odp_schedule.c @@ -585,10 +585,10 @@ static int schedule_loop(odp_queue_t *out_queue, uint64_t wait, odp_event_t out_ev[], unsigned int max_num, unsigned int max_deq) { - uint64_t start_cycle, cycle, diff; + odp_time_t start_time, time, diff; int ret; - start_cycle = 0; + start_time = ODP_TIME_NULL; while (1) { ret = schedule(out_queue, out_ev, max_num, max_deq); @@ -602,15 +602,15 @@ static int schedule_loop(odp_queue_t *out_queue, uint64_t wait, if (wait == ODP_SCHED_NO_WAIT) break; - if (start_cycle == 0) { - start_cycle = odp_time_cycles(); + if (!odp_time_cmp(start_time, ODP_TIME_NULL)) { + start_time = odp_time(); continue; } - cycle = odp_time_cycles(); - diff = odp_time_diff_cycles(start_cycle, cycle); + time = odp_time(); + diff = odp_time_diff(start_time, time); - if (wait < diff) + if (odp_time_cmp(diff, wait) > 0) break; } @@ -651,7 +651,7 @@ void odp_schedule_resume(void) uint64_t odp_schedule_wait_time(uint64_t ns) { - return odp_time_ns_to_cycles(ns); + return odp_time_to_u64(odp_time_from_ns(ns)); } diff --git a/platform/linux-generic/odp_time.c b/platform/linux-generic/odp_time.c index abafd12..e0aceb1 100644 --- a/platform/linux-generic/odp_time.c +++ b/platform/linux-generic/odp_time.c @@ -14,33 +14,73 @@ #define GIGA 1000000000 -uint64_t odp_time_cycles(void) +static inline +uint64_t time_to_tick(odp_time_t time) { - return odp_cpu_cycles(); + return (uint64_t)time; } -uint64_t odp_time_diff_cycles(uint64_t t1, uint64_t t2) +static inline +odp_time_t tick_to_time(uint64_t tick) { - return _odp_cpu_cycles_diff(t1, t2); + return (odp_time_t)tick; } -uint64_t odp_time_cycles_to_ns(uint64_t cycles) +odp_time_t odp_time(void) +{ + return tick_to_time(odp_cpu_cycles()); +} + +odp_time_t odp_time_diff(odp_time_t t1, odp_time_t t2) +{ + return tick_to_time(_odp_cpu_cycles_diff(t1, t2)); +} + +uint64_t odp_time_to_ns(odp_time_t time) { uint64_t hz = odp_cpu_hz_max(); + uint64_t tick = time_to_tick(time); - if (cycles > (UINT64_MAX / GIGA)) - return (cycles/hz)*GIGA; + if (tick > (UINT64_MAX / GIGA)) + return (tick / hz) * GIGA; - return (cycles*GIGA)/hz; + return (tick * GIGA) / hz; } -uint64_t odp_time_ns_to_cycles(uint64_t ns) +odp_time_t odp_time_from_ns(uint64_t ns) { uint64_t hz = odp_cpu_hz_max(); if (ns > (UINT64_MAX / hz)) - return (ns/GIGA)*hz; + return tick_to_time((ns / GIGA) * hz); + + return tick_to_time((ns * hz) / GIGA); +} + +int odp_time_cmp(odp_time_t t1, odp_time_t t2) +{ + uint64_t tick1 = time_to_tick(t1); + uint64_t tick2 = time_to_tick(t2); - return (ns*hz)/GIGA; + if (tick1 < tick2) + return 1; + + if (tick1 > tick2) + return -1; + + return 0; +} + +odp_time_t odp_time_sum(odp_time_t t1, odp_time_t t2) +{ + uint64_t tick1 = time_to_tick(t1); + uint64_t tick2 = time_to_tick(t2); + + return tick_to_time(tick1 + tick2); +} + +uint64_t odp_time_to_u64(odp_time_t hdl) +{ + return time_to_tick(hdl); }