concept Operations & procedures
Monotonic clocks versus wall time for deadlines
Use a monotonic clock for a timeout: a wall-clock step can make the same wait appear too short or too long. Choose the elapsed-time clock by whether time spent suspended should count.
What it means
Use a monotonic clock to decide whether a timeout budget has elapsed. A wall clock tells you the date and time. If it is set back between the start of a request and the timeout check, subtracting its two timestamps can make the wait look shorter than it was. A monotonic clock lets you measure the interval without counting that clock change as part of the wait.
Try it
Simulation. Start with 8 seconds elapsed, a wall clock adjustment of −10 seconds, a 5-second timeout budget, and scenario evidence set to provided. Compare the two readings at the end of the same wait:
Monotonic clocks versus wall time for deadlines
Explain why timeout measurement needs a monotonic source
Monotonic elapsed time and adjusted wall-clock subtraction can lead to different deadline decisions.
Deadline comparisons
- Monotonic elapsed8
- Monotonic expiredYes
- Wall elapsed (signed)-2
- Wall expiredNo
Elapsed wall time may be negative after a backward step. Keep the signed value in text rather than clipping it to a zero-length duration. This does not model suspend or oscillator drift.
Evaluated inputs
- Required scenario evidence
- provided
- Real modeled elapsed duration
- 8 s
- Wall clock adjustment
- -10 s
- Timeout budget
- 5 s
Ideal monotonic clock for active interval, wall step only; no suspend semantics, real OS clock or distributed clock synchronization.
About this model
The controls set only a local, bounded scenario. The computed branch is not a verdict about a live system. Inputs listed as not evaluated did not participate in this branch after validation.
Reset restores the original inputs. It does not change the open or closed state of help or FAQ answers.
| Reading | Difference from the start | Has the 5-second budget elapsed? |
|---|---|---|
| Monotonic clock | 8 s | Yes |
| Wall clock | 8 s − 10 s = −2 s | No, by this reading |
With the controls enabled, change only the wall clock adjustment to 0 seconds. The wall-clock difference becomes 8 seconds, so both comparisons now say the budget has elapsed. The wait did not get longer. The only thing you removed was the backward step in the timestamps.
For the opposite mistake, set the elapsed duration to 2 seconds and the adjustment to +10 seconds. Keep the budget at 5 seconds. The monotonic reading is still short of the budget, but the wall-clock difference is 12 seconds and makes the timeout look due already. Use Reset to return to the original backward-step example.
The inputs take whole seconds: 0 to 100 for elapsed duration, −100 to 100 for the adjustment, and 1 to 100 for the budget. A missing or fractional duration is invalid; it does not count as zero or leave the previous result in force. With valid inputs, switching scenario evidence to missing instead gives an unknown result: neither clock comparison is evaluated.
How a clock step changes the answer
A timeout check asks whether the difference between the end and start readings is at least the budget. Exactly 5 seconds meets a 5-second budget. The comparison rule is the same on both timelines; what differs is the number going into it.
On the ideal monotonic timeline, the difference is just the active time that passed. On the wall timeline, the difference includes both the time that passed and the signed adjustment. In the first example, the end timestamp is 2 seconds earlier than the start timestamp. That is a negative timestamp difference, not a negative wait. The simulation compares readings at one check; it does not run a timer or measure when a real timeout fires.
The default backward step produces wall elapsed minus two seconds while monotonic elapsed is eight seconds. A negative signed reading is not a negative amount of physical work. Set the step to zero and the two deadline tests agree. If the deadline must count time spent suspended, consult the specific clock contract instead of choosing from this two-clock example alone.
In practice
For a request log, keep the two questions separate. Record a wall timestamp for “When did this happen?” To answer “How long did this request take?”, measure from start to finish with the same suitable elapsed-time clock. Two wall timestamps alone cannot tell you how much of their difference came from a clock step.
Before choosing that elapsed-time clock, decide what should happen if the machine sleeps. On Linux, CLOCK_MONOTONIC excludes time spent suspended, while CLOCK_BOOTTIME includes it. If a wait should use up its budget during suspend, that distinction matters even when nobody changes the wall clock. The simulation covers only an active interval and a wall-clock step; it does not read your operating system's clocks, simulate suspend, or establish that clocks on different hosts agree.
For a timeout, choose the clock by what the budget is meant to count. Look for protection from wall-clock steps first, then check the platform's documented suspend behavior. If that behavior is unknown, a pair of log timestamps is not a substitute for the missing clock contract.
Frequently asked questions
Editorial questions based on the listed sources and explicitly labeled local examples.
Can monotonic clocks be compared across hosts?
No shared absolute epoch follows from a monotonic clock. Use it for elapsed differences within its documented clock domain; cross-host event correlation needs other evidence.
Does monotonic mean unaffected by all rate adjustments?
Not necessarily; the clock contract matters.
What about suspend time?
Check the platform contract. On Linux CLOCK_MONOTONIC does not include time spent suspended, while CLOCK_BOOTTIME does. The model compares a wall-clock step with an elapsed clock and does not simulate suspend.
Should logs abandon wall time?
No. Wall-clock timestamps serve calendar and cross-system correlation tasks, while elapsed clocks measure durations according to their clock semantics. On Linux, CLOCK_REALTIME can step and CLOCK_MONOTONIC avoids such steps; the lab excludes suspend and distributed-clock synchronization.
Sources & model boundaries
Primary references used for this explanation. The interactive example is an educational model, not a live check.
- clock_gettime(2)
CLOCK_REALTIME; CLOCK_MONOTONIC; CLOCK_BOOTTIME. CLOCK_REALTIME can step; CLOCK_MONOTONIC is not subject to discontinuous wall-clock steps and excludes suspend time on Linux. CLOCK_BOOTTIME includes suspend.
Checked .
- Linux timerfd_create(2)
DESCRIPTION: clockid. On Linux, CLOCK_BOOTTIME includes suspended time while CLOCK_MONOTONIC excludes it. Choose the elapsed-time semantics required by the deadline; the model excludes suspend.
Checked .