Correct PrepareReschedule

master
Fernando Sahmkow 2019-04-02 09:22:53 +07:00 committed by FernandoS27
parent 3a94e7ea33
commit fcc6b34fff
6 changed files with 29 additions and 38 deletions

@ -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();
}

@ -185,6 +185,9 @@ public:
/// Prepare the core emulation for a reschedule
void PrepareReschedule();
/// Prepare the core emulation for a reschedule
void PrepareReschedule(s32 core_index);
/// Gets and resets core performance statistics
PerfStatsResults GetAndResetPerfStats();

@ -14,7 +14,7 @@
namespace Kernel {
class Scheduler;
class GlobalScheduler;
}
} // namespace Kernel
namespace Core {
class System;

@ -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;
}

@ -516,7 +516,7 @@ static ResultCode WaitSynchronization(Core::System& system, Handle* index, VAddr
thread->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 act
thread->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 pri
thread->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 e
thread->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_var
thread->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_var
thread->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;
}

@ -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());
}
}