From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 7A691595A for ; Mon, 2 Mar 2015 11:16:30 +0100 (CET) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP; 02 Mar 2015 02:14:07 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.09,674,1418112000"; d="scan'208";a="461251009" Received: from bricha3-mobl3.ger.corp.intel.com ([10.243.20.27]) by FMSMGA003.fm.intel.com with SMTP; 02 Mar 2015 02:10:21 -0800 Received: by (sSMTP sendmail emulation); Mon, 02 Mar 2015 10:16:25 +0025 Date: Mon, 2 Mar 2015 10:16:25 +0000 From: Bruce Richardson To: "Wiles, Keith" Message-ID: <20150302101625.GA8520@bricha3-MOBL3> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Shannon Ltd. User-Agent: Mutt/1.5.23 (2014-03-12) Cc: "dev@dpdk.org" Subject: Re: [dpdk-dev] Do we need the refcnt set to zero again? X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Mar 2015 10:16:30 -0000 On Sat, Feb 28, 2015 at 06:08:16PM +0000, Wiles, Keith wrote: > Looking that the code below does the rte_mbuf_refcnt_set(m,0) need to be present? > > static inline struct rte_mbuf* __attribute__((always_inline)) > __rte_pktmbuf_prefree_seg(struct rte_mbuf *m) > { > __rte_mbuf_sanity_check(m, 0); > > if (likely (rte_mbuf_refcnt_read(m) == 1) || > likely (rte_mbuf_refcnt_update(m, -1) == 0)) { > > rte_mbuf_refcnt_set(m, 0); > > /* if this is an indirect mbuf, then > * - detach mbuf > * - free attached mbuf segment > */ > if (RTE_MBUF_INDIRECT(m)) { > struct rte_mbuf *md = RTE_MBUF_FROM_BADDR(m->buf_addr); > rte_pktmbuf_detach(m); > if (rte_mbuf_refcnt_update(md, -1) == 0) > __rte_mbuf_raw_free(md); > } > return(m); > } > return (NULL); > } > > It seems like the code could be this or did I miss a race-condition? What you are really missing is the initial check for refcnt == 1. In the case of the atomic refcnt, this allows us to skip the atomic decrement operation, which is very expensive, and instead just do a regular assignment of the refcnt to zero, in the refcnt_set call. /Bruce > > static inline struct rte_mbuf* __attribute__((always_inline)) > __rte_pktmbuf_prefree_seg(struct rte_mbuf *m) > { > __rte_mbuf_sanity_check(m, 0); > > /* The sanity check above should have checked for refcnt being zero */ > if ( likely (rte_mbuf_refcnt_update(m, -1) == 0 ) { > > /* if this is an indirect mbuf, then > * - detach mbuf > * - free attached mbuf segment > */ > if (RTE_MBUF_INDIRECT(m)) { > struct rte_mbuf *md = RTE_MBUF_FROM_BADDR(m->buf_addr); > rte_pktmbuf_detach(m); > if (rte_mbuf_refcnt_update(md, -1) == 0) > __rte_mbuf_raw_free(md); > } > return(m); > } > return (NULL); > } >