Skip to contentSkip to conversation

mbuf: cleanup rte_pktmbuf_lastseg(), fix atomic usage

PATCH Superseded Hanoh Haim 2 participants 2 messages Nov 15, 2017

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Hanoh Haim

author
#0 lore raw

PATCH 1/1 mbuf: cleanup rte_pktmbuf_lastseg(), fix atomic usage

---
 lib/librte_mbuf/rte_mbuf.h | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)
lib/librte_mbuf/rte_mbuf.h +0 -0
index 7e326bb..ab110f8 100644
@@ -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;
Signature · 1 line
2.9.3
#1 lore raw

Hi Hanon,

Quoted 47 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Hanoh Haim
Sent: Wednesday, November 15, 2017 8:36 AM
To: [email protected]
Cc: Hanoh Haim <[email protected]>
Subject: [dpdk-dev] [PATCH] mbuf: cleanup rte_pktmbuf_lastseg(), fix atomic usage

---
 lib/librte_mbuf/rte_mbuf.h | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)
lib/librte_mbuf/rte_mbuf.h +10 -3
index 7e326bb..ab110f8 100644
@@ -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) {

lib/librte_mbuf/rte_mbuf.h rte_pktmbuf_prefree_seg(struct rte_mbuf *m) · line 1368

Quoted 10 lines
lib/librte_mbuf/rte_mbuf.h +2 -6
-			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) {

That would cause extra read; cmp (and possible slowdown) for atomic refcnt.
If that really need to be fixed - probably we need to introduce a new function that would do update without trying to read refctn first - rte_mbuf_refcnt_update_blind() or so. Konstantin

Quoted 16 lines
lib/librte_mbuf/rte_mbuf.h +1 -6
 		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