DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] mbuf: cleanup rte_pktmbuf_lastseg(), fix atomic usage
@ 2017-11-15  8:30 Hanoh Haim
  2017-11-15  8:41 ` Olivier MATZ
  0 siblings, 1 reply; 7+ messages in thread
From: Hanoh Haim @ 2017-11-15  8:30 UTC (permalink / raw)
  To: dev; +Cc: Hanoh Haim

Signed-off-by: Hanoh Haim <hhaim@cisco.com>
---
 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(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

^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: [dpdk-dev] [PATCH] mbuf: cleanup rte_pktmbuf_lastseg(), fix atomic usage
@ 2017-11-15 11:08 Ananyev, Konstantin
  0 siblings, 0 replies; 7+ messages in thread
From: Ananyev, Konstantin @ 2017-11-15 11:08 UTC (permalink / raw)
  To: dev, Hanoh Haim



Hi Hanon,

> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Hanoh Haim
> Sent: Wednesday, November 15, 2017 8:36 AM
> To: dev@dpdk.org
> Cc: Hanoh Haim <hhaim@cisco.com>
> Subject: [dpdk-dev] [PATCH] mbuf: cleanup rte_pktmbuf_lastseg(), fix atomic usage
> 
> Signed-off-by: Hanoh Haim <hhaim@cisco.com>
> ---
>  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) {

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


> 
> 		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

^ permalink raw reply	[flat|nested] 7+ messages in thread
* [dpdk-dev] [PATCH] mbuf: cleanup rte_pktmbuf_lastseg(), fix atomic usage
@ 2017-11-15  8:35 Hanoh Haim
  2017-11-15  8:50 ` Ananyev, Konstantin
  0 siblings, 1 reply; 7+ messages in thread
From: Hanoh Haim @ 2017-11-15  8:35 UTC (permalink / raw)
  To: dev; +Cc: Hanoh Haim

Signed-off-by: Hanoh Haim <hhaim@cisco.com>
---
 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

^ permalink raw reply	[flat|nested] 7+ messages in thread
* [dpdk-dev] [PATCH] mbuf: cleanup rte_pktmbuf_lastseg(), fix atomic usage
@ 2017-11-15  8:25 Hanoh Haim
  0 siblings, 0 replies; 7+ messages in thread
From: Hanoh Haim @ 2017-11-15  8:25 UTC (permalink / raw)
  To: dev; +Cc: Hanoh Haim

Signed-off-by: Hanoh Haim <hhaim@cisco.com>
---
 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

^ permalink raw reply	[flat|nested] 7+ messages in thread
* [dpdk-dev] [PATCH] mbuf: cleanup rte_pktmbuf_lastseg(), fix atomic usage
@ 2017-11-15  8:16 Hanoh Haim
  0 siblings, 0 replies; 7+ messages in thread
From: Hanoh Haim @ 2017-11-15  8:16 UTC (permalink / raw)
  To: dev; +Cc: Hanoh Haim

Signed-off-by: Hanoh Haim <hhaim@cisco.com>
---
 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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-11-15 11:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-15  8:30 [dpdk-dev] [PATCH] mbuf: cleanup rte_pktmbuf_lastseg(), fix atomic usage Hanoh Haim
2017-11-15  8:41 ` Olivier MATZ
  -- strict thread matches above, loose matches on Subject: below --
2017-11-15 11:08 Ananyev, Konstantin
2017-11-15  8:35 Hanoh Haim
2017-11-15  8:50 ` Ananyev, Konstantin
2017-11-15  8:25 Hanoh Haim
2017-11-15  8:16 Hanoh Haim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).