Skip to contentSkip to conversation

x86/platform/UV: Update TSC support

PATCH In review [email protected] 3 participants 9 messages Oct 2, 2017 – Oct 4, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover x86/platform/UV: Update TSC support

The UV BIOS goes to considerable effort to get the TSC synchronization accurate across the entire system. Included in that are multiple chassis that can have 32+ sockets. The architecture does support an external high resolution clock to aid in maintaining this synchronization.

The resulting TSC accuracy set by the UV system BIOS is much better than the generic kernel TSC ADJUST functions. This is important for applications that read the TSC values directly for accessing data bases.

* Patch 1 disables an assumption made by the kernel tsc sync functions
that Socket 0 in the system should all have a TSC ADJUST value of zero. This is not correct when the chassis are reset asynchronously to each other so which TSC's should be zero is not predictable.

* Patch 2 prevents the kernel from attempting to fix the TSC if the
system BIOS has determined that the TSC is not stable. This prevents a slew of useless warning messages.

* Patch 3 eliminates another avalanche of warning messages from older
BIOS that did not have the TSC ADJUST MSR (ex. >3000 msgs in a 32 socket Skylake system). It now notes this with a single warning message and then moves on with fixing them.

* Patch 4 puts in a facility to disable ART if the art to tsc conversion
factor is not constant for all sockets.

* Patch 5 puts a new check in the UV system init to check this new BIOS
flag that displays the result of the TSC synchronization phase. Three possible states are available, "sync is valid", "sync is unstable", or TSC sync state is unavailable in this BIOS. In the later case, the UV kernel init reverts to prior assumptions about TSC sync state.

#1 lore raw

PATCH 1/5 x86/kernel: Add option that TSC on Socket 0 being non-zero is valid

Add a flag to indicate and process that TSC counters are on chassis that reset at different times during system startup. Therefore which TSC ADJUST values should be zero is not predictable.

---
 arch/x86/include/asm/tsc.h |    1 +
 arch/x86/kernel/tsc_sync.c |   39 +++++++++++++++++++++++++++++++++++----
 2 files changed, 36 insertions(+), 4 deletions(-)
arch/x86/include/asm/tsc.h +1 -0
@@ -35,6 +35,7 @@ extern void tsc_init(void);
 extern void mark_tsc_unstable(char *reason);
 extern int unsynchronized_tsc(void);
 extern int check_tsc_unstable(void);
+extern void mark_tsc_multi_sync_resets(char *reason);
 extern unsigned long native_calibrate_cpu(void);
 extern unsigned long native_calibrate_tsc(void);
 extern unsigned long long native_sched_clock_from_tsc(u64 tsc);
arch/x86/kernel/tsc_sync.c +35 -4
@@ -30,6 +30,20 @@ struct tsc_adjust {
 
 static DEFINE_PER_CPU(struct tsc_adjust, tsc_adjust);
 
+/*
+ * TSC's on different sockets may be reset asynchronously.
+ * This may cause the TSC ADJUST value on socket 0 to be NOT 0.
+ */
+static bool __read_mostly tsc_multi_sync_resets;
+
+void mark_tsc_multi_sync_resets(char *reason)
+{
+	if (tsc_multi_sync_resets)
+		return;
+	tsc_multi_sync_resets = true;
+	pr_info("tsc: Marking TSC multi sync resets true due to %s\n", reason);
+}
+
 void tsc_verify_tsc_adjust(bool resume)
 {
 	struct tsc_adjust *adj = this_cpu_ptr(&tsc_adjust);
@@ -71,12 +85,22 @@ static void tsc_sanitize_first_cpu(struc
 	 * non zero. We don't do that on non boot cpus because physical
 	 * hotplug should have set the ADJUST register to a value > 0 so
 	 * the TSC is in sync with the already running cpus.
+	 *
+	 * Also don't force the ADJUST value to zero if that is a valid value
+	 * for socket 0 as determined by the system arch.  This is required
+	 * when multiple sockets are reset asynchronously with each other
+	 * and socket 0 may not have an TSC ADJUST value of 0.
 	 */
 	if (bootcpu && bootval != 0) {
-		pr_warn(FW_BUG "TSC ADJUST: CPU%u: %lld force to 0\n", cpu,
-			bootval);
-		wrmsrl(MSR_IA32_TSC_ADJUST, 0);
-		bootval = 0;
+		if (likely(!tsc_multi_sync_resets)) {
+			pr_warn(FW_BUG "TSC ADJUST: CPU%u: %lld force to 0\n",
+				cpu, bootval);
+			wrmsrl(MSR_IA32_TSC_ADJUST, 0);
+			bootval = 0;
+		} else {
+			pr_info("TSC ADJUST: CPU%u: %lld NOT forced to 0\n",
+				cpu, bootval);
+		}
 	}
 	cur->adjusted = bootval;
 }
@@ -118,6 +142,13 @@ bool tsc_store_and_check_tsc_adjust(bool
 	cur->warned = false;
 
 	/*
+	 * If a non-zero TSC value for socket 0 may be valid then the default
+	 * adjusted value cannot assumed to be zero either.
+	 */
+	if (tsc_multi_sync_resets)
+		cur->adjusted = bootval;
+
+	/*
 	 * Check whether this CPU is the first in a package to come up. In
 	 * this case do not check the boot value against another package
 	 * because the new package might have been physically hotplugged,
#2 lore raw

PATCH 2/5 x86/kernel: Skip TSC test and error messages if already unstable

In reply to [email protected]

If the TSC has already been determined to be unstable, then checking TSC ADJUST values is a waste of time and generates unnecessary error messages.

---
 arch/x86/kernel/tsc_sync.c |    8 ++++++++
 1 file changed, 8 insertions(+)
arch/x86/kernel/tsc_sync.c +8 -0
@@ -38,6 +38,10 @@ void tsc_verify_tsc_adjust(bool resume)
 	if (!boot_cpu_has(X86_FEATURE_TSC_ADJUST))
 		return;
 
+	/* Skip unnecessary error messages if TSC already unstable */
+	if (check_tsc_unstable())
+		return;
+
 	/* Rate limit the MSR check */
 	if (!resume && time_before(jiffies, adj->nextcheck))
 		return;
@@ -89,6 +93,10 @@ bool tsc_store_and_check_tsc_adjust(bool
 	if (!boot_cpu_has(X86_FEATURE_TSC_ADJUST))
 		return false;
 
+	/* Skip unnecessary error messages if TSC already unstable */
+	if (check_tsc_unstable())
+		return false;
+
 	rdmsrl(MSR_IA32_TSC_ADJUST, bootval);
 	cur->bootval = bootval;
 	cur->adjusted = bootval;
#3 lore raw

PATCH 3/5 x86/kernel: Drastically reduce the number of firmware bug warnings

In reply to [email protected]

Prior to the TSC ADJUST MSR being available, the method to set TSC's in sync with each other naturally caused a small skew between cpu threads. This was NOT a firmware bug at the time so introducing a whole avalanche of alarming warning messages might cause unnecessary concern and customer complaints. (Example: >3000 msgs in a 32 socket Skylake system.)

Simply report the warning condition, if possible do the necessary fixes, and move on.

---
 arch/x86/kernel/tsc_sync.c |    9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
arch/x86/kernel/tsc_sync.c +3 -6
@@ -123,10 +123,9 @@ bool tsc_store_and_check_tsc_adjust(bool
 	 * Compare the boot value and complain if it differs in the
 	 * package.
 	 */
-	if (bootval != ref->bootval) {
-		pr_warn(FW_BUG "TSC ADJUST differs: Reference CPU%u: %lld CPU%u: %lld\n",
-			refcpu, ref->bootval, cpu, bootval);
-	}
+	if (bootval != ref->bootval)
+		printk_once(FW_BUG "TSC ADJUST differs within socket(s), fixing all errors\n");
+
 	/*
 	 * The TSC_ADJUST values in a package must be the same. If the boot
 	 * value on this newly upcoming CPU differs from the adjustment
@@ -134,8 +133,6 @@ bool tsc_store_and_check_tsc_adjust(bool
 	 * adjusted value.
 	 */
 	if (bootval != ref->adjusted) {
-		pr_warn("TSC ADJUST synchronize: Reference CPU%u: %lld CPU%u: %lld\n",
-			refcpu, ref->adjusted, cpu, bootval);
 		cur->adjusted = ref->adjusted;
 		wrmsrl(MSR_IA32_TSC_ADJUST, ref->adjusted);
 	}
#4 lore raw

PATCH 4/5 x86/kernel: Provide a means to disable TSC ART

In reply to [email protected]

On systems where multiple chassis are reset asynchronously there is not a constant ratio between the ART frequency and the TSC time that can be provided by the boot cpu. Provide a means to disable the ART capability by arches that have this characteristic.

---
 arch/x86/include/asm/tsc.h |    1 +
 arch/x86/kernel/tsc.c      |   16 +++++++++++++---
 2 files changed, 14 insertions(+), 3 deletions(-)
arch/x86/include/asm/tsc.h +1 -0
@@ -36,6 +36,7 @@ extern void mark_tsc_unstable(char *reas
 extern int unsynchronized_tsc(void);
 extern int check_tsc_unstable(void);
 extern void mark_tsc_multi_sync_resets(char *reason);
+extern void mark_tsc_art_disabled(char *reason);
 extern unsigned long native_calibrate_cpu(void);
 extern unsigned long native_calibrate_tsc(void);
 extern unsigned long long native_sched_clock_from_tsc(u64 tsc);
arch/x86/kernel/tsc.c +13 -3
@@ -955,15 +955,25 @@ core_initcall(cpufreq_register_tsc_scali
 #define ART_CPUID_LEAF (0x15)
 #define ART_MIN_DENOMINATOR (1)
 
-
 /*
- * If ART is present detect the numerator:denominator to convert to TSC
+ * If ART is present detect the numerator:denominator to convert to TSC.
+ * The CPU ART capability can be disabled.
  */
+static bool tsc_art_disabled;
+
+void mark_tsc_art_disabled(char *reason)
+{
+	if (tsc_art_disabled)
+		return;
+	tsc_art_disabled = true;
+	pr_info("TSC: ART disabled due to %s\n", reason);
+}
+
 static void detect_art(void)
 {
 	unsigned int unused[2];
 
-	if (boot_cpu_data.cpuid_level < ART_CPUID_LEAF)
+	if (boot_cpu_data.cpuid_level < ART_CPUID_LEAF || tsc_art_disabled)
 		return;
 
 	/* Don't enable ART in a VM, non-stop TSC and TSC_ADJUST required */
#5 lore raw

Re: [PATCH 4/5] x86/kernel: Provide a means to disable TSC ART

arch/x86/kernel/tsc.c core_initcall(cpufreq_register_tsc_scali · line 979

Quoted 9 lines · On Mon, Oct 02, 2017 at 10:12:18AM -0500, [email protected] wrote:

static void detect_art(void)
{

arch/x86/kernel/tsc.c +1 -1
 	unsigned int unused[2];
 
-	if (boot_cpu_data.cpuid_level < ART_CPUID_LEAF)
+	if (boot_cpu_data.cpuid_level < ART_CPUID_LEAF || tsc_art_disabled)
 		return;
 
 	/* Don't enable ART in a VM, non-stop TSC and TSC_ADJUST required */

So why can't we use is_uv_system() here an for the tsc_adjust thing?

Also (and I hate the name) tsc_multi_sync_resets is the reason you cannot use ART, I don't think it makes sense to introduce yet another knob.

#6 lore raw

Re: [PATCH 4/5] x86/kernel: Provide a means to disable TSC ART

Quoted 5 lines · Peter Zijlstra
Quoted 4 lines · On Mon, Oct 02, 2017 at 10:12:18AM -0500, [email protected] wrote:
  static void detect_art(void)
  {
  	unsigned int unused[2];
Quoted 8 lines

arch/x86/kernel/tsc.c core_initcall(cpufreq_register_tsc_scali · line 979

Quoted 5 lines
arch/x86/kernel/tsc.c +1 -1
-	if (boot_cpu_data.cpuid_level < ART_CPUID_LEAF)
+	if (boot_cpu_data.cpuid_level < ART_CPUID_LEAF || tsc_art_disabled)
  		return;
 
  	/* Don't enable ART in a VM, non-stop TSC and TSC_ADJUST required */

So why can't we use is_uv_system() here an for the tsc_adjust thing?

I could. I just thought that there may be future system arches that need the same facility?

Quoted 5 lines

Also (and I hate the name) tsc_multi_sync_resets is the reason you cannot use ART, I don't think it makes sense to introduce yet another knob.

Okay. I wasn't sure if there might be different causes for wanting one condition over the other. So does this mean change this later test to use is_uv_system() or tsc_multi_sync_resets?

Thanks.

#7 lore raw

Re: [PATCH 4/5] x86/kernel: Provide a means to disable TSC ART

Quoted 17 lines · Mike Travis
Quoted 12 lines · Peter Zijlstra
Quoted 8 lines · On Mon, Oct 02, 2017 at 10:12:18AM -0500, [email protected] wrote:
  static void detect_art(void)
  {
  	unsigned int unused[2];
  -	if (boot_cpu_data.cpuid_level < ART_CPUID_LEAF)
arch/x86/kernel/tsc.c +1 -0
+	if (boot_cpu_data.cpuid_level < ART_CPUID_LEAF || tsc_art_disabled)
  		return;
    	/* Don't enable ART in a VM, non-stop TSC and TSC_ADJUST

required */

So why can't we use is_uv_system() here an for the tsc_adjust thing?

I could. I just thought that there may be future system arches that need the same facility?

Quoted 1 line
Quoted 7 lines
Quoted 4 lines

Also (and I hate the name) tsc_multi_sync_resets is the reason you cannot use ART, I don't think it makes sense to introduce yet another knob.

Okay. I wasn't sure if there might be different causes for wanting one condition over the other. So does this mean change this later test to use is_uv_system() or tsc_multi_sync_resets?

tsc_multi_sync_resets because that's the reason to disable ART as not all sockets have the same TSC <-> ART offset.

Btw, your changelog is slightly wrong here:

Quoted 3 lines

On systems where multiple chassis are reset asynchronously there is not a constant ratio between the ART frequency and the TSC time that can be provided by the boot cpu.

The ratio is actually the same as the frequencies should be the same. Though the offset in that equation:

n
TSC = offset + ART * ---
d

is different because that offset is basically TSC_ADJUST.

Thanks,

tglx

#8 lore raw

PATCH 5/5 x86/platform/UV: Add check of TSC state set by UV BIOS

In reply to [email protected]

Insert a check early in UV system startup that checks whether BIOS was able to obtain satisfactory TSC Sync stability. If not, it usually is caused by an error in the external TSC clock generation source. In this case the best fallback is to use the builtin hardware RTC as the kernel will not be able to set an accurate TSC sync either.

---
 arch/x86/include/asm/uv/uv_hub.h   |   23 +++++++++++++----
 arch/x86/kernel/apic/x2apic_uv_x.c |   48 +++++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+), 5 deletions(-)
arch/x86/include/asm/uv/uv_hub.h +18 -5
@@ -776,23 +776,36 @@ static inline int uv_num_possible_blades
 extern void uv_nmi_setup(void);
 extern void uv_nmi_setup_hubless(void);
 
+/* BIOS/Kernel flags exchange MMR */
+#define UVH_BIOS_KERNEL_MMR		UVH_SCRATCH5
+#define UVH_BIOS_KERNEL_MMR_ALIAS	UVH_SCRATCH5_ALIAS
+#define UVH_BIOS_KERNEL_MMR_ALIAS_2	UVH_SCRATCH5_ALIAS_2
+
+/* TSC sync valid, set by BIOS */
+#define UVH_TSC_SYNC_MMR	UVH_BIOS_KERNEL_MMR
+#define UVH_TSC_SYNC_SHIFT	10
+#define UVH_TSC_SYNC_SHIFT_UV2K	16	/* UV2/3k have different bits */
+#define UVH_TSC_SYNC_MASK	3	/* 0011 */
+#define UVH_TSC_SYNC_VALID	3	/* 0011 */
+#define UVH_TSC_SYNC_INVALID	2	/* 0010 */
+
 /* BMC sets a bit this MMR non-zero before sending an NMI */
-#define UVH_NMI_MMR		UVH_SCRATCH5
-#define UVH_NMI_MMR_CLEAR	UVH_SCRATCH5_ALIAS
+#define UVH_NMI_MMR		UVH_BIOS_KERNEL_MMR
+#define UVH_NMI_MMR_CLEAR	UVH_BIOS_KERNEL_MMR_ALIAS
 #define UVH_NMI_MMR_SHIFT	63
-#define	UVH_NMI_MMR_TYPE	"SCRATCH5"
+#define UVH_NMI_MMR_TYPE	"SCRATCH5"
 
 /* Newer SMM NMI handler, not present in all systems */
 #define UVH_NMI_MMRX		UVH_EVENT_OCCURRED0
 #define UVH_NMI_MMRX_CLEAR	UVH_EVENT_OCCURRED0_ALIAS
 #define UVH_NMI_MMRX_SHIFT	UVH_EVENT_OCCURRED0_EXTIO_INT0_SHFT
-#define	UVH_NMI_MMRX_TYPE	"EXTIO_INT0"
+#define UVH_NMI_MMRX_TYPE	"EXTIO_INT0"
 
 /* Non-zero indicates newer SMM NMI handler present */
 #define UVH_NMI_MMRX_SUPPORTED	UVH_EXTIO_INT0_BROADCAST
 
 /* Indicates to BIOS that we want to use the newer SMM NMI handler */
-#define UVH_NMI_MMRX_REQ	UVH_SCRATCH5_ALIAS_2
+#define UVH_NMI_MMRX_REQ	UVH_BIOS_KERNEL_MMR_ALIAS_2
 #define UVH_NMI_MMRX_REQ_SHIFT	62
 
 struct uv_hub_nmi_s {
arch/x86/kernel/apic/x2apic_uv_x.c +48 -0

60 lines not on this page · raw message