diff options
author | Andreas Kling <kling@serenityos.org> | 2021-08-10 21:31:31 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-10 21:51:05 +0200 |
commit | b7dae4f90eca46220217b8a858afe5915f761a1b (patch) | |
tree | 73c5b63262ffbe1c4dfcca191330559beeae1ea5 | |
parent | aaead6f332f0fdeb453105f061741e1ad3ba576b (diff) | |
download | serenity-b7dae4f90eca46220217b8a858afe5915f761a1b.zip |
Kernel: Add CLOCK_MONOTONIC_COARSE to the kernel time page
This allows clock_gettime(CLOCK_MONOTONIC_COARSE) without syscalls.
Core::EventLoop takes advantage of this automatically. :^)
-rw-r--r-- | Kernel/API/TimePage.h | 2 | ||||
-rw-r--r-- | Kernel/Time/TimeManagement.cpp | 8 |
2 files changed, 6 insertions, 4 deletions
diff --git a/Kernel/API/TimePage.h b/Kernel/API/TimePage.h index e1492cd21f..76e6b44f8f 100644 --- a/Kernel/API/TimePage.h +++ b/Kernel/API/TimePage.h @@ -18,7 +18,7 @@ namespace Kernel { inline bool time_page_supports(clockid_t clock_id) { - return clock_id == CLOCK_REALTIME_COARSE; + return clock_id == CLOCK_REALTIME_COARSE || clock_id == CLOCK_MONOTONIC_COARSE; } struct TimePage { diff --git a/Kernel/Time/TimeManagement.cpp b/Kernel/Time/TimeManagement.cpp index 9c43604965..6d9f6c6bf1 100644 --- a/Kernel/Time/TimeManagement.cpp +++ b/Kernel/Time/TimeManagement.cpp @@ -363,9 +363,9 @@ void TimeManagement::increment_time_since_boot_hpet() // TODO: Apply m_remaining_epoch_time_adjustment timespec_add(m_epoch_time, { (time_t)(delta_ns / 1000000000), (long)(delta_ns % 1000000000) }, m_epoch_time); - update_time_page(); - m_update1.store(update_iteration + 1, AK::MemoryOrder::memory_order_release); + + update_time_page(); } void TimeManagement::increment_time_since_boot() @@ -396,8 +396,9 @@ void TimeManagement::increment_time_since_boot() m_ticks_this_second = 0; } - update_time_page(); m_update1.store(update_iteration + 1, AK::MemoryOrder::memory_order_release); + + update_time_page(); } void TimeManagement::system_timer_tick(const RegisterState& regs) @@ -432,6 +433,7 @@ void TimeManagement::update_time_page() auto* page = time_page(); u32 update_iteration = AK::atomic_fetch_add(&page->update2, 1u, AK::MemoryOrder::memory_order_acquire); page->clocks[CLOCK_REALTIME_COARSE] = m_epoch_time; + page->clocks[CLOCK_MONOTONIC_COARSE] = monotonic_time(TimePrecision::Coarse).to_timespec(); AK::atomic_store(&page->update1, update_iteration + 1u, AK::MemoryOrder::memory_order_release); } |