Procházet zdrojové kódy

Kernel: Take into account the time keeper's frequency (if no HPET)

The PIT is now also running at a rate of ~250 ticks/second, so rather
than assuming there are 1000 ticks/second we need to query the timer
being used for the actual frequency.

Fixes #4508
Tom před 4 roky
rodič
revize
f1534ff36e
2 změnil soubory, kde provedl 7 přidání a 3 odebrání
  1. 5 0
      Kernel/Time/HardwareTimer.h
  2. 2 3
      Kernel/Time/TimeManagement.cpp

+ 5 - 0
Kernel/Time/HardwareTimer.h

@@ -58,6 +58,7 @@ public:
     virtual void set_periodic() = 0;
     virtual void set_non_periodic() = 0;
     virtual void disable() = 0;
+    virtual u32 frequency() const = 0;
 
     virtual size_t ticks_per_second() const = 0;
 
@@ -88,6 +89,8 @@ public:
         return previous_callback;
     }
 
+    virtual u32 frequency() const override { return (u32)m_frequency; }
+
 protected:
     HardwareTimer(u8 irq_number, Function<void(const RegisterState&)> callback = nullptr)
         : IRQHandler(irq_number)
@@ -131,6 +134,8 @@ public:
     virtual const char* controller() const override { return nullptr; }
     virtual bool eoi() override;
 
+    virtual u32 frequency() const override { return (u32)m_frequency; }
+
 protected:
     HardwareTimer(u8 irq_number, Function<void(const RegisterState&)> callback = nullptr)
         : GenericInterruptHandler(irq_number)

+ 2 - 3
Kernel/Time/TimeManagement.cpp

@@ -366,9 +366,8 @@ void TimeManagement::increment_time_since_boot()
     // Compute time adjustment for adjtime. Let the clock run up to 1% fast or slow.
     // That way, adjtime can adjust up to 36 seconds per hour, without time getting very jumpy.
     // Once we have a smarter NTP service that also adjusts the frequency instead of just slewing time, maybe we can lower this.
-    constexpr long NanosPerTick = 1'000'000; // FIXME: Don't assume that one tick is 1 ms.
-    constexpr time_t MaxSlewNanos = NanosPerTick / 100;
-    static_assert(MaxSlewNanos < NanosPerTick);
+    long NanosPerTick = 1'000'000'000 / m_time_keeper_timer->frequency();
+    time_t MaxSlewNanos = NanosPerTick / 100;
 
     u32 update_iteration = m_update1.fetch_add(1, AK::MemoryOrder::memory_order_acquire);