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 715C95A89 for ; Fri, 27 Mar 2015 11:50:01 +0100 (CET) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 27 Mar 2015 03:50:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.11,478,1422950400"; d="scan'208";a="705033231" Received: from irsmsx103.ger.corp.intel.com ([163.33.3.157]) by orsmga002.jf.intel.com with ESMTP; 27 Mar 2015 03:49:59 -0700 Received: from irsmsx105.ger.corp.intel.com ([169.254.7.47]) by IRSMSX103.ger.corp.intel.com ([169.254.3.143]) with mapi id 14.03.0224.002; Fri, 27 Mar 2015 10:49:58 +0000 From: "Ananyev, Konstantin" To: Neil Horman , "Richardson, Bruce" Thread-Topic: [dpdk-dev] [PATCH] mbuf: add comment explaining confusing code Thread-Index: AQHQaAoB03aNTYz8GU2NESg47D/16J0wIdwAgAAFMiA= Date: Fri, 27 Mar 2015 10:49:58 +0000 Message-ID: <2601191342CEEE43887BDE71AB97725821407F2E@irsmsx105.ger.corp.intel.com> References: <1427404494-27256-1-git-send-email-bruce.richardson@intel.com> <20150327102956.GB5375@hmsreliant.think-freely.org> In-Reply-To: <20150327102956.GB5375@hmsreliant.think-freely.org> Accept-Language: en-IE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [163.33.239.182] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Cc: "dev@dpdk.org" 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: Fri, 27 Mar 2015 10:50:01 -0000 > -----Original Message----- > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Neil Horman > Sent: Friday, March 27, 2015 10:30 AM > To: Richardson, Bruce > Cc: dev@dpdk.org > Subject: Re: [dpdk-dev] [PATCH] mbuf: add comment explaining confusing co= de >=20 > On Thu, Mar 26, 2015 at 09:14:54PM +0000, 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 "atom= ic" > > + * 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 =3D=3D 1. > > + * If however, ref_cnt !=3D 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) =3D=3D 1) || > > likely (rte_mbuf_refcnt_update(m, -1) =3D=3D 0)) { > > > > -- > > 2.1.0 > > > > >=20 > NAK > the comment is incorrect, a return code of 1 from rte_mbuf_refcnt_read d= oesn't > guarantee you are the last holder of the buffer if two contexts have a po= inter > to it. Comment is absolutely correct. Zoltan's 'fix' will introduce unnecessary slowdown. Acked-by: Konstantin Ananyev >=20 > Zoltans patch is the correct solution here, expensive or not. I wrote up= my > explination in this thread: > http://dpdk.org/ml/archives/dev/2015-March/015839.html >=20