From f3429d7a446cb133732e7a78ab21c284b687520d Mon Sep 17 00:00:00 2001 From: Jeff Squyres Date: Fri, 4 Oct 2019 12:09:13 -0700 Subject: [PATCH] btl/usnic: pack a wire data struct Might as well save a few bytes when sending this struct across the network via the __opal_attribute_packed__ attribute. That being said, also re-order the elements in this struct so that there's no holes to begin with. Do this so that the compiler/runtime won't effect (slow) unaligned reads/writes because of the __opal_attribute_packed__ attribute. The "packed" attribute is really more about defensive programming (e.g., if we make a mistake and have a hole, "packed" will remove it for us). *** Do not bring this commit back to existing/already-released release branches: it will cause incompatibility, since it effectively changes the usNIC BTL wire protocol. Signed-off-by: Jeff Squyres --- opal/mca/btl/usnic/btl_usnic_frag.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/opal/mca/btl/usnic/btl_usnic_frag.h b/opal/mca/btl/usnic/btl_usnic_frag.h index 428bac082c..16782debf4 100644 --- a/opal/mca/btl/usnic/btl_usnic_frag.h +++ b/opal/mca/btl/usnic/btl_usnic_frag.h @@ -138,18 +138,24 @@ typedef struct { the length of the packet to meet a minimum size */ uint16_t payload_len; - /* If this is an emulated PUT, store at this address on receiver */ - char *put_addr; - /* Type of BTL header (see enum, above) */ uint8_t payload_type; /* true if there is piggy-backed ACK */ uint8_t ack_present; + /* This field is ordered here so that we have no holes in the + struct. Technically this doesn't matter, because we're using + the __packed__ attribute (so there will be no holes anyway), + but ordering things nicely in the struct prevents the need for + unaligned reads/writes when using _packed__. */ + /* If this is an emulated PUT, store at this address on + receiver */ + char *put_addr; + /* tag for upper layer */ mca_btl_base_tag_t tag; -} opal_btl_usnic_btl_header_t; +} __opal_attribute_packed__ opal_btl_usnic_btl_header_t; /** * BTL header for a chunk of a fragment