From patchwork Fri Dec 11 13:22:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 58278 Delivered-To: patch@linaro.org Received: by 10.112.157.166 with SMTP id wn6csp131707lbb; Fri, 11 Dec 2015 05:22:46 -0800 (PST) X-Received: by 10.55.75.8 with SMTP id y8mr23354151qka.2.1449840166481; Fri, 11 Dec 2015 05:22:46 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id b130si20112898qka.18.2015.12.11.05.22.45; Fri, 11 Dec 2015 05:22:46 -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 895CD61C8B; Fri, 11 Dec 2015 13:22:45 +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 80C9C61B63; Fri, 11 Dec 2015 13:22:43 +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 6E36461B6A; Fri, 11 Dec 2015 13:22:41 +0000 (UTC) Received: from mail-ob0-f170.google.com (mail-ob0-f170.google.com [209.85.214.170]) by lists.linaro.org (Postfix) with ESMTPS id 8C52C61B30 for ; Fri, 11 Dec 2015 13:22:40 +0000 (UTC) Received: by obc18 with SMTP id 18so82315616obc.2 for ; Fri, 11 Dec 2015 05:22:40 -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; bh=L5HJ1zOnNjY7V18GmlwBJVdo89UXr3JkPKHgGGQulec=; b=oawNk1hnYpZPalAvzfiJkyW4Be7l0YuUdgNWdzwMM9LBkDX8IA76YVQ8BpQwCXgMh/ zCX9J1NcsQW/ht2ibobk5aL2PMwCwWNxzJh0aFxcwiq6LAhRtVIH2VIvUpkMkZfmdobv 5xW68xGu7Bm2G/jl++ovthXXKdzfWzhwKu/DDiy65jy4bE4NRMMriF7spEkm9SjgwYJp 7HZW4LUy/v+bIEvzOQP4TAcww658+ts7HXUhE99upLoSA6qFAM2Yl7a+ZcxVaiIy//lW MCVJGvAtEfOw7ooVyYQ+TIuKXvEWAKD3ZVW7qxgTMrlfLyUzoqSgAmSBzh1g5iLicjl5 yy4A== 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; bh=L5HJ1zOnNjY7V18GmlwBJVdo89UXr3JkPKHgGGQulec=; b=B9m13vm0kQ0bRCNeERULAIy1yosFjkzCwWHW6UUBccOtLd+sACU+Sqep/gf31FYoGM dvlvw4ZV2GyAFE93r5EWF72IDXo4fmmgRMJRh9wFwyQ7BWo0sX7JbyNLhjhxYC4RK8pS vTX0xW+0nKRZ5Dsa4q0iy9hefC/Z8/oxtPzcweqS3PZ/rh9P6yX8vj5DG48dtJCthzy1 QugjlVq0gxe+w6kmxgExaZN4zEvGMYIxvhgvT+nRngJxwueaflxJ8lVNxcyJX3t8XLNb I6OptyINOxVp7B6Js1OLcdjdaG7esfxrMro1/pk2q/KHwMyn3R5633uueAYVmSzzgLp6 HalA== X-Gm-Message-State: ALoCoQlQ0viMt/AjhMVousIGCVQU7WJ6y+kW0gMGkSQ+wqhfayS4bjO1Baj6H/CSi5BtcLOXXWsfrA8BG5jvijZwNCrKPPxBFA== X-Received: by 10.182.153.6 with SMTP id vc6mr13775915obb.71.1449840159985; Fri, 11 Dec 2015 05:22:39 -0800 (PST) Received: from Ubuntu15.localdomain (cpe-66-68-129-43.austin.res.rr.com. [66.68.129.43]) by smtp.gmail.com with ESMTPSA id tt1sm8387828obb.8.2015.12.11.05.22.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 11 Dec 2015 05:22:39 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Fri, 11 Dec 2015 07:22:35 -0600 Message-Id: <1449840155-5550-1-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.1.4 X-Topics: patch Subject: [lng-odp] [API-NEXT PATCHv2] linux-generic: time: remove posix bleed through on odp_time_t 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 linux-generic implementation of odp_time_t makes use of POSIX APIs that are sensitive to the _POSIX_C_SOURCE level. Use an indirection mechanism so that these dependencies do not "bleed through" the ODP API. This means that ODP applications can be independent of _POSIX_C_SOURCE level. Signed-off-by: Bill Fischofer --- .../linux-generic/include/odp/plat/time_types.h | 9 ++++--- platform/linux-generic/odp_time.c | 30 +++++++++++----------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/platform/linux-generic/include/odp/plat/time_types.h b/platform/linux-generic/include/odp/plat/time_types.h index e5765ec..e999beb 100644 --- a/platform/linux-generic/include/odp/plat/time_types.h +++ b/platform/linux-generic/include/odp/plat/time_types.h @@ -21,11 +21,12 @@ extern "C" { * @{ **/ -typedef struct timespec odp_time_t; +typedef struct { + int64_t tv_sec; + int64_t tv_nsec; +} odp_time_t; -odp_time_t odp_time_null(void); - -#define ODP_TIME_NULL odp_time_null() +#define ODP_TIME_NULL ((odp_time_t){0, 0}) /** * @} diff --git a/platform/linux-generic/odp_time.c b/platform/linux-generic/odp_time.c index 1c7c214..9b64b37 100644 --- a/platform/linux-generic/odp_time.c +++ b/platform/linux-generic/odp_time.c @@ -11,7 +11,12 @@ #include #include -static struct timespec start_time; +typedef union { + odp_time_t ex; + struct timespec in; +} _odp_time_t; + +static odp_time_t start_time; static inline uint64_t time_to_ns(odp_time_t time) @@ -27,7 +32,7 @@ uint64_t time_to_ns(odp_time_t time) static inline odp_time_t time_diff(odp_time_t t2, odp_time_t t1) { - struct timespec time; + odp_time_t time; time.tv_sec = t2.tv_sec - t1.tv_sec; time.tv_nsec = t2.tv_nsec - t1.tv_nsec; @@ -43,13 +48,13 @@ odp_time_t time_diff(odp_time_t t2, odp_time_t t1) odp_time_t odp_time_local(void) { int ret; - struct timespec time; + _odp_time_t time; - ret = clock_gettime(CLOCK_MONOTONIC_RAW, &time); + ret = clock_gettime(CLOCK_MONOTONIC_RAW, &time.in); if (odp_unlikely(ret != 0)) ODP_ABORT("clock_gettime failed\n"); - return time_diff(time, start_time); + return time_diff(time.ex, start_time); } odp_time_t odp_time_diff(odp_time_t t2, odp_time_t t1) @@ -64,7 +69,7 @@ uint64_t odp_time_to_ns(odp_time_t time) odp_time_t odp_time_local_from_ns(uint64_t ns) { - struct timespec time; + odp_time_t time; time.tv_sec = ns / ODP_TIME_SEC_IN_NS; time.tv_nsec = ns - time.tv_sec * ODP_TIME_SEC_IN_NS; @@ -85,7 +90,7 @@ int odp_time_cmp(odp_time_t t2, odp_time_t t1) odp_time_t odp_time_sum(odp_time_t t1, odp_time_t t2) { - struct timespec time; + odp_time_t time; time.tv_sec = t2.tv_sec + t1.tv_sec; time.tv_nsec = t2.tv_nsec + t1.tv_nsec; @@ -113,18 +118,13 @@ uint64_t odp_time_to_u64(odp_time_t time) 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; + _odp_time_t time; - ret = clock_gettime(CLOCK_MONOTONIC_RAW, &time); - start_time = ret ? odp_time_null() : time; + ret = clock_gettime(CLOCK_MONOTONIC_RAW, &time.in); + start_time = ret ? ODP_TIME_NULL : time.ex; return ret; }