[dpdk-dev] net/thunderx: add compile-time checks

Message ID 20170501064018.5796-1-jerin.jacob@caviumnetworks.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Jerin Jacob May 1, 2017, 6:40 a.m. UTC
  The thunderx PMD is sensitive to the layout of the mbuf on
the RX path. Add in some compile-time checks to make sure the mbuf layout
assumptions are valid, and to provide hints to anyone changing the mbuf
where things may need to be updated.

Signed-off-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>
---
- As previously discussed*, add some compile time checks to the pmds to
help sanity-check their dependencies on the mbuf layout.

* http://dpdk.org/ml/archives/dev/2017-April/064988.html

- Targeted for v17.08
---
 drivers/net/thunderx/nicvf_ethdev.c | 7 +++++++
 1 file changed, 7 insertions(+)
  

Comments

Ferruh Yigit May 12, 2017, 11:24 a.m. UTC | #1
On 5/1/2017 7:40 AM, Jerin Jacob wrote:
> The thunderx PMD is sensitive to the layout of the mbuf on
> the RX path. Add in some compile-time checks to make sure the mbuf layout
> assumptions are valid, and to provide hints to anyone changing the mbuf
> where things may need to be updated.
> 
> Signed-off-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>

Applied to dpdk-next-net/master, thanks.
  

Patch

diff --git a/drivers/net/thunderx/nicvf_ethdev.c b/drivers/net/thunderx/nicvf_ethdev.c
index e4910c9b3..ddcfabaf7 100644
--- a/drivers/net/thunderx/nicvf_ethdev.c
+++ b/drivers/net/thunderx/nicvf_ethdev.c
@@ -1239,6 +1239,13 @@  nicvf_rxq_mbuf_setup(struct nicvf_rxq *rxq)
 	struct rte_mbuf mb_def;
 
 	RTE_BUILD_BUG_ON(sizeof(union mbuf_initializer) != 8);
+	RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, data_off) % 8 != 0);
+	RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, refcnt) -
+				offsetof(struct rte_mbuf, data_off) != 2);
+	RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, nb_segs) -
+				offsetof(struct rte_mbuf, data_off) != 4);
+	RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, port) -
+				offsetof(struct rte_mbuf, data_off) != 6);
 	mb_def.nb_segs = 1;
 	mb_def.data_off = RTE_PKTMBUF_HEADROOM;
 	mb_def.port = rxq->port_id;