Skip to content

Commit f3429d7

Browse files
committed
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 <[email protected]>
1 parent b774b47 commit f3429d7

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

opal/mca/btl/usnic/btl_usnic_frag.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,24 @@ typedef struct {
138138
the length of the packet to meet a minimum size */
139139
uint16_t payload_len;
140140

141-
/* If this is an emulated PUT, store at this address on receiver */
142-
char *put_addr;
143-
144141
/* Type of BTL header (see enum, above) */
145142
uint8_t payload_type;
146143

147144
/* true if there is piggy-backed ACK */
148145
uint8_t ack_present;
149146

147+
/* This field is ordered here so that we have no holes in the
148+
struct. Technically this doesn't matter, because we're using
149+
the __packed__ attribute (so there will be no holes anyway),
150+
but ordering things nicely in the struct prevents the need for
151+
unaligned reads/writes when using _packed__. */
152+
/* If this is an emulated PUT, store at this address on
153+
receiver */
154+
char *put_addr;
155+
150156
/* tag for upper layer */
151157
mca_btl_base_tag_t tag;
152-
} opal_btl_usnic_btl_header_t;
158+
} __opal_attribute_packed__ opal_btl_usnic_btl_header_t;
153159

154160
/**
155161
* BTL header for a chunk of a fragment

0 commit comments

Comments
 (0)