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 AD4AD569D for ; Thu, 26 Mar 2015 22:31:10 +0100 (CET) Received: from was59-1-82-226-113-214.fbx.proxad.net ([82.226.113.214] helo=[192.168.0.10]) by mail.droids-corp.org with esmtpsa (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1YbFQq-00059y-SO; Thu, 26 Mar 2015 22:35:20 +0100 Message-ID: <55147A95.6060102@6wind.com> Date: Thu, 26 Mar 2015 22:31:01 +0100 From: Olivier MATZ User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.5.0 MIME-Version: 1.0 To: Bruce Richardson , dev@dpdk.org References: <1427404494-27256-1-git-send-email-bruce.richardson@intel.com> In-Reply-To: <1427404494-27256-1-git-send-email-bruce.richardson@intel.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH] mbuf: add comment explaining confusing code 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: Thu, 26 Mar 2015 21:31:10 -0000 Hi Bruce, On 03/26/2015 10:14 PM, Bruce Richardson wrote: > The logic used in the condition check before freeing an mbuf is > sometimes confusing, so explain it in a proper comment. > > Signed-off-by: Bruce Richardson > --- > lib/librte_mbuf/rte_mbuf.h | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h > index 17ba791..0265172 100644 > --- a/lib/librte_mbuf/rte_mbuf.h > +++ b/lib/librte_mbuf/rte_mbuf.h > @@ -764,6 +764,16 @@ __rte_pktmbuf_prefree_seg(struct rte_mbuf *m) > { > __rte_mbuf_sanity_check(m, 0); > > + /* > + * Check to see if this is the last reference to the mbuf. > + * Note: the double check here is deliberate. If the ref_cnt is "atomic" > + * the call to "refcnt_update" is a very expensive operation, so we > + * don't want to call it in the case where we know we are the holder > + * of the last reference to this mbuf i.e. ref_cnt == 1. > + * If however, ref_cnt != 1, it's still possible that we may still be > + * the final decrementer of the count, so we need to check that > + * result also, to make sure the mbuf is freed properly. > + */ > if (likely (rte_mbuf_refcnt_read(m) == 1) || > likely (rte_mbuf_refcnt_update(m, -1) == 0)) { > > Acked-by: Olivier Matz Thanks!