From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from aer-iport-4.cisco.com (aer-iport-4.cisco.com [173.38.203.54]) by dpdk.org (Postfix) with ESMTP id 79CAE1B221 for ; Wed, 15 Nov 2017 09:16:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=1666; q=dns/txt; s=iport; t=1510733815; x=1511943415; h=from:to:cc:subject:date:message-id; bh=XufpBmJmtE+kItGBVxTZzrjOdHQOJTgdQI+k8vvH/Fg=; b=QX6SmtcUPz80Y0Hiu0fqi0mGTGUiLRHL50kpe1vb5hblHZO1NjueW/L1 GwliB2sCLrOdxVasUmbeVFb+sKathFTlnZlYESOt9ug4gDN9bgYgAasL7 cYy3m8hT4cncJ+SDrPb/sfT7wcK6wJfkynKkUgNAjlQfGS7b3Hl2/uyiH 4=; X-IronPort-AV: E=Sophos;i="5.44,398,1505779200"; d="scan'208";a="232051" Received: from aer-iport-nat.cisco.com (HELO aer-core-3.cisco.com) ([173.38.203.22]) by aer-iport-4.cisco.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Nov 2017 08:16:55 +0000 Received: from csi-sceasr-b94.cisco.com (csi-sceasr-b94.cisco.com [144.254.170.76]) by aer-core-3.cisco.com (8.14.5/8.14.5) with ESMTP id vAF8GsRB019440 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 15 Nov 2017 08:16:54 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 vAF8GrSE014534; Wed, 15 Nov 2017 10:16:53 +0200 Received: (from hhaim@localhost) by csi-sceasr-b94.cisco.com (8.13.8/8.13.8/Submit) id vAF8GrNh014530; Wed, 15 Nov 2017 10:16:53 +0200 From: Hanoh Haim To: dev@dpdk.org Cc: Hanoh Haim Date: Wed, 15 Nov 2017 10:16:52 +0200 Message-Id: <20171115081652.14490-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:16:55 -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