1

Quoting from https://wiki.archlinux.org/title/System_time:

Standard behavior of most operating systems is:

  • Set the system clock from the hardware clock on boot.
  • Keep accurate time of the system clock, see #Time synchronization.
  • Set the hardware clock from the system clock on shutdown.

Who is responsible for the last step of setting the hardware clock from the system clock on shutdown?

jan
  • 911

1 Answers1

2

The responsibility is the “operating system”’s. How that is implemented varies.

There are two cases to consider:

  1. If the system’s only time source is the RTC, then there’s no need to update it, except when the time is set. On Linux this is typically handled either by hwclock, or by timedatectl.

  2. If the system has an external time source (over the network), the RTC should be updated. On Linux this used to be handled at shutdown (using hwclock), but the kernel (since 3.7) can update the RTC automatically every eleven minutes if the system time is maintained using an external source and the RTC is configured appropriately.

On Linux, the kernel expects time synchonisation services to report whether time is synchronised; that is done by clearing or setting the STA_UNSYNC status bit using the adjtimex system call. The kernel itself can set that bit if it determines that time isn’t synchronised, but it never clears it on its own.

Stephen Kitt
  • 434,908
  • Regarding point 1: That means that a date --set command should be followed by a hwclock --systohc command, right? – jan Sep 30 '21 at 19:42
  • Regarding point 2: The documentation in the link you provided says "if userspace reports synchronized NTP status". Do you know what "reports" means here? – jan Sep 30 '21 at 19:43
  • 1
    Yes, a date --set command should be followed, sooner or later, by hwclock --systohc; doing so at system shutdown is usually considered to be sufficient. I’m about to update the answer to explain what “reports” means. – Stephen Kitt Oct 01 '21 at 06:56