From patchwork Wed Mar 11 12:15:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 45630 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DE6CA214BF for ; Wed, 11 Mar 2015 12:16:30 +0000 (UTC) Received: by lbvn10 with SMTP id n10sf6376716lbv.1 for ; Wed, 11 Mar 2015 05:16:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=bhBsAcAEVuTpRGpDXoBdWP54j9lpOhD00IV8hYi1W34=; b=BBf/ATge++envUky9xaGzZ9zo7U672S/KG4a5d6noXYiyYYlv30Gf4bWl0/4aio7nZ dosJcWUrMDXQGmjQrU+xpf7S0GPlKB1DN6aOckz2f3iBGINn+r4h39VQIqnGU4ohT+FO DTF90a3SLRj0rOcFizZu1ZOCcsgkef9thxe+uJqUoLtumupGt9LwKrzH3o3om3G6InpZ I+jBtjMv4ZfxWMlJtY+YT5kgxbejPsXIsZBauDT/oU+WOziQe0WwOjVjqk8y4Dc+UpPt nGFrzsG4RrQF98yJkVVAGAUVxut/BZ2mx26gIpXi3xrRBGQYn377K9RzNnX2kKj95PJC xB5g== X-Gm-Message-State: ALoCoQndcnwVVy7Mfj64VrH1vkad+rcMlZbMSJQIzAK74XIAq9977GW6YFYKp1nQhp33gFZJmyf0 X-Received: by 10.112.13.228 with SMTP id k4mr5330910lbc.8.1426076189963; Wed, 11 Mar 2015 05:16:29 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.10.5 with SMTP id e5ls137168lab.37.gmail; Wed, 11 Mar 2015 05:16:29 -0700 (PDT) X-Received: by 10.152.45.37 with SMTP id j5mr34902441lam.31.1426076189775; Wed, 11 Mar 2015 05:16:29 -0700 (PDT) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id w9si1499513laz.154.2015.03.11.05.16.29 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Mar 2015 05:16:29 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by labgq15 with SMTP id gq15so8325716lab.1 for ; Wed, 11 Mar 2015 05:16:29 -0700 (PDT) X-Received: by 10.112.204.197 with SMTP id la5mr34098168lbc.29.1426076189585; Wed, 11 Mar 2015 05:16:29 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp2737652lbj; Wed, 11 Mar 2015 05:16:28 -0700 (PDT) X-Received: by 10.55.31.94 with SMTP id f91mr22362620qkf.94.1426076188234; Wed, 11 Mar 2015 05:16:28 -0700 (PDT) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id a6si3256478qcc.24.2015.03.11.05.16.25 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 11 Mar 2015 05:16:28 -0700 (PDT) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YVfYl-0005m7-By; Wed, 11 Mar 2015 12:16:23 +0000 Received: from mail-la0-f50.google.com ([209.85.215.50]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YVfYa-0005kp-Ia for lng-odp@lists.linaro.org; Wed, 11 Mar 2015 12:16:12 +0000 Received: by labmn12 with SMTP id mn12so8367975lab.0 for ; Wed, 11 Mar 2015 05:16:06 -0700 (PDT) X-Received: by 10.112.55.5 with SMTP id n5mr14078817lbp.75.1426076166213; Wed, 11 Mar 2015 05:16:06 -0700 (PDT) Received: from localhost.localdomain (ppp91-76-169-66.pppoe.mtu-net.ru. [91.76.169.66]) by mx.google.com with ESMTPSA id a2sm615477lbm.32.2015.03.11.05.16.04 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Mar 2015 05:16:05 -0700 (PDT) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Wed, 11 Mar 2015 15:15:47 +0300 Message-Id: <1426076147-10053-4-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1426076147-10053-1-git-send-email-maxim.uvarov@linaro.org> References: <1426076147-10053-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: timers patch Subject: [lng-odp] [PATCH 3/3] linux-generic: timer: remove atomic ifdef from timer_reset() function body X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: 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-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: maxim.uvarov@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 No functional changes, just make code more readable. Signed-off-by: Maxim Uvarov --- platform/linux-generic/odp_timer.c | 76 +++++++++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 22 deletions(-) diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c index 33c2758..36480ed 100644 --- a/platform/linux-generic/odp_timer.c +++ b/platform/linux-generic/odp_timer.c @@ -334,6 +334,7 @@ static inline odp_buffer_t timer_free(odp_timer_pool *tp, uint32_t idx) * expire/reset/cancel timer *****************************************************************************/ +#ifdef ODP_ATOMIC_U128 static bool timer_reset(uint32_t idx, uint64_t abs_tck, odp_buffer_t *tmo_buf, @@ -343,8 +344,8 @@ 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; @@ -370,11 +371,52 @@ static bool timer_reset(uint32_t idx, (_uint128_t *)&new, _ODP_MEMMODEL_RLS, _ODP_MEMMODEL_RLX)); -#else + } else { + /* We have a new timeout buffer which replaces any old one */ + /* Fill in header fields if timeout event */ + if (_odp_buffer_type(*tmo_buf) == ODP_EVENT_TIMEOUT) { + /* Convert from buffer to timeout hdr */ + odp_timeout_hdr_t *tmo_hdr = + timeout_hdr_from_buf(*tmo_buf); + tmo_hdr->timer = tp_idx_to_handle(tp, idx); + tmo_hdr->user_ptr = tp->timers[idx].user_ptr; + /* expiration field filled in when timer expires */ + } + /* Else ignore buffers of other types */ + odp_buffer_t old_buf = ODP_BUFFER_INVALID; + 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; + /* Return old timeout buffer */ + *tmo_buf = old_buf; + } + return success; +} + +#else /*ODP_ATOMIC_U128*/ + +static bool timer_reset(uint32_t idx, + uint64_t abs_tck, + odp_buffer_t *tmo_buf, + odp_timer_pool *tp) +{ + bool success = true; + tick_buf_t *tb = &tp->tick_buf[idx]; + + if (tmo_buf == NULL || *tmo_buf == ODP_BUFFER_INVALID) { #ifdef __ARM_ARCH /* Since barriers are not good for C-A15, we take an * alternative approach using relaxed memory model */ uint64_t old; + /* Swap in new expiration tick, get back old tick which * will indicate active/inactive timer state */ old = _odp_atomic_u64_xchg_mm(&tb->exp_tck, abs_tck, @@ -398,7 +440,7 @@ static bool timer_reset(uint32_t idx, _ODP_MEMMODEL_RLX); success = false; } -#else +#else /*__ARM_ARCH*/ /* Take a related lock */ while (_odp_atomic_flag_tas(IDX2LOCK(idx))) /* While lock is taken, spin using relaxed loads */ @@ -417,9 +459,10 @@ static bool timer_reset(uint32_t idx, /* Release the lock */ _odp_atomic_flag_clear(IDX2LOCK(idx)); -#endif -#endif +#endif /*__ARM_ARCH*/ } else { + odp_buffer_t old_buf; + /* We have a new timeout buffer which replaces any old one */ /* Fill in header fields if timeout event */ if (_odp_buffer_type(*tmo_buf) == ODP_EVENT_TIMEOUT) { @@ -429,22 +472,10 @@ static bool timer_reset(uint32_t idx, tmo_hdr->timer = tp_idx_to_handle(tp, idx); tmo_hdr->user_ptr = tp->timers[idx].user_ptr; /* expiration field filled in when timer expires */ + } else { + /* Else ignore buffers of other types */ } - /* 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 */ @@ -460,13 +491,14 @@ 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; } + return success; } - +#endif /*ODP_ATOMIC_U128*/ #ifdef ODP_ATOMIC_U128 static odp_buffer_t timer_cancel(odp_timer_pool *tp,