tech-kern archive

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

Re: kern.boottime drift after boot?



On Tue, 10 Oct 2023 at 18:07, Robert Elz <kre%munnari.oz.au@localhost> wrote:
>
>     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)

(More context) - It's used as a dhcpcd-exit.hook to ensure some
services are enabled only after an interface has an IP address, so in
this case cron @reboot would not fit.

>   |      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.

The manpage is correct, but incomplete. On reading it without
understanding the implementation, there is ambiguity as to whether
kern.boottime will be constant for any given boot (unless I've missed
something elsewhere in the page). Furthermore it has the unfortunate
behaviour of 'usually' appearing to be constant, which leads to easy
assumptions, based on lack of clarity. Particularly as it would be
easy to have an implementation which did have a constant per boot
value, which would be more useful in some ways and less in others (I'm
not arguing at this point that we should switch to such an
implementation)

David


Home | Main Index | Thread Index | Old Index