Skip to main content

clock_source

Function clock_source 

Source
pub fn clock_source(ctx: &ServiceContext) -> ClockSource
Expand description

Where the wall clock came from, so a displayed timestamp can say what it stands on.

This is the check datetime tells you to make, and it is the difference between a date and a date you can quote. The four answers are genuinely different claims:

ClockSource::UnsetNo clock at all. Whatever datetime renders is not today.
ClockSource::RtcA local hardware clock reading a plausible date.
ClockSource::NtpCorrected from the network this boot.
ClockSource::FloorA LOWER BOUND carried from the last boot - real, advancing correctly, but blind to how long the machine was off.

Floor is the one worth reading twice, and it is why this is an enum rather than a bool. Several of the boards this runs on have no RTC, so the clock starts from a persisted floor and creeps forward correctly while being arbitrarily far behind. Reporting that as Rtc would claim hardware the board does not have; reporting it as Unset would deny a time it is displaying.

A machine that cannot be asked reads ClockSource::Unset, deliberately. The time service is restartable, so an unanswered question is normal during a restart - and an unknown clock and an unset clock oblige a caller to do the same thing, which is not to quote the date as fact.