From mboxrd@z Thu Jan 1 00:00:00 1970 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) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=AZaAR048geF9HGkL0qhAplWpHb8vjbT3y6nTmgz1mMQ=; b=fta6b0evc8ZHs7hR2R33T32yuEHqqAqQHDGkJ5QFbIrah6eYfFllAB8z5JFRNH8a0E RuFq44AerfKF6qkMDmKmsdJYBebBrjRESHKgK4fzXFoAp/dOwKhq2qGcH2QWWXxGhzWS E4FyKa8Uu7D9ne0TE0bNMjcBWlBcsGLchCZghTHVqOZoLdwHzulo4EiHkAF8AUI1CdE3 jyPOnvcbMb5yPk5RrqdqEeWKChTvW+r2KEAb5PeAhKmcAGIMDljnSiwHSx23olSdqLen UcC/wj7/KxQSIEmfClMe7KExssNAYul5i7JQnaSk+G4Ezc50HqwSNXFw5rtT3h4+A0wW iNQg== X-Gm-Message-State: ALoCoQkuSUD3S+uFe2BStdEEiXj+DO4QZ81NrKSu/d72pXiIeERQExn9djVuXf71fx6xZH562O4n X-Received: by 10.194.176.165 with SMTP id cj5mr40042563wjc.72.1433151161771; 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) From: Olivier Matz To: dev@dpdk.org Date: Mon, 1 Jun 2015 11:32:25 +0200 Message-Id: <1433151145-8176-1-git-send-email-olivier.matz@6wind.com> X-Mailer: git-send-email 2.1.4 Subject: [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: Mon, 01 Jun 2015 09:32:42 -0000 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