From patchwork Fri Dec 4 17:51:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 57719 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp703498lbb; Fri, 4 Dec 2015 09:57:17 -0800 (PST) X-Received: by 10.140.175.65 with SMTP id v62mr21288410qhv.75.1449251837294; Fri, 04 Dec 2015 09:57:17 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id s85si7299548qkl.4.2015.12.04.09.57.16; Fri, 04 Dec 2015 09:57:17 -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 C001062D6E; Fri, 4 Dec 2015 17:57:16 +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 1B8C662D87; Fri, 4 Dec 2015 17:53:03 +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 0501362D85; Fri, 4 Dec 2015 17:52:54 +0000 (UTC) Received: from mail-lf0-f52.google.com (mail-lf0-f52.google.com [209.85.215.52]) by lists.linaro.org (Postfix) with ESMTPS id 3144B62D6E for ; Fri, 4 Dec 2015 17:51:54 +0000 (UTC) Received: by lffu14 with SMTP id u14so117095490lff.1 for ; Fri, 04 Dec 2015 09:51:53 -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=LbbT3iKqOagVZzQuyD0cFm/DSGfBtXWRhV5JTmIuEww=; b=QRLxPNiMvkvZXyuqa1+DQnbrOg496czZMC2zA3CRb7FOvyztw+3L0U0ehjxQRVLsHO 1vJ8MQpuvwf8+uGH3cafwsT+u4XbTVBsBinnH3Ijb9Y1RP7klt02fdIT6jLeLBRPO62q MX/GC9BDdS23EHV6PB8wm8WHapn5Un3274A8dHgPnr37eOcq+xGrQRl3KDcii4pUgPea Xc2qxTG+OfftKPO2cFZEgg+A62Zh5GsY0dYa//pF1JM8gwud+2RWEtvNvCpDbzIkv8Sv rNk7BUq+lS4GFmajOQR/Sh/ZWm8a4fTT2vVu4JwRAkzh4FNxsP2kZBFXsLiPIs//8doO KjaQ== 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=LbbT3iKqOagVZzQuyD0cFm/DSGfBtXWRhV5JTmIuEww=; b=hcuikdU8TY8ESM98E+yWIVGrAjphiREntAQQkw73vOCk+O+SLFFZf4c+0m+DT0YpNB Ew0hjlQ0u3PlIvpmV301KXeyhHcPjCbxAjwHWEjY5Y17881JZ3tOcDnuVlwLoU9RFk7h 9uLeTU7dlaDKR8E+n6mfvON1apEb+rYcR4AgX88qiAEnNGHag2WPfc2a/7joLP9BHWDe SI+O2/tN4xqxUMCYcvO1+2bN6d9IRhswG+pLsOyetQFXxsSa57tKtl35Nu41gDTEedNv etziwG1aYeEQpi0QQDTUpfWmhszs7s/sUUbdQdATMzovTOZ6Hpov8/vfSSnAauhnOesp mBhQ== X-Gm-Message-State: ALoCoQlBM6FzsrrCVxdmldbEfa8Ho3pjMtKz5W/XUaahSiGr0dvHgD5g85J9ZWjBos7qiTOh3lc3 X-Received: by 10.25.85.200 with SMTP id j191mr8545807lfb.131.1449251513119; Fri, 04 Dec 2015 09:51:53 -0800 (PST) Received: from localhost.localdomain ([212.90.60.8]) by smtp.gmail.com with ESMTPSA id rm5sm2483518lbb.20.2015.12.04.09.51.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 04 Dec 2015 09:51:52 -0800 (PST) From: Ivan Khoronzhuk To: lng-odp@lists.linaro.org Date: Fri, 4 Dec 2015 19:51:33 +0200 Message-Id: <1449251494-23210-9-git-send-email-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1449251494-23210-1-git-send-email-ivan.khoronzhuk@linaro.org> References: <1449251494-23210-1-git-send-email-ivan.khoronzhuk@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCH v7 8/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. Reviewed-by: Petri Savolainen Signed-off-by: Ivan Khoronzhuk --- platform/linux-generic/include/odp_internal.h | 2 + platform/linux-generic/odp_init.c | 4 ++ platform/linux-generic/odp_schedule.c | 9 ++-- platform/linux-generic/odp_time.c | 61 ++++++++++++++++++--------- 4 files changed, 49 insertions(+), 27 deletions(-) diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h index 74e48a9..49e23d9 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_global_init(void); + int odp_tm_init_global(void); void _odp_flush_caches(void); diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c index 7f35962..d93dab8 100644 --- a/platform/linux-generic/odp_init.c +++ b/platform/linux-generic/odp_init.c @@ -24,6 +24,10 @@ int odp_init_global(const odp_init_t *params, odp_global_data.abort_fn = params->abort_fn; } + if (odp_time_global_init()) { + ODP_ERR("ODP time init failed.\n"); + return -1; + } odp_system_info_init(); 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 89bbf0c..1c7c214 100644 --- a/platform/linux-generic/odp_time.c +++ b/platform/linux-generic/odp_time.c @@ -11,28 +11,24 @@ #include #include -odp_time_t odp_time_local(void) +static struct timespec start_time; + +static inline +uint64_t time_to_ns(odp_time_t time) { - 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 = time.tv_sec * ODP_TIME_SEC_IN_NS; + ns += time.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 time_diff(odp_time_t t2, odp_time_t t1) { - uint64_t ns1, ns2; struct timespec time; - ns1 = odp_time_to_ns(t1); - ns2 = odp_time_to_ns(t2); - if (ns2 < ns1) - return (struct timespec) {0, 1}; - time.tv_sec = t2.tv_sec - t1.tv_sec; time.tv_nsec = t2.tv_nsec - t1.tv_nsec; @@ -44,14 +40,26 @@ 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; - ns = time.tv_sec * ODP_TIME_SEC_IN_NS; - ns += time.tv_nsec; + ret = clock_gettime(CLOCK_MONOTONIC_RAW, &time); + if (odp_unlikely(ret != 0)) + ODP_ABORT("clock_gettime failed\n"); - return ns; + return time_diff(time, start_time); +} + +odp_time_t odp_time_diff(odp_time_t t2, odp_time_t t1) +{ + return time_diff(t2, t1); +} + +uint64_t odp_time_to_ns(odp_time_t time) +{ + return time_to_ns(time); } odp_time_t odp_time_local_from_ns(uint64_t ns) @@ -59,7 +67,7 @@ odp_time_t odp_time_local_from_ns(uint64_t ns) struct timespec time; time.tv_sec = ns / ODP_TIME_SEC_IN_NS; - time.tv_nsec = ns % ODP_TIME_SEC_IN_NS; + time.tv_nsec = ns - time.tv_sec * ODP_TIME_SEC_IN_NS; return time; } @@ -102,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 time_to_ns(time) / resolution; } odp_time_t odp_time_null(void) { return (struct timespec) {0, 0}; } + +int odp_time_global_init(void) +{ + int ret; + struct timespec time; + + ret = clock_gettime(CLOCK_MONOTONIC_RAW, &time); + start_time = ret ? odp_time_null() : time; + + return ret; +}