From patchwork Mon Dec 14 22:14:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 58370 Delivered-To: patch@linaro.org Received: by 10.112.73.68 with SMTP id j4csp1760381lbv; Mon, 14 Dec 2015 14:14:52 -0800 (PST) X-Received: by 10.140.176.130 with SMTP id w124mr13928598qhw.59.1450131292447; Mon, 14 Dec 2015 14:14:52 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id m6si36904797qki.10.2015.12.14.14.14.51; Mon, 14 Dec 2015 14:14:52 -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 5933261D6B; Mon, 14 Dec 2015 22:14:51 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=f7dNa1Qc; 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 E478F61D53; Mon, 14 Dec 2015 22:14:45 +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 E270F61D5A; Mon, 14 Dec 2015 22:14:43 +0000 (UTC) Received: from mail-oi0-f53.google.com (mail-oi0-f53.google.com [209.85.218.53]) by lists.linaro.org (Postfix) with ESMTPS id 1854261CE1 for ; Mon, 14 Dec 2015 22:14:43 +0000 (UTC) Received: by oiao124 with SMTP id o124so10222820oia.1 for ; Mon, 14 Dec 2015 14:14:42 -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=LmLOZrAl7kuHhQdQOraGiljE233h+DWnGXHBBmrxwO4=; b=f7dNa1Qc0SqcXoWm7fAVDocv/KcImcOaFnqNFHvqCnPxeHb6JBqWhTe8I6F+/aqMCD rPGRlzcFWp+9hGmKMKv5zLSbgKQzHcLk8gqWdF/sQ3MWdm8hPOPlaPs+4sjB6zZzFFZq zvf0dM8OUyO2HU053bV18aVQJAk97QRLsgYlc= 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=LmLOZrAl7kuHhQdQOraGiljE233h+DWnGXHBBmrxwO4=; b=LQm3vlFXSTxYc48nAnAyLJhkLbSLoTynSp8kFUeFyFv1IXVG3+wzCnAzP+7dXZtU0E MDoHbduF41L2nEaj4i//lLvphDr5etCwAnJ6nkX57M5qF0puscBDP3kpKY04ywvjlw6h fLhq3Cq4gNwqyR2t3N+fUmkgfSJmvEEkO0kyZwnagYscJX7OkWocdcOMJwA7eqmR4Wlg GpmJ1uz5+dJUZF1kXwTzxZ1EpURR9M/FdD+fyvvX9Jh7gpHCa4jxQXYmmNszfCc78Qba UGd2vLoJy5QsbA32Vf3tJI3eQfDkPgM09TicAf1+E6AM9iZajQAk8qlLrQr8Qgxgqib1 dS6g== X-Gm-Message-State: ALoCoQkQWt4oQKswtvoJhJ2zvfY71erF8ogeHPuEUBEpCLuxDaxfMvv77aLX1z+fhGTS/GOY7WkcNIoKYxHm8jerUHD5cx3PnQ== X-Received: by 10.202.78.1 with SMTP id c1mr25987099oib.53.1450131282651; Mon, 14 Dec 2015 14:14:42 -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 d6sm15586928oex.13.2015.12.14.14.14.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 14 Dec 2015 14:14:41 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Mon, 14 Dec 2015 16:14:36 -0600 Message-Id: <1450131276-16659-1-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.1.4 X-Topics: patch Subject: [lng-odp] [API-NEXT PATCHv3] 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 | 14 +++++++--- platform/linux-generic/odp_time.c | 30 +++++++++++----------- 2 files changed, 25 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..6269e40 100644 --- a/platform/linux-generic/include/odp/plat/time_types.h +++ b/platform/linux-generic/include/odp/plat/time_types.h @@ -21,11 +21,17 @@ extern "C" { * @{ **/ -typedef struct timespec odp_time_t; - -odp_time_t odp_time_null(void); +/** + * 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; /**< Seconds */ + int64_t tv_nsec; /**< 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; }