[PATCH v2] mbuf: replace GCC marker extension with C11 anonymous unions

Morten Brørup mb at smartsharesystems.com
Tue Feb 13 17:58:21 CET 2024


> From: Tyler Retzlaff [mailto:roretzla at linux.microsoft.com]
> Sent: Tuesday, 13 February 2024 07.46
> 
> Replace the use of RTE_MARKER<x> with C11 anonymous unions to improve
> code portability between toolchains.

How about combining the cacheline 0 marker and padding, like this:

 struct rte_mbuf {
-	RTE_MARKER cacheline0;
+	union {
+		char cacheline0[RTE_CACHE_LINE_MIN_SIZE];
 
+		struct {
-	void *buf_addr;           /**< Virtual address of segment buffer. */
+			void *buf_addr; /**< Virtual address of segment buffer. */
 #if RTE_IOVA_IN_MBUF


You could do the same with the cacheline1 marker:

	/* second cache line - fields only used in slow path or on TX */
-	RTE_MARKER cacheline1 __rte_cache_min_aligned;
+	union {
+		char cacheline1[RTE_CACHE_LINE_MIN_SIZE];
 
+		struct {
 #if RTE_IOVA_IN_MBUF
-	/**
-	 * Next segment of scattered packet. Must be NULL in the last
-	 * segment or in case of non-segmented packet.
-	 */
-	struct rte_mbuf *next;
+			/**
+			 * Next segment of scattered packet. Must be NULL in the last
+			 * segment or in case of non-segmented packet.
+			 */
+			struct rte_mbuf *next;
 #else


It also avoids the weird union between cacheline0 and buf_addr at the beginning of the structure, and between cacheline1 and next/dynfield2 at the beginning of the second cache line.

And then you can omit the pad_cacheline0 array at the end of the first part of the structure.


BTW: char is a weaker type than uint8_t - i.e. it is easier to cast to another type.
It might be a personal preference, but I would use char instead of uint8_t for the padding array.



More information about the dev mailing list