From patchwork Wed Mar 11 12:15:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 45628 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id F21BE214BF for ; Wed, 11 Mar 2015 12:16:20 +0000 (UTC) Received: by wibbs8 with SMTP id bs8sf6871572wib.3 for ; Wed, 11 Mar 2015 05:16:20 -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=au1cXmOKS9ty5iHkP3tKqRDMtfvbyC+V99ODNooj0l8=; b=MZ/tseJu3eGxizwvKBtO07FuYopbbTb+M8F/zcNQdK189/V+gxZ6ppC6uu+I6WHWh1 QCMKbszXgpU+F5IAoTxoDYjjrWS+DBvqUPBafs28KkUl0L//TBlOKkpYFfLpeUcY8HzA a9BN1yFw+RVV2k6/KsUShAGso8LbT7F4/Zaml+x8KsOdpCyuz6cPYsHcIeeI3mq8XfAT q1oWuu/rXuQeOMfbGTar5PBxpp+VRFnKti1z4Pu7NxmwYCJSK6n7qdFgSXkwOicOT3Zk BaBPqxp4rWBKMlHC+9XrbQeM0aPYujmzWSU6uLJGQqeNYi/jBNJvHsiJ+ph3y1YcRpmU uPfA== X-Gm-Message-State: ALoCoQlGS52PHKmSHILQ/rnZgDDNPVknqAG5+HXwKQDBjguCLLaGTmRh+9HSuhrcgXoXluCNIUrL X-Received: by 10.112.148.10 with SMTP id to10mr324553lbb.18.1426076180007; Wed, 11 Mar 2015 05:16:20 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.18.225 with SMTP id z1ls146647lad.109.gmail; Wed, 11 Mar 2015 05:16:19 -0700 (PDT) X-Received: by 10.152.43.201 with SMTP id y9mr33801580lal.25.1426076179855; Wed, 11 Mar 2015 05:16:19 -0700 (PDT) Received: from mail-lb0-f174.google.com (mail-lb0-f174.google.com. [209.85.217.174]) by mx.google.com with ESMTPS id jr14si2169367lab.166.2015.03.11.05.16.19 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Mar 2015 05:16:19 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) client-ip=209.85.217.174; Received: by lbjb6 with SMTP id b6so8308366lbj.9 for ; Wed, 11 Mar 2015 05:16:19 -0700 (PDT) X-Received: by 10.112.172.229 with SMTP id bf5mr33963640lbc.72.1426076179703; Wed, 11 Mar 2015 05:16:19 -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 h5csp2737561lbj; Wed, 11 Mar 2015 05:16:18 -0700 (PDT) X-Received: by 10.141.28.78 with SMTP id f75mr49170246qhe.18.1426076178103; Wed, 11 Mar 2015 05:16:18 -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 md3si3269754qcb.7.2015.03.11.05.16.16 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 11 Mar 2015 05:16:18 -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 1YVfYc-0005lL-Nk; Wed, 11 Mar 2015 12:16:14 +0000 Received: from mail-lb0-f182.google.com ([209.85.217.182]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YVfYW-0005kn-T4 for lng-odp@lists.linaro.org; Wed, 11 Mar 2015 12:16:09 +0000 Received: by lbdu10 with SMTP id u10so8340933lbd.4 for ; Wed, 11 Mar 2015 05:16:02 -0700 (PDT) X-Received: by 10.112.42.164 with SMTP id p4mr27973199lbl.119.1426076162527; Wed, 11 Mar 2015 05:16:02 -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.15.54 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Mar 2015 05:15:55 -0700 (PDT) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Wed, 11 Mar 2015 15:15:45 +0300 Message-Id: <1426076147-10053-2-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 1/3] linux-generic: timer simplify timer_expire 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.217.174 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 Current timer_expire() function implementation for linux-generic is too long and complex. This patch makes it simple to read. No functional changes. Signed-off-by: Maxim Uvarov --- platform/linux-generic/odp_timer.c | 102 ++++++++++++++++++++++--------------- 1 file changed, 61 insertions(+), 41 deletions(-) diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c index 6b48d2e..8b04bd2 100644 --- a/platform/linux-generic/odp_timer.c +++ b/platform/linux-generic/odp_timer.c @@ -506,20 +506,48 @@ static odp_buffer_t timer_cancel(odp_timer_pool *tp, return old_buf; } +static int post_timeout_to_queue(odp_queue_t queue, odp_buffer_t tmo_buf, + uint64_t exp_tck) +{ + odp_timeout_hdr_t *tmo_hdr; + int rc; + + if (odp_unlikely(tmo_buf == ODP_BUFFER_INVALID)) + return 0; + + /* Fill in expiration tick if timeout event */ + if (_odp_buffer_type(tmo_buf) == ODP_EVENT_TIMEOUT) { + /* Convert from buffer to timeout hdr */ + tmo_hdr = timeout_hdr_from_buf(tmo_buf); + tmo_hdr->expiration = exp_tck; + /* timer and user_ptr fields filled in when timer was set */ + } + /* Else ignore events of other types. + * Post the timeout to the destination queue. */ + rc = odp_queue_enq(queue, odp_buffer_to_event(tmo_buf)); + if (odp_unlikely(rc != 0)) + ODP_ABORT("Failed to enqueue timeout buffer (%d)\n", + rc); + return 1; +} + + +#ifdef ODP_ATOMIC_U128 static unsigned timer_expire(odp_timer_pool *tp, uint32_t idx, uint64_t tick) { odp_timer *tim = &tp->timers[idx]; tick_buf_t *tb = &tp->tick_buf[idx]; odp_buffer_t tmo_buf = ODP_BUFFER_INVALID; uint64_t exp_tck; -#ifdef ODP_ATOMIC_U128 + int rc; + tick_buf_t new, old; + /* 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); @@ -529,65 +557,57 @@ static unsigned timer_expire(odp_timer_pool *tp, uint32_t idx, uint64_t tick) 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( + rc = _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) + if (rc) tmo_buf = old.tmo_buf; /* Else CAS failed, something changed => skip timer * this tick, it will be checked again next tick */ + } else { + /* Else false positive, ignore */ } - /* Else false positive, ignore */ + + return post_timeout_to_queue(tim->queue, tmo_buf, exp_tck); +} #else +static unsigned timer_expire(odp_timer_pool *tp, uint32_t idx, uint64_t tick) +{ + odp_timer *tim = &tp->timers[idx]; + tick_buf_t *tb = &tp->tick_buf[idx]; + odp_buffer_t tmo_buf = ODP_BUFFER_INVALID; + uint64_t exp_tck; + /* 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_spin(); + /* Proper check for timer expired */ exp_tck = tb->exp_tck.v; - if (odp_likely(exp_tck <= tick)) { - /* Verify that there is a timeout buffer */ - if (odp_likely(tb->tmo_buf != ODP_BUFFER_INVALID)) { - /* Grab timeout buffer, replace with inactive timer - * and invalid buffer */ - tmo_buf = tb->tmo_buf; - tb->tmo_buf = ODP_BUFFER_INVALID; - /* 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 */ - tb->exp_tck.v |= TMO_INACTIVE; - } + + /* Check that tick expired and verify that there is a timeout buffer */ + if (odp_likely((exp_tck <= tick) && (tb->tmo_buf != ODP_BUFFER_INVALID))) { + /* Grab timeout buffer, replace with inactive timer + * and invalid buffer */ + tmo_buf = tb->tmo_buf; + tb->tmo_buf = ODP_BUFFER_INVALID; + /* 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 */ + tb->exp_tck.v |= TMO_INACTIVE; + } else { /* Else somehow active timer without user buffer */ + /* Else false positive, ignore */ } - /* 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 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->expiration = exp_tck; - /* timer and user_ptr fields filled in when timer - * was set */ - } - /* Else ignore events of other types */ - /* Post the timeout to the destination queue */ - int rc = odp_queue_enq(tim->queue, - odp_buffer_to_event(tmo_buf)); - if (odp_unlikely(rc != 0)) - ODP_ABORT("Failed to enqueue timeout buffer (%d)\n", - rc); - return 1; - } else { - /* Else false positive, ignore */ - return 0; - } + + return post_timeout_to_queue(tim->queue, tmo_buf, exp_tck); } +#endif static unsigned odp_timer_pool_expire(odp_timer_pool_t tpid, uint64_t tick) {