diff options
Diffstat (limited to 'src/core/hle/kernel/thread.cpp')
| -rw-r--r-- | src/core/hle/kernel/thread.cpp | 48 |
1 files changed, 18 insertions, 30 deletions
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 962530d2d..ee7531f2d 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp | |||
| @@ -77,18 +77,6 @@ void Thread::CancelWakeupTimer() { | |||
| 77 | callback_handle); | 77 | callback_handle); |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | static std::optional<s32> GetNextProcessorId(u64 mask) { | ||
| 81 | for (s32 index = 0; index < Core::NUM_CPU_CORES; ++index) { | ||
| 82 | if (mask & (1ULL << index)) { | ||
| 83 | if (!Core::System::GetInstance().Scheduler(index).GetCurrentThread()) { | ||
| 84 | // Core is enabled and not running any threads, use this one | ||
| 85 | return index; | ||
| 86 | } | ||
| 87 | } | ||
| 88 | } | ||
| 89 | return {}; | ||
| 90 | } | ||
| 91 | |||
| 92 | void Thread::ResumeFromWait() { | 80 | void Thread::ResumeFromWait() { |
| 93 | ASSERT_MSG(wait_objects.empty(), "Thread is waking up while waiting for objects"); | 81 | ASSERT_MSG(wait_objects.empty(), "Thread is waking up while waiting for objects"); |
| 94 | 82 | ||
| @@ -173,7 +161,7 @@ ResultVal<SharedPtr<Thread>> Thread::Create(KernelCore& kernel, std::string name | |||
| 173 | if (!Memory::IsValidVirtualAddress(owner_process, entry_point)) { | 161 | if (!Memory::IsValidVirtualAddress(owner_process, entry_point)) { |
| 174 | LOG_ERROR(Kernel_SVC, "(name={}): invalid entry {:016X}", name, entry_point); | 162 | LOG_ERROR(Kernel_SVC, "(name={}): invalid entry {:016X}", name, entry_point); |
| 175 | // TODO (bunnei): Find the correct error code to use here | 163 | // TODO (bunnei): Find the correct error code to use here |
| 176 | return ResultCode(-1); | 164 | return RESULT_UNKNOWN; |
| 177 | } | 165 | } |
| 178 | 166 | ||
| 179 | auto& system = Core::System::GetInstance(); | 167 | auto& system = Core::System::GetInstance(); |
| @@ -401,7 +389,7 @@ void Thread::SetCurrentPriority(u32 new_priority) { | |||
| 401 | 389 | ||
| 402 | ResultCode Thread::SetCoreAndAffinityMask(s32 new_core, u64 new_affinity_mask) { | 390 | ResultCode Thread::SetCoreAndAffinityMask(s32 new_core, u64 new_affinity_mask) { |
| 403 | const auto HighestSetCore = [](u64 mask, u32 max_cores) { | 391 | const auto HighestSetCore = [](u64 mask, u32 max_cores) { |
| 404 | for (s32 core = max_cores - 1; core >= 0; core--) { | 392 | for (s32 core = static_cast<s32>(max_cores - 1); core >= 0; core--) { |
| 405 | if (((mask >> core) & 1) != 0) { | 393 | if (((mask >> core) & 1) != 0) { |
| 406 | return core; | 394 | return core; |
| 407 | } | 395 | } |
| @@ -425,7 +413,7 @@ ResultCode Thread::SetCoreAndAffinityMask(s32 new_core, u64 new_affinity_mask) { | |||
| 425 | if (old_affinity_mask != new_affinity_mask) { | 413 | if (old_affinity_mask != new_affinity_mask) { |
| 426 | const s32 old_core = processor_id; | 414 | const s32 old_core = processor_id; |
| 427 | if (processor_id >= 0 && ((affinity_mask >> processor_id) & 1) == 0) { | 415 | if (processor_id >= 0 && ((affinity_mask >> processor_id) & 1) == 0) { |
| 428 | if (ideal_core < 0) { | 416 | if (static_cast<s32>(ideal_core) < 0) { |
| 429 | processor_id = HighestSetCore(affinity_mask, GlobalScheduler::NUM_CPU_CORES); | 417 | processor_id = HighestSetCore(affinity_mask, GlobalScheduler::NUM_CPU_CORES); |
| 430 | } else { | 418 | } else { |
| 431 | processor_id = ideal_core; | 419 | processor_id = ideal_core; |
| @@ -447,23 +435,23 @@ void Thread::AdjustSchedulingOnStatus(u32 old_flags) { | |||
| 447 | ThreadSchedStatus::Runnable) { | 435 | ThreadSchedStatus::Runnable) { |
| 448 | // In this case the thread was running, now it's pausing/exitting | 436 | // In this case the thread was running, now it's pausing/exitting |
| 449 | if (processor_id >= 0) { | 437 | if (processor_id >= 0) { |
| 450 | scheduler.Unschedule(current_priority, processor_id, this); | 438 | scheduler.Unschedule(current_priority, static_cast<u32>(processor_id), this); |
| 451 | } | 439 | } |
| 452 | 440 | ||
| 453 | for (s32 core = 0; core < GlobalScheduler::NUM_CPU_CORES; core++) { | 441 | for (u32 core = 0; core < GlobalScheduler::NUM_CPU_CORES; core++) { |
| 454 | if (core != processor_id && ((affinity_mask >> core) & 1) != 0) { | 442 | if (core != static_cast<u32>(processor_id) && ((affinity_mask >> core) & 1) != 0) { |
| 455 | scheduler.Unsuggest(current_priority, static_cast<u32>(core), this); | 443 | scheduler.Unsuggest(current_priority, core, this); |
| 456 | } | 444 | } |
| 457 | } | 445 | } |
| 458 | } else if (GetSchedulingStatus() == ThreadSchedStatus::Runnable) { | 446 | } else if (GetSchedulingStatus() == ThreadSchedStatus::Runnable) { |
| 459 | // The thread is now set to running from being stopped | 447 | // The thread is now set to running from being stopped |
| 460 | if (processor_id >= 0) { | 448 | if (processor_id >= 0) { |
| 461 | scheduler.Schedule(current_priority, processor_id, this); | 449 | scheduler.Schedule(current_priority, static_cast<u32>(processor_id), this); |
| 462 | } | 450 | } |
| 463 | 451 | ||
| 464 | for (s32 core = 0; core < GlobalScheduler::NUM_CPU_CORES; core++) { | 452 | for (u32 core = 0; core < GlobalScheduler::NUM_CPU_CORES; core++) { |
| 465 | if (core != processor_id && ((affinity_mask >> core) & 1) != 0) { | 453 | if (core != static_cast<u32>(processor_id) && ((affinity_mask >> core) & 1) != 0) { |
| 466 | scheduler.Suggest(current_priority, static_cast<u32>(core), this); | 454 | scheduler.Suggest(current_priority, core, this); |
| 467 | } | 455 | } |
| 468 | } | 456 | } |
| 469 | } | 457 | } |
| @@ -477,11 +465,11 @@ void Thread::AdjustSchedulingOnPriority(u32 old_priority) { | |||
| 477 | } | 465 | } |
| 478 | auto& scheduler = Core::System::GetInstance().GlobalScheduler(); | 466 | auto& scheduler = Core::System::GetInstance().GlobalScheduler(); |
| 479 | if (processor_id >= 0) { | 467 | if (processor_id >= 0) { |
| 480 | scheduler.Unschedule(old_priority, processor_id, this); | 468 | scheduler.Unschedule(old_priority, static_cast<u32>(processor_id), this); |
| 481 | } | 469 | } |
| 482 | 470 | ||
| 483 | for (u32 core = 0; core < GlobalScheduler::NUM_CPU_CORES; core++) { | 471 | for (u32 core = 0; core < GlobalScheduler::NUM_CPU_CORES; core++) { |
| 484 | if (core != processor_id && ((affinity_mask >> core) & 1) != 0) { | 472 | if (core != static_cast<u32>(processor_id) && ((affinity_mask >> core) & 1) != 0) { |
| 485 | scheduler.Unsuggest(old_priority, core, this); | 473 | scheduler.Unsuggest(old_priority, core, this); |
| 486 | } | 474 | } |
| 487 | } | 475 | } |
| @@ -491,14 +479,14 @@ void Thread::AdjustSchedulingOnPriority(u32 old_priority) { | |||
| 491 | 479 | ||
| 492 | if (processor_id >= 0) { | 480 | if (processor_id >= 0) { |
| 493 | if (current_thread == this) { | 481 | if (current_thread == this) { |
| 494 | scheduler.SchedulePrepend(current_priority, processor_id, this); | 482 | scheduler.SchedulePrepend(current_priority, static_cast<u32>(processor_id), this); |
| 495 | } else { | 483 | } else { |
| 496 | scheduler.Schedule(current_priority, processor_id, this); | 484 | scheduler.Schedule(current_priority, static_cast<u32>(processor_id), this); |
| 497 | } | 485 | } |
| 498 | } | 486 | } |
| 499 | 487 | ||
| 500 | for (u32 core = 0; core < GlobalScheduler::NUM_CPU_CORES; core++) { | 488 | for (u32 core = 0; core < GlobalScheduler::NUM_CPU_CORES; core++) { |
| 501 | if (core != processor_id && ((affinity_mask >> core) & 1) != 0) { | 489 | if (core != static_cast<u32>(processor_id) && ((affinity_mask >> core) & 1) != 0) { |
| 502 | scheduler.Suggest(current_priority, core, this); | 490 | scheduler.Suggest(current_priority, core, this); |
| 503 | } | 491 | } |
| 504 | } | 492 | } |
| @@ -515,7 +503,7 @@ void Thread::AdjustSchedulingOnAffinity(u64 old_affinity_mask, s32 old_core) { | |||
| 515 | 503 | ||
| 516 | for (u32 core = 0; core < GlobalScheduler::NUM_CPU_CORES; core++) { | 504 | for (u32 core = 0; core < GlobalScheduler::NUM_CPU_CORES; core++) { |
| 517 | if (((old_affinity_mask >> core) & 1) != 0) { | 505 | if (((old_affinity_mask >> core) & 1) != 0) { |
| 518 | if (core == old_core) { | 506 | if (core == static_cast<u32>(old_core)) { |
| 519 | scheduler.Unschedule(current_priority, core, this); | 507 | scheduler.Unschedule(current_priority, core, this); |
| 520 | } else { | 508 | } else { |
| 521 | scheduler.Unsuggest(current_priority, core, this); | 509 | scheduler.Unsuggest(current_priority, core, this); |
| @@ -525,7 +513,7 @@ void Thread::AdjustSchedulingOnAffinity(u64 old_affinity_mask, s32 old_core) { | |||
| 525 | 513 | ||
| 526 | for (u32 core = 0; core < GlobalScheduler::NUM_CPU_CORES; core++) { | 514 | for (u32 core = 0; core < GlobalScheduler::NUM_CPU_CORES; core++) { |
| 527 | if (((affinity_mask >> core) & 1) != 0) { | 515 | if (((affinity_mask >> core) & 1) != 0) { |
| 528 | if (core == processor_id) { | 516 | if (core == static_cast<u32>(processor_id)) { |
| 529 | scheduler.Schedule(current_priority, core, this); | 517 | scheduler.Schedule(current_priority, core, this); |
| 530 | } else { | 518 | } else { |
| 531 | scheduler.Suggest(current_priority, core, this); | 519 | scheduler.Suggest(current_priority, core, this); |