Skip to content

Cyber: Use monotonic time for Rate scheduling - #15820

Open
kVinsom wants to merge 1 commit into
ApolloAuto:masterfrom
kVinsom:fix/15763-monotonic-rate
Open

kVinsom wants to merge 1 commit into
ApolloAuto:masterfrom
kVinsom:fix/15763-monotonic-rate

Conversation

@kVinsom

@kVinsom kVinsom commented Oct 18, 2026

Copy link
Copy Markdown

Summary

CyberRT's timing wheel uses Rate to pace its ticks. Rate currently measures cycles using wall time and waits on a system-clock deadline, so changing the system clock can disrupt timer execution and produce incorrect cycle durations.

Use Time::MonoTime() in all Rate constructors, Sleep() and Reset(), and wait on the corresponding std::chrono::steady_clock deadline. Keep the existing cycle-overrun resynchronization behaviour and update its diagnostic. Time::SleepUntil() retains its wall-clock semantics for other callers.

Add a rate_test target and seven tests covering constructor periods, successive waits, cycle overruns, and forward/backward one-hour clock jumps before sleeping and resetting. The tests interpose clock reads in the test executable; they do not change the machine's clock or require clock-setting privileges. Include Doxygen documentation and comments explaining the clock domains.

Fixes #15763.

Validation

  • Compiled the actual Rate, Time, Duration and binary sources on Ubuntu/WSL with GCC 15, C++14 and -Wall -Wextra -Werror.
  • Used GoogleTest 1.10.0 pinned by Apollo, with its archive checksum verified. Building this older GoogleTest with GCC 15 required locally adding -include cstdint to its compilation; no dependency sources or repository build settings were changed.
  • All 15 tests passed: 7 new Rate tests plus 8 existing Time/Duration tests.
  • Against the original Rate implementation, 5 of the new tests failed, including the forward/backward jump cases.
  • clang-format --dry-run --Werror, Apollo's pinned cpplint 1.5.2, and git diff --check passed for the changed C++ files/diff.

Full Apollo/Bazel and timer integration validation remains outstanding: this machine does not have the Apollo development container/Bazel environment configured. The Windows checkout also has CRLF shell scripts, so the attempted apollo.sh check could not run. The results above are direct C++ compilation/tests, not a successful full Apollo build.

AI assistance

Codex assisted with implementation, test development, documentation and local validation.

@CLAassistant

CLAassistant commented Oct 18, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

No deployments
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.

[cyberRT][cyber_time] Time jumps when using a timer can cause the thread sleep duration to be incorrect.

2 participants