summaryrefslogtreecommitdiff
path: root/Kernel/Thread.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-12-30 18:46:17 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-12-30 18:46:17 +0100
commit50677bf806e73d6b2bf940e0192f170b7bbaf3e4 (patch)
treeded0adfb9b7ef673c85847ea0636e091101b31c0 /Kernel/Thread.cpp
parent816d3e6208bb4d24267d3c87833e550054a5248b (diff)
downloadserenity-50677bf806e73d6b2bf940e0192f170b7bbaf3e4.zip
Kernel: Refactor scheduler to use dynamic thread priorities
Threads now have numeric priorities with a base priority in the 1-99 range. Whenever a runnable thread is *not* scheduled, its effective priority is incremented by 1. This is tracked in Thread::m_extra_priority. The effective priority of a thread is m_priority + m_extra_priority. When a runnable thread *is* scheduled, its m_extra_priority is reset to zero and the effective priority returns to base. This means that lower-priority threads will always eventually get scheduled to run, once its effective priority becomes high enough to exceed the base priority of threads "above" it. The previous values for ThreadPriority (Low, Normal and High) are now replaced as follows: Low -> 10 Normal -> 30 High -> 50 In other words, it will take 20 ticks for a "Low" priority thread to get to "Normal" effective priority, and another 20 to reach "High". This is not perfect, and I've used some quite naive data structures, but I think the mechanism will allow us to build various new and interesting optimizations, and we can figure out better data structures later on. :^)
Diffstat (limited to 'Kernel/Thread.cpp')
-rw-r--r--Kernel/Thread.cpp17
1 files changed, 0 insertions, 17 deletions
diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp
index 9201752453..92078cae45 100644
--- a/Kernel/Thread.cpp
+++ b/Kernel/Thread.cpp
@@ -765,23 +765,6 @@ const LogStream& operator<<(const LogStream& stream, const Thread& value)
return stream << value.process().name() << "(" << value.pid() << ":" << value.tid() << ")";
}
-const char* to_string(ThreadPriority priority)
-{
- switch (priority) {
- case ThreadPriority::Idle:
- return "Idle";
- case ThreadPriority::Low:
- return "Low";
- case ThreadPriority::Normal:
- return "Normal";
- case ThreadPriority::High:
- return "High";
- }
- dbg() << "to_string(ThreadPriority): Invalid priority: " << (u32)priority;
- ASSERT_NOT_REACHED();
- return nullptr;
-}
-
void Thread::wait_on(WaitQueue& queue, Thread* beneficiary, const char* reason)
{
bool did_unlock = unlock_process_if_locked();