From patchwork Wed May 4 15:02:43 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: 67144 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp232701qge; Wed, 4 May 2016 08:04:09 -0700 (PDT) X-Received: by 10.55.81.87 with SMTP id f84mr9269114qkb.10.1462374245655; Wed, 04 May 2016 08:04:05 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 143si2808933qhx.131.2016.05.04.08.04.04; Wed, 04 May 2016 08:04:04 -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 27727615E3; Wed, 4 May 2016 15:04:04 +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 4A5FF615C8; Wed, 4 May 2016 15:03:22 +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 D4712611FE; Wed, 4 May 2016 15:02:52 +0000 (UTC) Received: from demumfd002.nsn-inter.net (demumfd002.nsn-inter.net [93.183.12.31]) by lists.linaro.org (Postfix) with ESMTPS id 0A863615BB for ; Wed, 4 May 2016 15:02:50 +0000 (UTC) Received: from demuprx016.emea.nsn-intra.net ([10.150.129.55]) by demumfd002.nsn-inter.net (8.15.2/8.15.2) with ESMTPS id u44F2nZl002510 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 4 May 2016 15:02:49 GMT Received: from 10.144.19.15 ([10.144.104.109]) by demuprx016.emea.nsn-intra.net (8.12.11.20060308/8.12.11) with ESMTP id u44F2i7E017763 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO) for ; Wed, 4 May 2016 17:02:45 +0200 From: Matias Elo To: lng-odp@lists.linaro.org Date: Wed, 4 May 2016 18:02:43 +0300 Message-Id: <1462374164-29676-1-git-send-email-matias.elo@nokia.com> X-Mailer: git-send-email 1.9.1 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: 4293 X-purgate-ID: 151667::1462374169-00002418-0A748B2A/0/0 X-Topics: timers patch Subject: [lng-odp] [PATCH v2 1/2] linux-generic: timer: use strong typing 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" Use strong typing for odp_timer_t and odp_timeout_t. Fix couple exposed usage errors. Signed-off-by: Matias Elo --- example/timer/odp_timer_test.c | 8 ++++---- platform/linux-generic/include/odp/api/plat/timer_types.h | 10 ++++++---- platform/linux-generic/odp_timer.c | 6 +++--- test/validation/timer/timer.c | 2 +- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/example/timer/odp_timer_test.c b/example/timer/odp_timer_test.c index f1d3be4..c07d6ed 100644 --- a/example/timer/odp_timer_test.c +++ b/example/timer/odp_timer_test.c @@ -165,16 +165,16 @@ static void test_abs_timeouts(int thr, test_globals_t *gbls) if (!odp_timeout_fresh(tmo)) { /* Not the expected expiration tick, timer has * been reset or cancelled or freed */ - EXAMPLE_ABORT("Unexpected timeout received (timer %" PRIx32 ", tick %" PRIu64 ")\n", - ttp->tim, tick); + EXAMPLE_ABORT("Unexpected timeout received (timer %" PRIu64 ", tick %" PRIu64 ")\n", + odp_timer_to_u64(ttp->tim), tick); } EXAMPLE_DBG(" [%i] timeout, tick %"PRIu64"\n", thr, tick); uint32_t rx_num = odp_atomic_fetch_dec_u32(&gbls->remain); if (!rx_num) - EXAMPLE_ABORT("Unexpected timeout received (timer %x, tick %"PRIu64")\n", - ttp->tim, tick); + EXAMPLE_ABORT("Unexpected timeout received (timer %" PRIu64 ", tick %" PRIu64 ")\n", + odp_timer_to_u64(ttp->tim), tick); else if (rx_num > num_workers) continue; diff --git a/platform/linux-generic/include/odp/api/plat/timer_types.h b/platform/linux-generic/include/odp/api/plat/timer_types.h index 006683e..93ea162 100644 --- a/platform/linux-generic/include/odp/api/plat/timer_types.h +++ b/platform/linux-generic/include/odp/api/plat/timer_types.h @@ -18,6 +18,8 @@ extern "C" { #endif +#include + /** @addtogroup odp_timer * @{ **/ @@ -28,13 +30,13 @@ typedef struct odp_timer_pool_s *odp_timer_pool_t; #define ODP_TIMER_POOL_INVALID NULL -typedef uint32_t odp_timer_t; +typedef ODP_HANDLE_T(odp_timer_t); -#define ODP_TIMER_INVALID ((uint32_t)~0U) +#define ODP_TIMER_INVALID _odp_cast_scalar(odp_timer_t, 0xffffffff) -typedef void *odp_timeout_t; +typedef ODP_HANDLE_T(odp_timeout_t); -#define ODP_TIMEOUT_INVALID NULL +#define ODP_TIMEOUT_INVALID _odp_cast_scalar(odp_timeout_t, 0) /** * @} diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c index f4fb1f6..9e21f3a 100644 --- a/platform/linux-generic/odp_timer.c +++ b/platform/linux-generic/odp_timer.c @@ -184,7 +184,7 @@ static odp_timer_pool *timer_pool[MAX_TIMER_POOLS]; static inline odp_timer_pool *handle_to_tp(odp_timer_t hdl) { - uint32_t tp_idx = hdl >> INDEX_BITS; + uint32_t tp_idx = _odp_typeval(hdl) >> INDEX_BITS; if (odp_likely(tp_idx < MAX_TIMER_POOLS)) { odp_timer_pool *tp = timer_pool[tp_idx]; if (odp_likely(tp != NULL)) @@ -196,7 +196,7 @@ static inline odp_timer_pool *handle_to_tp(odp_timer_t hdl) static inline uint32_t handle_to_idx(odp_timer_t hdl, struct odp_timer_pool_s *tp) { - uint32_t idx = hdl & ((1U << INDEX_BITS) - 1U); + uint32_t idx = _odp_typeval(hdl) & ((1U << INDEX_BITS) - 1U); PREFETCH(&tp->tick_buf[idx]); if (odp_likely(idx < odp_atomic_load_u32(&tp->high_wm))) return idx; @@ -207,7 +207,7 @@ static inline odp_timer_t tp_idx_to_handle(struct odp_timer_pool_s *tp, uint32_t idx) { ODP_ASSERT(idx < (1U << INDEX_BITS)); - return (tp->tp_idx << INDEX_BITS) | idx; + return _odp_cast_scalar(odp_timer_t, (tp->tp_idx << INDEX_BITS) | idx); } /* Forward declarations */ diff --git a/test/validation/timer/timer.c b/test/validation/timer/timer.c index aad11aa..1032adc 100644 --- a/test/validation/timer/timer.c +++ b/test/validation/timer/timer.c @@ -297,7 +297,7 @@ static void *worker_entrypoint(void *arg TEST_UNUSED) if (tt[i].tim == ODP_TIMER_INVALID) { LOG_DBG("Failed to allocate timer (%" PRIu32 "/%d)\n", i, NTIMERS); - odp_timeout_free(tt[i].ev); + odp_event_free(tt[i].ev); break; } tt[i].ev2 = tt[i].ev;