Skip to content

Commit 3ffdaab

Browse files
tomutaawesomekling
authored andcommitted
Kernel: Only consider scheduler Running threads if they're the current
There will be as many threads in Running state as there are CPUs. Only consider a thread in that state if it is the current thread already.
1 parent 1e2e3ee commit 3ffdaab

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Kernel/Scheduler.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,8 @@ bool Scheduler::pick_next()
465465
});
466466

467467
#ifdef SCHEDULER_RUNNABLE_DEBUG
468-
dbg() << "Non-runnables:";
469-
Scheduler::for_each_nonrunnable([](Thread& thread) -> IterationDecision {
468+
dbg() << "Scheduler[" << Processor::current().id() << "]: Non-runnables:";
469+
Scheduler::for_each_nonrunnable([&](Thread& thread) -> IterationDecision {
470470
if (thread.state() == Thread::Queued)
471471
dbg() << " " << String::format("%-12s", thread.state_string()) << " " << thread << " @ " << String::format("%w", thread.tss().cs) << ":" << String::format("%x", thread.tss().eip) << " Reason: " << (thread.wait_reason() ? thread.wait_reason() : "none");
472472
else if (thread.state() == Thread::Dying)
@@ -476,7 +476,7 @@ bool Scheduler::pick_next()
476476
return IterationDecision::Continue;
477477
});
478478

479-
dbg() << "Runnables:";
479+
dbg() << "Scheduler[" << Processor::current().id() << "]: Runnables:";
480480
Scheduler::for_each_runnable([](Thread& thread) -> IterationDecision {
481481
dbg() << " " << String::format("%3u", thread.effective_priority()) << "/" << String::format("%2u", thread.priority()) << " " << String::format("%-12s", thread.state_string()) << " " << thread << " @ " << String::format("%w", thread.tss().cs) << ":" << String::format("%x", thread.tss().eip);
482482
return IterationDecision::Continue;
@@ -487,8 +487,11 @@ bool Scheduler::pick_next()
487487

488488
Vector<Thread*, 128> sorted_runnables;
489489
for_each_runnable([&](auto& thread) {
490-
if ((thread.affinity() & (1u << Processor::current().id())) != 0)
491-
sorted_runnables.append(&thread);
490+
if ((thread.affinity() & (1u << Processor::current().id())) == 0)
491+
return IterationDecision::Continue;
492+
if (thread.state() == Thread::Running && &thread != current_thread)
493+
return IterationDecision::Continue;
494+
sorted_runnables.append(&thread);
492495
if (&thread == scheduler_data.m_pending_beneficiary) {
493496
thread_to_schedule = &thread;
494497
return IterationDecision::Break;

0 commit comments

Comments
 (0)