From 63117f826b8750fd7f57c16aa7acbb71bab529e4 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 11 Dec 2021 18:59:40 +0100 Subject: [PATCH] Kernel: Simplify 64-bit HPET reads on x86_64 We don't have to worry about racy 32-bit reads when we're reading the 64-bit HPET value using a 64-bit CPU. :^) --- Kernel/Time/HPET.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Kernel/Time/HPET.cpp b/Kernel/Time/HPET.cpp index 6feb05af86..990661611d 100644 --- a/Kernel/Time/HPET.cpp +++ b/Kernel/Time/HPET.cpp @@ -46,8 +46,13 @@ enum class TimerConfiguration : u32 { }; struct [[gnu::packed]] HPETRegister { - volatile u32 low; - volatile u32 high; + union { + volatile u64 full; + struct { + volatile u32 low; + volatile u32 high; + }; + }; }; struct [[gnu::packed]] TimerStructure { @@ -87,6 +92,9 @@ static_assert(AssertSize()); static u64 read_register_safe64(const HPETRegister& reg) { +#if ARCH(X86_64) + return reg.full; +#else // As per 2.4.7 this reads the 64 bit value in a consistent manner // using only 32 bit reads u32 low, high = reg.high; @@ -98,6 +106,7 @@ static u64 read_register_safe64(const HPETRegister& reg) high = new_high; } return ((u64)high << 32) | (u64)low; +#endif } static HPET* s_hpet;