You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add strong guarantee on monotonicity of system clock (#31885)
* Add strong guarantee on monotonicity of system clock
- It was observed some platforms have decrementing values from
`SystemClock::GetMonotonicMilliseconds64()` implementation
which can violate the required invariant that they NEVER go back,
since multiple deadlines are computed from this clock, which could
then never hit. This was observed to break in the field in subtle
ways after ~48 days (2^32 milliseconds).
- This change introduces a VerifyOrDie to allow crash/restart if
the invariant is broken, since that leaves the stack in a possibly
wedged state.
- The new invariant is constructed to be reentrant-safe to maintain
the invariant, in a way that it will eventually be caught, even
if there are many threads/cores calling `GetMonotonicTimestamp()`.
This was done in a lock-free manner, and was added since the public
API of SystemLayer is not guaranteed to only be called from Matter
thread context.
Issue #31875
Testing done:
- All unit tests still pass.
- All integration tests still pass.
- When `mockClock.AdvanceMonotonic(200_ms);` is replaced with
`mockClock.AdvanceMonotonic(0xffff'ffff'ffff'ffff_ms);` in
`TestSystemTimer.cpp::CheckOrder()`, the test crashes as expected
due to detection of wraparound.
* Fix review comments and move to intrinsics
* Restyled by clang-format
* Fix build and add warning
* Fix build
* Restyled by clang-format
* Address review comment, add new define instead of linux && darwin
* Restyled by clang-format
---------
Co-authored-by: tennessee.carmelveilleux@gmail.com <tennessee@google.com>
Co-authored-by: Restyled.io <commits@restyled.io>
0 commit comments