Linux – CONFIG_RTC_SYSTOHC: how to use the NTP synchronization option in the kernel

linux-kernel

I have noticed in kernel 3.10, there is an option CONFIG_RTC_SYSTOHC

Device Drivers -> RTC -> Set the RTC time based on NTP synchronization

The help says:

If you say yes here, the system time (wall clock) will be stored
in the RTC specified by RTC_HCTOSYS_DEVICE approximately every 11
minutes if userspace reports synchronized NTP status.

I don't understand how I can make use of this function. Does it mean, I don't need any userspace tools anymore (ntpdate) to synchronize time ? How is this different from using ntpdate ? Where do I specify the ntp server to be used?

Could somebody please clarify ?

Best Answer

Linux stores time internally, regardless of your hardware clock (a.k.a. RTC). That means your system can show one time when you run date (Linux clock), and a different time when you run hwclock (hardware clock).

Usually, you would want to load the time from the hardware to Linux when the machine boots (with hwclock -hctosys), and when the machine goes down, you want to store your pretty accurate time (you do use ntpd, don't you? ;)) - back to the hardware clock, with hwclock -systohc.

Now, what happens if your system dies, reboots abnormally, etc? The clock doesn't get synchronized to hardware. On next boot, you might have a large clock skew, because the hardware clock is not that accurate... next time you'll say "I need my system to start with ntpdate before ntpd, because otherwise, ntpd might not sync the time at all, because the delta on the current clock and the real time is too big". The problem with that approach is... what happens if you happen to sync to a machine which by itself is not in sync, and then your ntp will never have the right time?

So in order to avoid all that, it's good to keep the right time synchronized to the hardware at all times. What the kernel option you're asking about seems to do, is to note if your time is actually synchronized with NTP (there is a way to know that...) - and if it is - sync that time regularly from Linux time (a.k.a. System Time), to the hardware clock, so it will be very accurate at all times, including sudden system crashes.

Related Question