From mboxrd@z Thu Jan 1 00:00:00 1970 From: Olivier Matz Subject: [PATCH] mbuf: optimize first reference increment in rte_pktmbuf_attach Date: Mon, 1 Jun 2015 11:32:25 +0200 Message-ID: <1433151145-8176-1-git-send-email-olivier.matz@6wind.com> To: dev@dpdk.org Return-path: Received: from mail-wi0-f174.google.com (mail-wi0-f174.google.com [209.85.212.174]) by dpdk.org (Postfix) with ESMTP id DB1A41288 for ; Mon, 1 Jun 2015 11:32:41 +0200 (CEST) Received: by wibdq8 with SMTP id dq8so23123940wib.1 for ; Mon, 01 Jun 2015 02:32:41 -0700 (PDT) Received: from glumotte.dev.6wind.com (guy78-3-82-239-227-177.fbx.proxad.net. [82.239.227.177]) by mx.google.com with ESMTPSA id bg4sm20985061wjc.10.2015.06.01.02.32.40 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 01 Jun 2015 02:32:41 -0700 (PDT) List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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