DPDK patches and discussions
 help / color / mirror / Atom feed
From: Shijith Thotton <sthotton@marvell.com>
To: <jerinj@marvell.com>
Cc: <thomas@monjalon.net>, Shijith Thotton <sthotton@marvell.com>,
	<dev@dpdk.org>, Olivier Matz <olivier.matz@6wind.com>
Subject: [PATCH] mbuf: add mbuf physical address field to dynamic field
Date: Thu, 30 Jun 2022 21:55:16 +0530	[thread overview]
Message-ID: <57d2ab7fff672716d37ba4078e2e3bb2db126607.1656605763.git.sthotton@marvell.com> (raw)

If all devices are configured to run in IOVA mode as VA, physical
address field of mbuf (buf_iova) won't be used. In such cases, buf_iova
space is free to use as a dynamic field. So a new dynamic field member
(dynfield2) is added in mbuf structure to make use of that space.

A new mbuf flag RTE_MBUF_F_DYNFIELD2 is introduced to help identify the
mbuf that can use dynfield2.

Signed-off-by: Shijith Thotton <sthotton@marvell.com>
---
 lib/mbuf/rte_mbuf.c      |  8 ++++++++
 lib/mbuf/rte_mbuf.h      | 16 +++++++++++++---
 lib/mbuf/rte_mbuf_core.h | 29 ++++++++++++++++++++++-------
 lib/mbuf/rte_mbuf_dyn.c  |  3 +++
 4 files changed, 46 insertions(+), 10 deletions(-)

diff --git a/lib/mbuf/rte_mbuf.c b/lib/mbuf/rte_mbuf.c
index a2307cebe6..718b4505c4 100644
--- a/lib/mbuf/rte_mbuf.c
+++ b/lib/mbuf/rte_mbuf.c
@@ -101,6 +101,10 @@ rte_pktmbuf_init(struct rte_mempool *mp,
 	m->port = RTE_MBUF_PORT_INVALID;
 	rte_mbuf_refcnt_set(m, 1);
 	m->next = NULL;
+
+	/* enable dynfield2 if IOVA mode is VA */
+	if (rte_eal_iova_mode() == RTE_IOVA_VA)
+		m->ol_flags = RTE_MBUF_F_DYNFIELD2;
 }
 
 /*
@@ -206,6 +210,10 @@ __rte_pktmbuf_init_extmem(struct rte_mempool *mp,
 	rte_mbuf_refcnt_set(m, 1);
 	m->next = NULL;
 
+	/* enable dynfield2 if IOVA mode is VA */
+	if (rte_eal_iova_mode() == RTE_IOVA_VA)
+		m->ol_flags |= RTE_MBUF_F_DYNFIELD2;
+
 	/* init external buffer shared info items */
 	shinfo = RTE_PTR_ADD(m, mbuf_size);
 	m->shinfo = shinfo;
diff --git a/lib/mbuf/rte_mbuf.h b/lib/mbuf/rte_mbuf.h
index 9811e8c760..59485f04ed 100644
--- a/lib/mbuf/rte_mbuf.h
+++ b/lib/mbuf/rte_mbuf.h
@@ -1056,9 +1056,11 @@ rte_pktmbuf_attach_extbuf(struct rte_mbuf *m, void *buf_addr,
 	RTE_ASSERT(shinfo->free_cb != NULL);
 
 	m->buf_addr = buf_addr;
-	m->buf_iova = buf_iova;
 	m->buf_len = buf_len;
 
+	if (!RTE_MBUF_HAS_DYNFIELD2(m))
+		m->buf_iova = buf_iova;
+
 	m->data_len = 0;
 	m->data_off = 0;
 
@@ -1087,6 +1089,10 @@ static inline void
 rte_mbuf_dynfield_copy(struct rte_mbuf *mdst, const struct rte_mbuf *msrc)
 {
 	memcpy(&mdst->dynfield1, msrc->dynfield1, sizeof(mdst->dynfield1));
+
+	if (RTE_MBUF_HAS_DYNFIELD2(mdst))
+		memcpy(&mdst->dynfield2, &msrc->dynfield2,
+		       sizeof(mdst->dynfield2));
 }
 
 /* internal */
@@ -1143,10 +1149,12 @@ static inline void rte_pktmbuf_attach(struct rte_mbuf *mi, struct rte_mbuf *m)
 
 	mi->data_off = m->data_off;
 	mi->data_len = m->data_len;
-	mi->buf_iova = m->buf_iova;
 	mi->buf_addr = m->buf_addr;
 	mi->buf_len = m->buf_len;
 
+	if (!RTE_MBUF_HAS_DYNFIELD2(mi))
+		mi->buf_iova = m->buf_iova;
+
 	mi->next = NULL;
 	mi->pkt_len = mi->data_len;
 	mi->nb_segs = 1;
@@ -1245,11 +1253,13 @@ static inline void rte_pktmbuf_detach(struct rte_mbuf *m)
 
 	m->priv_size = priv_size;
 	m->buf_addr = (char *)m + mbuf_size;
-	m->buf_iova = rte_mempool_virt2iova(m) + mbuf_size;
 	m->buf_len = (uint16_t)buf_len;
 	rte_pktmbuf_reset_headroom(m);
 	m->data_len = 0;
 	m->ol_flags = 0;
+
+	if (!RTE_MBUF_HAS_DYNFIELD2(m))
+		m->buf_iova = rte_mempool_virt2iova(m) + mbuf_size;
 }
 
 /**
diff --git a/lib/mbuf/rte_mbuf_core.h b/lib/mbuf/rte_mbuf_core.h
index 3d6ddd6773..a549e36464 100644
--- a/lib/mbuf/rte_mbuf_core.h
+++ b/lib/mbuf/rte_mbuf_core.h
@@ -504,6 +504,8 @@ extern "C" {
 #define RTE_MBUF_F_INDIRECT    (1ULL << 62) /**< Indirect attached mbuf */
 #define IND_ATTACHED_MBUF RTE_DEPRECATED(IND_ATTACHED_MBUF) RTE_MBUF_F_INDIRECT
 
+#define RTE_MBUF_F_DYNFIELD2	(1ULL << 63) /**< dynfield2 mbuf field enabled */
+
 /** Alignment constraint of mbuf private area. */
 #define RTE_MBUF_PRIV_ALIGN 8
 
@@ -579,13 +581,18 @@ struct rte_mbuf {
 	RTE_MARKER cacheline0;
 
 	void *buf_addr;           /**< Virtual address of segment buffer. */
-	/**
-	 * Physical address of segment buffer.
-	 * Force alignment to 8-bytes, so as to ensure we have the exact
-	 * same mbuf cacheline0 layout for 32-bit and 64-bit. This makes
-	 * working on vector drivers easier.
-	 */
-	rte_iova_t buf_iova __rte_aligned(sizeof(rte_iova_t));
+	RTE_STD_C11
+	union {
+		/**
+		 * Physical address of segment buffer if IOVA mode is not VA.
+		 * Force alignment to 8-bytes, so as to ensure we have the exact
+		 * same mbuf cacheline0 layout for 32-bit and 64-bit. This makes
+		 * working on vector drivers easier.
+		 */
+		rte_iova_t buf_iova __rte_aligned(sizeof(rte_iova_t));
+		/* Reserved for dynamic field if IOVA mode is VA. */
+		uint64_t dynfield2;
+	};
 
 	/* next 8 bytes are initialised on RX descriptor rearm */
 	RTE_MARKER64 rearm_data;
@@ -803,6 +810,14 @@ struct rte_mbuf_ext_shared_info {
 #define RTE_MBUF_DIRECT(mb) \
 	(!((mb)->ol_flags & (RTE_MBUF_F_INDIRECT | RTE_MBUF_F_EXTERNAL)))
 
+/**
+ *
+ * Retrurns TRUE if given mbuf has dynfield2 field enabled, or FALSE otherwise.
+ *
+ * dynfield2 field can be enabled if IOVA mode is configured as VA.
+ */
+#define RTE_MBUF_HAS_DYNFIELD2(mb) (!!((mb)->ol_flags & RTE_MBUF_F_DYNFIELD2))
+
 /** Uninitialized or unspecified port. */
 #define RTE_MBUF_PORT_INVALID UINT16_MAX
 /** For backwards compatibility. */
diff --git a/lib/mbuf/rte_mbuf_dyn.c b/lib/mbuf/rte_mbuf_dyn.c
index 4ae79383b5..7bfe50e0e2 100644
--- a/lib/mbuf/rte_mbuf_dyn.c
+++ b/lib/mbuf/rte_mbuf_dyn.c
@@ -127,7 +127,10 @@ init_shared_mem(void)
 		 * rte_mbuf_dynfield_copy().
 		 */
 		memset(shm, 0, sizeof(*shm));
+
 		mark_free(dynfield1);
+		if (rte_eal_iova_mode() == RTE_IOVA_VA)
+			mark_free(dynfield2);
 
 		/* init free_flags */
 		for (mask = RTE_MBUF_F_FIRST_FREE; mask <= RTE_MBUF_F_LAST_FREE; mask <<= 1)
-- 
2.25.1


             reply	other threads:[~2022-06-30 16:25 UTC|newest]

Thread overview: 88+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-30 16:25 Shijith Thotton [this message]
2022-06-30 16:45 ` Stephen Hemminger
2022-07-01 12:16   ` Shijith Thotton
2022-07-01 12:24   ` Shijith Thotton
2022-07-03  7:31     ` Morten Brørup
2022-07-04 14:00       ` Bruce Richardson
2022-08-03 15:34         ` [EXT] " Shijith Thotton
2022-08-29 15:16           ` [PATCH v1 0/4] mbuf dynamic field expansion Shijith Thotton
2022-09-07 13:43             ` [PATCH v2 0/5] " Shijith Thotton
2022-09-21  9:43               ` David Marchand
2022-09-21 14:01                 ` [EXT] " Shijith Thotton
2022-09-21 13:56               ` [PATCH v3 " Shijith Thotton
2022-09-21 13:56                 ` [PATCH v3 1/5] build: add meson option to configure IOVA mode as VA Shijith Thotton
2022-09-28 12:52                   ` Olivier Matz
2022-09-29  5:48                     ` [EXT] " Shijith Thotton
2022-09-21 13:56                 ` [PATCH v3 2/5] mbuf: add second dynamic field member for VA only build Shijith Thotton
2022-09-28  7:24                   ` Thomas Monjalon
2022-09-28 12:52                     ` Olivier Matz
2022-09-28 19:33                       ` Thomas Monjalon
2022-09-28 19:48                       ` Stephen Hemminger
2022-09-29  6:13                         ` [EXT] " Shijith Thotton
2022-09-28 12:52                   ` Olivier Matz
2022-09-21 13:56                 ` [PATCH v3 3/5] lib: move mbuf next pointer to first cache line Shijith Thotton
2022-09-21 14:07                   ` Morten Brørup
2022-09-28 12:52                   ` Olivier Matz
2022-09-29  6:14                     ` [EXT] " Shijith Thotton
2022-09-21 13:56                 ` [PATCH v3 4/5] drivers: mark Marvell cnxk PMDs work with IOVA as VA Shijith Thotton
2022-09-28 12:53                   ` Olivier Matz
2022-09-29  6:19                     ` [EXT] " Shijith Thotton
2022-09-29  7:44                       ` Olivier Matz
2022-09-29  8:10                         ` Shijith Thotton
2022-10-07 20:17                   ` Olivier Matz
2022-10-07 20:22                     ` [EXT] " Shijith Thotton
2022-09-21 13:56                 ` [PATCH v3 5/5] drivers: mark software " Shijith Thotton
2022-09-28  5:41                 ` [PATCH v3 0/5] mbuf dynamic field expansion Shijith Thotton
2022-09-28 12:52                 ` Olivier Matz
2022-09-29  4:51                   ` [EXT] " Shijith Thotton
2022-10-07 13:50                 ` Thomas Monjalon
2022-10-07 19:35                   ` [EXT] " Shijith Thotton
2022-10-07 19:30                 ` [PATCH v4 0/7] " Shijith Thotton
2022-10-07 19:30                   ` [PATCH v4 1/7] mbuf: add API to get and set mbuf physical address Shijith Thotton
2022-10-07 20:16                     ` Olivier Matz
2022-10-07 20:20                       ` [EXT] " Shijith Thotton
2022-10-07 19:30                   ` [PATCH v4 2/7] test/dma: use API to get mbuf data " Shijith Thotton
2022-10-07 20:17                     ` Olivier Matz
2022-10-07 19:30                   ` [PATCH v4 3/7] build: add meson option to configure IOVA mode as PA Shijith Thotton
2022-10-07 19:30                   ` [PATCH v4 4/7] mbuf: add second dynamic field member Shijith Thotton
2022-10-07 19:30                   ` [PATCH v4 5/7] lib: move mbuf next pointer to first cache line Shijith Thotton
2022-10-07 19:30                   ` [PATCH v4 6/7] drivers: mark cnxk PMDs work with IOVA as PA disabled Shijith Thotton
2022-10-07 19:30                   ` [PATCH v4 7/7] drivers: mark software " Shijith Thotton
2022-10-07 20:19                   ` [PATCH v4 0/7] mbuf dynamic field expansion Olivier Matz
2022-10-07 21:02                   ` [PATCH v5 " Shijith Thotton
2022-10-07 21:02                     ` [PATCH v5 1/7] mbuf: add API to get and set mbuf physical address Shijith Thotton
2022-10-07 21:20                       ` Stephen Hemminger
2022-10-07 21:02                     ` [PATCH v5 2/7] test/dma: use API to get mbuf data " Shijith Thotton
2022-10-07 21:02                     ` [PATCH v5 3/7] build: add meson option to configure IOVA mode as PA Shijith Thotton
2022-10-07 21:02                     ` [PATCH v5 4/7] mbuf: add second dynamic field member Shijith Thotton
2022-10-07 21:02                     ` [PATCH v5 5/7] lib: move mbuf next pointer to first cache line Shijith Thotton
2022-10-07 21:22                       ` Stephen Hemminger
2022-10-07 21:30                         ` [EXT] " Shijith Thotton
2022-10-07 21:02                     ` [PATCH v5 6/7] drivers: mark cnxk PMDs work with IOVA as PA disabled Shijith Thotton
2022-10-07 21:02                     ` [PATCH v5 7/7] drivers: mark software " Shijith Thotton
2022-10-09  9:34                     ` [PATCH v5 0/7] mbuf dynamic field expansion Thomas Monjalon
2022-09-07 13:43             ` [PATCH v2 1/5] build: add meson option to configure IOVA mode as VA Shijith Thotton
2022-09-07 15:31               ` Stephen Hemminger
2022-09-07 15:38                 ` Bruce Richardson
2022-09-07 21:33                   ` Morten Brørup
2022-09-07 13:43             ` [PATCH v2 2/5] mbuf: add second dynamic field member for VA only build Shijith Thotton
2022-09-07 13:43             ` [PATCH v2 3/5] lib: move mbuf next pointer to first cache line Shijith Thotton
2022-09-07 13:43             ` [PATCH v2 4/5] drivers: mark Marvell cnxk PMDs work with IOVA as VA Shijith Thotton
2022-09-07 13:43             ` [PATCH v2 5/5] drivers: mark software " Shijith Thotton
2022-08-29 15:16           ` [PATCH v1 1/4] build: add meson option to configure IOVA mode " Shijith Thotton
2022-08-29 18:18             ` Morten Brørup
2022-08-30  8:32               ` Bruce Richardson
2022-08-29 15:16           ` [PATCH v1 2/4] mbuf: add second dynamic field member for VA only build Shijith Thotton
2022-08-29 18:32             ` Morten Brørup
2022-08-30  8:35               ` Bruce Richardson
2022-08-30  8:41                 ` [EXT] " Pavan Nikhilesh Bhagavatula
2022-08-30 13:22                   ` Honnappa Nagarahalli
2022-09-07 13:55                     ` Shijith Thotton
2022-08-29 15:16           ` [PATCH v1 3/4] drivers: mark Marvell cnxk PMDs work with IOVA as VA Shijith Thotton
2022-08-29 15:16           ` [PATCH v1 4/4] drivers: mark software " Shijith Thotton
2022-08-30 13:07     ` [PATCH] mbuf: add mbuf physical address field to dynamic field Ferruh Yigit
2022-09-12 13:19       ` [EXT] " Shijith Thotton
2022-06-30 16:55 ` Bruce Richardson
2022-07-01  9:48   ` Olivier Matz
2022-07-01 11:53     ` Slava Ovsiienko
2022-07-01 12:01     ` [EXT] " Shijith Thotton

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=57d2ab7fff672716d37ba4078e2e3bb2db126607.1656605763.git.sthotton@marvell.com \
    --to=sthotton@marvell.com \
    --cc=dev@dpdk.org \
    --cc=jerinj@marvell.com \
    --cc=olivier.matz@6wind.com \
    --cc=thomas@monjalon.net \
    /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).