Skip to content

Commit 9407f5a

Browse files
Peter ZijlstraKAGA-KOKO
authored andcommitted
sched/clock: Close a hole in sched_clock_init()
All data required for the 'unstable' sched_clock must be set-up _before_ enabling it -- setting sched_clock_running. This includes the __gtod_offset but also a recent scd stamp. Make the gtod-offset update also set the csd stamp -- it requires the same two clock reads _anyway_. This doesn't hurt in the sched_clock_tick_stable() case and ensures sched_clock_init() gets everything set-up before use. Also switch to unconditional IRQ-disable/enable because the static key stuff already requires this is not ran with IRQs disabled. Fixes: 857baa8 ("sched/clock: Enable sched clock early") Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: Pavel Tatashin <pasha.tatashin@oracle.com> Cc: steven.sistare@oracle.com Cc: daniel.m.jordan@oracle.com Cc: linux@armlinux.org.uk Cc: schwidefsky@de.ibm.com Cc: heiko.carstens@de.ibm.com Cc: john.stultz@linaro.org Cc: sboyd@codeaurora.org Cc: hpa@zytor.com Cc: douly.fnst@cn.fujitsu.com Cc: prarit@redhat.com Cc: feng.tang@intel.com Cc: pmladek@suse.com Cc: gnomes@lxorguk.ukuu.org.uk Cc: linux-s390@vger.kernel.org Cc: boris.ostrovsky@oracle.com Cc: jgross@suse.com Cc: pbonzini@redhat.com Link: https://lkml.kernel.org/r/20180720080911.GM2494@hirez.programming.kicks-ass.net
1 parent 8dbe438 commit 9407f5a

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

kernel/sched/clock.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,30 +197,26 @@ void clear_sched_clock_stable(void)
197197

198198
static void __sched_clock_gtod_offset(void)
199199
{
200-
__gtod_offset = (sched_clock() + __sched_clock_offset) - ktime_get_ns();
200+
struct sched_clock_data *scd = this_scd();
201+
202+
__scd_stamp(scd);
203+
__gtod_offset = (scd->tick_raw + __sched_clock_offset) - scd->tick_gtod;
201204
}
202205

203206
void __init sched_clock_init(void)
204207
{
205-
unsigned long flags;
206-
207208
/*
208209
* Set __gtod_offset such that once we mark sched_clock_running,
209210
* sched_clock_tick() continues where sched_clock() left off.
210211
*
211212
* Even if TSC is buggered, we're still UP at this point so it
212213
* can't really be out of sync.
213214
*/
214-
local_irq_save(flags);
215+
local_irq_disable();
215216
__sched_clock_gtod_offset();
216-
local_irq_restore(flags);
217+
local_irq_enable();
217218

218219
static_branch_inc(&sched_clock_running);
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);
224220
}
225221
/*
226222
* We run this as late_initcall() such that it runs after all built-in drivers,

0 commit comments

Comments
 (0)