Skip to content

Update rcutils_steady_time_now to return the same data as std::chrono - #357

Merged
clalancette merged 2 commits into
masterfrom
clalancette/update-steady-time
Apr 27, 2022
Merged

clalancette merged 2 commits into
masterfrom
clalancette/update-steady-time

Conversation

@clalancette

Copy link
Copy Markdown
Contributor

Based on an investigation several years ago, rcutils_steady_time_now
has slightly different behavior than std::chrono::now . In
particular, on Linux rcutils_steady_time_now was using
CLOCK_MONOTONIC_RAW, while std::chrono is using CLOCK_MONOTONIC.
On macOS, rcutils_steady_time_now was using SYSTEM_CLOCK, while std::chrono
was using CLOCK_MONOTONIC_RAW. Fix both of these so they
match what std::chrono does, and in the case of macOS, significantly
simplify the code by switching to clock_gettime.

Signed-off-by: Chris Lalancette [email protected]

This should fix #43 . Draft for now, as I haven't even compile tested this on macOS yet.

Based on an investigation several years ago, rcutils_steady_time_now
has slightly different behavior than std::chrono::now .  In
particular, on Linux rcutils_steady_time_now was using
CLOCK_MONOTONIC_RAW, while std::chrono is using CLOCK_MONOTONIC.
On macOS, rcutils_steady_time_now was using SYSTEM_CLOCK, while std::chrono
was using CLOCK_MONOTONIC_RAW.  Fix both of these so they
match what std::chrono does, and in the case of macOS, significantly
simplify the code by switching to clock_gettime.

Signed-off-by: Chris Lalancette <[email protected]>

@aprotyas aprotyas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM with a minor nit

Comment thread src/time_unix.c Resolved

@fujitatomoya fujitatomoya left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lgtm, aligned with std::chrono would be better for user application.

With this, all of the tests seem to pass.

Signed-off-by: Chris Lalancette <[email protected]>
@clalancette
clalancette marked this pull request as ready for review April 26, 2022 18:48
@clalancette

clalancette commented Apr 26, 2022 •

Copy link
Copy Markdown
Contributor Author

CI:

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

@clalancette

Copy link
Copy Markdown
Contributor Author

The test failing on Windows shows up in the Windows repeated jobs as well: https://ci.ros2.org/view/nightly/job/nightly_win_rep/2596 . So I'm going to go ahead and merge this, thanks for the reviews.

@clalancette
clalancette merged commit 91d21c6 into master Apr 27, 2022
@delete-merged-branch
delete-merged-branch Bot deleted the clalancette/update-steady-time branch April 27, 2022 16:28
alsora pushed a commit to irobot-ros/rcutils that referenced this pull request Jul 28, 2023
…ros2#357)

* Update rcutils_steady_time_now to return the same data as std::chrono

Based on an investigation several years ago, rcutils_steady_time_now
has slightly different behavior than std::chrono::now .  In
particular, on Linux rcutils_steady_time_now was using
CLOCK_MONOTONIC_RAW, while std::chrono is using CLOCK_MONOTONIC.
On macOS, rcutils_steady_time_now was using SYSTEM_CLOCK, while std::chrono
was using CLOCK_MONOTONIC_RAW.  Fix both of these so they
match what std::chrono does, and in the case of macOS, significantly
simplify the code by switching to clock_gettime.

Signed-off-by: Chris Lalancette <[email protected]>
alsora pushed a commit to irobot-ros/rcutils that referenced this pull request Jul 28, 2023
…ros2#357)

* Update rcutils_steady_time_now to return the same data as std::chrono

Based on an investigation several years ago, rcutils_steady_time_now
has slightly different behavior than std::chrono::now .  In
particular, on Linux rcutils_steady_time_now was using
CLOCK_MONOTONIC_RAW, while std::chrono is using CLOCK_MONOTONIC.
On macOS, rcutils_steady_time_now was using SYSTEM_CLOCK, while std::chrono
was using CLOCK_MONOTONIC_RAW.  Fix both of these so they
match what std::chrono does, and in the case of macOS, significantly
simplify the code by switching to clock_gettime.

Signed-off-by: Chris Lalancette <[email protected]>
bobzwik added a commit to bobzwik/camera_ros that referenced this pull request Nov 5, 2026
libcamera's SensorTimestamp is on CLOCK_MONOTONIC. Before rcutils 5.2.0
(ros2/rcutils#357), RCL_STEADY_TIME reads CLOCK_MONOTONIC_RAW instead,
and the gap between the two clocks grows with uptime and ends up in
header.stamp.

With rcutils < 5.2.0 (Humble), measure the latency with
std::chrono::steady_clock, which is CLOCK_MONOTONIC.

Fixes christianrauch#180
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.

reconsider use of CLOCK_MONOTONIC_RAW

3 participants