From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from aer-iport-3.cisco.com (aer-iport-3.cisco.com [173.38.203.53]) by dpdk.org (Postfix) with ESMTP id A8001101B for ; Wed, 15 Nov 2017 09:35:51 +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=1510734951; x=1511944551; h=from:to:cc:subject:date:message-id; bh=vJkyq19ayPq+aRAqEiUCaN6SUfTbLs58skoVvyadN1k=; b=KsPrzyV42ZQIi4FgFDGC5humZbNpo2eazS4lxRCn9O4XrLq2CYU2qp9b rw7CaSTl2pun3OEgG2T68+myjyH4x0PmdQ3kpffIxTx2JQlIbkseL0BGX CH8R13oWIXj5C+h9rEBH8p1f1WvV0dq3r1iDxoObK3B2XdEhtD9U91ZjT 8=; X-IronPort-AV: E=Sophos;i="5.44,398,1505779200"; d="scan'208";a="240102" Received: from aer-iport-nat.cisco.com (HELO aer-core-4.cisco.com) ([173.38.203.22]) by aer-iport-3.cisco.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Nov 2017 08:35:51 +0000 Received: from csi-sceasr-b94.cisco.com (csi-sceasr-b94.cisco.com [144.254.170.76]) by aer-core-4.cisco.com (8.14.5/8.14.5) with ESMTP id vAF8ZoXT026302 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 15 Nov 2017 08:35:51 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 vAF8Zof1018616; Wed, 15 Nov 2017 10:35:50 +0200 Received: (from hhaim@localhost) by csi-sceasr-b94.cisco.com (8.13.8/8.13.8/Submit) id vAF8ZoL9018612; Wed, 15 Nov 2017 10:35:50 +0200 From: Hanoh Haim To: dev@dpdk.org Cc: Hanoh Haim Date: Wed, 15 Nov 2017 10:35:48 +0200 Message-Id: <20171115083548.18572-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:35:51 -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(md); 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(m, -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