timekeeping: Utilize local_clock() for NMI safe timekeeper during early boot
authorThomas Gleixner <tglx@linutronix.de>
Fri, 14 Aug 2020 10:19:34 +0000 (12:19 +0200)
committerThomas Gleixner <tglx@linutronix.de>
Sun, 23 Aug 2020 08:38:24 +0000 (10:38 +0200)
commit71419b30cab099f7ca37e61bf41028d8b7d4984d
treeef0c7511fd56f4f7d22b22f07f3b0e56c44fd275
parent9123e3a74ec7b934a4a099e98af6a61c2f80bbf5
timekeeping: Utilize local_clock() for NMI safe timekeeper during early boot

During early boot the NMI safe timekeeper returns 0 until the first
clocksource becomes available.

This prevents it from being used for printk or other facilities which today
use sched clock. sched clock can be available way before timekeeping is
initialized.

The obvious workaround for this is to utilize the early sched clock in the
default dummy clock read function until a clocksource becomes available.

After switching to the clocksource clock MONOTONIC and BOOTTIME will not
jump because the timekeeping_init() bases clock MONOTONIC on sched clock
and the offset between clock MONOTONIC and BOOTTIME is zero during boot.

Clock REALTIME cannot provide useful timestamps during early boot up to
the point where a persistent clock becomes available, which is either in
timekeeping_init() or later when the RTC driver which might depend on I2C
or other subsystems is initialized.

There is a minor difference to sched_clock() vs. suspend/resume. As the
timekeeper clock source might not be accessible during suspend, after
timekeeping_suspend() timestamps freeze up to the point where
timekeeping_resume() is invoked. OTOH this is true for some sched clock
implementations as well.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20200814115512.041422402@linutronix.de
kernel/time/timekeeping.c