Definition
A clock domain is the set of timestamps read from one clock, such as a host computer’s monotonic clock §9.35 or a device’s cycle counter. Timestamps in one domain share a zero point, called the epoch, and a tick rate, so the difference between two of them is an elapsed time. Timestamps from two domains cannot be subtracted, even when both are in milliseconds, until the relationship between the two clocks has been measured. In digital hardware design, a clock domain is the set of circuits driven by one clock signal.
Where it fits
Main entry: Wall clock and clock synchronization (§9.36).
The Wall clock and clock synchronization entry explains how to measure the relationship between two clocks: their offset, the difference between their readings at the same instant; their rate difference, which makes the offset change over time; and an error bound for converting a reading from one clock to the other. This entry covers the bookkeeping that makes such a conversion possible. Every timestamp carries the name of its domain, and each domain is described by its source clock, its epoch (what a reading of 0 means), its rate and resolution, and its behavior on pause, reset and wraparound.
Pause and reset behavior is where domains most often differ unnoticed. On Linux, CLOCK_MONOTONIC stops counting while the system is suspended but CLOCK_BOOTTIME does not, so the gap between these two clocks on one machine grows by the length of each suspend. A device counter that restarts at 0 when the device resets starts a new domain. A 32-bit counter that ticks 64 million times per second wraps to 0 every s.
In hardware design, a signal that passes between clock domains needs a synchronizer circuit, because a flip-flop, the element that stores one bit at each clock edge, can hover between 0 and 1 for an unpredictable time if its input changes as it samples, which is called metastability.
Limits and common mistakes
Identical units are not a shared domain: a host timestamp and a device timestamp, both in milliseconds, differ by an unknown offset and drift apart. Each reading is also rounded to whole ticks (counter quantization §11.35), an error separate from the conversion error.
Questions answered
How is offset, drift, and pause behavior bounded between domains?
Offset, drift and pause behavior between two clock domains are bounded by measuring them, not by assuming them; a clock domain is the set of timestamps read from one clock.
Offset, the difference between the two clocks’ readings at one instant: timestamp one event in both domains. With a message exchange, the estimate is uncertain by at most half the round-trip delay; a shared physical event, such as one electrical pulse seen by both sides, removes that travel-time uncertainty.
Drift, the change of the offset over time caused by a rate difference: measure the offset again later and divide the change by the elapsed time, or take a bound from the oscillator’s specification, such as 50 parts per million (ppm). The conversion error then grows by at most the rate bound times the time since the last offset measurement. With an offset error of 0.5 ms and 50 ppm, the bound 60 s later is ms.
Pause and reset: find out, from documentation and by test, whether each clock keeps counting while the host suspends, the device sleeps or a debugger halts the processor, and whether a reset restarts it. Detect a violation by comparing the elapsed time of one interval in both domains: a difference larger than the drift bound allows shows a pause, a step or a reset, after which the offset must be measured again.
The total error bound of a converted timestamp is the offset error, plus the drift term, plus the timestamp’s own reading delay and resolution. Two events in different domains are ordered only if their difference, after conversion, exceeds that bound.
Related entries: Clock source and drift (§6.18), Counter quantization (§11.35), Wall clock and clock synchronization (§9.36), Monotonic clock (§9.35).