From e31425df3877636c098ec7426ebd2067920715cb Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Mon, 24 Feb 2020 22:04:12 -0400 Subject: General: Recover Prometheus project from harddrive failure This commit: Implements CPU Interrupts, Replaces Cycle Timing for Host Timing, Reworks the Kernel's Scheduler, Introduce Idle State and Suspended State, Recreates the bootmanager, Initializes Multicore system. --- src/core/cpu_manager.cpp | 194 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 153 insertions(+), 41 deletions(-) (limited to 'src/core/cpu_manager.cpp') diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp index 70ddbdcca..494850992 100644 --- a/src/core/cpu_manager.cpp +++ b/src/core/cpu_manager.cpp @@ -2,80 +2,192 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include "common/fiber.h" +#include "common/thread.h" #include "core/arm/exclusive_monitor.h" #include "core/core.h" -#include "core/core_manager.h" #include "core/core_timing.h" #include "core/cpu_manager.h" #include "core/gdbstub/gdbstub.h" +#include "core/hle/kernel/kernel.h" +#include "core/hle/kernel/physical_core.h" +#include "core/hle/kernel/scheduler.h" +#include "core/hle/kernel/thread.h" namespace Core { CpuManager::CpuManager(System& system) : system{system} {} CpuManager::~CpuManager() = default; +void CpuManager::ThreadStart(CpuManager& cpu_manager, std::size_t core) { + cpu_manager.RunThread(core); +} + void CpuManager::Initialize() { - for (std::size_t index = 0; index < core_managers.size(); ++index) { - core_managers[index] = std::make_unique(system, index); + running_mode = true; + for (std::size_t core = 0; core < Core::Hardware::NUM_CPU_CORES; core++) { + core_data[core].host_thread = + std::make_unique(ThreadStart, std::ref(*this), core); } } void CpuManager::Shutdown() { - for (auto& cpu_core : core_managers) { - cpu_core.reset(); + running_mode = false; + Pause(false); + for (std::size_t core = 0; core < Core::Hardware::NUM_CPU_CORES; core++) { + core_data[core].host_thread->join(); } } -CoreManager& CpuManager::GetCoreManager(std::size_t index) { - return *core_managers.at(index); +void CpuManager::GuestThreadFunction(void* cpu_manager_) { + CpuManager* cpu_manager = static_cast(cpu_manager_); + cpu_manager->RunGuestThread(); } -const CoreManager& CpuManager::GetCoreManager(std::size_t index) const { - return *core_managers.at(index); +void CpuManager::IdleThreadFunction(void* cpu_manager_) { + CpuManager* cpu_manager = static_cast(cpu_manager_); + cpu_manager->RunIdleThread(); } -CoreManager& CpuManager::GetCurrentCoreManager() { - // Otherwise, use single-threaded mode active_core variable - return *core_managers[active_core]; +void CpuManager::SuspendThreadFunction(void* cpu_manager_) { + CpuManager* cpu_manager = static_cast(cpu_manager_); + cpu_manager->RunSuspendThread(); } -const CoreManager& CpuManager::GetCurrentCoreManager() const { - // Otherwise, use single-threaded mode active_core variable - return *core_managers[active_core]; +std::function CpuManager::GetGuestThreadStartFunc() { + return std::function(GuestThreadFunction); } -void CpuManager::RunLoop(bool tight_loop) { - if (GDBStub::IsServerEnabled()) { - GDBStub::HandlePacket(); - - // If the loop is halted and we want to step, use a tiny (1) number of instructions to - // execute. Otherwise, get out of the loop function. - if (GDBStub::GetCpuHaltFlag()) { - if (GDBStub::GetCpuStepFlag()) { - tight_loop = false; - } else { - return; - } - } +std::function CpuManager::GetIdleThreadStartFunc() { + return std::function(IdleThreadFunction); +} + +std::function CpuManager::GetSuspendThreadStartFunc() { + return std::function(SuspendThreadFunction); +} + +void* CpuManager::GetStartFuncParamater() { + return static_cast(this); +} + +void CpuManager::RunGuestThread() { + auto& kernel = system.Kernel(); + { + auto& sched = kernel.CurrentScheduler(); + sched.OnThreadStart(); + } + while (true) { + auto& physical_core = kernel.CurrentPhysicalCore(); + LOG_CRITICAL(Core_ARM, "Running Guest Thread"); + physical_core.Idle(); + LOG_CRITICAL(Core_ARM, "Leaving Guest Thread"); + // physical_core.Run(); + auto& scheduler = physical_core.Scheduler(); + scheduler.TryDoContextSwitch(); } +} - auto& core_timing = system.CoreTiming(); - core_timing.ResetRun(); - bool keep_running{}; - do { - keep_running = false; - for (active_core = 0; active_core < NUM_CPU_CORES; ++active_core) { - core_timing.SwitchContext(active_core); - if (core_timing.CanCurrentContextRun()) { - core_managers[active_core]->RunLoop(tight_loop); +void CpuManager::RunIdleThread() { + auto& kernel = system.Kernel(); + while (true) { + auto& physical_core = kernel.CurrentPhysicalCore(); + LOG_CRITICAL(Core_ARM, "Running Idle Thread"); + physical_core.Idle(); + auto& scheduler = physical_core.Scheduler(); + scheduler.TryDoContextSwitch(); + } +} + +void CpuManager::RunSuspendThread() { + LOG_CRITICAL(Core_ARM, "Suspending Thread Entered"); + auto& kernel = system.Kernel(); + { + auto& sched = kernel.CurrentScheduler(); + sched.OnThreadStart(); + } + while (true) { + auto core = kernel.GetCurrentHostThreadID(); + auto& scheduler = kernel.CurrentScheduler(); + Kernel::Thread* current_thread = scheduler.GetCurrentThread(); + LOG_CRITICAL(Core_ARM, "Suspending Core {}", core); + Common::Fiber::YieldTo(current_thread->GetHostContext(), core_data[core].host_context); + LOG_CRITICAL(Core_ARM, "Unsuspending Core {}", core); + ASSERT(scheduler.ContextSwitchPending()); + ASSERT(core == kernel.GetCurrentHostThreadID()); + scheduler.TryDoContextSwitch(); + } +} + +void CpuManager::Pause(bool paused) { + if (!paused) { + bool all_not_barrier = false; + while (!all_not_barrier) { + all_not_barrier = true; + for (std::size_t core = 0; core < Core::Hardware::NUM_CPU_CORES; core++) { + all_not_barrier &= + !core_data[core].is_running.load() && core_data[core].initialized.load(); } - keep_running |= core_timing.CanCurrentContextRun(); } - } while (keep_running); + for (std::size_t core = 0; core < Core::Hardware::NUM_CPU_CORES; core++) { + core_data[core].enter_barrier->Set(); + } + if (paused_state.load()) { + bool all_barrier = false; + while (!all_barrier) { + all_barrier = true; + for (std::size_t core = 0; core < Core::Hardware::NUM_CPU_CORES; core++) { + all_barrier &= + core_data[core].is_paused.load() && core_data[core].initialized.load(); + } + } + for (std::size_t core = 0; core < Core::Hardware::NUM_CPU_CORES; core++) { + core_data[core].exit_barrier->Set(); + } + } + } else { + /// Wait until all cores are paused. + bool all_barrier = false; + while (!all_barrier) { + all_barrier = true; + for (std::size_t core = 0; core < Core::Hardware::NUM_CPU_CORES; core++) { + all_barrier &= + core_data[core].is_paused.load() && core_data[core].initialized.load(); + } + } + /// Don't release the barrier + } + paused_state = paused; +} - if (GDBStub::IsServerEnabled()) { - GDBStub::SetCpuStepFlag(false); +void CpuManager::RunThread(std::size_t core) { + /// Initialization + system.RegisterCoreThread(core); + std::string name = "yuzu:CoreHostThread_" + std::to_string(core); + Common::SetCurrentThreadName(name.c_str()); + auto& data = core_data[core]; + data.enter_barrier = std::make_unique(); + data.exit_barrier = std::make_unique(); + data.host_context = Common::Fiber::ThreadToFiber(); + data.is_running = false; + data.initialized = true; + /// Running + while (running_mode) { + data.is_running = false; + data.enter_barrier->Wait(); + auto& scheduler = system.Kernel().CurrentScheduler(); + Kernel::Thread* current_thread = scheduler.GetCurrentThread(); + data.is_running = true; + Common::Fiber::YieldTo(data.host_context, current_thread->GetHostContext()); + data.is_running = false; + data.is_paused = true; + data.exit_barrier->Wait(); + data.is_paused = false; } + /// Time to cleanup + data.host_context->Exit(); + data.enter_barrier.reset(); + data.exit_barrier.reset(); + data.initialized = false; } } // namespace Core -- cgit v1.2.3 From a5c58a25ef3ed7975c8466933ca38e03c999b027 Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Tue, 25 Feb 2020 10:43:34 -0400 Subject: CPU_Manager: remove debugging code. --- src/core/cpu_manager.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/core/cpu_manager.cpp') diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp index 494850992..ff2fe8ead 100644 --- a/src/core/cpu_manager.cpp +++ b/src/core/cpu_manager.cpp @@ -78,10 +78,10 @@ void CpuManager::RunGuestThread() { } while (true) { auto& physical_core = kernel.CurrentPhysicalCore(); - LOG_CRITICAL(Core_ARM, "Running Guest Thread"); - physical_core.Idle(); - LOG_CRITICAL(Core_ARM, "Leaving Guest Thread"); - // physical_core.Run(); + if (!physical_core.IsInterrupted()) { + physical_core.Idle(); + //physical_core.Run(); + } auto& scheduler = physical_core.Scheduler(); scheduler.TryDoContextSwitch(); } @@ -91,7 +91,6 @@ void CpuManager::RunIdleThread() { auto& kernel = system.Kernel(); while (true) { auto& physical_core = kernel.CurrentPhysicalCore(); - LOG_CRITICAL(Core_ARM, "Running Idle Thread"); physical_core.Idle(); auto& scheduler = physical_core.Scheduler(); scheduler.TryDoContextSwitch(); @@ -99,7 +98,6 @@ void CpuManager::RunIdleThread() { } void CpuManager::RunSuspendThread() { - LOG_CRITICAL(Core_ARM, "Suspending Thread Entered"); auto& kernel = system.Kernel(); { auto& sched = kernel.CurrentScheduler(); @@ -109,9 +107,7 @@ void CpuManager::RunSuspendThread() { auto core = kernel.GetCurrentHostThreadID(); auto& scheduler = kernel.CurrentScheduler(); Kernel::Thread* current_thread = scheduler.GetCurrentThread(); - LOG_CRITICAL(Core_ARM, "Suspending Core {}", core); Common::Fiber::YieldTo(current_thread->GetHostContext(), core_data[core].host_context); - LOG_CRITICAL(Core_ARM, "Unsuspending Core {}", core); ASSERT(scheduler.ContextSwitchPending()); ASSERT(core == kernel.GetCurrentHostThreadID()); scheduler.TryDoContextSwitch(); -- cgit v1.2.3 From dc580582034fb5937aa53176fdaa4bd0fc4acce8 Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Tue, 25 Feb 2020 11:12:46 -0400 Subject: General: Setup yuzu threads' microprofile, naming and registry. --- src/core/cpu_manager.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/core/cpu_manager.cpp') diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp index ff2fe8ead..9b9337131 100644 --- a/src/core/cpu_manager.cpp +++ b/src/core/cpu_manager.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include "common/fiber.h" +#include "common/microprofile.h" #include "common/thread.h" #include "core/arm/exclusive_monitor.h" #include "core/core.h" @@ -36,6 +37,7 @@ void CpuManager::Shutdown() { Pause(false); for (std::size_t core = 0; core < Core::Hardware::NUM_CPU_CORES; core++) { core_data[core].host_thread->join(); + core_data[core].host_thread.reset(); } } @@ -80,7 +82,7 @@ void CpuManager::RunGuestThread() { auto& physical_core = kernel.CurrentPhysicalCore(); if (!physical_core.IsInterrupted()) { physical_core.Idle(); - //physical_core.Run(); + // physical_core.Run(); } auto& scheduler = physical_core.Scheduler(); scheduler.TryDoContextSwitch(); @@ -159,6 +161,7 @@ void CpuManager::RunThread(std::size_t core) { /// Initialization system.RegisterCoreThread(core); std::string name = "yuzu:CoreHostThread_" + std::to_string(core); + MicroProfileOnThreadCreate(name.c_str()); Common::SetCurrentThreadName(name.c_str()); auto& data = core_data[core]; data.enter_barrier = std::make_unique(); -- cgit v1.2.3 From 15a79eb0d7abe752a9a55d0cfa7ea220e17318b7 Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Tue, 25 Feb 2020 19:43:28 -0400 Subject: SVC: Correct SendSyncRequest. --- src/core/cpu_manager.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/core/cpu_manager.cpp') diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp index 9b9337131..6032cb0bf 100644 --- a/src/core/cpu_manager.cpp +++ b/src/core/cpu_manager.cpp @@ -81,8 +81,7 @@ void CpuManager::RunGuestThread() { while (true) { auto& physical_core = kernel.CurrentPhysicalCore(); if (!physical_core.IsInterrupted()) { - physical_core.Idle(); - // physical_core.Run(); + physical_core.Run(); } auto& scheduler = physical_core.Scheduler(); scheduler.TryDoContextSwitch(); -- cgit v1.2.3 From 3d9fbb8226e9bf7dce99568f6e616e7361d43c41 Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Wed, 26 Feb 2020 10:44:21 -0400 Subject: CPU_Manager: Reconfigre guest threads for dynamrmic downsides --- src/core/cpu_manager.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/core/cpu_manager.cpp') diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp index 6032cb0bf..241971ff3 100644 --- a/src/core/cpu_manager.cpp +++ b/src/core/cpu_manager.cpp @@ -80,9 +80,10 @@ void CpuManager::RunGuestThread() { } while (true) { auto& physical_core = kernel.CurrentPhysicalCore(); - if (!physical_core.IsInterrupted()) { + while (!physical_core.IsInterrupted()) { physical_core.Run(); } + physical_core.ClearExclusive(); auto& scheduler = physical_core.Scheduler(); scheduler.TryDoContextSwitch(); } -- cgit v1.2.3 From bd36eaf15d88c3875aba7032fe5124fbb150bd5d Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Thu, 27 Feb 2020 11:25:42 -0400 Subject: SVC: Correct races on physical core switching. --- src/core/cpu_manager.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/core/cpu_manager.cpp') diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp index 241971ff3..904aacd97 100644 --- a/src/core/cpu_manager.cpp +++ b/src/core/cpu_manager.cpp @@ -79,12 +79,13 @@ void CpuManager::RunGuestThread() { sched.OnThreadStart(); } while (true) { - auto& physical_core = kernel.CurrentPhysicalCore(); - while (!physical_core.IsInterrupted()) { - physical_core.Run(); + auto* physical_core = &kernel.CurrentPhysicalCore(); + while (!physical_core->IsInterrupted()) { + physical_core->Run(); + physical_core = &kernel.CurrentPhysicalCore(); } - physical_core.ClearExclusive(); - auto& scheduler = physical_core.Scheduler(); + physical_core->ClearExclusive(); + auto& scheduler = physical_core->Scheduler(); scheduler.TryDoContextSwitch(); } } -- cgit v1.2.3 From 04e0f8776c26930d7dc8015e53914b11bf1929c1 Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Thu, 27 Feb 2020 19:12:41 -0400 Subject: General: Add better safety for JIT use. --- src/core/cpu_manager.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'src/core/cpu_manager.cpp') diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp index 904aacd97..9a261968a 100644 --- a/src/core/cpu_manager.cpp +++ b/src/core/cpu_manager.cpp @@ -46,6 +46,11 @@ void CpuManager::GuestThreadFunction(void* cpu_manager_) { cpu_manager->RunGuestThread(); } +void CpuManager::GuestRewindFunction(void* cpu_manager_) { + CpuManager* cpu_manager = static_cast(cpu_manager_); + cpu_manager->RunGuestLoop(); +} + void CpuManager::IdleThreadFunction(void* cpu_manager_) { CpuManager* cpu_manager = static_cast(cpu_manager_); cpu_manager->RunIdleThread(); @@ -78,14 +83,22 @@ void CpuManager::RunGuestThread() { auto& sched = kernel.CurrentScheduler(); sched.OnThreadStart(); } + RunGuestLoop(); +} + +void CpuManager::RunGuestLoop() { + auto& kernel = system.Kernel(); + auto* thread = kernel.CurrentScheduler().GetCurrentThread(); + auto host_context = thread->GetHostContext(); + host_context->SetRewindPoint(std::function(GuestRewindFunction), this); + host_context.reset(); while (true) { - auto* physical_core = &kernel.CurrentPhysicalCore(); - while (!physical_core->IsInterrupted()) { - physical_core->Run(); - physical_core = &kernel.CurrentPhysicalCore(); + auto& physical_core = kernel.CurrentPhysicalCore(); + while (!physical_core.IsInterrupted()) { + physical_core.Run(); } - physical_core->ClearExclusive(); - auto& scheduler = physical_core->Scheduler(); + physical_core.ClearExclusive(); + auto& scheduler = physical_core.Scheduler(); scheduler.TryDoContextSwitch(); } } -- cgit v1.2.3 From ab9aae28bf5daa5fa7105bb4ef41b6d0b3c9cdc1 Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Sun, 8 Mar 2020 22:39:41 -0400 Subject: General: Initial Setup for Single Core. --- src/core/cpu_manager.cpp | 186 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 160 insertions(+), 26 deletions(-) (limited to 'src/core/cpu_manager.cpp') diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp index 9a261968a..e72f89808 100644 --- a/src/core/cpu_manager.cpp +++ b/src/core/cpu_manager.cpp @@ -26,9 +26,13 @@ void CpuManager::ThreadStart(CpuManager& cpu_manager, std::size_t core) { void CpuManager::Initialize() { running_mode = true; - for (std::size_t core = 0; core < Core::Hardware::NUM_CPU_CORES; core++) { - core_data[core].host_thread = - std::make_unique(ThreadStart, std::ref(*this), core); + if (is_multicore) { + for (std::size_t core = 0; core < Core::Hardware::NUM_CPU_CORES; core++) { + core_data[core].host_thread = + std::make_unique(ThreadStart, std::ref(*this), core); + } + } else { + core_data[0].host_thread = std::make_unique(ThreadStart, std::ref(*this), 0); } } @@ -41,52 +45,72 @@ void CpuManager::Shutdown() { } } +std::function CpuManager::GetGuestThreadStartFunc() { + return std::function(GuestThreadFunction); +} + +std::function CpuManager::GetIdleThreadStartFunc() { + return std::function(IdleThreadFunction); +} + +std::function CpuManager::GetSuspendThreadStartFunc() { + return std::function(SuspendThreadFunction); +} + void CpuManager::GuestThreadFunction(void* cpu_manager_) { CpuManager* cpu_manager = static_cast(cpu_manager_); - cpu_manager->RunGuestThread(); + if (cpu_manager->is_multicore) { + cpu_manager->MultiCoreRunGuestThread(); + } else { + cpu_manager->SingleCoreRunGuestThread(); + } } void CpuManager::GuestRewindFunction(void* cpu_manager_) { CpuManager* cpu_manager = static_cast(cpu_manager_); - cpu_manager->RunGuestLoop(); + if (cpu_manager->is_multicore) { + cpu_manager->MultiCoreRunGuestLoop(); + } else { + cpu_manager->SingleCoreRunGuestLoop(); + } } void CpuManager::IdleThreadFunction(void* cpu_manager_) { CpuManager* cpu_manager = static_cast(cpu_manager_); - cpu_manager->RunIdleThread(); + if (cpu_manager->is_multicore) { + cpu_manager->MultiCoreRunIdleThread(); + } else { + cpu_manager->SingleCoreRunIdleThread(); + } } void CpuManager::SuspendThreadFunction(void* cpu_manager_) { CpuManager* cpu_manager = static_cast(cpu_manager_); - cpu_manager->RunSuspendThread(); -} - -std::function CpuManager::GetGuestThreadStartFunc() { - return std::function(GuestThreadFunction); -} - -std::function CpuManager::GetIdleThreadStartFunc() { - return std::function(IdleThreadFunction); -} - -std::function CpuManager::GetSuspendThreadStartFunc() { - return std::function(SuspendThreadFunction); + if (cpu_manager->is_multicore) { + cpu_manager->MultiCoreRunSuspendThread(); + } else { + cpu_manager->SingleCoreRunSuspendThread(); + } } void* CpuManager::GetStartFuncParamater() { return static_cast(this); } -void CpuManager::RunGuestThread() { +/////////////////////////////////////////////////////////////////////////////// +/// MultiCore /// +/////////////////////////////////////////////////////////////////////////////// + +void CpuManager::MultiCoreRunGuestThread() { auto& kernel = system.Kernel(); { auto& sched = kernel.CurrentScheduler(); sched.OnThreadStart(); } - RunGuestLoop(); + MultiCoreRunGuestLoop(); } -void CpuManager::RunGuestLoop() { +void CpuManager::MultiCoreRunGuestLoop() { auto& kernel = system.Kernel(); auto* thread = kernel.CurrentScheduler().GetCurrentThread(); auto host_context = thread->GetHostContext(); @@ -103,7 +127,7 @@ void CpuManager::RunGuestLoop() { } } -void CpuManager::RunIdleThread() { +void CpuManager::MultiCoreRunIdleThread() { auto& kernel = system.Kernel(); while (true) { auto& physical_core = kernel.CurrentPhysicalCore(); @@ -113,7 +137,7 @@ void CpuManager::RunIdleThread() { } } -void CpuManager::RunSuspendThread() { +void CpuManager::MultiCoreRunSuspendThread() { auto& kernel = system.Kernel(); { auto& sched = kernel.CurrentScheduler(); @@ -130,7 +154,7 @@ void CpuManager::RunSuspendThread() { } } -void CpuManager::Pause(bool paused) { +void CpuManager::MultiCorePause(bool paused) { if (!paused) { bool all_not_barrier = false; while (!all_not_barrier) { @@ -171,10 +195,120 @@ void CpuManager::Pause(bool paused) { paused_state = paused; } +/////////////////////////////////////////////////////////////////////////////// +/// SingleCore /// +/////////////////////////////////////////////////////////////////////////////// + +void CpuManager::SingleCoreRunGuestThread() { + auto& kernel = system.Kernel(); + { + auto& sched = kernel.CurrentScheduler(); + sched.OnThreadStart(); + } + SingleCoreRunGuestLoop(); +} + +void CpuManager::SingleCoreRunGuestLoop() { + auto& kernel = system.Kernel(); + auto* thread = kernel.CurrentScheduler().GetCurrentThread(); + auto host_context = thread->GetHostContext(); + host_context->SetRewindPoint(std::function(GuestRewindFunction), this); + host_context.reset(); + while (true) { + auto& physical_core = kernel.CurrentPhysicalCore(); + while (!physical_core.IsInterrupted()) { + physical_core.Run(); + preemption_count++; + if (preemption_count % max_cycle_runs == 0) { + break; + } + } + physical_core.ClearExclusive(); + PreemptSingleCore(); + auto& scheduler = physical_core.Scheduler(); + scheduler.TryDoContextSwitch(); + } +} + +void CpuManager::SingleCoreRunIdleThread() { + auto& kernel = system.Kernel(); + while (true) { + auto& physical_core = kernel.CurrentPhysicalCore(); + PreemptSingleCore(); + auto& scheduler = physical_core.Scheduler(); + scheduler.TryDoContextSwitch(); + } +} + +void CpuManager::SingleCoreRunSuspendThread() { + auto& kernel = system.Kernel(); + { + auto& sched = kernel.CurrentScheduler(); + sched.OnThreadStart(); + } + while (true) { + auto core = kernel.GetCurrentHostThreadID(); + auto& scheduler = kernel.CurrentScheduler(); + Kernel::Thread* current_thread = scheduler.GetCurrentThread(); + Common::Fiber::YieldTo(current_thread->GetHostContext(), core_data[0].host_context); + ASSERT(scheduler.ContextSwitchPending()); + ASSERT(core == kernel.GetCurrentHostThreadID()); + scheduler.TryDoContextSwitch(); + } +} + +void CpuManager::PreemptSingleCore() { + preemption_count = 0; + std::size_t old_core = current_core; + current_core = (current_core + 1) % Core::Hardware::NUM_CPU_CORES; + auto& scheduler = system.Kernel().Scheduler(old_core); + Kernel::Thread* current_thread = system.Kernel().Scheduler(old_core).GetCurrentThread(); + Kernel::Thread* next_thread = system.Kernel().Scheduler(current_core).GetCurrentThread(); + Common::Fiber::YieldTo(current_thread->GetHostContext(), next_thread->GetHostContext()); +} + +void CpuManager::SingleCorePause(bool paused) { + if (!paused) { + bool all_not_barrier = false; + while (!all_not_barrier) { + all_not_barrier = !core_data[0].is_running.load() && core_data[0].initialized.load(); + } + core_data[0].enter_barrier->Set(); + if (paused_state.load()) { + bool all_barrier = false; + while (!all_barrier) { + all_barrier = core_data[0].is_paused.load() && core_data[0].initialized.load(); + } + core_data[0].exit_barrier->Set(); + } + } else { + /// Wait until all cores are paused. + bool all_barrier = false; + while (!all_barrier) { + all_barrier = core_data[0].is_paused.load() && core_data[0].initialized.load(); + } + /// Don't release the barrier + } + paused_state = paused; +} + +void CpuManager::Pause(bool paused) { + if (is_multicore) { + MultiCorePause(paused); + } else { + SingleCorePause(paused); + } +} + void CpuManager::RunThread(std::size_t core) { /// Initialization system.RegisterCoreThread(core); - std::string name = "yuzu:CoreHostThread_" + std::to_string(core); + std::string name; + if (is_multicore) { + name = "yuzu:CoreCPUThread_" + std::to_string(core); + } else { + name = "yuzu:CPUThread"; + } MicroProfileOnThreadCreate(name.c_str()); Common::SetCurrentThreadName(name.c_str()); auto& data = core_data[core]; -- cgit v1.2.3 From a439cdf22ea50f0e39cb51f6dff15fee3b495d16 Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Tue, 10 Mar 2020 11:50:33 -0400 Subject: CPU_Manager: Unload/Reload threads on preemption on SingleCore --- src/core/cpu_manager.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/core/cpu_manager.cpp') diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp index e72f89808..95842aad1 100644 --- a/src/core/cpu_manager.cpp +++ b/src/core/cpu_manager.cpp @@ -225,7 +225,7 @@ void CpuManager::SingleCoreRunGuestLoop() { } physical_core.ClearExclusive(); PreemptSingleCore(); - auto& scheduler = physical_core.Scheduler(); + auto& scheduler = kernel.Scheduler(current_core); scheduler.TryDoContextSwitch(); } } @@ -260,11 +260,15 @@ void CpuManager::SingleCoreRunSuspendThread() { void CpuManager::PreemptSingleCore() { preemption_count = 0; std::size_t old_core = current_core; - current_core = (current_core + 1) % Core::Hardware::NUM_CPU_CORES; + current_core.store((current_core + 1) % Core::Hardware::NUM_CPU_CORES); auto& scheduler = system.Kernel().Scheduler(old_core); - Kernel::Thread* current_thread = system.Kernel().Scheduler(old_core).GetCurrentThread(); - Kernel::Thread* next_thread = system.Kernel().Scheduler(current_core).GetCurrentThread(); - Common::Fiber::YieldTo(current_thread->GetHostContext(), next_thread->GetHostContext()); + Kernel::Thread* current_thread = scheduler.GetCurrentThread(); + scheduler.Unload(); + 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(); } void CpuManager::SingleCorePause(bool paused) { -- cgit v1.2.3 From 7020d498c5aef7c1180bfc57031cdd7fbfecdf0f Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Thu, 12 Mar 2020 16:48:43 -0400 Subject: General: Fix microprofile on dynarmic/svc, fix wait tree showing which threads were running. --- src/core/cpu_manager.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/core/cpu_manager.cpp') diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp index 95842aad1..9e2e6d49f 100644 --- a/src/core/cpu_manager.cpp +++ b/src/core/cpu_manager.cpp @@ -118,9 +118,11 @@ void CpuManager::MultiCoreRunGuestLoop() { host_context.reset(); while (true) { auto& physical_core = kernel.CurrentPhysicalCore(); + system.EnterDynarmicProfile(); while (!physical_core.IsInterrupted()) { physical_core.Run(); } + system.ExitDynarmicProfile(); physical_core.ClearExclusive(); auto& scheduler = physical_core.Scheduler(); scheduler.TryDoContextSwitch(); @@ -216,6 +218,7 @@ void CpuManager::SingleCoreRunGuestLoop() { host_context.reset(); while (true) { auto& physical_core = kernel.CurrentPhysicalCore(); + system.EnterDynarmicProfile(); while (!physical_core.IsInterrupted()) { physical_core.Run(); preemption_count++; @@ -224,6 +227,7 @@ void CpuManager::SingleCoreRunGuestLoop() { } } physical_core.ClearExclusive(); + system.ExitDynarmicProfile(); PreemptSingleCore(); auto& scheduler = kernel.Scheduler(current_core); scheduler.TryDoContextSwitch(); -- cgit v1.2.3 From 1a5f2e290ba831ad6d18514bcdfcd92673643e4b Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Thu, 12 Mar 2020 19:55:53 -0400 Subject: CPU_Manager: Correct stopping on SingleCore. --- src/core/cpu_manager.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/core/cpu_manager.cpp') diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp index 9e2e6d49f..e92b0fb37 100644 --- a/src/core/cpu_manager.cpp +++ b/src/core/cpu_manager.cpp @@ -39,9 +39,14 @@ void CpuManager::Initialize() { void CpuManager::Shutdown() { running_mode = false; Pause(false); - for (std::size_t core = 0; core < Core::Hardware::NUM_CPU_CORES; core++) { - core_data[core].host_thread->join(); - core_data[core].host_thread.reset(); + if (is_multicore) { + for (std::size_t core = 0; core < Core::Hardware::NUM_CPU_CORES; core++) { + core_data[core].host_thread->join(); + core_data[core].host_thread.reset(); + } + } else { + core_data[0].host_thread->join(); + core_data[0].host_thread.reset(); } } -- cgit v1.2.3 From 5d3a2be04f265c2d6a8687431593029f7329060f Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Sun, 15 Mar 2020 21:34:22 -0400 Subject: GUI: Make multicore only work with Async and add GUI for multicore. --- src/core/cpu_manager.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/core/cpu_manager.cpp') diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp index e92b0fb37..d7bd162bc 100644 --- a/src/core/cpu_manager.cpp +++ b/src/core/cpu_manager.cpp @@ -9,6 +9,7 @@ #include "core/core.h" #include "core/core_timing.h" #include "core/cpu_manager.h" +#include "core/frontend/emu_window.h" #include "core/gdbstub/gdbstub.h" #include "core/hle/kernel/kernel.h" #include "core/hle/kernel/physical_core.h" @@ -21,7 +22,17 @@ CpuManager::CpuManager(System& system) : system{system} {} CpuManager::~CpuManager() = default; void CpuManager::ThreadStart(CpuManager& cpu_manager, std::size_t core) { + if (!cpu_manager.is_async_gpu && !cpu_manager.is_multicore) { + cpu_manager.render_window->MakeCurrent(); + } cpu_manager.RunThread(core); + if (!cpu_manager.is_async_gpu && !cpu_manager.is_multicore) { + cpu_manager.render_window->DoneCurrent(); + } +} + +void CpuManager::SetRenderWindow(Core::Frontend::EmuWindow& render_window) { + this->render_window = &render_window; } void CpuManager::Initialize() { -- cgit v1.2.3 From f2ade343e2492c213ac93680a55e9bed712dac9a Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Thu, 19 Mar 2020 13:09:32 -0400 Subject: SingleCore: Move Host Timing from a sepparate thread to main cpu thread. --- src/core/cpu_manager.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/core/cpu_manager.cpp') diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp index d7bd162bc..2aea95a25 100644 --- a/src/core/cpu_manager.cpp +++ b/src/core/cpu_manager.cpp @@ -242,8 +242,11 @@ void CpuManager::SingleCoreRunGuestLoop() { break; } } - physical_core.ClearExclusive(); system.ExitDynarmicProfile(); + thread->SetPhantomMode(true); + system.CoreTiming().Advance(); + thread->SetPhantomMode(false); + physical_core.ClearExclusive(); PreemptSingleCore(); auto& scheduler = kernel.Scheduler(current_core); scheduler.TryDoContextSwitch(); @@ -255,6 +258,7 @@ void CpuManager::SingleCoreRunIdleThread() { while (true) { auto& physical_core = kernel.CurrentPhysicalCore(); PreemptSingleCore(); + idle_count++; auto& scheduler = physical_core.Scheduler(); scheduler.TryDoContextSwitch(); } @@ -280,15 +284,24 @@ void CpuManager::SingleCoreRunSuspendThread() { void CpuManager::PreemptSingleCore() { preemption_count = 0; std::size_t old_core = current_core; - current_core.store((current_core + 1) % Core::Hardware::NUM_CPU_CORES); auto& scheduler = system.Kernel().Scheduler(old_core); Kernel::Thread* current_thread = scheduler.GetCurrentThread(); + if (idle_count >= 4) { + current_thread->SetPhantomMode(true); + system.CoreTiming().Advance(); + current_thread->SetPhantomMode(false); + } + current_core.store((current_core + 1) % Core::Hardware::NUM_CPU_CORES); scheduler.Unload(); 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(); + auto* currrent_thread2 = current_scheduler.GetCurrentThread(); + if (!currrent_thread2->IsIdleThread()) { + idle_count = 0; + } } void CpuManager::SingleCorePause(bool paused) { -- cgit v1.2.3 From 1567824d2da8e9b49b433f3d1d753d8ad84e65f9 Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Sun, 1 Mar 2020 12:14:17 -0400 Subject: General: Move ARM_Interface into Threads. --- src/core/cpu_manager.cpp | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'src/core/cpu_manager.cpp') diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp index 2aea95a25..2e9dc9dc3 100644 --- a/src/core/cpu_manager.cpp +++ b/src/core/cpu_manager.cpp @@ -129,18 +129,17 @@ void CpuManager::MultiCoreRunGuestThread() { void CpuManager::MultiCoreRunGuestLoop() { auto& kernel = system.Kernel(); auto* thread = kernel.CurrentScheduler().GetCurrentThread(); - auto host_context = thread->GetHostContext(); - host_context->SetRewindPoint(std::function(GuestRewindFunction), this); - host_context.reset(); while (true) { - auto& physical_core = kernel.CurrentPhysicalCore(); + auto* physical_core = &kernel.CurrentPhysicalCore(); + auto& arm_interface = thread->ArmInterface(); system.EnterDynarmicProfile(); - while (!physical_core.IsInterrupted()) { - physical_core.Run(); + while (!physical_core->IsInterrupted()) { + arm_interface.Run(); + physical_core = &kernel.CurrentPhysicalCore(); } system.ExitDynarmicProfile(); - physical_core.ClearExclusive(); - auto& scheduler = physical_core.Scheduler(); + arm_interface.ClearExclusiveState(); + auto& scheduler = kernel.CurrentScheduler(); scheduler.TryDoContextSwitch(); } } @@ -150,7 +149,7 @@ void CpuManager::MultiCoreRunIdleThread() { while (true) { auto& physical_core = kernel.CurrentPhysicalCore(); physical_core.Idle(); - auto& scheduler = physical_core.Scheduler(); + auto& scheduler = kernel.CurrentScheduler(); scheduler.TryDoContextSwitch(); } } @@ -229,14 +228,13 @@ void CpuManager::SingleCoreRunGuestThread() { void CpuManager::SingleCoreRunGuestLoop() { auto& kernel = system.Kernel(); auto* thread = kernel.CurrentScheduler().GetCurrentThread(); - auto host_context = thread->GetHostContext(); - host_context->SetRewindPoint(std::function(GuestRewindFunction), this); - host_context.reset(); while (true) { - auto& physical_core = kernel.CurrentPhysicalCore(); + auto* physical_core = &kernel.CurrentPhysicalCore(); + auto& arm_interface = thread->ArmInterface(); system.EnterDynarmicProfile(); - while (!physical_core.IsInterrupted()) { - physical_core.Run(); + while (!physical_core->IsInterrupted()) { + arm_interface.Run(); + physical_core = &kernel.CurrentPhysicalCore(); preemption_count++; if (preemption_count % max_cycle_runs == 0) { break; @@ -246,7 +244,7 @@ void CpuManager::SingleCoreRunGuestLoop() { thread->SetPhantomMode(true); system.CoreTiming().Advance(); thread->SetPhantomMode(false); - physical_core.ClearExclusive(); + arm_interface.ClearExclusiveState(); PreemptSingleCore(); auto& scheduler = kernel.Scheduler(current_core); scheduler.TryDoContextSwitch(); -- cgit v1.2.3 From f5e32935ca9d1727624c86ca78aff91027caf819 Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Sat, 28 Mar 2020 15:23:28 -0400 Subject: SingleCore: Use Cycle Timing instead of Host Timing. --- src/core/cpu_manager.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/core/cpu_manager.cpp') diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp index 2e9dc9dc3..604405060 100644 --- a/src/core/cpu_manager.cpp +++ b/src/core/cpu_manager.cpp @@ -232,13 +232,10 @@ void CpuManager::SingleCoreRunGuestLoop() { auto* physical_core = &kernel.CurrentPhysicalCore(); auto& arm_interface = thread->ArmInterface(); system.EnterDynarmicProfile(); - while (!physical_core->IsInterrupted()) { + if (!physical_core->IsInterrupted()) { + system.CoreTiming().ResetTicks(); arm_interface.Run(); physical_core = &kernel.CurrentPhysicalCore(); - preemption_count++; - if (preemption_count % max_cycle_runs == 0) { - break; - } } system.ExitDynarmicProfile(); thread->SetPhantomMode(true); @@ -255,7 +252,7 @@ void CpuManager::SingleCoreRunIdleThread() { auto& kernel = system.Kernel(); while (true) { auto& physical_core = kernel.CurrentPhysicalCore(); - PreemptSingleCore(); + PreemptSingleCore(false); idle_count++; auto& scheduler = physical_core.Scheduler(); scheduler.TryDoContextSwitch(); @@ -279,12 +276,15 @@ void CpuManager::SingleCoreRunSuspendThread() { } } -void CpuManager::PreemptSingleCore() { - preemption_count = 0; +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) { + 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); -- cgit v1.2.3 From 7e2ce2f7f47e77b46d66dcefbd0c391e58421103 Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Sun, 29 Mar 2020 17:06:46 -0400 Subject: SingleCore: Improve Cycle timing Behavior and replace mutex in global scheduler for spinlock. --- src/core/cpu_manager.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/core/cpu_manager.cpp') diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp index 604405060..d604aa446 100644 --- a/src/core/cpu_manager.cpp +++ b/src/core/cpu_manager.cpp @@ -253,6 +253,7 @@ void CpuManager::SingleCoreRunIdleThread() { while (true) { auto& physical_core = kernel.CurrentPhysicalCore(); PreemptSingleCore(false); + system.CoreTiming().AddTicks(1000U); idle_count++; auto& scheduler = physical_core.Scheduler(); scheduler.TryDoContextSwitch(); -- cgit v1.2.3 From 54e304fe2a38984ea27a7f2240c41a85931d7f6b Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Tue, 31 Mar 2020 13:52:07 -0400 Subject: Bootmanager/CPU_Manager: Correct shader caches and sync GPU on OpenGL. --- src/core/cpu_manager.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/core/cpu_manager.cpp') diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp index d604aa446..c0974ee38 100644 --- a/src/core/cpu_manager.cpp +++ b/src/core/cpu_manager.cpp @@ -22,13 +22,7 @@ CpuManager::CpuManager(System& system) : system{system} {} CpuManager::~CpuManager() = default; void CpuManager::ThreadStart(CpuManager& cpu_manager, std::size_t core) { - if (!cpu_manager.is_async_gpu && !cpu_manager.is_multicore) { - cpu_manager.render_window->MakeCurrent(); - } cpu_manager.RunThread(core); - if (!cpu_manager.is_async_gpu && !cpu_manager.is_multicore) { - cpu_manager.render_window->DoneCurrent(); - } } void CpuManager::SetRenderWindow(Core::Frontend::EmuWindow& render_window) { @@ -353,10 +347,16 @@ void CpuManager::RunThread(std::size_t core) { data.host_context = Common::Fiber::ThreadToFiber(); data.is_running = false; data.initialized = true; + const bool sc_sync = !is_async_gpu && !is_multicore; + bool sc_sync_first_use = sc_sync; /// Running while (running_mode) { data.is_running = false; data.enter_barrier->Wait(); + if (sc_sync_first_use) { + render_window->MakeCurrent(); + sc_sync_first_use = false; + } auto& scheduler = system.Kernel().CurrentScheduler(); Kernel::Thread* current_thread = scheduler.GetCurrentThread(); data.is_running = true; @@ -366,6 +366,9 @@ void CpuManager::RunThread(std::size_t core) { data.exit_barrier->Wait(); data.is_paused = false; } + if (sc_sync) { + render_window->DoneCurrent(); + } /// Time to cleanup data.host_context->Exit(); data.enter_barrier.reset(); -- cgit v1.2.3 From bece52cd810197e905416fa46a4ed484caa41db5 Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Thu, 2 Apr 2020 13:24:39 -0400 Subject: SingleCore: Correct ticks reset to be on preemption. --- src/core/cpu_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/cpu_manager.cpp') diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp index c0974ee38..b7c2a7832 100644 --- a/src/core/cpu_manager.cpp +++ b/src/core/cpu_manager.cpp @@ -227,7 +227,6 @@ void CpuManager::SingleCoreRunGuestLoop() { auto& arm_interface = thread->ArmInterface(); system.EnterDynarmicProfile(); if (!physical_core->IsInterrupted()) { - system.CoreTiming().ResetTicks(); arm_interface.Run(); physical_core = &kernel.CurrentPhysicalCore(); } @@ -285,6 +284,7 @@ void CpuManager::PreemptSingleCore(bool from_running_enviroment) { current_thread->SetPhantomMode(false); } current_core.store((current_core + 1) % Core::Hardware::NUM_CPU_CORES); + system.CoreTiming().ResetTicks(); scheduler.Unload(); auto& next_scheduler = system.Kernel().Scheduler(current_core); Common::Fiber::YieldTo(current_thread->GetHostContext(), next_scheduler.ControlContext()); -- cgit v1.2.3 From ad92865497f83fe4c19cd9ab78cce9da1a8c3a6c Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Fri, 3 Apr 2020 11:58:43 -0400 Subject: General: Correct rebase, sync gpu and context management. --- src/core/cpu_manager.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'src/core/cpu_manager.cpp') diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp index b7c2a7832..63c578852 100644 --- a/src/core/cpu_manager.cpp +++ b/src/core/cpu_manager.cpp @@ -9,12 +9,12 @@ #include "core/core.h" #include "core/core_timing.h" #include "core/cpu_manager.h" -#include "core/frontend/emu_window.h" #include "core/gdbstub/gdbstub.h" #include "core/hle/kernel/kernel.h" #include "core/hle/kernel/physical_core.h" #include "core/hle/kernel/scheduler.h" #include "core/hle/kernel/thread.h" +#include "video_core/gpu.h" namespace Core { @@ -25,10 +25,6 @@ void CpuManager::ThreadStart(CpuManager& cpu_manager, std::size_t core) { cpu_manager.RunThread(core); } -void CpuManager::SetRenderWindow(Core::Frontend::EmuWindow& render_window) { - this->render_window = &render_window; -} - void CpuManager::Initialize() { running_mode = true; if (is_multicore) { @@ -354,7 +350,7 @@ void CpuManager::RunThread(std::size_t core) { data.is_running = false; data.enter_barrier->Wait(); if (sc_sync_first_use) { - render_window->MakeCurrent(); + system.GPU().ObtainContext(); sc_sync_first_use = false; } auto& scheduler = system.Kernel().CurrentScheduler(); @@ -366,9 +362,6 @@ void CpuManager::RunThread(std::size_t core) { data.exit_barrier->Wait(); data.is_paused = false; } - if (sc_sync) { - render_window->DoneCurrent(); - } /// Time to cleanup data.host_context->Exit(); data.enter_barrier.reset(); -- cgit v1.2.3 From 528b19a84287167d7699465e495b196d216b99db Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Sun, 5 Apr 2020 09:48:53 -0400 Subject: General: Tune the priority of main emulation threads so they have higher priority than less important helper threads. --- src/core/cpu_manager.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/core/cpu_manager.cpp') diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp index 63c578852..32afcf3ae 100644 --- a/src/core/cpu_manager.cpp +++ b/src/core/cpu_manager.cpp @@ -337,6 +337,7 @@ void CpuManager::RunThread(std::size_t core) { } MicroProfileOnThreadCreate(name.c_str()); Common::SetCurrentThreadName(name.c_str()); + Common::SetCurrentThreadPriority(Common::ThreadPriority::High); auto& data = core_data[core]; data.enter_barrier = std::make_unique(); data.exit_barrier = std::make_unique(); -- cgit v1.2.3