diff options
| author | 2018-11-15 14:47:42 -0800 | |
|---|---|---|
| committer | 2018-11-15 14:47:42 -0800 | |
| commit | f7319b0d3c601434785177157bb267266b9492c7 (patch) | |
| tree | 33afc9d73dcc2b4b2ff0572c69ec53050153515f | |
| parent | Merge pull request #1618 from DarkLordZach/dump-nso (diff) | |
| parent | kernel/thread: Deduplicate scheduler switching code (diff) | |
| download | yuzu-f7319b0d3c601434785177157bb267266b9492c7.tar.gz yuzu-f7319b0d3c601434785177157bb267266b9492c7.tar.xz yuzu-f7319b0d3c601434785177157bb267266b9492c7.zip | |
Merge pull request #1687 from lioncash/deduplication
kernel/thread: Deduplicate scheduler switching code
Diffstat (limited to '')
| -rw-r--r-- | src/core/hle/kernel/thread.cpp | 48 | ||||
| -rw-r--r-- | src/core/hle/kernel/thread.h | 2 |
2 files changed, 13 insertions, 37 deletions
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index dd5cd9ced..4ffb76818 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp | |||
| @@ -142,36 +142,7 @@ void Thread::ResumeFromWait() { | |||
| 142 | 142 | ||
| 143 | status = ThreadStatus::Ready; | 143 | status = ThreadStatus::Ready; |
| 144 | 144 | ||
| 145 | std::optional<s32> new_processor_id = GetNextProcessorId(affinity_mask); | 145 | ChangeScheduler(); |
| 146 | if (!new_processor_id) { | ||
| 147 | new_processor_id = processor_id; | ||
| 148 | } | ||
| 149 | if (ideal_core != -1 && | ||
| 150 | Core::System::GetInstance().Scheduler(ideal_core).GetCurrentThread() == nullptr) { | ||
| 151 | new_processor_id = ideal_core; | ||
| 152 | } | ||
| 153 | |||
| 154 | ASSERT(*new_processor_id < 4); | ||
| 155 | |||
| 156 | // Add thread to new core's scheduler | ||
| 157 | auto* next_scheduler = &Core::System::GetInstance().Scheduler(*new_processor_id); | ||
| 158 | |||
| 159 | if (*new_processor_id != processor_id) { | ||
| 160 | // Remove thread from previous core's scheduler | ||
| 161 | scheduler->RemoveThread(this); | ||
| 162 | next_scheduler->AddThread(this, current_priority); | ||
| 163 | } | ||
| 164 | |||
| 165 | processor_id = *new_processor_id; | ||
| 166 | |||
| 167 | // If the thread was ready, unschedule from the previous core and schedule on the new core | ||
| 168 | scheduler->UnscheduleThread(this, current_priority); | ||
| 169 | next_scheduler->ScheduleThread(this, current_priority); | ||
| 170 | |||
| 171 | // Change thread's scheduler | ||
| 172 | scheduler = next_scheduler; | ||
| 173 | |||
| 174 | Core::System::GetInstance().CpuCore(processor_id).PrepareReschedule(); | ||
| 175 | } | 146 | } |
| 176 | 147 | ||
| 177 | /** | 148 | /** |
| @@ -364,42 +335,45 @@ void Thread::UpdatePriority() { | |||
| 364 | void Thread::ChangeCore(u32 core, u64 mask) { | 335 | void Thread::ChangeCore(u32 core, u64 mask) { |
| 365 | ideal_core = core; | 336 | ideal_core = core; |
| 366 | affinity_mask = mask; | 337 | affinity_mask = mask; |
| 338 | ChangeScheduler(); | ||
| 339 | } | ||
| 367 | 340 | ||
| 341 | void Thread::ChangeScheduler() { | ||
| 368 | if (status != ThreadStatus::Ready) { | 342 | if (status != ThreadStatus::Ready) { |
| 369 | return; | 343 | return; |
| 370 | } | 344 | } |
| 371 | 345 | ||
| 346 | auto& system = Core::System::GetInstance(); | ||
| 372 | std::optional<s32> new_processor_id{GetNextProcessorId(affinity_mask)}; | 347 | std::optional<s32> new_processor_id{GetNextProcessorId(affinity_mask)}; |
| 373 | 348 | ||
| 374 | if (!new_processor_id) { | 349 | if (!new_processor_id) { |
| 375 | new_processor_id = processor_id; | 350 | new_processor_id = processor_id; |
| 376 | } | 351 | } |
| 377 | if (ideal_core != -1 && | 352 | if (ideal_core != -1 && system.Scheduler(ideal_core).GetCurrentThread() == nullptr) { |
| 378 | Core::System::GetInstance().Scheduler(ideal_core).GetCurrentThread() == nullptr) { | ||
| 379 | new_processor_id = ideal_core; | 353 | new_processor_id = ideal_core; |
| 380 | } | 354 | } |
| 381 | 355 | ||
| 382 | ASSERT(*new_processor_id < 4); | 356 | ASSERT(*new_processor_id < 4); |
| 383 | 357 | ||
| 384 | // Add thread to new core's scheduler | 358 | // Add thread to new core's scheduler |
| 385 | auto* next_scheduler = &Core::System::GetInstance().Scheduler(*new_processor_id); | 359 | auto& next_scheduler = system.Scheduler(*new_processor_id); |
| 386 | 360 | ||
| 387 | if (*new_processor_id != processor_id) { | 361 | if (*new_processor_id != processor_id) { |
| 388 | // Remove thread from previous core's scheduler | 362 | // Remove thread from previous core's scheduler |
| 389 | scheduler->RemoveThread(this); | 363 | scheduler->RemoveThread(this); |
| 390 | next_scheduler->AddThread(this, current_priority); | 364 | next_scheduler.AddThread(this, current_priority); |
| 391 | } | 365 | } |
| 392 | 366 | ||
| 393 | processor_id = *new_processor_id; | 367 | processor_id = *new_processor_id; |
| 394 | 368 | ||
| 395 | // If the thread was ready, unschedule from the previous core and schedule on the new core | 369 | // If the thread was ready, unschedule from the previous core and schedule on the new core |
| 396 | scheduler->UnscheduleThread(this, current_priority); | 370 | scheduler->UnscheduleThread(this, current_priority); |
| 397 | next_scheduler->ScheduleThread(this, current_priority); | 371 | next_scheduler.ScheduleThread(this, current_priority); |
| 398 | 372 | ||
| 399 | // Change thread's scheduler | 373 | // Change thread's scheduler |
| 400 | scheduler = next_scheduler; | 374 | scheduler = &next_scheduler; |
| 401 | 375 | ||
| 402 | Core::System::GetInstance().CpuCore(processor_id).PrepareReschedule(); | 376 | system.CpuCore(processor_id).PrepareReschedule(); |
| 403 | } | 377 | } |
| 404 | 378 | ||
| 405 | bool Thread::AllWaitObjectsReady() { | 379 | bool Thread::AllWaitObjectsReady() { |
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index 4a6e11239..d384d50db 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h | |||
| @@ -374,6 +374,8 @@ private: | |||
| 374 | explicit Thread(KernelCore& kernel); | 374 | explicit Thread(KernelCore& kernel); |
| 375 | ~Thread() override; | 375 | ~Thread() override; |
| 376 | 376 | ||
| 377 | void ChangeScheduler(); | ||
| 378 | |||
| 377 | Core::ARM_Interface::ThreadContext context{}; | 379 | Core::ARM_Interface::ThreadContext context{}; |
| 378 | 380 | ||
| 379 | u32 thread_id = 0; | 381 | u32 thread_id = 0; |