Skip to content

Commit b50db70

Browse files
ftang1KAGA-KOKO
authored andcommitted
x86/tsc: Disable clocksource watchdog for TSC on qualified platorms
There are cases that the TSC clocksource is wrongly judged as unstable by the clocksource watchdog mechanism which tries to validate the TSC against HPET, PM_TIMER or jiffies. While there is hardly a general reliable way to check the validity of a watchdog, Thomas Gleixner proposed [1]: "I'm inclined to lift that requirement when the CPU has: 1) X86_FEATURE_CONSTANT_TSC 2) X86_FEATURE_NONSTOP_TSC 3) X86_FEATURE_NONSTOP_TSC_S3 4) X86_FEATURE_TSC_ADJUST 5) At max. 4 sockets After two decades of horrors we're finally at a point where TSC seems to be halfway reliable and less abused by BIOS tinkerers. TSC_ADJUST was really key as we can now detect even small modifications reliably and the important point is that we can cure them as well (not pretty but better than all other options)." As feature #3 X86_FEATURE_NONSTOP_TSC_S3 only exists on several generations of Atom processorz, and is always coupled with X86_FEATURE_CONSTANT_TSC and X86_FEATURE_NONSTOP_TSC, skip checking it, and also be more defensive to use maximal 2 sockets. The check is done inside tsc_init() before registering 'tsc-early' and 'tsc' clocksources, as there were cases that both of them had been wrongly judged as unreliable. For more background of tsc/watchdog, there is a good summary in [2] [tglx} Update vs. jiffies: On systems where the only remaining clocksource aside of TSC is jiffies there is no way to make this work because that creates a circular dependency. Jiffies accuracy depends on not missing a periodic timer interrupt, which is not guaranteed. That could be detected by TSC, but as TSC is not trusted this cannot be compensated. The consequence is a circulus vitiosus which results in shutting down TSC and falling back to the jiffies clocksource which is even more unreliable. [1]. https://lore.kernel.org/lkml/[email protected]/ [2]. https://lore.kernel.org/lkml/[email protected]/ [ tglx: Refine comment and amend changelog ] Fixes: 6e3cd95 ("x86/hpet: Use another crystalball to evaluate HPET usability") Suggested-by: Thomas Gleixner <[email protected]> Signed-off-by: Feng Tang <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Cc: "Paul E. McKenney" <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected]
1 parent c7719e7 commit b50db70

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

arch/x86/kernel/tsc.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,12 @@ void mark_tsc_unstable(char *reason)
11801180

11811181
EXPORT_SYMBOL_GPL(mark_tsc_unstable);
11821182

1183+
static void __init tsc_disable_clocksource_watchdog(void)
1184+
{
1185+
clocksource_tsc_early.flags &= ~CLOCK_SOURCE_MUST_VERIFY;
1186+
clocksource_tsc.flags &= ~CLOCK_SOURCE_MUST_VERIFY;
1187+
}
1188+
11831189
static void __init check_system_tsc_reliable(void)
11841190
{
11851191
#if defined(CONFIG_MGEODEGX1) || defined(CONFIG_MGEODE_LX) || defined(CONFIG_X86_GENERIC)
@@ -1196,6 +1202,23 @@ static void __init check_system_tsc_reliable(void)
11961202
#endif
11971203
if (boot_cpu_has(X86_FEATURE_TSC_RELIABLE))
11981204
tsc_clocksource_reliable = 1;
1205+
1206+
/*
1207+
* Disable the clocksource watchdog when the system has:
1208+
* - TSC running at constant frequency
1209+
* - TSC which does not stop in C-States
1210+
* - the TSC_ADJUST register which allows to detect even minimal
1211+
* modifications
1212+
* - not more than two sockets. As the number of sockets cannot be
1213+
* evaluated at the early boot stage where this has to be
1214+
* invoked, check the number of online memory nodes as a
1215+
* fallback solution which is an reasonable estimate.
1216+
*/
1217+
if (boot_cpu_has(X86_FEATURE_CONSTANT_TSC) &&
1218+
boot_cpu_has(X86_FEATURE_NONSTOP_TSC) &&
1219+
boot_cpu_has(X86_FEATURE_TSC_ADJUST) &&
1220+
nr_online_nodes <= 2)
1221+
tsc_disable_clocksource_watchdog();
11991222
}
12001223

12011224
/*
@@ -1387,9 +1410,6 @@ static int __init init_tsc_clocksource(void)
13871410
if (tsc_unstable)
13881411
goto unreg;
13891412

1390-
if (tsc_clocksource_reliable || no_tsc_watchdog)
1391-
clocksource_tsc.flags &= ~CLOCK_SOURCE_MUST_VERIFY;
1392-
13931413
if (boot_cpu_has(X86_FEATURE_NONSTOP_TSC_S3))
13941414
clocksource_tsc.flags |= CLOCK_SOURCE_SUSPEND_NONSTOP;
13951415

@@ -1527,7 +1547,7 @@ void __init tsc_init(void)
15271547
}
15281548

15291549
if (tsc_clocksource_reliable || no_tsc_watchdog)
1530-
clocksource_tsc_early.flags &= ~CLOCK_SOURCE_MUST_VERIFY;
1550+
tsc_disable_clocksource_watchdog();
15311551

15321552
clocksource_register_khz(&clocksource_tsc_early, tsc_khz);
15331553
detect_art();

0 commit comments

Comments
 (0)