-
Notifications
You must be signed in to change notification settings - Fork 395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
prov/efa: Improve efa_rdm_pke
definition
#9471
prov/efa: Improve efa_rdm_pke
definition
#9471
Conversation
#else | ||
static_assert(sizeof(struct efa_rdm_pke) == 128, "efa_rdm_pke check"); | ||
#endif | ||
static_assert(sizeof (struct efa_rdm_pke) % EFA_RDM_PKE_ALIGNMENT == 0, "efa_rdm_pke alignment check"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to make EFA_RDM_PKE_ALIGNMENT 256 when ENABLE_DEBUG=1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. This change makes the size of struct efa_rdm_pke
128 bytes regardless of whether debug mode is enabled or not. The extra struct dlist_entry
when debug mode is enabled is currently smaller than the unused space added by _Alignas(128)
.
In the event the preceding struct members exceed 128 bytes, wiredata
would be at the 256 byte offset, since _Alignas(128)
specifies it be aligned to the nearest 128 byte boundary (Try it online!). So EFA_RDM_PKE_ALIGNMENT
should remain as the intended alignment for wiredata
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then why was there a uint8_t pad[112]
in the ENABLE_DEBUG
condition? It seems like we were trying to align to 256 when ENABLE_DEBUG=1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But performance doesn't matter in debug mode, so I think it's OK to align to 128 all the time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then why was there a
uint8_t pad[112]
in theENABLE_DEBUG
condition? It seems like we were trying to align to 256 when ENABLE_DEBUG=1
You can look through the blame/commit history for context. From my view, it's a side-effect of:
- Padding was originally added just before
wiredata
to align it to 128 bytes. - The debug
struct dlist_entry
was later added further up the struct, which naturally modifies the size/padding. Instead of modifying the original padding at the end of the struct,ENABLE_DEBUG
-only padding was added to align it to 192 bytes. - 64 more
ENABLE_DEBUG
-only bytes were added to align it to 256 due to cache misses.
...which illustrates precisely why manual struct alignment should be avoided when possible (packing is a different story). _Alignas(128)
will always keep wiredata
aligned to a 128 byte offset/boundary without relying on future developers to manually maintain the memory layout of a struct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then why was there a uint8_t pad[112] in the ENABLE_DEBUG condition? It seems like we were trying to align to 256 when ENABLE_DEBUG=1
It was aimed to make both debug and non-debug builds to be 128 aligned. There are more members introduced in debug build which makes efa_rdm_pke exceed 128 bytes, so we seek for the next 128 aligned integer (256)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are safe as long as the total size of efa_rdm_pke can be multiples of 128 bytes for both builds
AWS CI failing due to Windows build test, which uses |
Reached out to @gurugubs for some guidance here. We can either override the |
84480c0
to
c5945a6
Compare
Added a (test) commit to bump |
c5945a6
to
80d0072
Compare
80d0072
to
b9a64ea
Compare
Per @gurugubs, the VS-related files are fine to edit manually (and have been in the past). Specifying |
bot:aws:retest |
Capturing an internal Slack conversation: GCC 4.7 is the earliest version with |
b9a64ea
to
1a67276
Compare
Rebased commits |
Signed-off-by: Darryl Abbate <drl@amazon.com>
This removes the hardcoded padding bytes from the struct definition, which were ostensibly used as a mechanism to enforce alignment of wiredata to the 128 byte boundary. While the static_asserts somewhat protect against changes made to the members which the struct is composed of, the manual calculation is a maintenance headache which is prone to developer error, as well as implementation-defined quirks. More importantly, this change more clearly indicates the intent to align to the 128-byte boundary. This commit also makes the struct size uniform when debug mode is enabled. This wasn't (currently) necessary, as the 32 bytes of padding were already sufficient for the 16-byte dlist_entry struct. This is the C11-compliant version, utilizing _Alignas (stdalign.h) Signed-off-by: Darryl Abbate <drl@amazon.com>
1a67276
to
17476b9
Compare
Rebasing again |
#else | ||
static_assert(sizeof(struct efa_rdm_pke) == 128, "efa_rdm_pke check"); | ||
#endif | ||
static_assert(sizeof (struct efa_rdm_pke) % EFA_RDM_PKE_ALIGNMENT == 0, "efa_rdm_pke alignment check"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are safe as long as the total size of efa_rdm_pke can be multiples of 128 bytes for both builds
Do you think this need to be part of 1.20 release? @darrylabbate |
This removes the hardcoded padding bytes from the struct definition, which were ostensibly used as a mechanism to enforce alignment of
wiredata
to the 128 byte boundary.While the
static_assert
s somewhat protect against changes made to the members which the struct is composed of, the manual calculation is a maintenance headache which is prone to developer error, as well as implementation-defined quirks.More importantly, this change more clearly indicates the intent to align to the 128-byte boundary.
This commit also makes the struct size uniform when debug mode is enabled. This wasn't (currently) necessary, as the 32 bytes of padding were already sufficient for the 16-byte
dlist_entry
struct.This is the C11-compliant version, utilizing
_Alignas
(stdalign.h)For sake of comparison, I also pushed a (less-preferred) C99 version: darrylabbate@b479b5c