From patchwork Tue May 17 18:58:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ola Liljedahl X-Patchwork-Id: 68003 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp2238922qge; Tue, 17 May 2016 11:59:48 -0700 (PDT) X-Received: by 10.55.74.14 with SMTP id x14mr3664035qka.70.1463511588609; Tue, 17 May 2016 11:59:48 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id h129si3221682qkf.258.2016.05.17.11.59.48; Tue, 17 May 2016 11:59:48 -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=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 49B4561735; Tue, 17 May 2016 18:59: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=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, 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 82A8D61780; Tue, 17 May 2016 18:58: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 0FFD2616AF; Tue, 17 May 2016 18:58:41 +0000 (UTC) Received: from mail-lf0-f43.google.com (mail-lf0-f43.google.com [209.85.215.43]) by lists.linaro.org (Postfix) with ESMTPS id 12C0F6157E for ; Tue, 17 May 2016 18:58:39 +0000 (UTC) Received: by mail-lf0-f43.google.com with SMTP id m64so10817959lfd.1 for ; Tue, 17 May 2016 11:58:39 -0700 (PDT) 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:in-reply-to :references; bh=Q+e8mC2nj8BeDmOptCLjBxOfQmdSixe/3CJPap3S9uo=; b=QPxqI0Bo339yCGtWVIEltfDa6JKef3/TfD7pAEv/+vEoRiFH0f8u3F4PmTbm9v8HOZ zSrIOhcf9fDXki/Or6hpaLv4x/9XwS9SKdenD7MYpxHE2ACxPrJci4MEaP/fJsb9EoCn Fc++ySaoGViCqXZmPRbg90Y1JAIMueQH2u5NwSoJtenk5t6YwVqtBgmy5+3Yc5EAoBl7 qW7G2/OALrgC7Crm1If3eQzaklxIXJsv+nBQT5tW24iYx6Gr4N/+DcvmUBLiHhfNhpyJ rRaWDW6PM7dpRKh1s/o6prChuw0qvAAD72j3Cg9GmGPWm2rAZ2SGcpLjHAkzclW2XOkp vdAw== X-Gm-Message-State: AOPr4FWnwtK2557LOF6B3SlVyG6nD+ZWrgIzXv6dDXXa8buHrYOJLijwcQtMRFi6VbwhNMx9nWM= X-Received: by 10.25.91.207 with SMTP id p198mr1143215lfb.142.1463511517874; Tue, 17 May 2016 11:58:37 -0700 (PDT) Received: from localhost.localdomain (h-155-4-131-235.na.cust.bahnhof.se. [155.4.131.235]) by smtp.gmail.com with ESMTPSA id v4sm758712lbi.20.2016.05.17.11.58.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 17 May 2016 11:58:37 -0700 (PDT) From: Ola Liljedahl To: lng-odp@lists.linaro.org Date: Tue, 17 May 2016 20:58:18 +0200 Message-Id: <1463511498-855-3-git-send-email-ola.liljedahl@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1463511498-855-1-git-send-email-ola.liljedahl@linaro.org> References: <1463511498-855-1-git-send-email-ola.liljedahl@linaro.org> X-Topics: timers patch Subject: [lng-odp] [PATCHv2 2/2] linux-generic: timer: fix failed static assert 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" (This document/code contribution attached is provided under the terms of agreement LES-LTM-21309) Ensure tick_buf_t structure is max 128 bits large on all platforms, regardless of support for 64-bit atomic operations. Only assert that tick_buf_t is 128 bits large when performing atomic operations on it (requires ODP and platform support for 128 bit atomics). Signed-off-by: Ola Liljedahl --- platform/linux-generic/odp_timer.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c index 41e7195..a6d3332 100644 --- a/platform/linux-generic/odp_timer.c +++ b/platform/linux-generic/odp_timer.c @@ -94,7 +94,15 @@ static odp_timeout_hdr_t *timeout_hdr(odp_timeout_t tmo) *****************************************************************************/ typedef struct tick_buf_s { +#if __GCC_ATOMIC_LLONG_LOCK_FREE < 2 + /* No atomics support for 64-bit variables, will use separate lock */ + /* Use the same layout as odp_atomic_u64_t but without lock variable */ + struct { + uint64_t v; + } exp_tck;/* Expiration tick or TMO_xxx */ +#else odp_atomic_u64_t exp_tck;/* Expiration tick or TMO_xxx */ +#endif odp_buffer_t tmo_buf;/* ODP_BUFFER_INVALID if timer not active */ #ifdef TB_NEEDS_PAD uint32_t pad;/* Need to be able to access padding for successful CAS */ @@ -105,7 +113,10 @@ ODP_ALIGNED(16) /* 16-byte atomic operations need properly aligned addresses */ #endif ; +#if __GCC_ATOMIC_LLONG_LOCK_FREE >= 2 +/* Only assert this when we perform atomic operations on tick_buf_t */ ODP_STATIC_ASSERT(sizeof(tick_buf_t) == 16, "sizeof(tick_buf_t) == 16"); +#endif typedef struct odp_timer_s { void *user_ptr; @@ -123,7 +134,11 @@ static void timer_init(odp_timer *tim, /* All pad fields need a defined and constant value */ TB_SET_PAD(*tb); /* Release the timer by setting timer state to inactive */ +#if __GCC_ATOMIC_LLONG_LOCK_FREE < 2 + tb->exp_tck.v = TMO_INACTIVE; +#else _odp_atomic_u64_store_mm(&tb->exp_tck, TMO_INACTIVE, _ODP_MEMMODEL_RLS); +#endif } /* Teardown when timer is freed */ @@ -253,7 +268,11 @@ static odp_timer_pool *odp_timer_pool_new( tp->timers[i].queue = ODP_QUEUE_INVALID; set_next_free(&tp->timers[i], i + 1); tp->timers[i].user_ptr = NULL; +#if __GCC_ATOMIC_LLONG_LOCK_FREE < 2 + tp->tick_buf[i].exp_tck.v = TMO_UNUSED; +#else odp_atomic_init_u64(&tp->tick_buf[i].exp_tck, TMO_UNUSED); +#endif tp->tick_buf[i].tmo_buf = ODP_BUFFER_INVALID; } tp->tp_idx = tp_idx; @@ -935,7 +954,11 @@ int odp_timeout_fresh(odp_timeout_t tmo) odp_timer_pool *tp = handle_to_tp(hdl); uint32_t idx = handle_to_idx(hdl, tp); tick_buf_t *tb = &tp->tick_buf[idx]; +#if __GCC_ATOMIC_LLONG_LOCK_FREE < 2 + uint64_t exp_tck = tb->exp_tck.v; +#else uint64_t exp_tck = odp_atomic_load_u64(&tb->exp_tck); +#endif /* Return true if the timer still has the same expiration tick * (ignoring the inactive/expired bit) as the timeout */ return hdr->expiration == (exp_tck & ~TMO_INACTIVE);