VERY experimental Nintendo Switch 2 emulator
C++
Correct PrepareReschedule
Fernando Sahmkow87334f0f1699
diff --git a/src/core/core.cpp b/src/core/core.cppindex 5565840fd9..4a95630bd0 100644--- a/src/core/core.cpp+++ b/src/core/core.cpp@@ -404,6 +404,11 @@ void System::PrepareReschedule() {CurrentCpuCore().PrepareReschedule();}+void System::PrepareReschedule(s32 core_index) {+ if (core_index >= 0)+ CpuCore(core_index).PrepareReschedule();+}+PerfStatsResults System::GetAndResetPerfStats() {return impl->GetAndResetPerfStats();}diff --git a/src/core/core.h b/src/core/core.hindex 2a002f6d77..0d1008895d 100644--- a/src/core/core.h+++ b/src/core/core.h@@ -185,6 +185,9 @@ public:/// Prepare the core emulation for a reschedulevoid PrepareReschedule();+ /// Prepare the core emulation for a reschedule+ void PrepareReschedule(s32 core_index);+/// Gets and resets core performance statisticsPerfStatsResults GetAndResetPerfStats();diff --git a/src/core/core_cpu.h b/src/core/core_cpu.hindex 5dde2994ce..0cde547878 100644--- a/src/core/core_cpu.h+++ b/src/core/core_cpu.h@@ -14,7 +14,7 @@namespace Kernel {class Scheduler;class GlobalScheduler;-}+} // namespace Kernelnamespace Core {class System;diff --git a/src/core/hle/kernel/address_arbiter.cpp b/src/core/hle/kernel/address_arbiter.cppindex 77f7bb451a..c66cd16ef3 100644--- a/src/core/hle/kernel/address_arbiter.cpp+++ b/src/core/hle/kernel/address_arbiter.cpp@@ -37,8 +37,7 @@ void WakeThreads(const std::vector<SharedPtr<Thread>>& waiting_threads, s32 num_waiting_threads[i]->SetWaitSynchronizationResult(RESULT_SUCCESS);waiting_threads[i]->SetArbiterWaitAddress(0);waiting_threads[i]->ResumeFromWait();- if (waiting_threads[i]->GetProcessorID() >= 0)- system.CpuCore(waiting_threads[i]->GetProcessorID()).PrepareReschedule();+ system.PrepareReschedule(waiting_threads[i]->GetProcessorID());}}} // Anonymous namespace@@ -173,7 +172,7 @@ ResultCode AddressArbiter::WaitForAddressImpl(VAddr address, s64 timeout) {current_thread->WakeAfterDelay(timeout);- system.CpuCore(current_thread->GetProcessorID()).PrepareReschedule();+ system.PrepareReschedule(current_thread->GetProcessorID());return RESULT_TIMEOUT;}diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cppindex ee1e9f006a..560ac39455 100644--- a/src/core/hle/kernel/svc.cpp+++ b/src/core/hle/kernel/svc.cpp@@ -516,7 +516,7 @@ static ResultCode WaitSynchronization(Core::System& system, Handle* index, VAddrthread->WakeAfterDelay(nano_seconds);thread->SetWakeupCallback(DefaultThreadWakeupCallback);- system.CpuCore(thread->GetProcessorID()).PrepareReschedule();+ system.PrepareReschedule(thread->GetProcessorID());return RESULT_TIMEOUT;}@@ -534,8 +534,7 @@ static ResultCode CancelSynchronization(Core::System& system, Handle thread_hand}thread->CancelWait();- if (thread->GetProcessorID() >= 0)- Core::System::GetInstance().CpuCore(thread->GetProcessorID()).PrepareReschedule();+ system.PrepareReschedule(thread->GetProcessorID());return RESULT_SUCCESS;}@@ -1069,8 +1068,7 @@ static ResultCode SetThreadActivity(Core::System& system, Handle handle, u32 actthread->SetActivity(static_cast<ThreadActivity>(activity));- if (thread->GetProcessorID() >= 0)- Core::System::GetInstance().CpuCore(thread->GetProcessorID()).PrepareReschedule();+ system.PrepareReschedule(thread->GetProcessorID());return RESULT_SUCCESS;}@@ -1152,8 +1150,7 @@ static ResultCode SetThreadPriority(Core::System& system, Handle handle, u32 prithread->SetPriority(priority);- if (thread->GetProcessorID() >= 0)- Core::System::GetInstance().CpuCore(thread->GetProcessorID()).PrepareReschedule();+ system.PrepareReschedule(thread->GetProcessorID());return RESULT_SUCCESS;}@@ -1509,8 +1506,7 @@ static ResultCode CreateThread(Core::System& system, Handle* out_handle, VAddr ethread->SetName(fmt::format("thread[entry_point={:X}, handle={:X}]", entry_point, *new_thread_handle));- if (thread->GetProcessorID() >= 0)- Core::System::GetInstance().CpuCore(thread->GetProcessorID()).PrepareReschedule();+ system.PrepareReschedule(thread->GetProcessorID());return RESULT_SUCCESS;}@@ -1532,10 +1528,7 @@ static ResultCode StartThread(Core::System& system, Handle thread_handle) {thread->ResumeFromWait();if (thread->GetStatus() == ThreadStatus::Ready) {- if (thread->GetProcessorID() >= 0)- Core::System::GetInstance().CpuCore(thread->GetProcessorID()).PrepareReschedule();- else- Core::System::GetInstance().GlobalScheduler().SetReselectionPending();+ system.PrepareReschedule(thread->GetProcessorID());}return RESULT_SUCCESS;@@ -1582,10 +1575,7 @@ static void SleepThread(Core::System& system, s64 nanoseconds) {current_thread->Sleep(nanoseconds);}- // Reschedule all CPU cores- for (std::size_t i = 0; i < Core::NUM_CPU_CORES; ++i) {- system.CpuCore(i).PrepareReschedule();- }+ system.PrepareReschedule(current_thread->GetProcessorID());}/// Wait process wide key atomic@@ -1632,7 +1622,7 @@ static ResultCode WaitProcessWideKeyAtomic(Core::System& system, VAddr mutex_add// Note: Deliberately don't attempt to inherit the lock owner's priority.- system.CpuCore(current_thread->GetProcessorID()).PrepareReschedule();+ system.PrepareReschedule(current_thread->GetProcessorID());return RESULT_SUCCESS;}@@ -1644,7 +1634,7 @@ static ResultCode SignalProcessWideKey(Core::System& system, VAddr condition_var// Retrieve a list of all threads that are waiting for this condition variable.std::vector<SharedPtr<Thread>> waiting_threads;- const auto& scheduler = Core::System::GetInstance().GlobalScheduler();+ const auto& scheduler = system.GlobalScheduler();const auto& thread_list = scheduler.GetThreadList();for (const auto& thread : thread_list) {@@ -1706,8 +1696,7 @@ static ResultCode SignalProcessWideKey(Core::System& system, VAddr condition_varthread->SetLockOwner(nullptr);thread->SetMutexWaitAddress(0);thread->SetWaitHandle(0);- if (thread->GetProcessorID() >= 0)- Core::System::GetInstance().CpuCore(thread->GetProcessorID()).PrepareReschedule();+ system.PrepareReschedule(thread->GetProcessorID());} else {// Atomically signal that the mutex now has a waiting thread.do {@@ -1731,8 +1720,7 @@ static ResultCode SignalProcessWideKey(Core::System& system, VAddr condition_varthread->SetStatus(ThreadStatus::WaitMutex);owner->AddMutexWaiter(thread);- if (thread->GetProcessorID() >= 0)- Core::System::GetInstance().CpuCore(thread->GetProcessorID()).PrepareReschedule();+ system.PrepareReschedule(thread->GetProcessorID());}}@@ -1758,13 +1746,10 @@ static ResultCode WaitForAddress(Core::System& system, VAddr address, u32 type,}const auto arbitration_type = static_cast<AddressArbiter::ArbitrationType>(type);- auto& address_arbiter =- system.Kernel().CurrentProcess()->GetAddressArbiter();+ auto& address_arbiter = system.Kernel().CurrentProcess()->GetAddressArbiter();ResultCode result = address_arbiter.WaitForAddress(address, arbitration_type, value, timeout);if (result == RESULT_SUCCESS)- Core::System::GetInstance()- .CpuCore(GetCurrentThread()->GetProcessorID())- .PrepareReschedule();+ system.PrepareReschedule();return result;}@@ -2051,10 +2036,10 @@ static ResultCode SetThreadCoreMask(Core::System& system, Handle thread_handle,return ERR_INVALID_HANDLE;}- Core::System::GetInstance().CpuCore(thread->GetProcessorID()).PrepareReschedule();+ system.PrepareReschedule(thread->GetProcessorID());thread->ChangeCore(core, affinity_mask);- if (thread->GetProcessorID() >= 0)- Core::System::GetInstance().CpuCore(thread->GetProcessorID()).PrepareReschedule();+ system.PrepareReschedule(thread->GetProcessorID());+return RESULT_SUCCESS;}@@ -2165,7 +2150,7 @@ static ResultCode SignalEvent(Core::System& system, Handle handle) {}writable_event->Signal();- Core::System::GetInstance().PrepareReschedule();+ system.PrepareReschedule();return RESULT_SUCCESS;}diff --git a/src/core/hle/kernel/wait_object.cpp b/src/core/hle/kernel/wait_object.cppindex e035a67e99..a65ec7dbc3 100644--- a/src/core/hle/kernel/wait_object.cpp+++ b/src/core/hle/kernel/wait_object.cpp@@ -97,8 +97,7 @@ void WaitObject::WakeupWaitingThread(SharedPtr<Thread> thread) {}if (resume) {thread->ResumeFromWait();- if (thread->GetProcessorID() >= 0)- Core::System::GetInstance().CpuCore(thread->GetProcessorID()).PrepareReschedule();+ Core::System::GetInstance().PrepareReschedule(thread->GetProcessorID());}}