From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wg0-f49.google.com (mail-wg0-f49.google.com [74.125.82.49]) by dpdk.org (Postfix) with ESMTP id 7ECDE20F for ; Thu, 26 Mar 2015 19:11:14 +0100 (CET) Received: by wgra20 with SMTP id a20so73299369wgr.3 for ; Thu, 26 Mar 2015 11:11:14 -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:cc:subject:date:message-id; bh=QHfmQSoMxUd35YXNUh+3XqoJTbzzGQxwZdF3QHBIA9Y=; b=Gklkiw8TBqym14hokWDPeOFLD7Ck1Lz+LBmnvCtR2DLp7vq2qSGsFteE6XPtciNfZh Lnyz0nJq8uKPWB5JMXWJaMTSgS3FPhifE41tIoYvQ9GsaweXw8F4B8ta0gjGzWke9BYC 5ObCoGj0VWoLbsxC7Lz10jb8EGnaCN+Q31UpJ2xFXUQOhqwtd2RDc38sYk4p8tGILGSK Fh/s+SyOlaw8jTrkADKzq0utqqxcmxOXVAOEBoHnYvb0KpXXIbqcqzKktKPzvbhzx0O4 XN7czRw2Ay3krCLNT0ooIFM3eMc10rEZMEqLwqcr9YuvV0oZT1O/e3KeeKAJNkY2Wyuf h/4A== X-Gm-Message-State: ALoCoQk0bZETZr/LOw3rNbL1X1Bs3MbmhdaLaESCRd5sHaz+NeXVCokZJfnKH2fh0fz0qj3XZ0lY X-Received: by 10.180.91.103 with SMTP id cd7mr17263345wib.77.1427393474147; Thu, 26 Mar 2015 11:11:14 -0700 (PDT) Received: from localhost.localdomain ([90.152.119.35]) by mx.google.com with ESMTPSA id j7sm10014734wix.4.2015.03.26.11.11.12 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 26 Mar 2015 11:11:13 -0700 (PDT) From: Zoltan Kiss To: dev@dpdk.org Date: Thu, 26 Mar 2015 18:10:57 +0000 Message-Id: <1427393457-7080-1-git-send-email-zoltan.kiss@linaro.org> X-Mailer: git-send-email 1.9.1 X-Mailman-Approved-At: Thu, 26 Mar 2015 20:28:03 +0100 Cc: Zoltan Kiss Subject: [dpdk-dev] [PATCH] mbuf: optimize refcnt handling during free 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 18:11:14 -0000 The current way is not the most efficient: if m->refcnt is 1, the second condition never evaluates, and we set it to 0. If refcnt > 1, the 2nd condition fails again, although the code suggest otherwise to branch prediction. Instead we should keep the second condition only, and remove the duplicate set to zero. Signed-off-by: Zoltan Kiss --- lib/librte_mbuf/rte_mbuf.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index 17ba791..3ec4024 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -764,10 +764,7 @@ __rte_pktmbuf_prefree_seg(struct rte_mbuf *m) { __rte_mbuf_sanity_check(m, 0); - if (likely (rte_mbuf_refcnt_read(m) == 1) || - likely (rte_mbuf_refcnt_update(m, -1) == 0)) { - - rte_mbuf_refcnt_set(m, 0); + if (likely (rte_mbuf_refcnt_update(m, -1) == 0)) { /* if this is an indirect mbuf, then * - detach mbuf -- 1.9.1