From patchwork Tue Feb 20 17:00:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 128928 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp4851037ljc; Tue, 20 Feb 2018 09:02:35 -0800 (PST) X-Google-Smtp-Source: AH8x227PMBb12Yk72Fg8PjWNlkuK1aiV1uZ2ELbU3KlGHoYWPVaysX7LF47SQZRSGYDvPK7WO8hN X-Received: by 10.237.37.161 with SMTP id x30mr477726qtc.78.1519146154976; Tue, 20 Feb 2018 09:02:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519146154; cv=none; d=google.com; s=arc-20160816; b=OuCHtxDwYT5Qu9+ll3hD1cqSMVqGbO6c77uAXpsURkPSathj+nQqrsUeipbJfJhuDM W8gi4rB8EekGUzgo/YkL5BwZqlfmWKr39gz1D4zH4LHAKpHa6moZxyGDZbJSKfH8WeEX yT6xO0Ju+eo5NoraZAP7ZgxN51EChh+SiXQgLf0hYRa3BatzE0cB7C9bvWuAK1wo1H8V AySl2Wsr/Z8DIIoBcIyAp4Dy0cUFhK4ASNxa37cQu71zbdnkUp7/LN0GTAp7j+OMGcIW fbjovJSpj4HJ16+GAfcFNHs6KvfImORQeqso4OCdxmEiILeXsT2DDte4ISbgaJPin6gh vzJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=LW+5e4L8+J7JAXvqjrdJmtKtIUS9icys8DSJLZ3aEsI=; b=iFfuH0Kr7E5majsjpgQz+GxefTLpUjVsCn/I/483LnWLhDBHjO3Ao9X9L7iLhp41R8 zXLTWZBpZwiwirXSzXYVEesYm9LEDFNPj5W2P7z+Dg1JiyHW8pNrZEq3hvBvMKlIg38t Ohx9jw/Wfe5R9hVkzcAFRWk32snddPId2h5wYLEWOwE9kZNgMTDUSZmsVnyF91BB/5dE GL9lE8T0N6xxNr0g992ftq1mlJ9AJXKZfvVg5BgxZT/boE7FUa6tW1IKNmCQtBf/yQi6 mWIjaAyLDcJy/Pb9Y8rDXv0LU6JJdbyYv84ht/SRv5Rl4A3zfBbsjVdD+lB0+fcOaM0o gh1g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (ec2-54-197-127-237.compute-1.amazonaws.com. [54.197.127.237]) by mx.google.com with ESMTP id m28si203231qta.91.2018.02.20.09.02.34; Tue, 20 Feb 2018 09:02:34 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) client-ip=54.197.127.237; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id A1D9E61737; Tue, 20 Feb 2018 17:02:34 +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,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL 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 9BA08609ED; Tue, 20 Feb 2018 17:00: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 CF30E6150C; Tue, 20 Feb 2018 17:00:19 +0000 (UTC) Received: from forward102j.mail.yandex.net (forward102j.mail.yandex.net [5.45.198.243]) by lists.linaro.org (Postfix) with ESMTPS id F19B7609A8 for ; Tue, 20 Feb 2018 17:00:12 +0000 (UTC) Received: from mxback12g.mail.yandex.net (mxback12g.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b7:91]) by forward102j.mail.yandex.net (Yandex) with ESMTP id 868B056048D2 for ; Tue, 20 Feb 2018 20:00:10 +0300 (MSK) Received: from smtp2j.mail.yandex.net (smtp2j.mail.yandex.net [2a02:6b8:0:801::ac]) by mxback12g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id nnQVUPsi6v-0AuCZVkT; Tue, 20 Feb 2018 20:00:10 +0300 Received: by smtp2j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id j65fuiFbN5-0AE44VeW; Tue, 20 Feb 2018 20:00:10 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Tue, 20 Feb 2018 20:00:07 +0300 Message-Id: <1519146008-3368-3-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519146008-3368-1-git-send-email-odpbot@yandex.ru> References: <1519146008-3368-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 491 Subject: [lng-odp] [PATCH v1 2/3] linux-gen: timer: don't mark expired timeouts as stale on odp_timer_cancel 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: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Dmitry Eremin-Solenikov Don't replace expiry tick for fired timeouts during odp_timer_cancel(), so that corresponding timeouts won't be reported as stale even though they are fresh. Signed-off-by: Dmitry Eremin-Solenikov --- /** Email created from pull request 491 (lumag:timer-fix-2) ** https://github.com/Linaro/odp/pull/491 ** Patch: https://github.com/Linaro/odp/pull/491.patch ** Base sha: d5419e8857b2bc61d3be17fe53f171550fee426b ** Merge commit sha: 1623e4e7c0742c5238c1b97abe1e8af93f091443 **/ platform/linux-generic/odp_timer.c | 72 ++++++++++++++++++++++++++++++++------ 1 file changed, 62 insertions(+), 10 deletions(-) diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c index bdb25c60e..0928acdeb 100644 --- a/platform/linux-generic/odp_timer.c +++ b/platform/linux-generic/odp_timer.c @@ -375,9 +375,8 @@ static inline odp_timer_t timer_alloc(timer_pool_t *tp, return hdl; } -static odp_buffer_t timer_cancel(timer_pool_t *tp, - uint32_t idx, - uint64_t new_state); +static odp_buffer_t timer_set_unused(timer_pool_t *tp, + uint32_t idx); static inline odp_buffer_t timer_free(timer_pool_t *tp, uint32_t idx) { @@ -385,7 +384,7 @@ static inline odp_buffer_t timer_free(timer_pool_t *tp, uint32_t idx) /* Free the timer by setting timer state to unused and * grab any timeout buffer */ - odp_buffer_t old_buf = timer_cancel(tp, idx, TMO_UNUSED); + odp_buffer_t old_buf = timer_set_unused(tp, idx); /* Destroy timer */ timer_fini(tim, &tp->tick_buf[idx]); @@ -540,9 +539,8 @@ static bool timer_reset(uint32_t idx, return success; } -static odp_buffer_t timer_cancel(timer_pool_t *tp, - uint32_t idx, - uint64_t new_state) +static odp_buffer_t timer_set_unused(timer_pool_t *tp, + uint32_t idx) { tick_buf_t *tb = &tp->tick_buf[idx]; odp_buffer_t old_buf; @@ -550,7 +548,7 @@ static odp_buffer_t timer_cancel(timer_pool_t *tp, #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; + new.exp_tck.v = TMO_UNUSED; /* Swap out the old buffer */ new.tmo_buf = ODP_BUFFER_INVALID; TB_SET_PAD(new); @@ -566,7 +564,7 @@ static odp_buffer_t timer_cancel(timer_pool_t *tp, odp_cpu_pause(); /* Update the timer state (e.g. cancel the current timeout) */ - tb->exp_tck.v = new_state; + tb->exp_tck.v = TMO_UNUSED; /* Swap out the old buffer */ old_buf = tb->tmo_buf; @@ -579,6 +577,60 @@ static odp_buffer_t timer_cancel(timer_pool_t *tp, return old_buf; } +static odp_buffer_t timer_cancel(timer_pool_t *tp, + uint32_t idx) +{ + tick_buf_t *tb = &tp->tick_buf[idx]; + odp_buffer_t old_buf; + +#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 it is not expired already */ + if (!(old.exp_tck.v & TMO_INACTIVE)) + break; + + /* Set up new values */ + new.exp_tck.v = TMO_INACTIVE; + new.tmo_buf = ODP_BUFFER_INVALID; + 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)); + 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 */ + while (_odp_atomic_flag_load(IDX2LOCK(idx))) + odp_cpu_pause(); + + /* Swap in new buffer, save any old buffer */ + old_buf = tb->tmo_buf; + tb->tmo_buf = ODP_BUFFER_INVALID; + + /* Write the new expiration tick if it not cancelled */ + if (!(tb->exp_tck.v & TMO_INACTIVE)) + tb->exp_tck.v = TMO_INACTIVE; + + /* Release the lock */ + _odp_atomic_flag_clear(IDX2LOCK(idx)); +#endif + /* Return the old buffer */ + return old_buf; +} + static unsigned timer_expire(timer_pool_t *tp, uint32_t idx, uint64_t tick) { _odp_timer_t *tim = &tp->timers[idx]; @@ -1109,7 +1161,7 @@ int odp_timer_cancel(odp_timer_t hdl, odp_event_t *tmo_ev) timer_pool_t *tp = handle_to_tp(hdl); uint32_t idx = handle_to_idx(hdl, tp); /* Set the expiration tick of the timer to TMO_INACTIVE */ - odp_buffer_t old_buf = timer_cancel(tp, idx, TMO_INACTIVE); + odp_buffer_t old_buf = timer_cancel(tp, idx); if (old_buf != ODP_BUFFER_INVALID) { *tmo_ev = odp_buffer_to_event(old_buf); return 0; /* Active timer cancelled, timeout returned */