VERY experimental Nintendo Switch 2 emulator
C++
Core: Refactor CpuCoreManager to CpuManager and Cpu to Core Manager.
Fernando Sahmkow0a5e0d4777a3
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txtindex d5b8091aef..d342cafe03 100644--- a/src/core/CMakeLists.txt+++ b/src/core/CMakeLists.txt@@ -15,14 +15,14 @@ add_library(core STATICconstants.hcore.cppcore.h- core_cpu.cpp- core_cpu.h+ core_manager.cpp+ core_manager.hcore_timing.cppcore_timing.hcore_timing_util.cppcore_timing_util.h- cpu_core_manager.cpp- cpu_core_manager.h+ cpu_manager.cpp+ cpu_manager.hcrypto/aes_util.cppcrypto/aes_util.hcrypto/encryption_layer.cppdiff --git a/src/core/arm/dynarmic/arm_dynarmic.cpp b/src/core/arm/dynarmic/arm_dynarmic.cppindex e825c05268..f468e57e46 100644--- a/src/core/arm/dynarmic/arm_dynarmic.cpp+++ b/src/core/arm/dynarmic/arm_dynarmic.cpp@@ -10,7 +10,7 @@#include "common/microprofile.h"#include "core/arm/dynarmic/arm_dynarmic.h"#include "core/core.h"-#include "core/core_cpu.h"+#include "core/core_manager.h"#include "core/core_timing.h"#include "core/core_timing_util.h"#include "core/gdbstub/gdbstub.h"diff --git a/src/core/core.cpp b/src/core/core.cppindex 27b8d34087..bfe9525150 100644--- a/src/core/core.cpp+++ b/src/core/core.cpp@@ -11,9 +11,9 @@#include "common/string_util.h"#include "core/arm/exclusive_monitor.h"#include "core/core.h"-#include "core/core_cpu.h"+#include "core/core_manager.h"#include "core/core_timing.h"-#include "core/cpu_core_manager.h"+#include "core/cpu_manager.h"#include "core/file_sys/bis_factory.h"#include "core/file_sys/card_image.h"#include "core/file_sys/mode.h"@@ -114,14 +114,14 @@ FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs,struct System::Impl {explicit Impl(System& system): kernel{system}, fs_controller{system}, memory{system},- cpu_core_manager{system}, reporter{system}, applet_manager{system} {}+ cpu_manager{system}, reporter{system}, applet_manager{system} {}- Cpu& CurrentCpuCore() {- return cpu_core_manager.GetCurrentCore();+ CoreManager& CurrentCoreManager() {+ return cpu_manager.GetCurrentCoreManager();}Kernel::PhysicalCore& CurrentPhysicalCore() {- const auto i = cpu_core_manager.GetCurrentCoreIndex();+ const auto i = cpu_manager.GetActiveCoreIndex();return kernel.PhysicalCore(i);}@@ -132,7 +132,7 @@ struct System::Impl {ResultStatus RunLoop(bool tight_loop) {status = ResultStatus::Success;- cpu_core_manager.RunLoop(tight_loop);+ cpu_manager.RunLoop(tight_loop);return status;}@@ -142,7 +142,7 @@ struct System::Impl {core_timing.Initialize();kernel.Initialize();- cpu_core_manager.Initialize();+ cpu_manager.Initialize();const auto current_time = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch());@@ -281,7 +281,7 @@ struct System::Impl {gpu_core.reset();// Close all CPU/threading state- cpu_core_manager.Shutdown();+ cpu_manager.Shutdown();// Shutdown kernel and core timingkernel.Shutdown();@@ -351,7 +351,7 @@ struct System::Impl {std::unique_ptr<Tegra::GPU> gpu_core;std::unique_ptr<Hardware::InterruptManager> interrupt_manager;Memory::Memory memory;- CpuCoreManager cpu_core_manager;+ CpuManager cpu_manager;bool is_powered_on = false;bool exit_lock = false;@@ -386,12 +386,12 @@ struct System::Impl {System::System() : impl{std::make_unique<Impl>(*this)} {}System::~System() = default;-Cpu& System::CurrentCpuCore() {- return impl->CurrentCpuCore();+CoreManager& System::CurrentCoreManager() {+ return impl->CurrentCoreManager();}-const Cpu& System::CurrentCpuCore() const {- return impl->CurrentCpuCore();+const CoreManager& System::CurrentCoreManager() const {+ return impl->CurrentCoreManager();}System::ResultStatus System::RunLoop(bool tight_loop) {@@ -415,13 +415,11 @@ bool System::IsPoweredOn() const {}void System::PrepareReschedule() {- CurrentCpuCore().PrepareReschedule();+ CurrentCoreManager().PrepareReschedule();}void System::PrepareReschedule(const u32 core_index) {- if (core_index < GlobalScheduler().CpuCoresCount()) {- CpuCore(core_index).PrepareReschedule();- }+ impl->kernel.PrepareReschedule(core_index);}PerfStatsResults System::GetAndResetPerfStats() {@@ -445,7 +443,7 @@ const ARM_Interface& System::CurrentArmInterface() const {}std::size_t System::CurrentCoreIndex() const {- return CurrentCpuCore().CoreIndex();+ return impl->cpu_manager.GetActiveCoreIndex();}Kernel::Scheduler& System::CurrentScheduler() {@@ -490,13 +488,13 @@ const ARM_Interface& System::ArmInterface(std::size_t core_index) const {return impl->GetPhysicalCore(core_index).ArmInterface();}-Cpu& System::CpuCore(std::size_t core_index) {- return impl->cpu_core_manager.GetCore(core_index);+CoreManager& System::GetCoreManager(std::size_t core_index) {+ return impl->cpu_manager.GetCoreManager(core_index);}-const Cpu& System::CpuCore(std::size_t core_index) const {+const CoreManager& System::GetCoreManager(std::size_t core_index) const {ASSERT(core_index < NUM_CPU_CORES);- return impl->cpu_core_manager.GetCore(core_index);+ return impl->cpu_manager.GetCoreManager(core_index);}ExclusiveMonitor& System::Monitor() {diff --git a/src/core/core.h b/src/core/core.hindex e240c5c585..e69d68fcf9 100644--- a/src/core/core.h+++ b/src/core/core.h@@ -93,7 +93,7 @@ class Memory;namespace Core {class ARM_Interface;-class Cpu;+class CoreManager;class ExclusiveMonitor;class FrameLimiter;class PerfStats;@@ -218,10 +218,10 @@ public:const ARM_Interface& ArmInterface(std::size_t core_index) const;/// Gets a CPU interface to the CPU core with the specified index- Cpu& CpuCore(std::size_t core_index);+ CoreManager& GetCoreManager(std::size_t core_index);/// Gets a CPU interface to the CPU core with the specified index- const Cpu& CpuCore(std::size_t core_index) const;+ const CoreManager& GetCoreManager(std::size_t core_index) const;/// Gets a reference to the exclusive monitorExclusiveMonitor& Monitor();@@ -364,10 +364,10 @@ private:System();/// Returns the currently running CPU core- Cpu& CurrentCpuCore();+ CoreManager& CurrentCoreManager();/// Returns the currently running CPU core- const Cpu& CurrentCpuCore() const;+ const CoreManager& CurrentCoreManager() const;/*** Initialize the emulated system.diff --git a/src/core/core_cpu.cpp b/src/core/core_manager.cppsimilarity index 85%rename from src/core/core_cpu.cpprename to src/core/core_manager.cppindex bcfdf01985..bb03857d5b 100644--- a/src/core/core_cpu.cpp+++ b/src/core/core_manager.cpp@@ -12,7 +12,7 @@#include "core/arm/exclusive_monitor.h"#include "core/arm/unicorn/arm_unicorn.h"#include "core/core.h"-#include "core/core_cpu.h"+#include "core/core_manager.h"#include "core/core_timing.h"#include "core/hle/kernel/kernel.h"#include "core/hle/kernel/physical_core.h"@@ -23,15 +23,15 @@namespace Core {-Cpu::Cpu(System& system, std::size_t core_index)+CoreManager::CoreManager(System& system, std::size_t core_index): global_scheduler{system.GlobalScheduler()},physical_core{system.Kernel().PhysicalCore(core_index)}, core_timing{system.CoreTiming()},core_index{core_index} {}-Cpu::~Cpu() = default;+CoreManager::~CoreManager() = default;-void Cpu::RunLoop(bool tight_loop) {+void CoreManager::RunLoop(bool tight_loop) {Reschedule();// If we don't have a currently active thread then don't execute instructions,@@ -51,15 +51,15 @@ void Cpu::RunLoop(bool tight_loop) {Reschedule();}-void Cpu::SingleStep() {+void CoreManager::SingleStep() {return RunLoop(false);}-void Cpu::PrepareReschedule() {+void CoreManager::PrepareReschedule() {physical_core.Stop();}-void Cpu::Reschedule() {+void CoreManager::Reschedule() {// Lock the global kernel mutex when we manipulate the HLE statestd::lock_guard lock(HLE::g_hle_lock);diff --git a/src/core/core_cpu.h b/src/core/core_manager.hsimilarity index 91%rename from src/core/core_cpu.hrename to src/core/core_manager.hindex 6f7aec8f98..7bc9679c16 100644--- a/src/core/core_cpu.h+++ b/src/core/core_manager.h@@ -32,10 +32,10 @@ namespace Core {constexpr unsigned NUM_CPU_CORES{4};-class Cpu {+class CoreManager {public:- Cpu(System& system, std::size_t core_index);- ~Cpu();+ CoreManager(System& system, std::size_t core_index);+ ~CoreManager();void RunLoop(bool tight_loop = true);diff --git a/src/core/cpu_core_manager.h b/src/core/cpu_core_manager.hdeleted file mode 100644index 2a7f84d5cf..0000000000--- a/src/core/cpu_core_manager.h+++ /dev/null@@ -1,52 +0,0 @@-// Copyright 2018 yuzu emulator team-// Licensed under GPLv2 or any later version-// Refer to the license.txt file included.--#pragma once--#include <array>-#include <map>-#include <memory>-#include <thread>--namespace Core {--class Cpu;-class System;--class CpuCoreManager {-public:- explicit CpuCoreManager(System& system);- CpuCoreManager(const CpuCoreManager&) = delete;- CpuCoreManager(CpuCoreManager&&) = delete;-- ~CpuCoreManager();-- CpuCoreManager& operator=(const CpuCoreManager&) = delete;- CpuCoreManager& operator=(CpuCoreManager&&) = delete;-- void Initialize();- void Shutdown();-- Cpu& GetCore(std::size_t index);- const Cpu& GetCore(std::size_t index) const;-- Cpu& GetCurrentCore();- const Cpu& GetCurrentCore() const;-- std::size_t GetCurrentCoreIndex() const {- return active_core;- }-- void RunLoop(bool tight_loop);--private:- static constexpr std::size_t NUM_CPU_CORES = 4;-- std::array<std::unique_ptr<Cpu>, NUM_CPU_CORES> cores;- std::size_t active_core{}; ///< Active core, only used in single thread mode-- System& system;-};--} // namespace Corediff --git a/src/core/cpu_core_manager.cpp b/src/core/cpu_manager.cppsimilarity index 59%rename from src/core/cpu_core_manager.cpprename to src/core/cpu_manager.cppindex ab03e8fdf2..abc8aad9ef 100644--- a/src/core/cpu_core_manager.cpp+++ b/src/core/cpu_manager.cpp@@ -5,56 +5,49 @@#include "common/assert.h"#include "core/arm/exclusive_monitor.h"#include "core/core.h"-#include "core/core_cpu.h"+#include "core/core_manager.h"#include "core/core_timing.h"-#include "core/cpu_core_manager.h"+#include "core/cpu_manager.h"#include "core/gdbstub/gdbstub.h"#include "core/settings.h"namespace Core {-namespace {-void RunCpuCore(const System& system, Cpu& cpu_state) {- while (system.IsPoweredOn()) {- cpu_state.RunLoop(true);- }-}-} // Anonymous namespace-CpuCoreManager::CpuCoreManager(System& system) : system{system} {}-CpuCoreManager::~CpuCoreManager() = default;+CpuManager::CpuManager(System& system) : system{system} {}+CpuManager::~CpuManager() = default;-void CpuCoreManager::Initialize() {+void CpuManager::Initialize() {- for (std::size_t index = 0; index < cores.size(); ++index) {- cores[index] = std::make_unique<Cpu>(system, index);+ for (std::size_t index = 0; index < core_managers.size(); ++index) {+ core_managers[index] = std::make_unique<CoreManager>(system, index);}}-void CpuCoreManager::Shutdown() {- for (auto& cpu_core : cores) {+void CpuManager::Shutdown() {+ for (auto& cpu_core : core_managers) {cpu_core.reset();}}-Cpu& CpuCoreManager::GetCore(std::size_t index) {- return *cores.at(index);+CoreManager& CpuManager::GetCoreManager(std::size_t index) {+ return *core_managers.at(index);}-const Cpu& CpuCoreManager::GetCore(std::size_t index) const {- return *cores.at(index);+const CoreManager& CpuManager::GetCoreManager(std::size_t index) const {+ return *core_managers.at(index);}-Cpu& CpuCoreManager::GetCurrentCore() {+CoreManager& CpuManager::GetCurrentCoreManager() {// Otherwise, use single-threaded mode active_core variable- return *cores[active_core];+ return *core_managers[active_core];}-const Cpu& CpuCoreManager::GetCurrentCore() const {+const CoreManager& CpuManager::GetCurrentCoreManager() const {// Otherwise, use single-threaded mode active_core variable- return *cores[active_core];+ return *core_managers[active_core];}-void CpuCoreManager::RunLoop(bool tight_loop) {+void CpuManager::RunLoop(bool tight_loop) {if (GDBStub::IsServerEnabled()) {GDBStub::HandlePacket();@@ -77,7 +70,7 @@ void CpuCoreManager::RunLoop(bool tight_loop) {for (active_core = 0; active_core < NUM_CPU_CORES; ++active_core) {core_timing.SwitchContext(active_core);if (core_timing.CanCurrentContextRun()) {- cores[active_core]->RunLoop(tight_loop);+ core_managers[active_core]->RunLoop(tight_loop);}keep_running |= core_timing.CanCurrentContextRun();}diff --git a/src/core/cpu_manager.h b/src/core/cpu_manager.hnew file mode 100644index 0000000000..5371d448e1--- /dev/null+++ b/src/core/cpu_manager.h@@ -0,0 +1,52 @@+// Copyright 2018 yuzu emulator team+// Licensed under GPLv2 or any later version+// Refer to the license.txt file included.++#pragma once++#include <array>+#include <map>+#include <memory>+#include <thread>++namespace Core {++class CoreManager;+class System;++class CpuManager {+public:+ explicit CpuManager(System& system);+ CpuManager(const CpuManager&) = delete;+ CpuManager(CpuManager&&) = delete;++ ~CpuManager();++ CpuManager& operator=(const CpuManager&) = delete;+ CpuManager& operator=(CpuManager&&) = delete;++ void Initialize();+ void Shutdown();++ CoreManager& GetCoreManager(std::size_t index);+ const CoreManager& GetCoreManager(std::size_t index) const;++ CoreManager& GetCurrentCoreManager();+ const CoreManager& GetCurrentCoreManager() const;++ std::size_t GetActiveCoreIndex() const {+ return active_core;+ }++ void RunLoop(bool tight_loop);++private:+ static constexpr std::size_t NUM_CPU_CORES = 4;++ std::array<std::unique_ptr<CoreManager>, NUM_CPU_CORES> core_managers;+ std::size_t active_core{}; ///< Active core, only used in single thread mode++ System& system;+};++} // namespace Corediff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cppindex 37cb288483..67e95999d8 100644--- a/src/core/gdbstub/gdbstub.cpp+++ b/src/core/gdbstub/gdbstub.cpp@@ -35,7 +35,7 @@#include "common/swap.h"#include "core/arm/arm_interface.h"#include "core/core.h"-#include "core/core_cpu.h"+#include "core/core_manager.h"#include "core/gdbstub/gdbstub.h"#include "core/hle/kernel/process.h"#include "core/hle/kernel/scheduler.h"diff --git a/src/core/hle/kernel/address_arbiter.cpp b/src/core/hle/kernel/address_arbiter.cppindex db189c8e35..2ea3dcb61a 100644--- a/src/core/hle/kernel/address_arbiter.cpp+++ b/src/core/hle/kernel/address_arbiter.cpp@@ -8,7 +8,6 @@#include "common/assert.h"#include "common/common_types.h"#include "core/core.h"-#include "core/core_cpu.h"#include "core/hle/kernel/address_arbiter.h"#include "core/hle/kernel/errors.h"#include "core/hle/kernel/scheduler.h"diff --git a/src/core/hle/kernel/scheduler.cpp b/src/core/hle/kernel/scheduler.cppindex d36fcd7d99..eb196a6904 100644--- a/src/core/hle/kernel/scheduler.cpp+++ b/src/core/hle/kernel/scheduler.cpp@@ -14,7 +14,6 @@#include "common/logging/log.h"#include "core/arm/arm_interface.h"#include "core/core.h"-#include "core/core_cpu.h"#include "core/core_timing.h"#include "core/hle/kernel/kernel.h"#include "core/hle/kernel/process.h"diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cppindex dbcdb0b881..1d99bf7a25 100644--- a/src/core/hle/kernel/svc.cpp+++ b/src/core/hle/kernel/svc.cpp@@ -15,7 +15,7 @@#include "common/string_util.h"#include "core/arm/exclusive_monitor.h"#include "core/core.h"-#include "core/core_cpu.h"+#include "core/core_manager.h"#include "core/core_timing.h"#include "core/core_timing_util.h"#include "core/hle/kernel/address_arbiter.h"diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cppindex e84e5ce0d0..278e46bad4 100644--- a/src/core/hle/kernel/thread.cpp+++ b/src/core/hle/kernel/thread.cpp@@ -13,7 +13,6 @@#include "common/thread_queue_list.h"#include "core/arm/arm_interface.h"#include "core/core.h"-#include "core/core_cpu.h"#include "core/core_timing.h"#include "core/core_timing_util.h"#include "core/hle/kernel/errors.h"@@ -356,7 +355,7 @@ void Thread::SetActivity(ThreadActivity value) {// Set status if not waitingif (status == ThreadStatus::Ready || status == ThreadStatus::Running) {SetStatus(ThreadStatus::Paused);- Core::System::GetInstance().CpuCore(processor_id).PrepareReschedule();+ Core::System::GetInstance().PrepareReschedule(processor_id);}} else if (status == ThreadStatus::Paused) {// Ready to reschedulediff --git a/src/core/hle/kernel/wait_object.cpp b/src/core/hle/kernel/wait_object.cppindex 745f2c4e81..aa72889df5 100644--- a/src/core/hle/kernel/wait_object.cpp+++ b/src/core/hle/kernel/wait_object.cpp@@ -7,7 +7,6 @@#include "common/common_types.h"#include "common/logging/log.h"#include "core/core.h"-#include "core/core_cpu.h"#include "core/hle/kernel/kernel.h"#include "core/hle/kernel/object.h"#include "core/hle/kernel/process.h"