From patchwork Tue Dec 15 11:55:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 58428 Delivered-To: patch@linaro.org Received: by 10.112.129.4 with SMTP id ns4csp145787lbb; Tue, 15 Dec 2015 03:56:07 -0800 (PST) X-Received: by 10.140.128.87 with SMTP id 84mr41836009qha.54.1450180567034; Tue, 15 Dec 2015 03:56:07 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id s67si877726qhs.12.2015.12.15.03.56.06; Tue, 15 Dec 2015 03:56:06 -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 Received: by lists.linaro.org (Postfix, from userid 109) id 2FC66619B8; Tue, 15 Dec 2015 11:56:06 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=S5CIXPap; dkim-adsp=none (unprotected policy); dkim-atps=neutral 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 03E37618D9; Tue, 15 Dec 2015 11:56:00 +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 0311E618F0; Tue, 15 Dec 2015 11:55:56 +0000 (UTC) Received: from mail-ob0-f169.google.com (mail-ob0-f169.google.com [209.85.214.169]) by lists.linaro.org (Postfix) with ESMTPS id C4D2261565 for ; Tue, 15 Dec 2015 11:55:55 +0000 (UTC) Received: by mail-ob0-f169.google.com with SMTP id 18so4418338obc.2 for ; Tue, 15 Dec 2015 03:55:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=ZlcJxxOrYiygg/80O/Rf03bjqb8xAqyHe2+9IXlhk7g=; b=S5CIXPap+OxgAFFGvMPLD4TUCBNjqhcBYo46ig3dxG+dcLJISjLi1aaXoXcbTjeOnB igDzmLjXuQ0gMBrV0Wx4h3/ZlUTIh0j6yFN4Va0FP/HRHwTuLf6gEaY3srKHoY/5xfm2 l5PE0Nj6y3ACCJ8GPXQpkiVMWoJ6lA1CLQMM4= 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=ZlcJxxOrYiygg/80O/Rf03bjqb8xAqyHe2+9IXlhk7g=; b=MqK7RKS7ihusPX1SCv8tL5mXiWx+3Y6uQwn5QN+HZWbC0MZqDAVN7Smxo4mLvN2SQ2 cgv+1GwhDYsJbH09RB89vxXxQUmYWUDynUXSb16Y/IaG9NQiBmNortkCMEx6DvzpO9cM irV0fWYz496i1eDtQrR4AX6D9eLnE4TWWSn5bR6fkRJNxDPOwoqflQFY4kMBcfYSqane 0EeCqIBMXP8O762ROG63QFTxUADYy2ez5TTKC5Y4Gx0xWAlwKMdZ3M2uTEcNDMQZZXNX lYNfPFjdop5UPRvHlbNBiGwSRrnxh/29igwiKPBMOw9E4u1V34csmOziEFvIK+6YLzHV K+1w== X-Gm-Message-State: ALoCoQlqrXIVdN1JZeRgf5E5OMDPXEKTiV8sQr5vVVMBtxtMrYFwVGKDuhNlDyIQ3ZlJzsKaTvjBxbN6hYQD6txZDfgkHKBU+w== X-Received: by 10.182.76.68 with SMTP id i4mr28875129obw.33.1450180555200; Tue, 15 Dec 2015 03:55:55 -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 mm4sm275547obb.1.2015.12.15.03.55.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 15 Dec 2015 03:55:54 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Tue, 15 Dec 2015 05:55:48 -0600 Message-Id: <1450180548-7393-1-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.1.4 X-Topics: patch Subject: [lng-odp] [API-NEXT PATCHv4] 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 Reviewed-by: Ivan Khoronzhuk --- .../linux-generic/include/odp/plat/time_types.h | 13 +++++++--- platform/linux-generic/odp_time.c | 30 +++++++++++----------- 2 files changed, 24 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..14c35f0 100644 --- a/platform/linux-generic/include/odp/plat/time_types.h +++ b/platform/linux-generic/include/odp/plat/time_types.h @@ -21,11 +21,16 @@ extern "C" { * @{ **/ -typedef struct timespec odp_time_t; - -odp_time_t odp_time_null(void); +/** + * @internal Time structure used to isolate linux-generic implementation from + * the linux timespec structure, which is dependent on _POSIX_C_SOURCE level. + */ +typedef struct odp_time_t { + int64_t tv_sec; /**< @internal Seconds */ + int64_t tv_nsec; /**< @internal Nanoseconds */ +} odp_time_t; -#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; }