From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 4DBA55693 for ; Wed, 3 Jun 2015 12:59:53 +0200 (CEST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga102.jf.intel.com with ESMTP; 03 Jun 2015 03:59:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,546,1427785200"; d="scan'208";a="502053598" Received: from bricha3-mobl3.ger.corp.intel.com ([10.243.20.22]) by FMSMGA003.fm.intel.com with SMTP; 03 Jun 2015 03:59:50 -0700 Received: by (sSMTP sendmail emulation); Wed, 03 Jun 2015 11:59:49 +0025 Date: Wed, 3 Jun 2015 11:59:49 +0100 From: Bruce Richardson To: Olivier Matz Message-ID: <20150603105948.GC12832@bricha3-MOBL3> References: <1433151145-8176-1-git-send-email-olivier.matz@6wind.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1433151145-8176-1-git-send-email-olivier.matz@6wind.com> Organization: Intel Shannon Ltd. User-Agent: Mutt/1.5.23 (2014-03-12) Cc: dev@dpdk.org Subject: Re: [dpdk-dev] [PATCH] mbuf: optimize first reference increment in rte_pktmbuf_attach 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: Wed, 03 Jun 2015 10:59:53 -0000 On Mon, Jun 01, 2015 at 11:32:25AM +0200, Olivier Matz wrote: > As it's done in __rte_pktmbuf_prefree_seg(), we can avoid using an > atomic increment in rte_pktmbuf_attach() by checking if we are the > only owner of the mbuf first. > > Signed-off-by: Olivier Matz > --- > lib/librte_mbuf/rte_mbuf.h | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h > index ab6de67..cea35b7 100644 > --- a/lib/librte_mbuf/rte_mbuf.h > +++ b/lib/librte_mbuf/rte_mbuf.h > @@ -838,7 +838,11 @@ static inline void rte_pktmbuf_attach(struct rte_mbuf *mi, struct rte_mbuf *m) > else > md = rte_mbuf_from_indirect(m); > > - rte_mbuf_refcnt_update(md, 1); > + /* optimize the case where we are the only owner */ > + if (likely(rte_mbuf_refcnt_read(md) == 1)) > + rte_mbuf_refcnt_set(md, 2); > + else > + rte_mbuf_refcnt_update(md, 1); > mi->priv_size = m->priv_size; > mi->buf_physaddr = m->buf_physaddr; > mi->buf_addr = m->buf_addr; > -- > 2.1.4 > Why not make the change inside rte_mbuf_refcnt_update itself? If it is ever called with a current refcnt of 1, it should always be safe to do the update without a cmpset. /Bruce