From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 29EFED492 for ; Wed, 29 Mar 2017 15:10:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1490793032; x=1522329032; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=otWP/nCjjTSdHMuhWumdiczJP1gbnkgpfnLMXh2SQ8c=; b=mt0TcZ/Fok9nY0xXj4Cn6BhYRG8JUqObobxR34jfgZrR3O2YQ8TVVkcZ 3+KAKNNB0q9FXDSr1+wr0pUxbT/2kg==; Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Mar 2017 06:10:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,241,1486454400"; d="scan'208";a="839655286" Received: from sivswdev01.ir.intel.com ([10.237.217.45]) by FMSMGA003.fm.intel.com with ESMTP; 29 Mar 2017 06:10:14 -0700 From: Bruce Richardson To: olivier.matz@6wind.com Cc: dev@dpdk.org, Bruce Richardson Date: Wed, 29 Mar 2017 14:09:40 +0100 Message-Id: <20170329130941.31190-14-bruce.richardson@intel.com> X-Mailer: git-send-email 2.8.4 In-Reply-To: <20170329130941.31190-1-bruce.richardson@intel.com> References: <20170328203606.27457-1-bruce.richardson@intel.com> <20170329130941.31190-1-bruce.richardson@intel.com> Subject: [dpdk-dev] [PATCH v5 13/14] ring: create common function for updating tail idx X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Mar 2017 13:10:32 -0000 Both producer and consumer use the same logic for updating the tail index so merge into a single function. Signed-off-by: Bruce Richardson Reviewed-by: Yuanhan Liu Acked-by: Olivier Matz --- V3: added check for "single" mode in tail update to buypass unneeded check --- lib/librte_ring/rte_ring.h | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/librte_ring/rte_ring.h b/lib/librte_ring/rte_ring.h index fa66638..3e013ad 100644 --- a/lib/librte_ring/rte_ring.h +++ b/lib/librte_ring/rte_ring.h @@ -341,6 +341,21 @@ void rte_ring_dump(FILE *f, const struct rte_ring *r); } \ } while (0) +static inline __attribute__((always_inline)) void +update_tail(struct rte_ring_headtail *ht, uint32_t old_val, uint32_t new_val, + uint32_t single) +{ + /* + * If there are other enqueues/dequeues in progress that preceded us, + * we need to wait for them to complete + */ + if (!single) + while (unlikely(ht->tail != old_val)) + rte_pause(); + + ht->tail = new_val; +} + /** * @internal This function updates the producer head for enqueue * @@ -440,15 +455,7 @@ __rte_ring_do_enqueue(struct rte_ring *r, void * const *obj_table, ENQUEUE_PTRS(); rte_smp_wmb(); - /* - * If there are other enqueues in progress that preceded us, - * we need to wait for them to complete - */ - while (unlikely(r->prod.tail != prod_head)) - rte_pause(); - - r->prod.tail = prod_next; - + update_tail(&r->prod, prod_head, prod_next, is_sp); end: if (free_space != NULL) *free_space = free_entries - n; @@ -553,14 +560,7 @@ __rte_ring_do_dequeue(struct rte_ring *r, void **obj_table, DEQUEUE_PTRS(); rte_smp_rmb(); - /* - * If there are other enqueues in progress that preceded us, - * we need to wait for them to complete - */ - while (unlikely(r->cons.tail != cons_head)) - rte_pause(); - - r->cons.tail = cons_next; + update_tail(&r->cons, cons_head, cons_next, is_sc); end: if (available != NULL) -- 2.9.3