From patchwork Mon May 16 19:15:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 67915 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp1695137qge; Mon, 16 May 2016 12:15:40 -0700 (PDT) X-Received: by 10.140.135.207 with SMTP id 198mr28099111qhh.73.1463426140425; Mon, 16 May 2016 12:15:40 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id z68si21279507qkd.285.2016.05.16.12.15.40; Mon, 16 May 2016 12:15:40 -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 0905B61757; Mon, 16 May 2016 19:15:40 +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 731C76173D; Mon, 16 May 2016 19:15:33 +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 8B50761750; Mon, 16 May 2016 19:15:19 +0000 (UTC) Received: from mail-lf0-f51.google.com (mail-lf0-f51.google.com [209.85.215.51]) by lists.linaro.org (Postfix) with ESMTPS id 803576174C for ; Mon, 16 May 2016 19:15:16 +0000 (UTC) Received: by mail-lf0-f51.google.com with SMTP id j8so120496558lfd.2 for ; Mon, 16 May 2016 12:15:16 -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; bh=4Fihvm8n/745Jg5erYEZjDHnrNOXR3h6cR33ILYEz3I=; b=SnYr4EBNqI6KTVtOQYA/B1pd0IpKXy0QsydEFBp28oNx3NRkgnZ2AvPvlROgKxcW71 Yae403SfWzzZvmAFSwZuntCzskagsnssoNn+gOsfW2ryzvwl5ELUUzAlGszmDb4RCxPF 98q41R6DSNKIQh3RVmqFAh2Fktv+UrJxBVK/KhDY+zOB/z972jxDkYKaFC9EWs1EZwqN Kv0/uEDdSQt6rHhVXOwp+sRMqumC8/SY0cu233irxA7aJ7K2/2QGLKOfVXLfBQ/tzeBA YsSxKTegBjV3AFjygxyDenw2Ye04BQASx+PO21GDo2ZtiTqvQCU/nTpNoZ6CiHGKNyLA vAdA== X-Gm-Message-State: AOPr4FWfir7/Cr9NHa60pO/pv0gly2KJHqK16FBL05u36sNghNomdrzJjyqx7321A8WhdbUBOMs= X-Received: by 10.25.20.78 with SMTP id k75mr10342146lfi.82.1463426115387; Mon, 16 May 2016 12:15:15 -0700 (PDT) Received: from localhost.localdomain (ppp91-77-173-31.pppoe.mtu-net.ru. [91.77.173.31]) by smtp.gmail.com with ESMTPSA id m7sm5552693lbr.6.2016.05.16.12.15.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 16 May 2016 12:15:14 -0700 (PDT) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Mon, 16 May 2016 22:15:07 +0300 Message-Id: <1463426107-24816-1-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.7.1.250.gff4ea60 X-Topics: timers patch Subject: [lng-odp] [PATCHv2] linux-generic: timer: remove dead 128 bit optimizations 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" Remove totally untested branch with 128 bit optimizations for timer code. This also fixes static assert bug: https://bugs.linaro.org/show_bug.cgi?id=2211 Signed-off-by: Maxim Uvarov --- platform/linux-generic/odp_timer.c | 107 ------------------------------------- 1 file changed, 107 deletions(-) diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c index 6b84309..be28da3 100644 --- a/platform/linux-generic/odp_timer.c +++ b/platform/linux-generic/odp_timer.c @@ -11,15 +11,7 @@ * */ -/* Check if compiler supports 16-byte atomics. GCC needs -mcx16 flag on x86 */ -/* Using spin lock actually seems faster on Core2 */ -#ifdef ODP_ATOMIC_U128 -/* TB_NEEDS_PAD defined if sizeof(odp_buffer_t) != 8 */ -#define TB_NEEDS_PAD -#define TB_SET_PAD(x) ((x).pad = 0) -#else #define TB_SET_PAD(x) (void)(x) -#endif #include @@ -70,11 +62,9 @@ * Mutual exclusion in the absence of CAS16 *****************************************************************************/ -#ifndef ODP_ATOMIC_U128 #define NUM_LOCKS 1024 static _odp_atomic_flag_t locks[NUM_LOCKS]; /* Multiple locks per cache line! */ #define IDX2LOCK(idx) (&locks[(idx) % NUM_LOCKS]) -#endif /****************************************************************************** * Translation between timeout buffer and timeout header @@ -98,17 +88,9 @@ static odp_timeout_hdr_t *timeout_hdr(odp_timeout_t tmo) typedef struct tick_buf_s { odp_atomic_u64_t exp_tck;/* Expiration tick or TMO_xxx */ 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 */ -#endif } tick_buf_t -#ifdef ODP_ATOMIC_U128 -ODP_ALIGNED(16) /* 16-byte atomic operations need properly aligned addresses */ -#endif ; -ODP_STATIC_ASSERT(sizeof(tick_buf_t) == 16, "sizeof(tick_buf_t) == 16"); - typedef struct odp_timer_s { void *user_ptr; odp_queue_t queue;/* Used for free list when timer is free */ @@ -378,34 +360,6 @@ static bool timer_reset(uint32_t idx, tick_buf_t *tb = &tp->tick_buf[idx]; if (tmo_buf == NULL || *tmo_buf == ODP_BUFFER_INVALID) { -#ifdef ODP_ATOMIC_U128 - tick_buf_t new, old; - do { - /* Relaxed and non-atomic read of current values */ - old.exp_tck.v = tb->exp_tck.v; - old.tmo_buf = tb->tmo_buf; - TB_SET_PAD(old); - /* Check if there actually is a timeout buffer - * present */ - if (old.tmo_buf == ODP_BUFFER_INVALID) { - /* Cannot reset a timer with neither old nor - * new timeout buffer */ - success = false; - break; - } - /* Set up new values */ - new.exp_tck.v = abs_tck; - new.tmo_buf = old.tmo_buf; - TB_SET_PAD(new); - /* Atomic CAS will fail if we experienced torn reads, - * retry update sequence until CAS succeeds */ - } while (!_odp_atomic_u128_cmp_xchg_mm( - (_odp_atomic_u128_t *)tb, - (_uint128_t *)&old, - (_uint128_t *)&new, - _ODP_MEMMODEL_RLS, - _ODP_MEMMODEL_RLX)); -#else #ifdef __ARM_ARCH /* Since barriers are not good for C-A15, we take an * alternative approach using relaxed memory model */ @@ -453,7 +407,6 @@ static bool timer_reset(uint32_t idx, /* Release the lock */ _odp_atomic_flag_clear(IDX2LOCK(idx)); #endif -#endif } else { /* We have a new timeout buffer which replaces any old one */ /* Fill in some (constant) header fields for timeout events */ @@ -468,19 +421,6 @@ static bool timer_reset(uint32_t idx, } /* Else ignore buffers of other types */ odp_buffer_t old_buf = ODP_BUFFER_INVALID; -#ifdef ODP_ATOMIC_U128 - tick_buf_t new, old; - new.exp_tck.v = abs_tck; - new.tmo_buf = *tmo_buf; - TB_SET_PAD(new); - /* We are releasing the new timeout buffer to some other - * thread */ - _odp_atomic_u128_xchg_mm((_odp_atomic_u128_t *)tb, - (_uint128_t *)&new, - (_uint128_t *)&old, - _ODP_MEMMODEL_ACQ_RLS); - old_buf = old.tmo_buf; -#else /* Take a related lock */ while (_odp_atomic_flag_tas(IDX2LOCK(idx))) /* While lock is taken, spin using relaxed loads */ @@ -496,7 +436,6 @@ static bool timer_reset(uint32_t idx, /* Release the lock */ _odp_atomic_flag_clear(IDX2LOCK(idx)); -#endif /* Return old timeout buffer */ *tmo_buf = old_buf; } @@ -510,18 +449,6 @@ static odp_buffer_t timer_cancel(odp_timer_pool *tp, tick_buf_t *tb = &tp->tick_buf[idx]; odp_buffer_t old_buf; -#ifdef ODP_ATOMIC_U128 - tick_buf_t new, old; - /* Update the timer state (e.g. cancel the current timeout) */ - new.exp_tck.v = new_state; - /* Swap out the old buffer */ - new.tmo_buf = ODP_BUFFER_INVALID; - TB_SET_PAD(new); - _odp_atomic_u128_xchg_mm((_odp_atomic_u128_t *)tb, - (_uint128_t *)&new, (_uint128_t *)&old, - _ODP_MEMMODEL_RLX); - old_buf = old.tmo_buf; -#else /* Take a related lock */ while (_odp_atomic_flag_tas(IDX2LOCK(idx))) /* While lock is taken, spin using relaxed loads */ @@ -537,7 +464,6 @@ static odp_buffer_t timer_cancel(odp_timer_pool *tp, /* Release the lock */ _odp_atomic_flag_clear(IDX2LOCK(idx)); -#endif /* Return the old buffer */ return old_buf; } @@ -548,34 +474,6 @@ static unsigned timer_expire(odp_timer_pool *tp, uint32_t idx, uint64_t tick) tick_buf_t *tb = &tp->tick_buf[idx]; odp_buffer_t tmo_buf = ODP_BUFFER_INVALID; uint64_t exp_tck; -#ifdef ODP_ATOMIC_U128 - /* Atomic re-read for correctness */ - exp_tck = _odp_atomic_u64_load_mm(&tb->exp_tck, _ODP_MEMMODEL_RLX); - /* Re-check exp_tck */ - if (odp_likely(exp_tck <= tick)) { - /* Attempt to grab timeout buffer, replace with inactive timer - * and invalid buffer */ - tick_buf_t new, old; - old.exp_tck.v = exp_tck; - old.tmo_buf = tb->tmo_buf; - TB_SET_PAD(old); - /* Set the inactive/expired bit keeping the expiration tick so - * that we can check against the expiration tick of the timeout - * when it is received */ - new.exp_tck.v = exp_tck | TMO_INACTIVE; - new.tmo_buf = ODP_BUFFER_INVALID; - TB_SET_PAD(new); - int succ = _odp_atomic_u128_cmp_xchg_mm( - (_odp_atomic_u128_t *)tb, - (_uint128_t *)&old, (_uint128_t *)&new, - _ODP_MEMMODEL_RLS, _ODP_MEMMODEL_RLX); - if (succ) - tmo_buf = old.tmo_buf; - /* Else CAS failed, something changed => skip timer - * this tick, it will be checked again next tick */ - } - /* Else false positive, ignore */ -#else /* Take a related lock */ while (_odp_atomic_flag_tas(IDX2LOCK(idx))) /* While lock is taken, spin using relaxed loads */ @@ -600,7 +498,6 @@ static unsigned timer_expire(odp_timer_pool *tp, uint32_t idx, uint64_t tick) /* Else false positive, ignore */ /* Release the lock */ _odp_atomic_flag_clear(IDX2LOCK(idx)); -#endif if (odp_likely(tmo_buf != ODP_BUFFER_INVALID)) { /* Fill in expiration tick for timeout events */ if (odp_event_type(odp_buffer_to_event(tmo_buf)) == @@ -974,13 +871,9 @@ void odp_timeout_free(odp_timeout_t tmo) int odp_timer_init_global(void) { -#ifndef ODP_ATOMIC_U128 uint32_t i; for (i = 0; i < NUM_LOCKS; i++) _odp_atomic_flag_clear(&locks[i]); -#else - ODP_DBG("Using lock-less timer implementation\n"); -#endif odp_atomic_init_u32(&num_timer_pools, 0); block_sigalarm();