From patchwork Tue Dec 1 15:08: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: 57509 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp2241207lbb; Tue, 1 Dec 2015 07:18:05 -0800 (PST) X-Received: by 10.140.95.2 with SMTP id h2mr28125565qge.91.1448983085231; Tue, 01 Dec 2015 07:18:05 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id u66si50621556qku.123.2015.12.01.07.18.04; Tue, 01 Dec 2015 07:18:05 -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.20150623.gappssmtp.com Received: by lists.linaro.org (Postfix, from userid 109) id B9D2861E56; Tue, 1 Dec 2015 15:18:04 +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.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 EEA6461E6C; Tue, 1 Dec 2015 15:11:46 +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 8C06161E56; Tue, 1 Dec 2015 15:11:36 +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 5EAB961E96 for ; Tue, 1 Dec 2015 15:08:29 +0000 (UTC) Received: by lfaz4 with SMTP id z4so12169491lfa.0 for ; Tue, 01 Dec 2015 07:08:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nXfm9HbGkZChJtWaEBgfNlgHLld4zLQTv1R1TcrSi0I=; b=DwQyiv3qJtwVAVBNaQRgMGnp96XwfV72foGc3wwXq6BeR1NPwhK6Q/yhcsxdzD0qIC uaECwcBZgDQghdF4r2QRfliKbR+i2KVYVMSaAAVg6xImNfkL6ycINkGmtiSaulF8U7My pEWI3uO9dfyfCWonmO/I0hxkIXpfJojMByH+TsfEezEv9hQNfM660xnjbYoGkcd8Hf6m Zdmc8LPWRNYztNSIfaomDx19LpaGEx1fMoV8evoxY8Csc2glMGgT+XY2E319AJA3U4Oz KGIyUsrkNAn9Jg8n8+glvLO9w3/KdTiQ6gUxVVA6e1VX4fj71AX114Vrjnj34H4mIi2M +PUA== 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=nXfm9HbGkZChJtWaEBgfNlgHLld4zLQTv1R1TcrSi0I=; b=CWqq6i4jrYoGnpdAYkWgp68+K77PBMFgCzmX83IZQyt3Oq9qdo9E65Letk09b2Jz+F dPV7HFqJyZY1ODaDmSiDA9Wt1HsORYSSZcBW1XFGJZ/pNGXJNRLoGtf1PfabJZ/ISy7J LSkgmjLNx99eFxMjaxgPsaA/lFnOGM6PiZl+bzmyehI6yEarLnsgIrgxXW6SeLvA7e8h ZOZ+lV4zj5EBVFYdwM1VmXr38/BTJc47EGO4C4lY0oyVD++9XhD47B7Axn6MomTUPJCy +eSscHzb4LUHzSDN7CE5sfvoh8O9I9lDlVLkxWViUOMHCrAv7AYk71GkExm6z6lCLa1e CmcQ== X-Gm-Message-State: ALoCoQl1xqNS0Mt2rzbwVJjV7vR4/1CCvCZlouUchPWTtEdsWlgjNB4p55ayhTr7QD8SPejg2hXY X-Received: by 10.112.12.193 with SMTP id a1mr29979525lbc.52.1448982508318; Tue, 01 Dec 2015 07:08:28 -0800 (PST) Received: from localhost.localdomain ([212.90.60.8]) by smtp.gmail.com with ESMTPSA id i194sm8278535lfg.20.2015.12.01.07.08.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 01 Dec 2015 07:08:27 -0800 (PST) From: Ivan Khoronzhuk To: lng-odp@lists.linaro.org Date: Tue, 1 Dec 2015 17:08:11 +0200 Message-Id: <1448982493-8236-8-git-send-email-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1448982493-8236-1-git-send-email-ivan.khoronzhuk@linaro.org> References: <1448982493-8236-1-git-send-email-ivan.khoronzhuk@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCH v5 7/9] linux-generic: align with new wall 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" The local time API supposes the time source is wall time. So correct linux-generic implementation. Signed-off-by: Ivan Khoronzhuk --- platform/linux-generic/include/odp_internal.h | 2 + platform/linux-generic/odp_schedule.c | 9 ++-- platform/linux-generic/odp_time.c | 61 +++++++++++++++++++-------- 3 files changed, 48 insertions(+), 24 deletions(-) diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h index 74e48a9..50bf6c8 100644 --- a/platform/linux-generic/include/odp_internal.h +++ b/platform/linux-generic/include/odp_internal.h @@ -79,6 +79,8 @@ int odp_schedule_term_local(void); int odp_timer_init_global(void); int odp_timer_disarm_all(void); +int odp_time_local_init(void); + int odp_tm_init_global(void); void _odp_flush_caches(void); diff --git a/platform/linux-generic/odp_schedule.c b/platform/linux-generic/odp_schedule.c index 96b3ac5..3017876 100644 --- a/platform/linux-generic/odp_schedule.c +++ b/platform/linux-generic/odp_schedule.c @@ -586,7 +586,7 @@ 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) { - odp_time_t start_time, time, diff, wtime; + odp_time_t next, wtime; int first = 1; int ret; @@ -604,15 +604,12 @@ static int schedule_loop(odp_queue_t *out_queue, uint64_t wait, if (first) { wtime = odp_time_local_from_ns(wait); - start_time = odp_time_local(); + next = odp_time_sum(odp_time_local(), wtime); first = 0; continue; } - time = odp_time_local(); - diff = odp_time_diff(time, start_time); - - if (odp_time_cmp(wtime, diff) < 0) + if (odp_time_cmp(next, odp_time_local()) < 0) break; } diff --git a/platform/linux-generic/odp_time.c b/platform/linux-generic/odp_time.c index b725086..1aae88c 100644 --- a/platform/linux-generic/odp_time.c +++ b/platform/linux-generic/odp_time.c @@ -11,19 +11,21 @@ #include #include -odp_time_t odp_time_local(void) +static __thread struct timespec start_local; + +static inline +uint64_t _odp_time_to_ns(odp_time_t val) { - int ret; - struct timespec time; + uint64_t ns; - ret = clock_gettime(CLOCK_MONOTONIC_RAW, &time); - if (odp_unlikely(ret != 0)) - ODP_ABORT("clock_gettime failed\n"); + ns = val.tv_sec * ODP_TIME_SEC_IN_NS; + ns += val.tv_nsec; - return time; + return ns; } -odp_time_t odp_time_diff(odp_time_t t2, odp_time_t t1) +static inline +odp_time_t _odp_time_diff(odp_time_t t2, odp_time_t t1) { struct timespec time; @@ -38,24 +40,36 @@ odp_time_t odp_time_diff(odp_time_t t2, odp_time_t t1) return time; } -uint64_t odp_time_to_ns(odp_time_t time) +odp_time_t odp_time_local(void) { - uint64_t ns; + int ret; + struct timespec time; + + ret = clock_gettime(CLOCK_MONOTONIC_RAW, &time); + if (odp_unlikely(ret != 0)) + ODP_ABORT("clock_gettime failed\n"); - ns = time.tv_sec * ODP_TIME_SEC_IN_NS; - ns += time.tv_nsec; + return _odp_time_diff(time, start_local); +} - return ns; +odp_time_t odp_time_diff(odp_time_t t2, odp_time_t t1) +{ + return _odp_time_diff(t2, t1); +} + +uint64_t odp_time_to_ns(odp_time_t time) +{ + return _odp_time_to_ns(time); } odp_time_t odp_time_local_from_ns(uint64_t ns) { - struct timespec time; + struct timespec val; - time.tv_sec = ns / ODP_TIME_SEC_IN_NS; - time.tv_nsec = ns % ODP_TIME_SEC_IN_NS; + val.tv_sec = ns / ODP_TIME_SEC_IN_NS; + val.tv_nsec = ns % ODP_TIME_SEC_IN_NS; - return time; + return val; } int odp_time_cmp(odp_time_t t2, odp_time_t t1) @@ -96,10 +110,21 @@ uint64_t odp_time_to_u64(odp_time_t time) resolution = (uint64_t)tres.tv_nsec; - return odp_time_to_ns(time) / resolution; + return _odp_time_to_ns(time) / resolution; } odp_time_t odp_time_null(void) { return (struct timespec) {0, 0}; } + +int odp_time_local_init(void) +{ + int ret; + struct timespec time; + + ret = clock_gettime(CLOCK_MONOTONIC_RAW, &time); + start_local = ret ? odp_time_null() : time; + + return ret; +}