Skip to content

Commit efc8b32

Browse files
committed
clocksource: Verify HPET and PMTMR when TSC unverified
On systems with two or fewer sockets, when the boot CPU has CONSTANT_TSC, NONSTOP_TSC, and TSC_ADJUST, clocksource watchdog verification of the TSC is disabled. This works well much of the time, but there is the occasional production-level system that meets all of these criteria, but which still has a TSC that skews significantly from atomic-clock time. This is usually attributed to a firmware or hardware fault. Yes, the various NTP daemons do express their opinions of userspace-to-atomic-clock time skew, but they put them in various places, depending on the daemon and distro in question. It would therefore be good for the kernel to have some clue that there is a problem. The old behavior of marking the TSC unstable is a non-starter because a great many workloads simply cannot tolerate the overheads and latencies of the various non-TSC clocksources. In addition, NTP-corrected systems sometimes can tolerate significant kernel-space time skew as long as the userspace time sources are within epsilon of atomic-clock time. Therefore, when watchdog verification of TSC is disabled, enable it for HPET and PMTMR (AKA ACPI PM timer). This provides the needed in-kernel time-skew diagnostic without degrading the system's performance. Signed-off-by: Paul E. McKenney <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Dave Hansen <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: Daniel Lezcano <[email protected]> Cc: Waiman Long <[email protected]> Cc: <[email protected]> Tested-by: Feng Tang <[email protected]>
1 parent a7ec817 commit efc8b32

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

arch/x86/include/asm/time.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
extern void hpet_time_init(void);
99
extern void time_init(void);
1010
extern bool pit_timer_init(void);
11+
extern bool tsc_clocksource_watchdog_disabled(void);
1112

1213
extern struct clock_event_device *global_clock_event;
1314

arch/x86/kernel/hpet.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,8 @@ int __init hpet_enable(void)
10911091
if (!hpet_counting())
10921092
goto out_nohpet;
10931093

1094+
if (tsc_clocksource_watchdog_disabled())
1095+
clocksource_hpet.flags |= CLOCK_SOURCE_MUST_VERIFY;
10941096
clocksource_register_hz(&clocksource_hpet, (u32)hpet_freq);
10951097

10961098
if (id & HPET_ID_LEGSUP) {

arch/x86/kernel/tsc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,11 @@ static void __init tsc_disable_clocksource_watchdog(void)
11901190
clocksource_tsc.flags &= ~CLOCK_SOURCE_MUST_VERIFY;
11911191
}
11921192

1193+
bool tsc_clocksource_watchdog_disabled(void)
1194+
{
1195+
return !(clocksource_tsc.flags & CLOCK_SOURCE_MUST_VERIFY);
1196+
}
1197+
11931198
static void __init check_system_tsc_reliable(void)
11941199
{
11951200
#if defined(CONFIG_MGEODEGX1) || defined(CONFIG_MGEODE_LX) || defined(CONFIG_X86_GENERIC)

drivers/clocksource/acpi_pm.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/pci.h>
2424
#include <linux/delay.h>
2525
#include <asm/io.h>
26+
#include <asm/time.h>
2627

2728
/*
2829
* The I/O port the PMTMR resides at.
@@ -210,8 +211,9 @@ static int __init init_acpi_pm_clocksource(void)
210211
return -ENODEV;
211212
}
212213

213-
return clocksource_register_hz(&clocksource_acpi_pm,
214-
PMTMR_TICKS_PER_SEC);
214+
if (tsc_clocksource_watchdog_disabled())
215+
clocksource_acpi_pm.flags |= CLOCK_SOURCE_MUST_VERIFY;
216+
return clocksource_register_hz(&clocksource_acpi_pm, PMTMR_TICKS_PER_SEC);
215217
}
216218

217219
/* We use fs_initcall because we want the PCI fixups to have run

0 commit comments

Comments
 (0)