Skip to content
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

[Galactic] Loan messages implementation #547

Merged
merged 5 commits into from
Aug 9, 2021

Conversation

MiguelCompany
Copy link
Collaborator

This is a backport of #523 into galactic without the need of ros2/rosidl_typesupport_fastrtps#67

MiguelCompany and others added 2 commits July 9, 2021 08:28
* Added is_plain_ attribute to base TypeSupport.
* Added new methods to base TypeSupport.
* Implementation of rmw_borrow_loaned_message.
* Implementation of rmw_return_loaned_message_from_publisher.
* Enable loan messages on publishers of plain types.
* Implementation for taking loaned messages.
* Enable loan messages on subscriptions of plain types.

Signed-off-by: Miguel Company <[email protected]>
Co-authored-by: Michel Hidalgo <[email protected]>
Copy link
Contributor

@hidmic hidmic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM. I'd like to hear @cottsay thoughts on backporting this though.

@@ -50,6 +56,7 @@ struct CustomSubscriberInfo : public CustomEventInfo
const void * type_support_impl_{nullptr};
rmw_gid_t subscription_gid_{};
const char * typesupport_identifier_{nullptr};
std::shared_ptr<rmw_fastrtps_shared_cpp::LoanManager> loan_manager_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MiguelCompany I know these bits are in a grey area when it comes to code visibility but this isn't ABI compatible, strictly speaking.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is, strictly speaking. But rmw_fastrtps_shared_cpp is designed to be only used by rmw_fastrtps_cpp and rmw_fastrtps_dynamic_cpp, which this PR is also modifying. This means ABI is kept to the users of the RMW.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a clearer definition of "public" here. Please correct me if I'm mistaken but as I understand it, this will technically break ABI compatibility even if you don't intend for this struct to be part of the formal rmw_fastrtps* public API. By that, I mean that if we publish this, and I apt update ros-rolling-rmw-fastrtps-shared-cpp without updating the consumers of that package, the consumers won't allocate adequate space for this struct but code in rmw_fastrtps_shared_cpp will try to access it anyway.

One can blur the lines of what constitutes "public API" by claiming that not everything exposed in the headers are formally part of the API, but the linker doesn't care what we say. ABI is ABI, and when you change the size of a struct, it is no longer compatible.

I'm going to bring this up at the next ROS 2 meeting so that we can get some solid documentation on the matter and clearly define our goals regarding ABI stability within a rosdistro so that we can come up with some criteria for when we can break it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new field is added at the end, so offsets of the old fields are not modified. The new field is only being accessed from new functions of rmw_fastrtps_shared_cpp. This means that consumers which are not updated will not be calling code accessing the new field.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed this at the ROS 2 meeting, and it sounds like stability among arbitrary combinations of package updates isn't part of our ABI stability goal, so my concerns are no longer valid. Thanks for your patience.

auto item = loan_mgr->items.emplace_back();
if (nullptr == item) {
RMW_SET_ERROR_MSG("Out of resources for loaned message info");
return RMW_RET_ERROR;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MiguelCompany nit: RMW_RET_BAD_ALLOC?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 1332adb

Signed-off-by: Miguel Company <[email protected]>
@MiguelCompany
Copy link
Collaborator Author

@hidmic @cottsay This is ready for review

@@ -47,6 +47,7 @@ void TypeSupport::set_members(const message_type_support_callbacks_t * members)

// Total size is encapsulation size + data size
m_typeSize = 4 + data_size;
m_typeSize = (m_typeSize + 3) & ~3;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MiguelCompany mind to explain this change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hidmic
TL/DR: Account for RTPS sub-message alignment

The DDSI-RTPS spec requires each submessage to be aligned on a 4-byte boundary. This means that, when using PREALLOCATED memory policy, we could receive a serialized payload bigger than m_typeSize, which would thus be discarded. When using the rmw's default PREALLOCATED_WITH_REALLOC memory policy, an unnecessary reallocation could happen.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some comments on f40ff2d

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. How is this not a problem on master? Upstream Fast-DDS differences?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hidmic You are right! It is a problem on master. I've created #550 with the proper fix.

Signed-off-by: Miguel Company <[email protected]>
@hidmic
Copy link
Contributor

hidmic commented Jul 26, 2021

Galactic CI up to test_rmw_implementation and test_communication, against both Fast-DDS based RMW implementations:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@hidmic
Copy link
Contributor

hidmic commented Jul 29, 2021

Alright, this is good to go. @cottsay ?

@cottsay
Copy link
Member

cottsay commented Jul 29, 2021

Beyond the one ABI break discussed above, this seems like a straightforward feature addition, so 👍 from me. I'd like to hold off on merging until we discuss it at the ROS 2 meeting on Tuesday, however.

@@ -50,6 +56,7 @@ struct CustomSubscriberInfo : public CustomEventInfo
const void * type_support_impl_{nullptr};
rmw_gid_t subscription_gid_{};
const char * typesupport_identifier_{nullptr};
std::shared_ptr<rmw_fastrtps_shared_cpp::LoanManager> loan_manager_;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed this at the ROS 2 meeting, and it sounds like stability among arbitrary combinations of package updates isn't part of our ABI stability goal, so my concerns are no longer valid. Thanks for your patience.

@hidmic
Copy link
Contributor

hidmic commented Aug 9, 2021

Alright. Going in! Thanks for double-checking @cottsay.

@hidmic hidmic merged commit 723a489 into ros2:galactic Aug 9, 2021
mehmetkillioglu pushed a commit to tiiuae/rmw_fastrtps that referenced this pull request Aug 10, 2022
* Loan messages implementation (ros2#523)

* Added is_plain_ attribute to base TypeSupport.
* Added new methods to base TypeSupport.
* Implementation of rmw_borrow_loaned_message.
* Implementation of rmw_return_loaned_message_from_publisher.
* Enable loan messages on publishers of plain types.
* Implementation for taking loaned messages.
* Enable loan messages on subscriptions of plain types.

Signed-off-by: Miguel Company <[email protected]>
Co-authored-by: Michel Hidalgo <[email protected]>

* Changes to work with galactic type support.

Signed-off-by: Miguel Company <[email protected]>

* Improve return code.

Signed-off-by: Miguel Company <[email protected]>

* Prepare type size for alignment requirements.

Signed-off-by: Miguel Company <[email protected]>

* Add comments on alignment code.

Signed-off-by: Miguel Company <[email protected]>

Co-authored-by: Michel Hidalgo <[email protected]>
@MiguelCompany MiguelCompany deleted the loan-messages-galactic branch March 7, 2023 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants