Przeglądaj źródła

Kernel: Remove the "kernel info page" used for fast gettimeofday()

We stopped using gettimeofday() in Core::EventLoop a while back,
in favor of clock_gettime() for monotonic time.

Maintaining an optimization for a syscall we're not using doesn't make
a lot of sense, so let's go back to the old-style sys$gettimeofday().
Andreas Kling 5 lat temu
rodzic
commit
3a92d0828d
6 zmienionych plików z 7 dodań i 46 usunięć
  1. 1 27
      Kernel/Process.cpp
  2. 0 3
      Kernel/Process.h
  3. 3 4
      Kernel/Scheduler.cpp
  4. 1 0
      Kernel/Scheduler.h
  5. 0 1
      Kernel/Syscall.h
  6. 2 11
      Libraries/LibC/time.cpp

+ 1 - 27
Kernel/Process.cpp

@@ -95,7 +95,6 @@
 namespace Kernel {
 
 static void create_signal_trampolines();
-static void create_kernel_info_page();
 
 Process* Process::current;
 
@@ -103,8 +102,6 @@ static pid_t next_pid;
 InlineLinkedList<Process>* g_processes;
 static String* s_hostname;
 static Lock* s_hostname_lock;
-static VirtualAddress s_info_page_address_for_userspace;
-static VirtualAddress s_info_page_address_for_kernel;
 VirtualAddress g_return_to_ring3_from_signal_trampoline;
 HashMap<String, OwnPtr<Module>>* g_modules;
 
@@ -124,14 +121,6 @@ void Process::initialize()
     s_hostname_lock = new Lock;
 
     create_signal_trampolines();
-    create_kernel_info_page();
-}
-
-void Process::update_info_page_timestamp(const timeval& tv)
-{
-    auto* info_page = (KernelInfoPage*)s_info_page_address_for_kernel.as_ptr();
-    info_page->serial++;
-    const_cast<timeval&>(info_page->now) = tv;
 }
 
 Vector<pid_t> Process::all_pids()
@@ -1500,15 +1489,6 @@ void create_signal_trampolines()
     trampoline_region->remap();
 }
 
-void create_kernel_info_page()
-{
-    auto* info_page_region_for_userspace = MM.allocate_user_accessible_kernel_region(PAGE_SIZE, "Kernel info page", Region::Access::Read).leak_ptr();
-    auto* info_page_region_for_kernel = MM.allocate_kernel_region_with_vmobject(info_page_region_for_userspace->vmobject(), PAGE_SIZE, "Kernel info page", Region::Access::Read | Region::Access::Write).leak_ptr();
-    s_info_page_address_for_userspace = info_page_region_for_userspace->vaddr();
-    s_info_page_address_for_kernel = info_page_region_for_kernel->vaddr();
-    memset(s_info_page_address_for_kernel.as_ptr(), 0, PAGE_SIZE);
-}
-
 int Process::sys$sigreturn(RegisterState& registers)
 {
     REQUIRE_PROMISE(stdio);
@@ -2330,7 +2310,7 @@ int Process::sys$sleep(unsigned seconds)
 
 timeval kgettimeofday()
 {
-    return const_cast<const timeval&>(((KernelInfoPage*)s_info_page_address_for_kernel.as_ptr())->now);
+    return g_timeofday;
 }
 
 void compute_relative_timeout_from_absolute(const timeval& absolute_time, timeval& relative_time)
@@ -4639,12 +4619,6 @@ int Process::sys$profiling_disable(pid_t pid)
     return 0;
 }
 
-void* Process::sys$get_kernel_info_page()
-{
-    REQUIRE_PROMISE(stdio);
-    return s_info_page_address_for_userspace.as_ptr();
-}
-
 Thread& Process::any_thread()
 {
     Thread* found_thread = nullptr;

+ 0 - 3
Kernel/Process.h

@@ -135,8 +135,6 @@ public:
 
     static Process* from_pid(pid_t);
 
-    static void update_info_page_timestamp(const timeval&);
-
     const String& name() const { return m_name; }
     pid_t pid() const { return m_pid; }
     pid_t sid() const { return m_sid; }
@@ -299,7 +297,6 @@ public:
     int sys$module_unload(const char* name, size_t name_length);
     int sys$profiling_enable(pid_t);
     int sys$profiling_disable(pid_t);
-    void* sys$get_kernel_info_page();
     int sys$futex(const Syscall::SC_futex_params*);
     int sys$set_thread_boost(int tid, int amount);
     int sys$set_process_boost(pid_t, int amount);

+ 3 - 4
Kernel/Scheduler.cpp

@@ -42,6 +42,7 @@
 namespace Kernel {
 
 SchedulerData* g_scheduler_data;
+timeval g_timeofday;
 
 void Scheduler::init_thread(Thread& thread)
 {
@@ -596,10 +597,8 @@ void Scheduler::timer_tick(const RegisterState& regs)
 
     ++g_uptime;
 
-    timeval tv;
-    tv.tv_sec = TimeManagement::the().epoch_time();
-    tv.tv_usec = TimeManagement::the().ticks_this_second() * 1000;
-    Process::update_info_page_timestamp(tv);
+    g_timeofday.tv_sec = TimeManagement::the().epoch_time();
+    g_timeofday.tv_usec = TimeManagement::the().ticks_this_second() * 1000;
 
     if (Process::current->is_profiling()) {
         SmapDisabler disabler;

+ 1 - 0
Kernel/Scheduler.h

@@ -46,6 +46,7 @@ extern WaitQueue* g_finalizer_wait_queue;
 extern bool g_finalizer_has_work;
 extern u64 g_uptime;
 extern SchedulerData* g_scheduler_data;
+extern timeval g_timeofday;
 
 class Scheduler {
 public:

+ 0 - 1
Kernel/Syscall.h

@@ -173,7 +173,6 @@ namespace Kernel {
     __ENUMERATE_SYSCALL(shbuf_set_volatile)   \
     __ENUMERATE_SYSCALL(profiling_enable)     \
     __ENUMERATE_SYSCALL(profiling_disable)    \
-    __ENUMERATE_SYSCALL(get_kernel_info_page) \
     __ENUMERATE_SYSCALL(futex)                \
     __ENUMERATE_SYSCALL(set_thread_boost)     \
     __ENUMERATE_SYSCALL(set_process_boost)    \

+ 2 - 11
Libraries/LibC/time.cpp

@@ -51,17 +51,8 @@ time_t time(time_t* tloc)
 
 int gettimeofday(struct timeval* __restrict__ tv, void* __restrict__)
 {
-    static volatile KernelInfoPage* kernel_info;
-    if (!kernel_info)
-        kernel_info = (volatile KernelInfoPage*)syscall(SC_get_kernel_info_page);
-
-    for (;;) {
-        auto serial = kernel_info->serial;
-        *tv = const_cast<struct timeval&>(kernel_info->now);
-        if (serial == kernel_info->serial)
-            break;
-    }
-    return 0;
+    int rc = syscall(SC_gettimeofday, tv);
+    __RETURN_WITH_ERRNO(rc, rc, -1);
 }
 
 char* ctime(const time_t* t)