1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 23:58:11 +00:00

Kernel+LibC: Allow clock_gettime() to run without syscalls

This patch adds a vDSO-like mechanism for exposing the current time as
an array of per-clock-source timestamps.

LibC's clock_gettime() calls sys$map_time_page() to map the kernel's
"time page" into the process address space (at a random address, ofc.)
This is only done on first call, and from then on the timestamps are
fetched from the time page.

This first patch only adds support for CLOCK_REALTIME, but eventually
we should be able to support all clock sources this way and get rid of
sys$clock_gettime() in the kernel entirely. :^)

Accesses are synchronized using two atomic integers that are incremented
at the start and finish of the kernel's time page update cycle.
This commit is contained in:
Andreas Kling 2021-08-10 13:44:01 +02:00
parent f02d73db4d
commit fdfc66db61
7 changed files with 117 additions and 0 deletions

View file

@ -7,9 +7,11 @@
#pragma once
#include <AK/NonnullRefPtrVector.h>
#include <AK/OwnPtr.h>
#include <AK/RefPtr.h>
#include <AK/Time.h>
#include <AK/Types.h>
#include <Kernel/API/TimePage.h>
#include <Kernel/Arch/x86/RegisterState.h>
#include <Kernel/KResult.h>
#include <Kernel/UnixTypes.h>
@ -71,7 +73,12 @@ public:
bool can_query_precise_time() const { return m_can_query_precise_time; }
Memory::VMObject& time_page_vmobject();
private:
TimePage* time_page();
void update_time_page();
bool probe_and_set_legacy_hardware_timers();
bool probe_and_set_non_legacy_hardware_timers();
Vector<HardwareTimerBase*> scan_and_initialize_periodic_timers();
@ -100,6 +107,8 @@ private:
Atomic<u32> m_profile_enable_count { 0 };
RefPtr<HardwareTimerBase> m_profile_timer;
OwnPtr<Memory::Region> m_time_page_region;
};
}