2012-02-22 02:29:45

by Alok Kataria

[permalink] [raw]
Subject: [PATCH] x86, tsc: Skip refined tsc calibration on systems with reliable TSC.

[Oops forgot to copy LKML, now it is, sorry for the duplicates]

While running the latest Linux as guest under VMware in highly
over-committed situations, we have seen cases when the refined TSC
algorithm fails to get a valid tsc_start value in
tsc_refine_calibration_work from multiple attempts. As a result the
kernel keeps on scheduling the tsc_irqwork task for later. Subsequently
after several attempts when it gets a valid start value it goes through
the refined calibration and either bails out or uses the new results.
Given that the kernel originally read the TSC frequency from the
platform, which is the best it can get, I don't think there is much
value in refining it.

So IMO, for systems which get the TSC frequency from the platform we
should skip the refined tsc algorithm.

We can use the TSC_RELIABLE cpu cap flag to detect this, right now it is
set only on VMware and for Moorestown Penwell both of which have there
own TSC calibration methods.

Thanks,
Alok

--

From: Alok N Kataria <[email protected]>

For systems which get the TSC frequency directly from the platform
and don't go through the native TSC calibration algorithm, we should
trust those values and not try to refine those.

This patch is applicable for kernel from v2.6.38 to current mainline.

Signed-off-by: Alok N Kataria <[email protected]>
Cc: John Stultz <[email protected]>
Cc: Dirk Brandewie <[email protected]>
Cc: Alan Cox <[email protected]>
Cc: [email protected]


Index: linux-2.6/arch/x86/kernel/tsc.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/tsc.c 2012-02-21 17:31:01.000000000 -0800
+++ linux-2.6/arch/x86/kernel/tsc.c 2012-02-21 17:39:05.000000000 -0800
@@ -874,6 +874,13 @@ static void tsc_refine_calibration_work(
goto out;

/*
+ * Trust the results of the earlier calibration on systems
+ * exporting a reliable TSC.
+ */
+ if (boot_cpu_has(X86_FEATURE_TSC_RELIABLE))
+ goto out;
+
+ /*
* Since the work is started early in boot, we may be
* delayed the first time we expire. So set the workqueue
* again once we know timers are working.


2012-02-28 19:09:18

by Alok Kataria

[permalink] [raw]
Subject: Re: [PATCH] x86, tsc: Skip refined tsc calibration on systems with reliable TSC.

Ping...any comments on this one.

Thanks,
Alok

On Tue, 2012-02-21 at 18:19 -0800, Alok Kataria wrote:
> [Oops forgot to copy LKML, now it is, sorry for the duplicates]
>
> While running the latest Linux as guest under VMware in highly
> over-committed situations, we have seen cases when the refined TSC
> algorithm fails to get a valid tsc_start value in
> tsc_refine_calibration_work from multiple attempts. As a result the
> kernel keeps on scheduling the tsc_irqwork task for later. Subsequently
> after several attempts when it gets a valid start value it goes through
> the refined calibration and either bails out or uses the new results.
> Given that the kernel originally read the TSC frequency from the
> platform, which is the best it can get, I don't think there is much
> value in refining it.
>
> So IMO, for systems which get the TSC frequency from the platform we
> should skip the refined tsc algorithm.
>
> We can use the TSC_RELIABLE cpu cap flag to detect this, right now it is
> set only on VMware and for Moorestown Penwell both of which have there
> own TSC calibration methods.
>
> Thanks,
> Alok
>
> --
>
> From: Alok N Kataria <[email protected]>
>
> For systems which get the TSC frequency directly from the platform
> and don't go through the native TSC calibration algorithm, we should
> trust those values and not try to refine those.
>
> This patch is applicable for kernel from v2.6.38 to current mainline.
>
> Signed-off-by: Alok N Kataria <[email protected]>
> Cc: John Stultz <[email protected]>
> Cc: Dirk Brandewie <[email protected]>
> Cc: Alan Cox <[email protected]>
> Cc: [email protected]
>
>
> Index: linux-2.6/arch/x86/kernel/tsc.c
> ===================================================================
> --- linux-2.6.orig/arch/x86/kernel/tsc.c 2012-02-21 17:31:01.000000000 -0800
> +++ linux-2.6/arch/x86/kernel/tsc.c 2012-02-21 17:39:05.000000000 -0800
> @@ -874,6 +874,13 @@ static void tsc_refine_calibration_work(
> goto out;
>
> /*
> + * Trust the results of the earlier calibration on systems
> + * exporting a reliable TSC.
> + */
> + if (boot_cpu_has(X86_FEATURE_TSC_RELIABLE))
> + goto out;
> +
> + /*
> * Since the work is started early in boot, we may be
> * delayed the first time we expire. So set the workqueue
> * again once we know timers are working.
>