Repository navigation
Conversation
Introduce monotonic_timestamp backed by CLOCK_MONOTONIC and use it in the timer scheduler to avoid deadline changes caused by calendar clock adjustments. Add ./configure checks and new tests covering timestamp operations, clock source, and timer behavior when calendar time moves backwards or forwards. Signed-off-by: Pavel Grakhov <altogetherx@gmail.com>
|
@holmuk : I appreciate the submission, but this isn't exactly what I had in mind if you look at the issue set as a whole. |
|
@ngie-eign , Thanks for clarifying the preferred direction. I agree that using Anyway, I think this points to a more fundamental architectural issue. Ideally, the signal handler should only notify the scheduler that work is pending. Deadline processing and callbacks should then run in an explicitly defined, ordinary execution context. As I see it, we have two options:
The second option would address the underlying architectural problem and probably require a series of PR under an epic issue. Would you prefer keeping the current PR as an incremental fix for the immediate timer issue, or should we close the current PR and address the architecture problem first? |
ngie-eign
left a comment
There was a problem hiding this comment.
Why not just inherit datetime::monotonic_timestamp from datetime::timestamp? It would cut down on a ton of duplicate code.
Bleh. I didn't know about that caveat with
Let's go for option 1. now and work towards 2. Thanks! |
The PR introduce
datetime::monotonic_timestamp, backed byclock_gettime(CLOCK_MONOTONIC), and use it in the timer scheduler for deadline creation, ordering, remaining-time calculations, and expiration checks.Monotonic time is preferable for deadlines because they depend on elapsed time rather than calendar time. This follows the clock semantics documented by FreeBSD:
CLOCK_MONOTONICuses an unspecified epoch, while setting the time of day operates onCLOCK_REALTIME. See FreeBSD clock_gettime(2).The new tests cover:
calendar_backward: verify that moving the calendar clock backwards does not prevent a timer from firing.calendar_forward: verify that moving the calendar clock forwards does not trigger a premature callback when processing an alarm.Resolves #335