Re: [PATCH v11 6/6] x86/tsc: use tsc early
From: Feng Tang
Date: Thu Jun 21 2018 - 01:49:48 EST
Hi Pavel,
On Wed, Jun 20, 2018 at 05:27:00PM -0400, Pavel Tatashin wrote:
> We want to get timestamps and high resultion clock available to us as early
> as possible in boot. But, native_sched_clock() outputs time based either on
> tsc after tsc_init() is called later in boot, or using jiffies when clock
> interrupts are enabled, which is also happens later in boot.
>
> On the other hand, we know tsc frequency from as early as when
> tsc_early_delay_calibrate() is called. So, we use the early tsc calibration
> to output timestamps early. Later in boot when tsc_init() is called we
> calibrate tsc again using more precise methods, and start using that.
>
> Since sched_clock() is in a hot path, we want to make sure that no
> regressions are introduced to this function after machine is booted, this
> is why we are using static branch that is enabled by default, but is
> disabled once we have initialized a permanent clock source.
>
> Signed-off-by: Pavel Tatashin <pasha.tatashin@xxxxxxxxxx>
> ---
> arch/x86/kernel/tsc.c | 64 ++++++++++++++++++++++++++++++-------------
> 1 file changed, 45 insertions(+), 19 deletions(-)
>
> diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
> index 654a01cc0358..1dd69612c69c 100644
> --- a/arch/x86/kernel/tsc.c
> +++ b/arch/x86/kernel/tsc.c
> @@ -39,6 +39,9 @@ EXPORT_SYMBOL(tsc_khz);
> static int __read_mostly tsc_unstable;
>
> static DEFINE_STATIC_KEY_FALSE(__use_tsc);
> +static DEFINE_STATIC_KEY_TRUE(tsc_early_enabled);
Do we still need add a static_key? after Peter worked out the patch
to enable ealy jump_label_init?
Thanks,
Feng