On Wed, 20 Jun 2018, Feng Tang wrote: > On Wed, Jun 20, 2018 at 01:52:10AM +0200, Thomas Gleixner wrote: > > > > static DEFINE_STATIC_KEY_FALSE(__use_tsc); > > +static DEFINE_STATIC_KEY_TRUE(tsc_early_enabled); > > One potential problem may be the several static_keys used here, > the "__use_tsc", the "__sched_clock_stable", it may not be used > very early in boot phase. As the the static_branch_enable() will > use pageing related code while the paging is not setup ready yet.
I know how static keys work and thats the reason for having the extra conditional. The key is disabled at a point where paging is available. > > /* > > * Scheduler clock - returns current time in nanosec units. > > */ > > u64 native_sched_clock(void) > > { > > - if (static_branch_likely(&__use_tsc)) { > > - u64 tsc_now = rdtsc(); > > + if (static_branch_likely(&__use_tsc)) > > + return cycles_2_ns(rdtsc()); > > > > - /* return the value in ns */ > > - return cycles_2_ns(tsc_now); > > + if (static_branch_unlikely(&tsc_early_enabled)) { > > + if (tsc_early_sched_clock) > > + return cycles_2_ns(rdtsc()); > > } Thanks, tglx