Skip to content

Commit 857baa8

Browse files
Pavel TatashinKAGA-KOKO
authored andcommitted
sched/clock: Enable sched clock early
Allow sched_clock() to be used before schec_clock_init() is called. This provides a way to get early boot timestamps on machines with unstable clocks. Signed-off-by: Pavel Tatashin <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected]
1 parent 5d2a4e9 commit 857baa8

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

init/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,6 @@ asmlinkage __visible void __init start_kernel(void)
642642
softirq_init();
643643
timekeeping_init();
644644
time_init();
645-
sched_clock_init();
646645
printk_safe_init();
647646
perf_event_init();
648647
profile_init();
@@ -697,6 +696,7 @@ asmlinkage __visible void __init start_kernel(void)
697696
acpi_early_init();
698697
if (late_time_init)
699698
late_time_init();
699+
sched_clock_init();
700700
calibrate_delay();
701701
pid_idr_init();
702702
anon_vma_init();

kernel/sched/clock.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,25 @@ static void __sched_clock_gtod_offset(void)
202202

203203
void __init sched_clock_init(void)
204204
{
205+
unsigned long flags;
206+
207+
/*
208+
* Set __gtod_offset such that once we mark sched_clock_running,
209+
* sched_clock_tick() continues where sched_clock() left off.
210+
*
211+
* Even if TSC is buggered, we're still UP at this point so it
212+
* can't really be out of sync.
213+
*/
214+
local_irq_save(flags);
215+
__sched_clock_gtod_offset();
216+
local_irq_restore(flags);
217+
205218
sched_clock_running = 1;
219+
220+
/* Now that sched_clock_running is set adjust scd */
221+
local_irq_save(flags);
222+
sched_clock_tick();
223+
local_irq_restore(flags);
206224
}
207225
/*
208226
* We run this as late_initcall() such that it runs after all built-in drivers,
@@ -356,7 +374,7 @@ u64 sched_clock_cpu(int cpu)
356374
return sched_clock() + __sched_clock_offset;
357375

358376
if (unlikely(!sched_clock_running))
359-
return 0ull;
377+
return sched_clock();
360378

361379
preempt_disable_notrace();
362380
scd = cpu_sdc(cpu);

0 commit comments

Comments
 (0)