-
Notifications
You must be signed in to change notification settings - Fork 204
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
Refactor message header alignment and "raw" types to fit a clear pattern #1009
Comments
Regarding discussion that came up in today's CCB - this may also affect/determine how we proceed with #689: This primarily deals with the alignment of messages. The fundamental concern - and what needs to be distinguished here - is what module is actually imposing the alignment requirement. Messages themselves only need to be aligned sufficiently for the types they actually contain (i.e. a message containing only However, the software bus implementation (CFE_SB) internally aligns all of its buffers, and it uses the (historical) Therefore -- since the extra alignement is actually driven by CFE_SB and its underlying implementation - my recommendation is to put the unions here. So:
The reason for following this pattern is that the For a specific case where this distinction matters - consider When sent across the software bus interface - the buffer will actually be 12 bytes or maybe even 16. But that extra padding is only necessary for runtime data alignment - the extra bytes should not be interpreted as part of the message. If these patterns I'm suggesting above are followed then things should mostly work (I think, or at least as well as can be expected using C structs and not a proper data dictionary implementation. |
If you aren't using the aligned headers to define the message, wouldn't we also need to make the raw headers end on the most restrictive boundary, so the payload will always start in the same location (and not break CFE_SB_GetUserData)? For "instantiating a message buffer locally" do you mean do the union between the raw message and
If that's the case, don't @ejtimmon - sounds like this isn't settled yet... |
If I'm interpreting correctly - you are referring to the possibility of a gap occurring between the header as defined by MSG and the actual start of data (for instance if the TLM header is 12 bytes and the payload contains a As you noted in #777 though, the Pedantically speaking there also no guarantee that using Again, padding avoidance is based on the assumption that the most probable worst case payload alignment will be 8 bytes, and it is therefore unlikely that the compiler will add extra padding in this case. "assumption", "probable" and "unlikely" being the key weasel-words here, because technically any compiler can add padding or extra alignment wherever it sees fit on the particular architecture it is compiling for. (i.e. it is entirely plausible that some FPU out there works better with 16 byte alignment, particularly if you use the My main point is - this can result in an unanticipated implicit padding gaps either way - whether the unionized "CFE_SB_CmdHdr_t" was used or the base structure was used to declare the struct. Compilers can do what they want - developers can only guess at the most likely memory padding, nothing is guaranteed about the layout of bits within a struct that isn't directly specified in the C standard. Hence why I would prefer to see the struct definitions in the |
I think so - these seem like surplus types now given the current design. Perhaps we can remove them. |
If my memory serves correctly, the main reason for making
We could simplify a lot by just making the interface type in SB to be |
We need to resolve this ASAP for Caelum... realizing it's not a perfect solution, we need something good enough. I understand the lack of guarantee, but a fix that works for most systems is better than something that is "broken" on all of them. I do dislike CFE_SB_GetUserData, but even if we deprecated it I also think it's undesirable to have the payload start at different locations depending on the alignment requirements of the payload (makes ground system databases more complex). |
Anyways, in an attempt to move forward I'll implement the alignment suggestion on top of #998 so we can at least get a PR in to discuss and see how the pattern settles. |
My recommendation is to use the envelope/post office analogy as I mentioned in #998 (review)
Upon receipt of a message we examine the MsgID and "open" the envelope. This can be a typecast to the CFE_MSG type (typically When sending a message we "wrap" the raw message in the envelope for sending. The CFE SB API should only have abstractions for those basic items which are required for message transport and delivery such as its MsgId and size. These should operate on a The CFE MSG API should have abstractions for all other metadata - timestamps, command codes, checksums, and any other relevant info. The CFE SB API should probably also provide helpers (either macros or helper functions) to facilitate the proper "packaging" and "unpackaging" of these raw messages. Right now this is basically just a typecast that is performed directly in the apps (e.g. casting of |
- Using CFE_SB_Buffer_t where appropriate - Replaced CFE_SB_CMD_HDR_SIZE and CFE_SB_TLM_HDR_SIZE with sizeof the appropriate type - Deprecated CFE_SB_SendMsg, CFE_SB_RcvMsg stubs - Added CFE_SB_TransmitBuffer, CFE_SB_TransmitMsg, and CFE_SB_ReceiveBuffer stubs
- Replaced CFE_SB_SendMsg and CFE_SB_PassMsg with CFE_SB_TransmitMsg - Replaced CFE_SB_ZeroCopySend and CFE_SB_ZeroCopyPass with CFE_SB_TransmitBuffer - Replaced CFE_SB_RcvMsg with CFE_SB_ReceiveBuffer - Used CFE_SB_Buffer_t and CFE_MSG_Message_t where appropriate - Added Cmd to all command types - Changed Syslog to SysLog for consistency - Removed "see also" blocks in documentation, APIs are already grouped and these typically don't add anything useful (simplifies maintenance)
- Added CFE_SB_TransmitMsg, CFE_SB_TransmitBuffer, CFE_SB_ReceiveBuffer (partial nasa#1019 fix) - Replace CFE_SB_RcvMsg with CFE_SB_ReceiveBuffer - Deprecated CFE_SB_SendMsg, CFE_SB_PassMsg, CFE_SB_RcvMsg CFE_SB_ZeroCopyPass, CFE_SB_ZeroCopySend - Use CFE_SB_Buffer_t for receiving and casting to command types - Use CFE_MSG_CommandHeader_t and CFE_MSG_TelemetryHeader_t in command and telemetry type definitions - Use CFE_SB_TransmitMsg to copy the command and telemetry into a CFE_SB_Buffer_t and send it where needed - Avoids need to create send buffers within the app (or union the packet types with CFE_SB_Buffer_t) - Eliminates references to CFE_SB_CmdHdr_t and CFE_SB_TlmHdr_t that formerly enforced alignment since these had potential to change the actual packet sizes - No need to cast to CFE_MSG_Message_t anywhere since it's available in the CFE_SB_Buffer_t union - CFE_MSG_Size_t redefined as size_t to simplify future transition - Replaced Syslog with SysLog for consistency - Added Cmd to all command typedefs - Replaced CFE_SB_CMD_HDR_SIZE and CFE_SB_TLM_HDR_SIZE with sizeof the appropriate type
- Documentation updates for applying the alignment pattern - Added Cmd to all command types - Updated example code - Converted Syslog to SysLog for consistency - CFE_SB_RcvMsg now CFE_SB_ReceiveBuffer - Replaced references to deprecated CFE_SB API's with MSG API's
- CFE_MSG_Message_t no longer worst case alignment - CFE_MSG_CommandHeader_t and CFE_MSG_TelemetryHeader_t now contain the base message type, CFE_MSG_Message_t - Fixed size type issue in CFE_MSG_ComputeChecksum - Replaced CFE_SB_TlmHdr_t and CFE_SB_CmdHdr_t with CFE_MSG_CommandHeader_t and CFE_MSG_TelemetryHeader_t
- Using CFE_SB_Buffer_t where appropriate - Replaced CFE_SB_CMD_HDR_SIZE and CFE_SB_TLM_HDR_SIZE with sizeof the appropriate type - Deprecated CFE_SB_SendMsg, CFE_SB_RcvMsg stubs - Added CFE_SB_TransmitBuffer, CFE_SB_TransmitMsg, and CFE_SB_ReceiveBuffer stubs
- Replaced CFE_SB_SendMsg and CFE_SB_PassMsg with CFE_SB_TransmitMsg - Replaced CFE_SB_ZeroCopySend and CFE_SB_ZeroCopyPass with CFE_SB_TransmitBuffer - Replaced CFE_SB_RcvMsg with CFE_SB_ReceiveBuffer - Used CFE_SB_Buffer_t and CFE_MSG_Message_t where appropriate - Added Cmd to all command types - Changed Syslog to SysLog for consistency - Removed "see also" blocks in documentation, APIs are already grouped and these typically don't add anything useful (simplifies maintenance)
- Added CFE_SB_TransmitMsg, CFE_SB_TransmitBuffer, CFE_SB_ReceiveBuffer (partial nasa#1019 fix) - Replace CFE_SB_RcvMsg with CFE_SB_ReceiveBuffer - Deprecated CFE_SB_SendMsg, CFE_SB_PassMsg, CFE_SB_RcvMsg CFE_SB_ZeroCopyPass, CFE_SB_ZeroCopySend - Use CFE_SB_Buffer_t for receiving and casting to command types - Use CFE_MSG_CommandHeader_t and CFE_MSG_TelemetryHeader_t in command and telemetry type definitions - Use CFE_SB_TransmitMsg to copy the command and telemetry into a CFE_SB_Buffer_t and send it where needed - Avoids need to create send buffers within the app (or union the packet types with CFE_SB_Buffer_t) - Eliminates references to CFE_SB_CmdHdr_t and CFE_SB_TlmHdr_t that formerly enforced alignment since these had potential to change the actual packet sizes - No need to cast to CFE_MSG_Message_t anywhere since it's available in the CFE_SB_Buffer_t union - CFE_MSG_Size_t redefined as size_t to simplify future transition - Replaced Syslog with SysLog for consistency - Added Cmd to all command typedefs - Replaced CFE_SB_CMD_HDR_SIZE and CFE_SB_TLM_HDR_SIZE with sizeof the appropriate type
- Documentation updates for applying the alignment pattern - Added Cmd to all command types - Updated example code - Converted Syslog to SysLog for consistency - CFE_SB_RcvMsg now CFE_SB_ReceiveBuffer - Replaced references to deprecated CFE_SB API's with MSG API's
- CFE_MSG_Message_t no longer worst case alignment - CFE_MSG_CommandHeader_t and CFE_MSG_TelemetryHeader_t now contain the base message type, CFE_MSG_Message_t - Fixed size type issue in CFE_MSG_ComputeChecksum - Replaced CFE_SB_TlmHdr_t and CFE_SB_CmdHdr_t with CFE_MSG_CommandHeader_t and CFE_MSG_TelemetryHeader_t
- Using CFE_SB_Buffer_t where appropriate - Replaced CFE_SB_CMD_HDR_SIZE and CFE_SB_TLM_HDR_SIZE with sizeof the appropriate type - Deprecated CFE_SB_SendMsg, CFE_SB_RcvMsg stubs - Added CFE_SB_TransmitBuffer, CFE_SB_TransmitMsg, and CFE_SB_ReceiveBuffer stubs
- Replaced CFE_SB_SendMsg and CFE_SB_PassMsg with CFE_SB_TransmitMsg - Replaced CFE_SB_ZeroCopySend and CFE_SB_ZeroCopyPass with CFE_SB_TransmitBuffer - Replaced CFE_SB_RcvMsg with CFE_SB_ReceiveBuffer - Used CFE_SB_Buffer_t and CFE_MSG_Message_t where appropriate - Added Cmd to all command types - Changed Syslog to SysLog for consistency - Removed "see also" blocks in documentation, APIs are already grouped and these typically don't add anything useful (simplifies maintenance)
- Added CFE_SB_TransmitMsg, CFE_SB_TransmitBuffer, CFE_SB_ReceiveBuffer (partial nasa#1019 fix) - Replace CFE_SB_RcvMsg with CFE_SB_ReceiveBuffer - Deprecated CFE_SB_SendMsg, CFE_SB_PassMsg, CFE_SB_RcvMsg CFE_SB_ZeroCopyPass, CFE_SB_ZeroCopySend - Use CFE_SB_Buffer_t for receiving and casting to command types - Use CFE_MSG_CommandHeader_t and CFE_MSG_TelemetryHeader_t in command and telemetry type definitions - Use CFE_SB_TransmitMsg to copy the command and telemetry into a CFE_SB_Buffer_t and send it where needed - Avoids need to create send buffers within the app (or union the packet types with CFE_SB_Buffer_t) - Eliminates references to CFE_SB_CmdHdr_t and CFE_SB_TlmHdr_t that formerly enforced alignment since these had potential to change the actual packet sizes - No need to cast to CFE_MSG_Message_t anywhere since it's available in the CFE_SB_Buffer_t union - CFE_MSG_Size_t redefined as size_t to simplify future transition - Replaced Syslog with SysLog for consistency - Added Cmd to all command typedefs - Replaced CFE_SB_CMD_HDR_SIZE and CFE_SB_TLM_HDR_SIZE with sizeof the appropriate type
- Documentation updates for applying the alignment pattern - Added Cmd to all command types - Updated example code - Converted Syslog to SysLog for consistency - CFE_SB_RcvMsg now CFE_SB_ReceiveBuffer - Replaced references to deprecated CFE_SB API's with MSG API's
- CFE_MSG_Message_t no longer worst case alignment - CFE_MSG_CommandHeader_t and CFE_MSG_TelemetryHeader_t now contain the base message type, CFE_MSG_Message_t - Fixed size type issue in CFE_MSG_ComputeChecksum - Replaced CFE_SB_TlmHdr_t and CFE_SB_CmdHdr_t with CFE_MSG_CommandHeader_t and CFE_MSG_TelemetryHeader_t
- Using CFE_SB_Buffer_t where appropriate - Replaced CFE_SB_CMD_HDR_SIZE and CFE_SB_TLM_HDR_SIZE with sizeof the appropriate type - Deprecated CFE_SB_SendMsg, CFE_SB_RcvMsg stubs - Added CFE_SB_TransmitBuffer, CFE_SB_TransmitMsg, and CFE_SB_ReceiveBuffer stubs
- Replaced CFE_SB_SendMsg and CFE_SB_PassMsg with CFE_SB_TransmitMsg - Replaced CFE_SB_ZeroCopySend and CFE_SB_ZeroCopyPass with CFE_SB_TransmitBuffer - Replaced CFE_SB_RcvMsg with CFE_SB_ReceiveBuffer - Used CFE_SB_Buffer_t and CFE_MSG_Message_t where appropriate - Added Cmd to all command types - Changed Syslog to SysLog for consistency - Removed "see also" blocks in documentation, APIs are already grouped and these typically don't add anything useful (simplifies maintenance)
- Added CFE_SB_TransmitMsg, CFE_SB_TransmitBuffer, CFE_SB_ReceiveBuffer (partial nasa#1019 fix) - Replace CFE_SB_RcvMsg with CFE_SB_ReceiveBuffer - Deprecated CFE_SB_SendMsg, CFE_SB_PassMsg, CFE_SB_RcvMsg CFE_SB_ZeroCopyPass, CFE_SB_ZeroCopySend - Use CFE_SB_Buffer_t for receiving and casting to command types - Use CFE_MSG_CommandHeader_t and CFE_MSG_TelemetryHeader_t in command and telemetry type definitions - Use CFE_SB_TransmitMsg to copy the command and telemetry into a CFE_SB_Buffer_t and send it where needed - Avoids need to create send buffers within the app (or union the packet types with CFE_SB_Buffer_t) - Eliminates references to CFE_SB_CmdHdr_t and CFE_SB_TlmHdr_t that formerly enforced alignment since these had potential to change the actual packet sizes - No need to cast to CFE_MSG_Message_t anywhere since it's available in the CFE_SB_Buffer_t union - CFE_MSG_Size_t redefined as size_t to simplify future transition - Replaced Syslog with SysLog for consistency - Added Cmd to all command typedefs - Replaced CFE_SB_CMD_HDR_SIZE and CFE_SB_TLM_HDR_SIZE with sizeof the appropriate type
Is your feature request related to a problem? Please describe.
Aligned version of message headers currently in SB, shows different handling of the base type.
cFE/fsw/cfe-core/src/inc/cfe_sb.h
Lines 150 to 163 in 9804b59
Describe the solution you'd like
See discussion below.
Describe alternatives you've considered
None.
Additional context
Brought up as part of #777/#998 review.
Requester Info
Jacob Hageman - NASA/GSFC (from CCB discussion)
The text was updated successfully, but these errors were encountered: