[15/15] examples: pack structures when building with MSVC

Message ID 1710968771-16435-16-git-send-email-roretzla@linux.microsoft.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series fix packing of structs when building with MSVC |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/intel-Functional success Functional PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS

Commit Message

Tyler Retzlaff March 20, 2024, 9:06 p.m. UTC
  Add __rte_msvc_pushpack(1) to all __rte_packed structs to cause packing
when building with MSVC.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 examples/common/neon/port_group.h | 1 +
 examples/ip_pipeline/cli.c        | 5 +++++
 examples/ipsec-secgw/ipsec.h      | 1 +
 examples/l3fwd-power/main.c       | 2 ++
 examples/ptpclient/ptpclient.c    | 8 ++++++++
 5 files changed, 17 insertions(+)
  

Comments

Bruce Richardson March 21, 2024, 4:31 p.m. UTC | #1
On Wed, Mar 20, 2024 at 02:06:11PM -0700, Tyler Retzlaff wrote:
> Add __rte_msvc_pushpack(1) to all __rte_packed structs to cause packing
> when building with MSVC.
> 
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> ---
>  examples/common/neon/port_group.h | 1 +
>  examples/ip_pipeline/cli.c        | 5 +++++
>  examples/ipsec-secgw/ipsec.h      | 1 +
>  examples/l3fwd-power/main.c       | 2 ++
>  examples/ptpclient/ptpclient.c    | 8 ++++++++
>  5 files changed, 17 insertions(+)
> 
> diff --git a/examples/common/neon/port_group.h b/examples/common/neon/port_group.h
> index 421e2e8..bd40590 100644
> --- a/examples/common/neon/port_group.h
> +++ b/examples/common/neon/port_group.h
> @@ -21,6 +21,7 @@
>  port_groupx4(uint16_t pn[FWDSTEP + 1], uint16_t *lp, uint16x8_t dp1,
>  		  uint16x8_t dp2)
>  {
> +	__rte_msvc_pack
>  	union {
>  		uint16_t u16[FWDSTEP + 1];
>  		uint64_t u64;
> diff --git a/examples/ip_pipeline/cli.c b/examples/ip_pipeline/cli.c
> index e8269ea..cae5c1f 100644
> --- a/examples/ip_pipeline/cli.c
> +++ b/examples/ip_pipeline/cli.c
> @@ -2566,6 +2566,7 @@
>   *    | lpm
>   *       ipv4 | ipv6 <addr> <depth>
>   */
> +__rte_msvc_pack
>  struct pkt_key_qinq {
>  	uint16_t ethertype_svlan;
>  	uint16_t svlan;
> @@ -2573,6 +2574,7 @@ struct pkt_key_qinq {
>  	uint16_t cvlan;
>  } __rte_packed;
>  
> +__rte_msvc_pack
>  struct pkt_key_ipv4_5tuple {
>  	uint8_t time_to_live;
>  	uint8_t proto;
> @@ -2583,6 +2585,7 @@ struct pkt_key_ipv4_5tuple {
>  	uint16_t dp;
>  } __rte_packed;
>  
> +__rte_msvc_pack
>  struct pkt_key_ipv6_5tuple {
>  	uint16_t payload_length;
>  	uint8_t proto;
> @@ -2593,10 +2596,12 @@ struct pkt_key_ipv6_5tuple {
>  	uint16_t dp;
>  } __rte_packed;
>  
> +__rte_msvc_pack
>  struct pkt_key_ipv4_addr {
>  	uint32_t addr;
>  } __rte_packed;
>  
> +__rte_msvc_pack
>  struct pkt_key_ipv6_addr {
>  	uint8_t addr[16];
>  } __rte_packed;

These structs don't look to me like they need packing. No padding should
appear between elements of the structs. The last struct definitely doesn't
need it, as it's a uint8_t array.

/Bruce
  

Patch

diff --git a/examples/common/neon/port_group.h b/examples/common/neon/port_group.h
index 421e2e8..bd40590 100644
--- a/examples/common/neon/port_group.h
+++ b/examples/common/neon/port_group.h
@@ -21,6 +21,7 @@ 
 port_groupx4(uint16_t pn[FWDSTEP + 1], uint16_t *lp, uint16x8_t dp1,
 		  uint16x8_t dp2)
 {
+	__rte_msvc_pack
 	union {
 		uint16_t u16[FWDSTEP + 1];
 		uint64_t u64;
diff --git a/examples/ip_pipeline/cli.c b/examples/ip_pipeline/cli.c
index e8269ea..cae5c1f 100644
--- a/examples/ip_pipeline/cli.c
+++ b/examples/ip_pipeline/cli.c
@@ -2566,6 +2566,7 @@ 
  *    | lpm
  *       ipv4 | ipv6 <addr> <depth>
  */
+__rte_msvc_pack
 struct pkt_key_qinq {
 	uint16_t ethertype_svlan;
 	uint16_t svlan;
@@ -2573,6 +2574,7 @@  struct pkt_key_qinq {
 	uint16_t cvlan;
 } __rte_packed;
 
+__rte_msvc_pack
 struct pkt_key_ipv4_5tuple {
 	uint8_t time_to_live;
 	uint8_t proto;
@@ -2583,6 +2585,7 @@  struct pkt_key_ipv4_5tuple {
 	uint16_t dp;
 } __rte_packed;
 
+__rte_msvc_pack
 struct pkt_key_ipv6_5tuple {
 	uint16_t payload_length;
 	uint8_t proto;
@@ -2593,10 +2596,12 @@  struct pkt_key_ipv6_5tuple {
 	uint16_t dp;
 } __rte_packed;
 
+__rte_msvc_pack
 struct pkt_key_ipv4_addr {
 	uint32_t addr;
 } __rte_packed;
 
+__rte_msvc_pack
 struct pkt_key_ipv6_addr {
 	uint8_t addr[16];
 } __rte_packed;
diff --git a/examples/ipsec-secgw/ipsec.h b/examples/ipsec-secgw/ipsec.h
index bdcada1..bdc6045 100644
--- a/examples/ipsec-secgw/ipsec.h
+++ b/examples/ipsec-secgw/ipsec.h
@@ -277,6 +277,7 @@  struct socket_ctx {
 	struct rte_mempool *session_pool;
 };
 
+__rte_msvc_pack
 struct cnt_blk {
 	uint32_t salt;
 	uint64_t iv;
diff --git a/examples/l3fwd-power/main.c b/examples/l3fwd-power/main.c
index f4adcf4..a3be37b 100644
--- a/examples/l3fwd-power/main.c
+++ b/examples/l3fwd-power/main.c
@@ -278,6 +278,7 @@  struct lcore_rx_queue {
 #define DEFAULT_HASH_FUNC       rte_jhash
 #endif
 
+__rte_msvc_pack
 struct ipv4_5tuple {
 	uint32_t ip_dst;
 	uint32_t ip_src;
@@ -286,6 +287,7 @@  struct ipv4_5tuple {
 	uint8_t  proto;
 } __rte_packed;
 
+__rte_msvc_pack
 struct ipv6_5tuple {
 	uint8_t  ip_dst[IPV6_ADDR_LEN];
 	uint8_t  ip_src[IPV6_ADDR_LEN];
diff --git a/examples/ptpclient/ptpclient.c b/examples/ptpclient/ptpclient.c
index afb61bb..cdd73fd 100644
--- a/examples/ptpclient/ptpclient.c
+++ b/examples/ptpclient/ptpclient.c
@@ -56,6 +56,7 @@ 
 };
 
 /* Structs used for PTP handling. */
+__rte_msvc_pack
 struct tstamp {
 	uint16_t   sec_msb;
 	uint32_t   sec_lsb;
@@ -66,11 +67,13 @@  struct clock_id {
 	uint8_t id[8];
 };
 
+__rte_msvc_pack
 struct port_id {
 	struct clock_id        clock_id;
 	uint16_t               port_number;
 }  __rte_packed;
 
+__rte_msvc_pack
 struct ptp_header {
 	uint8_t              msg_type;
 	uint8_t              ver;
@@ -86,22 +89,26 @@  struct ptp_header {
 	int8_t               log_message_interval;
 } __rte_packed;
 
+__rte_msvc_pack
 struct sync_msg {
 	struct ptp_header   hdr;
 	struct tstamp       origin_tstamp;
 } __rte_packed;
 
+__rte_msvc_pack
 struct follow_up_msg {
 	struct ptp_header   hdr;
 	struct tstamp       precise_origin_tstamp;
 	uint8_t             suffix[];
 } __rte_packed;
 
+__rte_msvc_pack
 struct delay_req_msg {
 	struct ptp_header   hdr;
 	struct tstamp       origin_tstamp;
 } __rte_packed;
 
+__rte_msvc_pack
 struct delay_resp_msg {
 	struct ptp_header    hdr;
 	struct tstamp        rx_tstamp;
@@ -110,6 +117,7 @@  struct delay_resp_msg {
 } __rte_packed;
 
 struct ptp_message {
+	__rte_msvc_pack
 	union {
 		struct ptp_header          header;
 		struct sync_msg            sync;