From patchwork Wed May 4 13:01:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Elo, Matias \(Nokia - FI/Espoo\)" X-Patchwork-Id: 67131 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp168238qge; Wed, 4 May 2016 06:02:49 -0700 (PDT) X-Received: by 10.50.73.169 with SMTP id m9mr35118541igv.11.1462366969266; Wed, 04 May 2016 06:02:49 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id o140si4186361iod.170.2016.05.04.06.02.48; Wed, 04 May 2016 06:02:49 -0700 (PDT) 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; dmarc=fail (p=NONE dis=NONE) header.from=nokia.com Received: by lists.linaro.org (Postfix, from userid 109) id C5BBE615D8; Wed, 4 May 2016 13:02:48 +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=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 9A07F615BD; Wed, 4 May 2016 13:02:01 +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 0EE36611FE; Wed, 4 May 2016 13:01:54 +0000 (UTC) Received: from demumfd001.nsn-inter.net (demumfd001.nsn-inter.net [93.183.12.32]) by lists.linaro.org (Postfix) with ESMTPS id 0DAF5611FD for ; Wed, 4 May 2016 13:01:49 +0000 (UTC) Received: from demuprx017.emea.nsn-intra.net ([10.150.129.56]) by demumfd001.nsn-inter.net (8.15.2/8.15.2) with ESMTPS id u44D1mhi015990 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 4 May 2016 13:01:48 GMT Received: from 10.144.19.15 ([10.144.104.109]) by demuprx017.emea.nsn-intra.net (8.12.11.20060308/8.12.11) with ESMTP id u44D1lGW012129 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO) for ; Wed, 4 May 2016 15:01:48 +0200 From: Matias Elo To: lng-odp@lists.linaro.org Date: Wed, 4 May 2016 16:01:47 +0300 Message-Id: <1462366907-28457-2-git-send-email-matias.elo@nokia.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1462366907-28457-1-git-send-email-matias.elo@nokia.com> References: <1462366907-28457-1-git-send-email-matias.elo@nokia.com> X-purgate-type: clean X-purgate-Ad: Categorized by eleven eXpurgate (R) http://www.eleven.de X-purgate: clean X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate-size: 1944 X-purgate-ID: 151667::1462366909-00001B3D-CCE6152A/0/0 X-Topics: patch Subject: [lng-odp] [PATCH 2/2] time: fix invalid casting on a 32-bit host 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 size of 'struct timespec' may vary on different host architectures as it includes type long members. This breaks time functions on a 32-bit x86 host. Fix this by individually copying struct timespec members to odp_time_t. Signed-off-by: Matias Elo --- platform/linux-generic/odp_time.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/platform/linux-generic/odp_time.c b/platform/linux-generic/odp_time.c index 040f754..81e0522 100644 --- a/platform/linux-generic/odp_time.c +++ b/platform/linux-generic/odp_time.c @@ -11,11 +11,6 @@ #include #include -typedef union { - odp_time_t ex; - struct timespec in; -} _odp_time_t; - static odp_time_t start_time; static inline @@ -47,13 +42,17 @@ static inline odp_time_t time_diff(odp_time_t t2, odp_time_t t1) static inline odp_time_t time_local(void) { int ret; - _odp_time_t time; + odp_time_t time; + struct timespec sys_time; - ret = clock_gettime(CLOCK_MONOTONIC_RAW, &time.in); + ret = clock_gettime(CLOCK_MONOTONIC_RAW, &sys_time); if (odp_unlikely(ret != 0)) ODP_ABORT("clock_gettime failed\n"); - return time_diff(time.ex, start_time); + time.tv_sec = sys_time.tv_sec; + time.tv_nsec = sys_time.tv_nsec; + + return time_diff(time, start_time); } static inline int time_cmp(odp_time_t t2, odp_time_t t1) @@ -195,10 +194,15 @@ uint64_t odp_time_to_u64(odp_time_t time) int odp_time_init_global(void) { int ret; - _odp_time_t time; + struct timespec time; - ret = clock_gettime(CLOCK_MONOTONIC_RAW, &time.in); - start_time = ret ? ODP_TIME_NULL : time.ex; + ret = clock_gettime(CLOCK_MONOTONIC_RAW, &time); + if (ret) { + start_time = ODP_TIME_NULL; + } else { + start_time.tv_sec = time.tv_sec; + start_time.tv_nsec = time.tv_nsec; + } return ret; }