1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-02 22:42:08 +00:00

Kernel: Retire SchedulerData and add Thread lookup table

This allows us to get rid of the thread lists in SchedulerData.
Also, instead of iterating over all threads to find a thread by id,
just use a lookup table. In the rare case of having to iterate over
all threads, just iterate the lookup table.
This commit is contained in:
Tom 2021-01-27 22:58:24 -07:00 committed by Andreas Kling
parent e55d227f93
commit d5472426ec
5 changed files with 57 additions and 153 deletions

View file

@ -53,15 +53,8 @@ public:
bool m_in_scheduler { true };
};
SchedulerData* g_scheduler_data;
RecursiveSpinLock g_scheduler_lock;
void Scheduler::init_thread(Thread& thread)
{
ASSERT(g_scheduler_data);
g_scheduler_data->m_nonrunnable_threads.append(thread);
}
static u32 time_slice_for(const Thread& thread)
{
// One time slice unit == 4ms (assuming 250 ticks/second)
@ -238,36 +231,29 @@ bool Scheduler::pick_next()
}
if constexpr (SCHEDULER_RUNNABLE_DEBUG) {
dbgln("Scheduler[{}j]: Non-runnables:", Processor::id());
Scheduler::for_each_nonrunnable([&](Thread& thread) -> IterationDecision {
if (thread.state() == Thread::Dying) {
dbgln("Scheduler thread list:", Processor::id());
Thread::for_each([&](Thread& thread) -> IterationDecision {
switch (thread.state()) {
case Thread::Dying:
dbgln(" {:12} {} @ {:04x}:{:08x} Finalizable: {}",
thread.state_string(),
thread,
thread.tss().cs,
thread.tss().eip,
thread.is_finalizable());
} else {
dbgln(" {:12} {} @ {:04x}:{:08x}",
break;
default:
dbgln(" {:12} Pr:{:2} {} @ {:04x}:{:08x}",
thread.state_string(),
thread.priority(),
thread,
thread.tss().cs,
thread.tss().eip);
break;
}
return IterationDecision::Continue;
});
dbgln("Scheduler[{}j]: Runnables:", Processor::id());
Scheduler::for_each_runnable([](Thread& thread) -> IterationDecision {
dbgln(" {:2} {:12} @ {:04x}:{:08x}",
thread.priority(),
thread.state_string(),
thread.tss().cs,
thread.tss().eip);
return IterationDecision::Continue;
});
}
auto pending_beneficiary = scheduler_data.m_pending_beneficiary.strong_ref();
@ -507,7 +493,6 @@ void Scheduler::initialize()
ASSERT(&Processor::current() != nullptr); // sanity check
RefPtr<Thread> idle_thread;
g_scheduler_data = new SchedulerData;
g_finalizer_wait_queue = new WaitQueue;
g_ready_queues = new ThreadReadyQueue[g_ready_queue_buckets];