Skip to contentSkip to conversation

x86/hpet: dovetail: Harden clocksource for use in oob

PATCH Applied Jan Kiszka 2 participants 2 messages Jun 18, 2021

Subsystems (2)
lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 1/1 x86/hpet: dovetail: Harden clocksource for use in oob

From: Jan Kiszka <[email protected]>

While it's slow, has scalability issues, it remains the second-best clocksource for Linux on x86. If Linux decides that the TSC is not reliable we will end up here and should avoid bringing the system into an unstable state.

---

While this does not give us hpet for Xenomai yet (vDSO fallback path still missing), it resolves the system stalls when Linux switches here.

 arch/x86/kernel/hpet.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/hpet.c +3 -3
index 67a9f248270c..ce8e15aa8a97 100644
@@ -811,7 +811,7 @@ static u64 read_hpet(struct clocksource *cs)
 	if (arch_spin_is_locked(&old.lock))
 		goto contended;
 
-	local_irq_save(flags);
+	flags = hard_local_irq_save();
 	if (arch_spin_trylock(&hpet.lock)) {
 		new.value = hpet_readl(HPET_COUNTER);
 		/*
@@ -819,10 +819,10 @@ static u64 read_hpet(struct clocksource *cs)
 		 */
 		WRITE_ONCE(hpet.value, new.value);
 		arch_spin_unlock(&hpet.lock);
-		local_irq_restore(flags);
+		hard_local_irq_restore(flags);
 		return (u64)new.value;
 	}
-	local_irq_restore(flags);
+	hard_local_irq_restore(flags);
 
 contended:
 	/*
Signature · 1 line
2.26.2
#1 lore raw
Quoted 33 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

While it's slow, has scalability issues, it remains the second-best clocksource for Linux on x86. If Linux decides that the TSC is not reliable we will end up here and should avoid bringing the system into an unstable state.

---

While this does not give us hpet for Xenomai yet (vDSO fallback path still missing), it resolves the system stalls when Linux switches here.

 arch/x86/kernel/hpet.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/hpet.c +1 -1
index 67a9f248270c..ce8e15aa8a97 100644
@@ -811,7 +811,7 @@ static u64 read_hpet(struct clocksource *cs)
 	if (arch_spin_is_locked(&old.lock))
 		goto contended;
 
-	local_irq_save(flags);
+	flags = hard_local_irq_save();
 	if (arch_spin_trylock(&hpet.lock)) {
 		new.value = hpet_readl(HPET_COUNTER);
 		/*
@@ -819,10 +819,10 @@ static u64 read_hpet(struct clocksource *cs)
 		 */
 		WRITE_ONCE(hpet.value, new.value);

arch/x86/kernel/hpet.c static u64 read_hpet(struct clocksource *cs) · line 828

Quoted 10 lines
arch/x86/kernel/hpet.c +2 -2
 		arch_spin_unlock(&hpet.lock);
-		local_irq_restore(flags);
+		hard_local_irq_restore(flags);
 		return (u64)new.value;
 	}
-	local_irq_restore(flags);
+	hard_local_irq_restore(flags);
 
 contended:
 	/*

Tested with EVL v5.10.42 on Atom x5 quad core (1.8 Ghz), with clocksource=hpet forced on the kernel command line, running latmus under stress. All good, although the typical latency is more than two times the one we have with TSC, as expected unfortunately. Nothing pathological, just the combination of slow hpet hardware and non-vDSO access to read it.

Merged, thanks.

Signature · 1 line
Philippe.