Kernel+LibC: Publish a "kernel info page" and use it for gettimeofday()

This patch adds a single "kernel info page" that is mappable read-only
by any process and contains the current time of day.

This is then used to implement a version of gettimeofday() that doesn't
have to make a syscall.

To protect against race condition issues, the info page also has a
serial number which is incremented whenever the kernel updates the
contents of the page. Make sure to verify that the serial number is the
same before and after reading the information you want from the page.
This commit is contained in:
Andreas Kling 2019-12-15 21:29:26 +01:00
commit 77cf607cda
Notes: sideshowbarker 2024-07-19 10:50:40 +09:00
6 changed files with 62 additions and 9 deletions

View file

@ -548,6 +548,11 @@ void Scheduler::timer_tick(RegisterDump& regs)
++g_uptime;
timeval tv;
tv.tv_sec = RTC::boot_time() + PIT::seconds_since_boot();
tv.tv_usec = PIT::ticks_this_second() * 1000;
Process::update_info_page_timestamp(tv);
if (s_beep_timeout && g_uptime > s_beep_timeout) {
PCSpeaker::tone_off();
s_beep_timeout = 0;