tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: kern.boottime drift after boot?



    Date:        Tue, 10 Oct 2023 12:42:48 +0100
    From:        David Brownlee <abs%absd.org@localhost>
    Message-ID:  <CAGN_6patexZwx8rdKh9oXOd+NBm_ro_Rexs4hqWR8evLmaSjhQ%mail.gmail.com@localhost>

  | I have a system which records the output of "sysctl -n kern.boottime"
  | as part of a dhcpcd-exit.hook to ensure some processing only occurs
  | once per boot.

Cron's @reboot might help with that, that's its purpose.  See crontab(5)

  |      kern.boottime (KERN_BOOTTIME)
  |              A struct timespec structure is returned.  This structure contains
  |              the time that the system was booted.  That time is defined (for
  |              this purpose) to be the time at which the kernel first started
  |              accumulating clock ticks.

That's correct, the issue is that the kernel doesn't really know what the
time is, early in the boot sequence, it just takes a guess based either
upon the RTC if the system has one (those tend not to be very accurate),
or the last mod time of the root filesystem (much less accurate) otherwise.

As Crystal said, as the system time is corrected, the kernel can form a
better idea of what the time actually was when the system booted, based upon
the corrections that are being made to the current time of day.

kern.boottime always contains the time that the system believes it was
booted, as best it knows what that was.   The man page section you qouted
above is correct, and doesn't need updating.

kre



Home | Main Index | Thread Index | Old Index