From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.droids-corp.org (zoll.droids-corp.org [94.23.50.67]) by dpdk.org (Postfix) with ESMTP id 84455106B for ; Fri, 5 Jun 2015 11:08:13 +0200 (CEST) Received: from [37.164.37.64] (helo=[192.168.42.157]) by mail.droids-corp.org with esmtpsa (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1Z0ngE-0002yn-Dq; Fri, 05 Jun 2015 11:12:51 +0200 Message-ID: <557166ED.9070204@6wind.com> Date: Fri, 05 Jun 2015 11:07:57 +0200 From: Olivier MATZ User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.6.0 MIME-Version: 1.0 To: Bruce Richardson References: <1433151145-8176-1-git-send-email-olivier.matz@6wind.com> <20150603105948.GC12832@bricha3-MOBL3> In-Reply-To: <20150603105948.GC12832@bricha3-MOBL3> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit 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: Fri, 05 Jun 2015 09:08:13 -0000 Hi Bruce, On 06/03/2015 12:59 PM, Bruce Richardson wrote: > 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. Good idea, I'll see if I can do that in a new version. Thanks, Olivier > > /Bruce >