|
|
|
@ -254,29 +254,34 @@ void CpuManager::SingleCoreRunSuspendThread() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CpuManager::PreemptSingleCore(bool from_running_enviroment) {
|
|
|
|
|
std::size_t old_core = current_core;
|
|
|
|
|
auto& scheduler = system.Kernel().Scheduler(old_core);
|
|
|
|
|
Kernel::Thread* current_thread = scheduler.GetCurrentThread();
|
|
|
|
|
if (idle_count >= 4 || from_running_enviroment) {
|
|
|
|
|
if (!from_running_enviroment) {
|
|
|
|
|
system.CoreTiming().Idle();
|
|
|
|
|
{
|
|
|
|
|
auto& scheduler = system.Kernel().Scheduler(current_core);
|
|
|
|
|
Kernel::Thread* current_thread = scheduler.GetCurrentThread();
|
|
|
|
|
if (idle_count >= 4 || from_running_enviroment) {
|
|
|
|
|
if (!from_running_enviroment) {
|
|
|
|
|
system.CoreTiming().Idle();
|
|
|
|
|
idle_count = 0;
|
|
|
|
|
}
|
|
|
|
|
current_thread->SetPhantomMode(true);
|
|
|
|
|
system.CoreTiming().Advance();
|
|
|
|
|
current_thread->SetPhantomMode(false);
|
|
|
|
|
}
|
|
|
|
|
current_core.store((current_core + 1) % Core::Hardware::NUM_CPU_CORES);
|
|
|
|
|
system.CoreTiming().ResetTicks();
|
|
|
|
|
scheduler.Unload(scheduler.GetCurrentThread());
|
|
|
|
|
|
|
|
|
|
auto& next_scheduler = system.Kernel().Scheduler(current_core);
|
|
|
|
|
Common::Fiber::YieldTo(current_thread->GetHostContext(), next_scheduler.ControlContext());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// May have changed scheduler
|
|
|
|
|
{
|
|
|
|
|
auto& scheduler = system.Kernel().Scheduler(current_core);
|
|
|
|
|
scheduler.Reload(scheduler.GetCurrentThread());
|
|
|
|
|
auto* currrent_thread2 = scheduler.GetCurrentThread();
|
|
|
|
|
if (!currrent_thread2->IsIdleThread()) {
|
|
|
|
|
idle_count = 0;
|
|
|
|
|
}
|
|
|
|
|
current_thread->SetPhantomMode(true);
|
|
|
|
|
system.CoreTiming().Advance();
|
|
|
|
|
current_thread->SetPhantomMode(false);
|
|
|
|
|
}
|
|
|
|
|
current_core.store((current_core + 1) % Core::Hardware::NUM_CPU_CORES);
|
|
|
|
|
system.CoreTiming().ResetTicks();
|
|
|
|
|
scheduler.Unload(scheduler.GetCurrentThread());
|
|
|
|
|
auto& next_scheduler = system.Kernel().Scheduler(current_core);
|
|
|
|
|
Common::Fiber::YieldTo(current_thread->GetHostContext(), next_scheduler.ControlContext());
|
|
|
|
|
/// May have changed scheduler
|
|
|
|
|
auto& current_scheduler = system.Kernel().Scheduler(current_core);
|
|
|
|
|
current_scheduler.Reload(scheduler.GetCurrentThread());
|
|
|
|
|
auto* currrent_thread2 = current_scheduler.GetCurrentThread();
|
|
|
|
|
if (!currrent_thread2->IsIdleThread()) {
|
|
|
|
|
idle_count = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|