From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Hanoch Haim (hhaim)" Subject: Re: [PATCH v4] mbuf: fix mbuf free performance with non atomic refcnt Date: Sun, 10 Dec 2017 08:37:22 +0000 Message-ID: <39032469f9204aa9b707d49670ceebba@XCH-RTP-017.cisco.com> References: <20171115091413.27119-1-hhaim@cisco.com> <20171208154651.16546-1-olivier.matz@6wind.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Cc: "matvejchikov@gmail.com" , "konstantin.ananyev@intel.com" To: Olivier Matz , "dev@dpdk.org" Return-path: Received: from alln-iport-8.cisco.com (alln-iport-8.cisco.com [173.37.142.95]) by dpdk.org (Postfix) with ESMTP id 36EC4293B for ; Sun, 10 Dec 2017 09:37:24 +0100 (CET) In-Reply-To: <20171208154651.16546-1-olivier.matz@6wind.com> Content-Language: en-US List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Oliver, Looks great.=20 Thanks, Hanoh -----Original Message----- From: Olivier Matz [mailto:olivier.matz@6wind.com]=20 Sent: Friday, December 08, 2017 5:47 PM To: dev@dpdk.org; Hanoch Haim (hhaim) Cc: matvejchikov@gmail.com; konstantin.ananyev@intel.com Subject: [PATCH v4] mbuf: fix mbuf free performance with non atomic refcnt When RTE_MBUF_REFCNT_ATOMIC=3Dn, the decrement of the mbuf reference counte= r uses an atomic operation. This is not necessary and impacts the performan= ce (seen with TRex traffic generator). We cannot replace rte_atomic16_add_return() by rte_mbuf_refcnt_update() bec= ause it would add an additional check. Solves this by introducing __rte_mbuf_refcnt_update(), which updates the re= ference counter without doing anything else. Fixes: 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool") Suggested-by: Hanoch Haim Signed-off-by: Olivier Matz --- Hanoh, The following patch implements what was discussed in the thread. Are you ok with it? Thanks, Olivier lib/librte_mbuf/rte_mbuf.h | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index = ce8a05ddf..dd08cb72b 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -764,6 +764,13 @@ rte_mbuf_refcnt_set(struct rte_mbuf *m, uint16_t new_v= alue) rte_atomic16_set(&m->refcnt_atomic, new_value); } =20 +/* internal */ +static inline uint16_t +__rte_mbuf_refcnt_update(struct rte_mbuf *m, int16_t value) { + return (uint16_t)(rte_atomic16_add_return(&m->refcnt_atomic, value));=20 +} + /** * Adds given value to an mbuf's refcnt and returns its new value. * @param m @@ -788,19 +795,26 @@ rte_mbuf_refcnt_update(struct rte_mbuf *m, int16_t va= lue) return 1 + value; } =20 - return (uint16_t)(rte_atomic16_add_return(&m->refcnt_atomic, value)); + return __rte_mbuf_refcnt_update(m, value); } =20 #else /* ! RTE_MBUF_REFCNT_ATOMIC */ =20 +/* internal */ +static inline uint16_t +__rte_mbuf_refcnt_update(struct rte_mbuf *m, int16_t value) { + m->refcnt =3D (uint16_t)(m->refcnt + value); + return m->refcnt; +} + /** * Adds given value to an mbuf's refcnt and returns its new value. */ static inline uint16_t rte_mbuf_refcnt_update(struct rte_mbuf *m, int16_t value) { - m->refcnt =3D (uint16_t)(m->refcnt + value); - return m->refcnt; + return __rte_mbuf_refcnt_update(m, value); } =20 /** @@ -1364,8 +1378,7 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m) =20 return m; =20 - } else if (rte_atomic16_add_return(&m->refcnt_atomic, -1) =3D=3D 0)= { - + } else if (__rte_mbuf_refcnt_update(m, -1) =3D=3D 0) { =20 if (RTE_MBUF_INDIRECT(m)) rte_pktmbuf_detach(m); -- 2.11.0