From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from aer-iport-2.cisco.com (aer-iport-2.cisco.com [173.38.203.52]) by dpdk.org (Postfix) with ESMTP id 4E3DC7D52 for ; Wed, 15 Nov 2017 09:25:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=1609; q=dns/txt; s=iport; t=1510734315; x=1511943915; h=from:to:cc:subject:date:message-id; bh=rpSq1R41xG7oVby9H4UPbQ4fQ9vfl2ITqgGsUvKg/QU=; b=Crj3lSl109TgDg14nkEbVtM+CpppbKICPcDpt0orJMKi/QDksiVxnH+D +0Ygz1ivk/vV1Kzl7t7sUtTIS7XFvOyinvIbWlW+R+ckQPnfX0gL3iCzt E+rGHo0smXP2Eut/fvbnX86WnzxgSDPbgIcZF5N2DJw5gGxQ7qpGQcfVH 4=; X-IronPort-AV: E=Sophos;i="5.44,398,1505779200"; d="scan'208";a="286196" Received: from aer-iport-nat.cisco.com (HELO aer-core-2.cisco.com) ([173.38.203.22]) by aer-iport-2.cisco.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Nov 2017 08:25:14 +0000 Received: from csi-sceasr-b94.cisco.com (csi-sceasr-b94.cisco.com [144.254.170.76]) by aer-core-2.cisco.com (8.14.5/8.14.5) with ESMTP id vAF8PDol002230 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 15 Nov 2017 08:25:14 GMT Received: from csi-sceasr-b94.cisco.com (localhost.localdomain [127.0.0.1]) by csi-sceasr-b94.cisco.com (8.13.8/8.13.8) with ESMTP id vAF8PDBW016154; Wed, 15 Nov 2017 10:25:13 +0200 Received: (from hhaim@localhost) by csi-sceasr-b94.cisco.com (8.13.8/8.13.8/Submit) id vAF8PD9E016150; Wed, 15 Nov 2017 10:25:13 +0200 From: Hanoh Haim To: dev@dpdk.org Cc: Hanoh Haim Date: Wed, 15 Nov 2017 10:25:11 +0200 Message-Id: <20171115082511.16110-1-hhaim@cisco.com> X-Mailer: git-send-email 2.9.3 Subject: [dpdk-dev] [PATCH] mbuf: cleanup rte_pktmbuf_lastseg(), fix atomic usage X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Nov 2017 08:25:15 -0000 Signed-off-by: Hanoh Haim --- lib/librte_mbuf/rte_mbuf.h | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index 7e326bb..ab110f8 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -1159,6 +1159,15 @@ static inline void rte_pktmbuf_reset(struct rte_mbuf *m) __rte_mbuf_sanity_check(m, 1); } + +static __rte_always_inline void rte_pktmbuf_reset_before_free(struct rte_mbuf *m) +{ + if (m->next != NULL) { + m->next = NULL; + m->nb_segs = 1; + } +} + /** * Allocate a new mbuf from a mempool. * @@ -1323,8 +1332,7 @@ static inline void rte_pktmbuf_detach(struct rte_mbuf *m) m->ol_flags = 0; if (rte_mbuf_refcnt_update(md, -1) == 0) { - md->next = NULL; - md->nb_segs = 1; + rte_pktmbuf_reset_before_free(m); rte_mbuf_refcnt_set(md, 1); rte_mbuf_raw_free(md); } @@ -1354,25 +1362,16 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m) if (RTE_MBUF_INDIRECT(m)) rte_pktmbuf_detach(m); - if (m->next != NULL) { - m->next = NULL; - m->nb_segs = 1; - } - + rte_pktmbuf_reset_before_free(m); return m; - } else if (rte_atomic16_add_return(&m->refcnt_atomic, -1) == 0) { - + } else if (rte_mbuf_refcnt_update(md, -1) == 0) { if (RTE_MBUF_INDIRECT(m)) rte_pktmbuf_detach(m); - if (m->next != NULL) { - m->next = NULL; - m->nb_segs = 1; - } + rte_pktmbuf_reset_before_free(m); rte_mbuf_refcnt_set(m, 1); - return m; } return NULL; -- 2.9.3