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

Create a utility function to limit rmw_time_t to 32-bit values #37

Merged
merged 4 commits into from
Nov 10, 2020

Conversation

mjeronimo
Copy link
Contributor

The RMW layer maintains the rmw_time_t's seconds and nanoseconds
values as 64-bit unsigned integers. However, the DDS standard
specifies the Time_t and Duration_t types with "long sec" and
"unsigned long nanosec", and the IDL to C++11 mapping states that
the C++ types for long and unsigned long are mapped to int32_t and
uint32_t, respectively. This difference can result in the seconds
(and/or nanoseconds) value being truncated and incorrect, causing
other downstream failures. This function can be used in different
RMW adaptation layers that interface to the DDS providers when
converting from rmw_time_to to the DDS Duration_t (or Time_t),
such as rmw_time_to_fast_rtps.

Signed-off-by: Michael Jeronimo michael.jeronimo@openrobotics.org

The RMW layer maintains the rmw_time_t's seconds and nanoseconds
values as 64-bit unsigned integers. However, the DDS standard
specifies the Time_t and Duration_t types with "long sec" and
"unsigned long nanosec", and the IDL to C++11 mapping states that
the C++ types for long and unsigned long are mapped to int32_t and
uint32_t, respectively. This difference can result in the seconds
(and/or nanoseconds) value being truncated and incorrect, causing
other downstream failures. This function can be used in different
RMW adaptation layers that interface to the DDS providers when
converting from rmw_time_to to the DDS Duration_t (or Time_t),
such as rmw_time_to_fast_rtps.

Signed-off-by: Michael Jeronimo <michael.jeronimo@openrobotics.org>
@mjeronimo mjeronimo requested a review from hidmic November 4, 2020 23:23
Copy link
Contributor

@clalancette clalancette left a comment

Choose a reason for hiding this comment

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

I've left a few things to consider inline.

*/
RMW_DDS_COMMON_PUBLIC
rmw_time_t
maintain_32bit_limits(const rmw_time_t & time);
Copy link
Contributor

Choose a reason for hiding this comment

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

To bikeshed the name of the function a bit: it doesn't say anything about dealing with time, so the calls are somewhat unclear:

 auto t1 = rmw_dds_common::maintain_32bit_limits(zeros);

I'll suggest naming this method something like: rmw_time_to_dds_time or something along those lines.

Copy link
Contributor

Choose a reason for hiding this comment

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

Separately, while this is an OK start, there are a few other questions that come up with regards to this:

  1. This works (to a degree) for passing an rmw_time down to the DDS layer. What happens when we get a time back from the DDS layer? I guess a 32-bit always fits into a 64-bit, so the answer may be "nothing", but it bears thinking about.
  2. Relatedly, what is going to happen in 2038 with 32-bit DDS times? I know @wjwwood mentioned that they were going to roll-over, do we have any documentation on how that is expected to work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, much better name. Updated.

Regarding the first item, I can't think of any potential issues with expanding the 32-bit values to their 64-bit counterparts.

As for the second item, I don't have any answers, but I see you mentioned it here: ros2/rcl_interfaces#85. Which also references this: https://issues.omg.org/issues/DDS15-13. So it would be good to hear from the DDS vendors about their plans.

Copy link
Member

Choose a reason for hiding this comment

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

You can try to @ some people here, or you could bring it up at the next Middleware Working Group meeting as a last resort, since several very knowledgeable DDS people are there sometimes.

I have been told how it was going to be resolved, but I can't find a link to any memorandum on the subject. It was likely in person.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if it makes sense to introduce a dds_time_to_rmw_time here. For now, it would be a direct assignment (so essentially a no-op). But once we figure out what the DDS solution to this problem is, we may have to implement something here (like rebasing from the DDS new "epoch" to the Unix one).

Or maybe we should just wait to hear back from the DDS vendors here. @MiguelCompany @eboasson any feedback on 32-bit times in the DDS standard and the year 2038 problem?

Copy link

Choose a reason for hiding this comment

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

It is still a point of discussion in the OMG. The tracking system has issues that are being worked on for the various standards, the difficulty is in resolving the backwards compatibility considerations. The difficulty here is that all options have different consequences for the different specifications.

Currently, the RTPS protocol should be fine until after 2100 (switch to unsigned 32-bit seconds in DDSI-RTPS 2.3, at the price of breaking applications using time stamps prior to 19700101 00:00:00 UTC). For the APIs it looks likely that the seconds field will be extended to 64-bits because a change to unsigned affects application code in nasty ways, but as far as I know, this hasn't been decided yet.

(Cyclone avoids the problem altogether by using 64-bit nanoseconds since the Unix epoch, both internally and in its C API, and so I need not worry about surviving until the point where roll-over is within the 30 year horizon that aerospace tends to use. I guess no-one's planning another Voyager 2 ...)

Copy link
Contributor

Choose a reason for hiding this comment

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

@eboasson Thanks so much for the feedback. That is very helpful.

What version of the RTPS spec does Cyclone currently implement?

@MiguelCompany @richiprosima Same question for eProsima; what version of the RTPS spec does Fast DDS currently implement?

Choose a reason for hiding this comment

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

@clalancette in this respect Cyclone still follows version 2.2 (that is, the interpretation of the seconds field hasn't been updated yet).

Signed-off-by: Michael Jeronimo <michael.jeronimo@openrobotics.org>
Signed-off-by: Michael Jeronimo <michael.jeronimo@openrobotics.org>
Copy link
Contributor

@clalancette clalancette left a comment

Choose a reason for hiding this comment

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

Looks good to me with green CI.

Signed-off-by: Michael Jeronimo <michael.jeronimo@openrobotics.org>
@mjeronimo mjeronimo merged commit 86384ff into master Nov 10, 2020
@delete-merged-branch delete-merged-branch bot deleted the mjeronimo/utility-function-for-32-bit-limits branch November 10, 2020 19:05
@mjeronimo
Copy link
Contributor Author

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

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.

4 participants