From patchwork Wed Sep 2 21:10:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 52993 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by patches.linaro.org (Postfix) with ESMTPS id 9CAA422E23 for ; Wed, 2 Sep 2015 21:13:23 +0000 (UTC) Received: by lbbmp1 with SMTP id mp1sf8073700lbb.2 for ; Wed, 02 Sep 2015 14:13:22 -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=Xn/aH09RrCLgqFCXf5oUi7KOtvYl9pndU7U1i09iIWw=; b=gaJZd2sROndhENS/p4V+bCfDkdBWy6HhPTMjTL7qaBoMxX3DadF9WsGjBYprmb7jsx jMZ7yLw1xcV0F6MLV5ZNXPOi6Ap25vMvrVSoVefks1uqxd56QCUrbaKfd6hpGvRIxb3a 12oYcV32+gjF56kQjdmQLUJ908GfYQ8cKhMxe4RQxc8jpR/X5nvHx4VifZfdQZ4ne3Ze Dk1KaFS4hfw0zkW1kfREfEImrSAbImioevs0zzSbIXyubCcPP3dM8DSMRiPyJDEo0MUc 95Ccq7aOFaMKU9oYc/ehasfKR3+ckgHXqdlzcmFyesK7wEml++g9ABrY1TJojiVIKTeL /hfg== X-Gm-Message-State: ALoCoQl3W/0rPmWJhpfdXHYItvDgee96QkdcsjOIKUHyaB3zeZ+g6TYWmL80X/WMYv36DfEAIhxD X-Received: by 10.112.170.67 with SMTP id ak3mr9682624lbc.6.1441228402623; Wed, 02 Sep 2015 14:13:22 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.26.225 with SMTP id o1ls119674lag.36.gmail; Wed, 02 Sep 2015 14:13:22 -0700 (PDT) X-Received: by 10.112.166.106 with SMTP id zf10mr18148911lbb.36.1441228402436; Wed, 02 Sep 2015 14:13:22 -0700 (PDT) Received: from mail-la0-f41.google.com (mail-la0-f41.google.com. [209.85.215.41]) by mx.google.com with ESMTPS id kz1si20951006lab.19.2015.09.02.14.13.22 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Sep 2015 14:13:22 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.41 as permitted sender) client-ip=209.85.215.41; Received: by lamp12 with SMTP id p12so15025162lam.0 for ; Wed, 02 Sep 2015 14:13:22 -0700 (PDT) X-Received: by 10.112.168.100 with SMTP id zv4mr17376042lbb.117.1441228402161; Wed, 02 Sep 2015 14:13:22 -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.164.42 with SMTP id yn10csp840024lbb; Wed, 2 Sep 2015 14:13:21 -0700 (PDT) X-Received: by 10.140.18.240 with SMTP id 103mr601113qgf.31.1441228401084; Wed, 02 Sep 2015 14:13:21 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 62si27198775qha.12.2015.09.02.14.13.20; Wed, 02 Sep 2015 14:13:20 -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 E1577619D6; Wed, 2 Sep 2015 21:13:19 +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 D695C619CF; Wed, 2 Sep 2015 21:11:29 +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 CF99B619D8; Wed, 2 Sep 2015 21:11:17 +0000 (UTC) Received: from mail-wi0-f179.google.com (mail-wi0-f179.google.com [209.85.212.179]) by lists.linaro.org (Postfix) with ESMTPS id 24FB66195C for ; Wed, 2 Sep 2015 21:11:13 +0000 (UTC) Received: by wiclp12 with SMTP id lp12so32095410wic.1 for ; Wed, 02 Sep 2015 14:11:12 -0700 (PDT) X-Received: by 10.194.143.6 with SMTP id sa6mr41282095wjb.67.1441228272171; Wed, 02 Sep 2015 14:11:12 -0700 (PDT) Received: from khorivan.synapse.com ([212.90.60.8]) by smtp.gmail.com with ESMTPSA id lg6sm34271216wjb.10.2015.09.02.14.11.11 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 02 Sep 2015 14:11:11 -0700 (PDT) From: Ivan Khoronzhuk To: lng-odp@lists.linaro.org Date: Thu, 3 Sep 2015 00:10:53 +0300 Message-Id: <1441228253-21225-4-git-send-email-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1441228253-21225-1-git-send-email-ivan.khoronzhuk@linaro.org> References: <1441228253-21225-1-git-send-email-ivan.khoronzhuk@linaro.org> X-Topics: patch Subject: [lng-odp] [odp-lng] [Patch v3 3/3] 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.215.41 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/arch/linux/odp_time_cycles.c | 4 +- .../linux-generic/arch/mips64/odp_time_cycles.c | 4 +- platform/linux-generic/arch/x86/odp_time_cycles.c | 4 +- .../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 | 65 ++++++++++++++++++---- 8 files changed, 106 insertions(+), 25 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 f2c081a..a2da4ed 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -70,6 +70,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/arch/linux/odp_time_cycles.c b/platform/linux-generic/arch/linux/odp_time_cycles.c index 4dc0764..70d611d 100644 --- a/platform/linux-generic/arch/linux/odp_time_cycles.c +++ b/platform/linux-generic/arch/linux/odp_time_cycles.c @@ -16,7 +16,7 @@ #define GIGA 1000000000 -uint64_t odp_time_cycles(void) +odp_time_t odp_time(void) { struct timespec time; uint64_t sec, ns, hz, cycles; @@ -34,5 +34,5 @@ uint64_t odp_time_cycles(void) cycles = sec * hz; cycles += (ns * hz) / GIGA; - return cycles; + return (odp_time_t)cycles; } diff --git a/platform/linux-generic/arch/mips64/odp_time_cycles.c b/platform/linux-generic/arch/mips64/odp_time_cycles.c index 4fb790b..0bbd18a 100644 --- a/platform/linux-generic/arch/mips64/odp_time_cycles.c +++ b/platform/linux-generic/arch/mips64/odp_time_cycles.c @@ -8,7 +8,7 @@ #include #include -uint64_t odp_time_cycles(void) +odp_time_t odp_time(void) { #define CVMX_TMP_STR(x) CVMX_TMP_STR2(x) #define CVMX_TMP_STR2(x) #x @@ -17,5 +17,5 @@ uint64_t odp_time_cycles(void) __asm__ __volatile__ ("rdhwr %[rt],$" CVMX_TMP_STR(31) : [rt] "=d" (cycle) : : "memory"); - return cycle; + return (odp_time_t)cycle; } diff --git a/platform/linux-generic/arch/x86/odp_time_cycles.c b/platform/linux-generic/arch/x86/odp_time_cycles.c index a111561..78651c4 100644 --- a/platform/linux-generic/arch/x86/odp_time_cycles.c +++ b/platform/linux-generic/arch/x86/odp_time_cycles.c @@ -5,7 +5,7 @@ */ #include -uint64_t odp_time_cycles(void) +odp_time_t odp_time(void) { union { uint64_t tsc_64; @@ -19,5 +19,5 @@ uint64_t odp_time_cycles(void) "=a" (tsc.lo_32), "=d" (tsc.hi_32) : : "memory"); - return tsc.tsc_64; + return (odp_time_t)tsc.tsc_64; } 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 5d32c81..fd7c263 100644 --- a/platform/linux-generic/odp_schedule.c +++ b/platform/linux-generic/odp_schedule.c @@ -510,10 +510,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); @@ -527,15 +527,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; } @@ -579,7 +579,7 @@ uint64_t odp_schedule_wait_time(uint64_t ns) if (ns <= ODP_SCHED_NO_WAIT) ns = ODP_SCHED_NO_WAIT + 1; - return odp_time_ns_to_cycles(ns); + return (uint64_t)odp_time_from_ns(ns); } diff --git a/platform/linux-generic/odp_time.c b/platform/linux-generic/odp_time.c index a007d69..6b1a6ff 100644 --- a/platform/linux-generic/odp_time.c +++ b/platform/linux-generic/odp_time.c @@ -12,31 +12,74 @@ #define GIGA 1000000000 -uint64_t odp_time_diff_cycles(uint64_t t1, uint64_t t2) +static inline +uint64_t time_to_tick(odp_time_t time) { - if (odp_likely(t2 >= t1)) - return t2 - t1; + return (uint64_t)time; +} + +static inline +odp_time_t tick_to_time(uint64_t tick) +{ + return (odp_time_t)tick; +} + +odp_time_t odp_time_diff(odp_time_t t1, odp_time_t t2) +{ + uint64_t tick1 = time_to_tick(t1); + uint64_t tick2 = time_to_tick(t2); + + if (odp_likely(tick2 >= tick1)) + return tick_to_time(tick2 - tick1); - return t2 + (UINT64_MAX - t1); + return tick_to_time(tick2 + (UINT64_MAX - tick1)); } -uint64_t odp_time_cycles_to_ns(uint64_t cycles) +uint64_t odp_time_to_ns(odp_time_t time) { uint64_t hz = odp_sys_cpu_hz(); + 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_sys_cpu_hz(); 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); + + if (tick1 < tick2) + return 1; + + if (tick1 > tick2) + return -1; + + return 0; +} - return (ns*hz)/GIGA; +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); }