瀏覽代碼

Scheduler: Use monotonic time for blocking threads

Liav A 5 年之前
父節點
當前提交
b4c92c24ee
共有 2 個文件被更改,包括 10 次插入4 次删除
  1. 8 4
      Kernel/Scheduler.cpp
  2. 2 0
      Kernel/Scheduler.h

+ 8 - 4
Kernel/Scheduler.cpp

@@ -67,6 +67,11 @@ static u32 time_slice_for(const Thread& thread)
     return 10;
 }
 
+timeval Scheduler::time_since_boot()
+{
+    return { TimeManagement::the().seconds_since_boot(), (suseconds_t)TimeManagement::the().ticks_this_second() * 1000 };
+}
+
 Thread* g_finalizer;
 Thread* g_colonel;
 WaitQueue* g_finalizer_wait_queue;
@@ -138,7 +143,7 @@ Thread::WriteBlocker::WriteBlocker(const FileDescription& description)
     if (description.is_socket()) {
         auto& socket = *description.socket();
         if (socket.has_send_timeout()) {
-            timeval deadline = kgettimeofday();
+            timeval deadline = Scheduler::time_since_boot();
             deadline.tv_sec += socket.send_timeout().tv_sec;
             deadline.tv_usec += socket.send_timeout().tv_usec;
             deadline.tv_sec += (socket.send_timeout().tv_usec / 1000000) * 1;
@@ -163,7 +168,7 @@ Thread::ReadBlocker::ReadBlocker(const FileDescription& description)
     if (description.is_socket()) {
         auto& socket = *description.socket();
         if (socket.has_receive_timeout()) {
-            timeval deadline = kgettimeofday();
+            timeval deadline = Scheduler::time_since_boot();
             deadline.tv_sec += socket.receive_timeout().tv_sec;
             deadline.tv_usec += socket.receive_timeout().tv_usec;
             deadline.tv_sec += (socket.receive_timeout().tv_usec / 1000000) * 1;
@@ -325,8 +330,7 @@ bool Scheduler::pick_next()
         return context_switch(*g_colonel);
     }
 
-    struct timeval now;
-    kgettimeofday(now);
+    auto now = time_since_boot();
 
     auto now_sec = now.tv_sec;
     auto now_usec = now.tv_usec;

+ 2 - 0
Kernel/Scheduler.h

@@ -30,6 +30,7 @@
 #include <AK/Function.h>
 #include <AK/IntrusiveList.h>
 #include <AK/Types.h>
+#include <Kernel/UnixTypes.h>
 
 namespace Kernel {
 
@@ -51,6 +52,7 @@ public:
     static void initialize();
     static void timer_tick(const RegisterState&);
     static bool pick_next();
+    static timeval time_since_boot();
     static void pick_next_and_switch_now();
     static void switch_now();
     static bool yield();