DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Morten Brørup" <mb@smartsharesystems.com>
To: dev@dpdk.org
Cc: "Morten Brørup" <mb@smartsharesystems.com>
Subject: [PATCH v2] mbuf: always use default headroom (TEST ONLY)
Date: Fri, 29 Sep 2023 20:21:09 +0200	[thread overview]
Message-ID: <20230929182109.33244-1-mb@smartsharesystems.com> (raw)
In-Reply-To: <20230929175614.32855-1-mb@smartsharesystems.com>

This is a test. Please ignore.

It seems silly using a non-default headroom when attaching external memory.

Most functions assume default headroom, so don't reset to anything less.

Signed-off-by: Morten Brørup <mb@smartsharesystems.com>
---
 app/test/test_mbuf.c       |  8 ++++----
 drivers/net/mlx5/mlx5_rx.h |  1 -
 lib/mbuf/rte_mbuf.c        |  4 ++--
 lib/mbuf/rte_mbuf.h        | 15 +++++++--------
 lib/vhost/virtio_net.c     |  1 -
 5 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/app/test/test_mbuf.c b/app/test/test_mbuf.c
index d7393df7eb..f10eee6ea7 100644
--- a/app/test/test_mbuf.c
+++ b/app/test/test_mbuf.c
@@ -608,9 +608,9 @@ test_attach_from_different_pool(struct rte_mempool *pktmbuf_pool,
 
 	/* save data pointer to compare it after detach() */
 	c_data = rte_pktmbuf_mtod(clone, char *);
-	if (c_data != (char *)clone + sizeof(*clone) + MBUF2_PRIV_SIZE)
+	if (c_data != (char *)clone + sizeof(*clone) + MBUF2_PRIV_SIZE + RTE_PKTMBUF_HEADROOM)
 		GOTO_FAIL("bad data pointer in clone");
-	if (rte_pktmbuf_headroom(clone) != 0)
+	if (rte_pktmbuf_headroom(clone) != RTE_PKTMBUF_HEADROOM)
 		GOTO_FAIL("bad headroom in clone");
 
 	rte_pktmbuf_attach(clone, m);
@@ -637,9 +637,9 @@ test_attach_from_different_pool(struct rte_mempool *pktmbuf_pool,
 
 	/* save data pointer to compare it after detach() */
 	c_data2 = rte_pktmbuf_mtod(clone2, char *);
-	if (c_data2 != (char *)clone2 + sizeof(*clone2) + MBUF2_PRIV_SIZE)
+	if (c_data2 != (char *)clone2 + sizeof(*clone2) + MBUF2_PRIV_SIZE + RTE_PKTMBUF_HEADROOM)
 		GOTO_FAIL("bad data pointer in clone2");
-	if (rte_pktmbuf_headroom(clone2) != 0)
+	if (rte_pktmbuf_headroom(clone2) != RTE_PKTMBUF_HEADROOM)
 		GOTO_FAIL("bad headroom in clone2");
 
 	rte_pktmbuf_attach(clone2, clone);
diff --git a/drivers/net/mlx5/mlx5_rx.h b/drivers/net/mlx5/mlx5_rx.h
index baeb4797aa..0927ac13ea 100644
--- a/drivers/net/mlx5/mlx5_rx.h
+++ b/drivers/net/mlx5/mlx5_rx.h
@@ -546,7 +546,6 @@ mprq_buf_to_pkt(struct mlx5_rxq_data *rxq, struct rte_mbuf *pkt, uint32_t len,
 		rte_pktmbuf_attach_extbuf(pkt, buf_addr, buf_iova,
 					  buf_len, shinfo);
 		/* Set mbuf head-room. */
-		SET_DATA_OFF(pkt, RTE_PKTMBUF_HEADROOM);
 		MLX5_ASSERT(pkt->ol_flags & RTE_MBUF_F_EXTERNAL);
 		MLX5_ASSERT(rte_pktmbuf_tailroom(pkt) >=
 			len - (hdrm_overlap > 0 ? hdrm_overlap : 0));
diff --git a/lib/mbuf/rte_mbuf.c b/lib/mbuf/rte_mbuf.c
index 686e797c80..7ccc814a75 100644
--- a/lib/mbuf/rte_mbuf.c
+++ b/lib/mbuf/rte_mbuf.c
@@ -93,7 +93,7 @@ rte_pktmbuf_init(struct rte_mempool *mp,
 	m->buf_len = (uint16_t)buf_len;
 
 	/* keep some headroom between start of buffer and data */
-	m->data_off = RTE_MIN(RTE_PKTMBUF_HEADROOM, (uint16_t)m->buf_len);
+	rte_pktmbuf_reset_headroom(m);
 
 	/* init some constant fields */
 	m->pool = mp;
@@ -196,7 +196,7 @@ __rte_pktmbuf_init_extmem(struct rte_mempool *mp,
 		++ctx->ext;
 	}
 	/* keep some headroom between start of buffer and data */
-	m->data_off = RTE_MIN(RTE_PKTMBUF_HEADROOM, (uint16_t)m->buf_len);
+	rte_pktmbuf_reset_headroom(m);
 
 	/* init some constant fields */
 	m->pool = mp;
diff --git a/lib/mbuf/rte_mbuf.h b/lib/mbuf/rte_mbuf.h
index 913c459b1c..b1047bc848 100644
--- a/lib/mbuf/rte_mbuf.h
+++ b/lib/mbuf/rte_mbuf.h
@@ -859,8 +859,7 @@ rte_pktmbuf_priv_size(struct rte_mempool *mp)
  */
 static inline void rte_pktmbuf_reset_headroom(struct rte_mbuf *m)
 {
-	m->data_off = (uint16_t)RTE_MIN((uint16_t)RTE_PKTMBUF_HEADROOM,
-					(uint16_t)m->buf_len);
+	m->data_off = RTE_PKTMBUF_HEADROOM;
 }
 
 /**
@@ -1028,14 +1027,14 @@ rte_pktmbuf_ext_shinfo_init_helper(void *buf_addr, uint16_t *buf_len,
  * provided via shinfo. This callback function will be called once all the
  * mbufs are detached from the buffer (refcnt becomes zero).
  *
- * The headroom length of the attaching mbuf will be set to zero and this
- * can be properly adjusted after attachment. For example, ``rte_pktmbuf_adj()``
- * or ``rte_pktmbuf_reset_headroom()`` might be used.
- *
- * Similarly, the packet length is initialized to 0. If the buffer contains
+ * The packet length is initialized to 0. If the buffer contains
  * data, the user has to adjust ``data_len`` and the ``pkt_len`` field of
  * the mbuf accordingly.
  *
+ * Similarly, the headroom length of the attaching mbuf will be set to the
+ * default (RTE_PKTMBUF_HEADROOM). This can also be properly adjusted after
+ * attachment. For example, ``rte_pktmbuf_adj()`` might be used.
+ *
  * More mbufs can be attached to the same external buffer by
  * ``rte_pktmbuf_attach()`` once the external buffer has been attached by
  * this API.
@@ -1094,7 +1093,7 @@ rte_pktmbuf_attach_extbuf(struct rte_mbuf *m, void *buf_addr,
 	m->buf_len = buf_len;
 
 	m->data_len = 0;
-	m->data_off = 0;
+	rte_pktmbuf_reset_headroom(m);
 
 	m->ol_flags |= RTE_MBUF_F_EXTERNAL;
 	m->shinfo = shinfo;
diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c
index 759a78e3e3..61e6fa1864 100644
--- a/lib/vhost/virtio_net.c
+++ b/lib/vhost/virtio_net.c
@@ -3042,7 +3042,6 @@ virtio_dev_extbuf_alloc(struct virtio_net *dev, struct rte_mbuf *pkt, uint32_t s
 
 	iova = rte_malloc_virt2iova(buf);
 	rte_pktmbuf_attach_extbuf(pkt, buf, iova, buf_len, shinfo);
-	rte_pktmbuf_reset_headroom(pkt);
 
 	return 0;
 }
-- 
2.17.1


      reply	other threads:[~2023-09-29 18:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-29 17:56 [PATCH] " Morten Brørup
2023-09-29 18:21 ` Morten Brørup [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230929182109.33244-1-mb@smartsharesystems.com \
    --to=mb@smartsharesystems.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).