diff options
Diffstat (limited to 'src/core/hle/kernel/scheduler.cpp')
| -rw-r--r-- | src/core/hle/kernel/scheduler.cpp | 55 |
1 files changed, 12 insertions, 43 deletions
diff --git a/src/core/hle/kernel/scheduler.cpp b/src/core/hle/kernel/scheduler.cpp index e6dcb9639..0e2dbf13e 100644 --- a/src/core/hle/kernel/scheduler.cpp +++ b/src/core/hle/kernel/scheduler.cpp | |||
| @@ -22,9 +22,9 @@ | |||
| 22 | 22 | ||
| 23 | namespace Kernel { | 23 | namespace Kernel { |
| 24 | 24 | ||
| 25 | GlobalScheduler::GlobalScheduler(Core::System& system) : system{system} { | 25 | GlobalScheduler::GlobalScheduler(Core::System& system) : system{system} {} |
| 26 | is_reselection_pending = false; | 26 | |
| 27 | } | 27 | GlobalScheduler::~GlobalScheduler() = default; |
| 28 | 28 | ||
| 29 | void GlobalScheduler::AddThread(SharedPtr<Thread> thread) { | 29 | void GlobalScheduler::AddThread(SharedPtr<Thread> thread) { |
| 30 | thread_list.push_back(std::move(thread)); | 30 | thread_list.push_back(std::move(thread)); |
| @@ -35,24 +35,11 @@ void GlobalScheduler::RemoveThread(const Thread* thread) { | |||
| 35 | thread_list.end()); | 35 | thread_list.end()); |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | /* | ||
| 39 | * UnloadThread selects a core and forces it to unload its current thread's context | ||
| 40 | */ | ||
| 41 | void GlobalScheduler::UnloadThread(s32 core) { | 38 | void GlobalScheduler::UnloadThread(s32 core) { |
| 42 | Scheduler& sched = system.Scheduler(core); | 39 | Scheduler& sched = system.Scheduler(core); |
| 43 | sched.UnloadThread(); | 40 | sched.UnloadThread(); |
| 44 | } | 41 | } |
| 45 | 42 | ||
| 46 | /* | ||
| 47 | * SelectThread takes care of selecting the new scheduled thread. | ||
| 48 | * It does it in 3 steps: | ||
| 49 | * - First a thread is selected from the top of the priority queue. If no thread | ||
| 50 | * is obtained then we move to step two, else we are done. | ||
| 51 | * - Second we try to get a suggested thread that's not assigned to any core or | ||
| 52 | * that is not the top thread in that core. | ||
| 53 | * - Third is no suggested thread is found, we do a second pass and pick a running | ||
| 54 | * thread in another core and swap it with its current thread. | ||
| 55 | */ | ||
| 56 | void GlobalScheduler::SelectThread(u32 core) { | 43 | void GlobalScheduler::SelectThread(u32 core) { |
| 57 | const auto update_thread = [](Thread* thread, Scheduler& sched) { | 44 | const auto update_thread = [](Thread* thread, Scheduler& sched) { |
| 58 | if (thread != sched.selected_thread) { | 45 | if (thread != sched.selected_thread) { |
| @@ -114,30 +101,19 @@ void GlobalScheduler::SelectThread(u32 core) { | |||
| 114 | update_thread(current_thread, sched); | 101 | update_thread(current_thread, sched); |
| 115 | } | 102 | } |
| 116 | 103 | ||
| 117 | /* | ||
| 118 | * YieldThread takes a thread and moves it to the back of the it's priority list | ||
| 119 | * This operation can be redundant and no scheduling is changed if marked as so. | ||
| 120 | */ | ||
| 121 | bool GlobalScheduler::YieldThread(Thread* yielding_thread) { | 104 | bool GlobalScheduler::YieldThread(Thread* yielding_thread) { |
| 122 | // Note: caller should use critical section, etc. | 105 | // Note: caller should use critical section, etc. |
| 123 | const u32 core_id = static_cast<u32>(yielding_thread->GetProcessorID()); | 106 | const u32 core_id = static_cast<u32>(yielding_thread->GetProcessorID()); |
| 124 | const u32 priority = yielding_thread->GetPriority(); | 107 | const u32 priority = yielding_thread->GetPriority(); |
| 125 | 108 | ||
| 126 | // Yield the thread | 109 | // Yield the thread |
| 127 | ASSERT_MSG(yielding_thread == scheduled_queue[core_id].front(priority), | 110 | const Thread* const winner = scheduled_queue[core_id].front(priority); |
| 128 | "Thread yielding without being in front"); | 111 | ASSERT_MSG(yielding_thread == winner, "Thread yielding without being in front"); |
| 129 | scheduled_queue[core_id].yield(priority); | 112 | scheduled_queue[core_id].yield(priority); |
| 130 | 113 | ||
| 131 | Thread* winner = scheduled_queue[core_id].front(priority); | ||
| 132 | return AskForReselectionOrMarkRedundant(yielding_thread, winner); | 114 | return AskForReselectionOrMarkRedundant(yielding_thread, winner); |
| 133 | } | 115 | } |
| 134 | 116 | ||
| 135 | /* | ||
| 136 | * YieldThreadAndBalanceLoad takes a thread and moves it to the back of the it's priority list. | ||
| 137 | * Afterwards, tries to pick a suggested thread from the suggested queue that has worse time or | ||
| 138 | * a better priority than the next thread in the core. | ||
| 139 | * This operation can be redundant and no scheduling is changed if marked as so. | ||
| 140 | */ | ||
| 141 | bool GlobalScheduler::YieldThreadAndBalanceLoad(Thread* yielding_thread) { | 117 | bool GlobalScheduler::YieldThreadAndBalanceLoad(Thread* yielding_thread) { |
| 142 | // Note: caller should check if !thread.IsSchedulerOperationRedundant and use critical section, | 118 | // Note: caller should check if !thread.IsSchedulerOperationRedundant and use critical section, |
| 143 | // etc. | 119 | // etc. |
| @@ -189,12 +165,6 @@ bool GlobalScheduler::YieldThreadAndBalanceLoad(Thread* yielding_thread) { | |||
| 189 | return AskForReselectionOrMarkRedundant(yielding_thread, winner); | 165 | return AskForReselectionOrMarkRedundant(yielding_thread, winner); |
| 190 | } | 166 | } |
| 191 | 167 | ||
| 192 | /* | ||
| 193 | * YieldThreadAndWaitForLoadBalancing takes a thread and moves it out of the scheduling queue | ||
| 194 | * and into the suggested queue. If no thread can be squeduled afterwards in that core, | ||
| 195 | * a suggested thread is obtained instead. | ||
| 196 | * This operation can be redundant and no scheduling is changed if marked as so. | ||
| 197 | */ | ||
| 198 | bool GlobalScheduler::YieldThreadAndWaitForLoadBalancing(Thread* yielding_thread) { | 168 | bool GlobalScheduler::YieldThreadAndWaitForLoadBalancing(Thread* yielding_thread) { |
| 199 | // Note: caller should check if !thread.IsSchedulerOperationRedundant and use critical section, | 169 | // Note: caller should check if !thread.IsSchedulerOperationRedundant and use critical section, |
| 200 | // etc. | 170 | // etc. |
| @@ -280,7 +250,7 @@ void GlobalScheduler::PreemptThreads() { | |||
| 280 | if (winner->IsRunning()) { | 250 | if (winner->IsRunning()) { |
| 281 | UnloadThread(winner->GetProcessorID()); | 251 | UnloadThread(winner->GetProcessorID()); |
| 282 | } | 252 | } |
| 283 | TransferToCore(winner->GetPriority(), core_id, winner); | 253 | TransferToCore(winner->GetPriority(), s32(core_id), winner); |
| 284 | current_thread = | 254 | current_thread = |
| 285 | winner->GetPriority() <= current_thread->GetPriority() ? winner : current_thread; | 255 | winner->GetPriority() <= current_thread->GetPriority() ? winner : current_thread; |
| 286 | } | 256 | } |
| @@ -313,7 +283,7 @@ void GlobalScheduler::PreemptThreads() { | |||
| 313 | if (winner->IsRunning()) { | 283 | if (winner->IsRunning()) { |
| 314 | UnloadThread(winner->GetProcessorID()); | 284 | UnloadThread(winner->GetProcessorID()); |
| 315 | } | 285 | } |
| 316 | TransferToCore(winner->GetPriority(), core_id, winner); | 286 | TransferToCore(winner->GetPriority(), s32(core_id), winner); |
| 317 | current_thread = winner; | 287 | current_thread = winner; |
| 318 | } | 288 | } |
| 319 | } | 289 | } |
| @@ -331,12 +301,12 @@ void GlobalScheduler::Unsuggest(u32 priority, u32 core, Thread* thread) { | |||
| 331 | } | 301 | } |
| 332 | 302 | ||
| 333 | void GlobalScheduler::Schedule(u32 priority, u32 core, Thread* thread) { | 303 | void GlobalScheduler::Schedule(u32 priority, u32 core, Thread* thread) { |
| 334 | ASSERT_MSG(thread->GetProcessorID() == core, "Thread must be assigned to this core."); | 304 | ASSERT_MSG(thread->GetProcessorID() == s32(core), "Thread must be assigned to this core."); |
| 335 | scheduled_queue[core].add(thread, priority); | 305 | scheduled_queue[core].add(thread, priority); |
| 336 | } | 306 | } |
| 337 | 307 | ||
| 338 | void GlobalScheduler::SchedulePrepend(u32 priority, u32 core, Thread* thread) { | 308 | void GlobalScheduler::SchedulePrepend(u32 priority, u32 core, Thread* thread) { |
| 339 | ASSERT_MSG(thread->GetProcessorID() == core, "Thread must be assigned to this core."); | 309 | ASSERT_MSG(thread->GetProcessorID() == s32(core), "Thread must be assigned to this core."); |
| 340 | scheduled_queue[core].add(thread, priority, false); | 310 | scheduled_queue[core].add(thread, priority, false); |
| 341 | } | 311 | } |
| 342 | 312 | ||
| @@ -368,7 +338,8 @@ void GlobalScheduler::TransferToCore(u32 priority, s32 destination_core, Thread* | |||
| 368 | } | 338 | } |
| 369 | } | 339 | } |
| 370 | 340 | ||
| 371 | bool GlobalScheduler::AskForReselectionOrMarkRedundant(Thread* current_thread, Thread* winner) { | 341 | bool GlobalScheduler::AskForReselectionOrMarkRedundant(Thread* current_thread, |
| 342 | const Thread* winner) { | ||
| 372 | if (current_thread == winner) { | 343 | if (current_thread == winner) { |
| 373 | current_thread->IncrementYieldCount(); | 344 | current_thread->IncrementYieldCount(); |
| 374 | return true; | 345 | return true; |
| @@ -386,8 +357,6 @@ void GlobalScheduler::Shutdown() { | |||
| 386 | thread_list.clear(); | 357 | thread_list.clear(); |
| 387 | } | 358 | } |
| 388 | 359 | ||
| 389 | GlobalScheduler::~GlobalScheduler() = default; | ||
| 390 | |||
| 391 | Scheduler::Scheduler(Core::System& system, Core::ARM_Interface& cpu_core, u32 core_id) | 360 | Scheduler::Scheduler(Core::System& system, Core::ARM_Interface& cpu_core, u32 core_id) |
| 392 | : system(system), cpu_core(cpu_core), core_id(core_id) {} | 361 | : system(system), cpu_core(cpu_core), core_id(core_id) {} |
| 393 | 362 | ||
| @@ -470,7 +439,7 @@ void Scheduler::SwitchContext() { | |||
| 470 | 439 | ||
| 471 | // Load context of new thread | 440 | // Load context of new thread |
| 472 | if (new_thread) { | 441 | if (new_thread) { |
| 473 | ASSERT_MSG(new_thread->GetProcessorID() == this->core_id, | 442 | ASSERT_MSG(new_thread->GetProcessorID() == s32(this->core_id), |
| 474 | "Thread must be assigned to this core."); | 443 | "Thread must be assigned to this core."); |
| 475 | ASSERT_MSG(new_thread->GetStatus() == ThreadStatus::Ready, | 444 | ASSERT_MSG(new_thread->GetStatus() == ThreadStatus::Ready, |
| 476 | "Thread must be ready to become running."); | 445 | "Thread must be ready to become running."); |