This introduces an optional arch_early_time() which by default doesn't exist and doesn't cause any extra code to be generated.
If it is configured and declared though, it can be used in an architecture or platform-specific way to provide time during early boot.
After early boot when normal time is available, it can stop counting and just add its offset, so time in the boot is monotonic.
Signed-off-by: Andy Green andy.green@linaro.org --- include/linux/time.h | 6 ++++++ kernel/sched/clock.c | 12 ++++++------ 2 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/include/linux/time.h b/include/linux/time.h index d5d229b..57dc58e 100644 --- a/include/linux/time.h +++ b/include/linux/time.h @@ -181,6 +181,12 @@ extern s32 timekeeping_get_tai_offset(void); extern void timekeeping_set_tai_offset(s32 tai_offset); extern void timekeeping_clocktai(struct timespec *ts);
+#ifdef CONFIG_HAS_ARCH_EARLY_TIME +extern u64 arch_early_time(u64 normal); +#else +#define arch_early_time(_x) ((u64)_x) +#endif + struct tms; extern void do_sys_times(struct tms *);
diff --git a/kernel/sched/clock.c b/kernel/sched/clock.c index c3ae144..04b0490 100644 --- a/kernel/sched/clock.c +++ b/kernel/sched/clock.c @@ -245,10 +245,10 @@ u64 sched_clock_cpu(int cpu) WARN_ON_ONCE(!irqs_disabled());
if (sched_clock_stable) - return sched_clock(); + return arch_early_time(sched_clock());
if (unlikely(!sched_clock_running)) - return 0ull; + return arch_early_time(0);
scd = cpu_sdc(cpu);
@@ -257,7 +257,7 @@ u64 sched_clock_cpu(int cpu) else clock = sched_clock_local(scd);
- return clock; + return arch_early_time(clock); }
void sched_clock_tick(void) @@ -339,7 +339,7 @@ u64 local_clock(void) unsigned long flags;
local_irq_save(flags); - clock = sched_clock_cpu(smp_processor_id()); + clock = arch_early_time(sched_clock_cpu(smp_processor_id())); local_irq_restore(flags);
return clock; @@ -355,9 +355,9 @@ void sched_clock_init(void) u64 sched_clock_cpu(int cpu) { if (unlikely(!sched_clock_running)) - return 0; + return arch_early_time(0);
- return sched_clock(); + return arch_early_time(sched_clock()); }
u64 cpu_clock(int cpu)