[PATCH 2/2] Revert "x86/hpet: Reduce HPET counter read contention"
From: Zhenzhong Duan
Date: Fri Mar 15 2019 - 04:41:52 EST
This reverts commit f99fd22e4d4bc84880a8a3117311bbf0e3a6a9dc.
It's unnecessory after commit "acpi_pm: Fix bootup softlockup due to PMTMR
counter read contention", the simple HPET access code could be restored.
On a general system with good TSC, TSC is the final default clocksource.
So the potential performce loss is only at bootup stage before TSC
replacing HPET, we didn't observe obvious delay of bootup.
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@xxxxxxxxxx>
Tested-by: Kin Cho <kin.cho@xxxxxxxxxx>
Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Borislav Petkov <bp@xxxxxxxxx>
Cc: "H. Peter Anvin" <hpa@xxxxxxxxx>
Cc: Waiman Long <longman@xxxxxxxxxx>
Cc: Srinivas Eeda <srinivas.eeda@xxxxxxxxxx>
Cc: x86@xxxxxxxxxx
---
arch/x86/kernel/hpet.c | 94 --------------------------------------------------
1 file changed, 94 deletions(-)
diff --git a/arch/x86/kernel/hpet.c b/arch/x86/kernel/hpet.c
index dfd3aca..b4fdee6a 100644
--- a/arch/x86/kernel/hpet.c
+++ b/arch/x86/kernel/hpet.c
@@ -749,104 +749,10 @@ static void hpet_reserve_msi_timers(struct hpet_data *hd)
/*
* Clock source related code
*/
-#if defined(CONFIG_SMP) && defined(CONFIG_64BIT)
-/*
- * Reading the HPET counter is a very slow operation. If a large number of
- * CPUs are trying to access the HPET counter simultaneously, it can cause
- * massive delay and slow down system performance dramatically. This may
- * happen when HPET is the default clock source instead of TSC. For a
- * really large system with hundreds of CPUs, the slowdown may be so
- * severe that it may actually crash the system because of a NMI watchdog
- * soft lockup, for example.
- *
- * If multiple CPUs are trying to access the HPET counter at the same time,
- * we don't actually need to read the counter multiple times. Instead, the
- * other CPUs can use the counter value read by the first CPU in the group.
- *
- * This special feature is only enabled on x86-64 systems. It is unlikely
- * that 32-bit x86 systems will have enough CPUs to require this feature
- * with its associated locking overhead. And we also need 64-bit atomic
- * read.
- *
- * The lock and the hpet value are stored together and can be read in a
- * single atomic 64-bit read. It is explicitly assumed that arch_spinlock_t
- * is 32 bits in size.
- */
-union hpet_lock {
- struct {
- arch_spinlock_t lock;
- u32 value;
- };
- u64 lockval;
-};
-
-static union hpet_lock hpet __cacheline_aligned = {
- { .lock = __ARCH_SPIN_LOCK_UNLOCKED, },
-};
-
-static u64 read_hpet(struct clocksource *cs)
-{
- unsigned long flags;
- union hpet_lock old, new;
-
- BUILD_BUG_ON(sizeof(union hpet_lock) != 8);
-
- /*
- * Read HPET directly if in NMI.
- */
- if (in_nmi())
- return (u64)hpet_readl(HPET_COUNTER);
-
- /*
- * Read the current state of the lock and HPET value atomically.
- */
- old.lockval = READ_ONCE(hpet.lockval);
-
- if (arch_spin_is_locked(&old.lock))
- goto contended;
-
- local_irq_save(flags);
- if (arch_spin_trylock(&hpet.lock)) {
- new.value = hpet_readl(HPET_COUNTER);
- /*
- * Use WRITE_ONCE() to prevent store tearing.
- */
- WRITE_ONCE(hpet.value, new.value);
- arch_spin_unlock(&hpet.lock);
- local_irq_restore(flags);
- return (u64)new.value;
- }
- local_irq_restore(flags);
-
-contended:
- /*
- * Contended case
- * --------------
- * Wait until the HPET value change or the lock is free to indicate
- * its value is up-to-date.
- *
- * It is possible that old.value has already contained the latest
- * HPET value while the lock holder was in the process of releasing
- * the lock. Checking for lock state change will enable us to return
- * the value immediately instead of waiting for the next HPET reader
- * to come along.
- */
- do {
- cpu_relax();
- new.lockval = READ_ONCE(hpet.lockval);
- } while ((new.value == old.value) && arch_spin_is_locked(&new.lock));
-
- return (u64)new.value;
-}
-#else
-/*
- * For UP or 32-bit.
- */
static u64 read_hpet(struct clocksource *cs)
{
return (u64)hpet_readl(HPET_COUNTER);
}
-#endif
static struct clocksource clocksource_hpet = {
.name = "hpet",
--
1.8.3.1