diff options
| author | 2020-01-26 14:07:22 -0400 | |
|---|---|---|
| committer | 2020-01-26 14:07:22 -0400 | |
| commit | e4a1ead897575ee9222b4fc1021aaa9cc58f12c8 (patch) | |
| tree | ef544a51ba2480400df62d40706f68fa3ae62693 | |
| parent | ArmInterface: Delegate Exclusive monitor factory to exclusive monitor interfa... (diff) | |
| download | yuzu-e4a1ead897575ee9222b4fc1021aaa9cc58f12c8.tar.gz yuzu-e4a1ead897575ee9222b4fc1021aaa9cc58f12c8.tar.xz yuzu-e4a1ead897575ee9222b4fc1021aaa9cc58f12c8.zip | |
Core: Refactor CpuCoreManager to CpuManager and Cpu to Core Manager.
This commit instends on better naming the new purpose of this classes.
| -rw-r--r-- | src/core/CMakeLists.txt | 8 | ||||
| -rw-r--r-- | src/core/arm/dynarmic/arm_dynarmic.cpp | 2 | ||||
| -rw-r--r-- | src/core/core.cpp | 44 | ||||
| -rw-r--r-- | src/core/core.h | 10 | ||||
| -rw-r--r-- | src/core/core_manager.cpp (renamed from src/core/core_cpu.cpp) | 14 | ||||
| -rw-r--r-- | src/core/core_manager.h (renamed from src/core/core_cpu.h) | 6 | ||||
| -rw-r--r-- | src/core/cpu_core_manager.h | 52 | ||||
| -rw-r--r-- | src/core/cpu_manager.cpp (renamed from src/core/cpu_core_manager.cpp) | 45 | ||||
| -rw-r--r-- | src/core/cpu_manager.h | 52 | ||||
| -rw-r--r-- | src/core/gdbstub/gdbstub.cpp | 2 | ||||
| -rw-r--r-- | src/core/hle/kernel/address_arbiter.cpp | 1 | ||||
| -rw-r--r-- | src/core/hle/kernel/scheduler.cpp | 1 | ||||
| -rw-r--r-- | src/core/hle/kernel/svc.cpp | 2 | ||||
| -rw-r--r-- | src/core/hle/kernel/thread.cpp | 3 | ||||
| -rw-r--r-- | src/core/hle/kernel/wait_object.cpp | 1 |
15 files changed, 115 insertions, 128 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index d5b8091ae..d342cafe0 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -15,14 +15,14 @@ add_library(core STATIC | |||
| 15 | constants.h | 15 | constants.h |
| 16 | core.cpp | 16 | core.cpp |
| 17 | core.h | 17 | core.h |
| 18 | core_cpu.cpp | 18 | core_manager.cpp |
| 19 | core_cpu.h | 19 | core_manager.h |
| 20 | core_timing.cpp | 20 | core_timing.cpp |
| 21 | core_timing.h | 21 | core_timing.h |
| 22 | core_timing_util.cpp | 22 | core_timing_util.cpp |
| 23 | core_timing_util.h | 23 | core_timing_util.h |
| 24 | cpu_core_manager.cpp | 24 | cpu_manager.cpp |
| 25 | cpu_core_manager.h | 25 | cpu_manager.h |
| 26 | crypto/aes_util.cpp | 26 | crypto/aes_util.cpp |
| 27 | crypto/aes_util.h | 27 | crypto/aes_util.h |
| 28 | crypto/encryption_layer.cpp | 28 | crypto/encryption_layer.cpp |
diff --git a/src/core/arm/dynarmic/arm_dynarmic.cpp b/src/core/arm/dynarmic/arm_dynarmic.cpp index e825c0526..f468e57e4 100644 --- a/src/core/arm/dynarmic/arm_dynarmic.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic.cpp | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | #include "common/microprofile.h" | 10 | #include "common/microprofile.h" |
| 11 | #include "core/arm/dynarmic/arm_dynarmic.h" | 11 | #include "core/arm/dynarmic/arm_dynarmic.h" |
| 12 | #include "core/core.h" | 12 | #include "core/core.h" |
| 13 | #include "core/core_cpu.h" | 13 | #include "core/core_manager.h" |
| 14 | #include "core/core_timing.h" | 14 | #include "core/core_timing.h" |
| 15 | #include "core/core_timing_util.h" | 15 | #include "core/core_timing_util.h" |
| 16 | #include "core/gdbstub/gdbstub.h" | 16 | #include "core/gdbstub/gdbstub.h" |
diff --git a/src/core/core.cpp b/src/core/core.cpp index 27b8d3408..bfe952515 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp | |||
| @@ -11,9 +11,9 @@ | |||
| 11 | #include "common/string_util.h" | 11 | #include "common/string_util.h" |
| 12 | #include "core/arm/exclusive_monitor.h" | 12 | #include "core/arm/exclusive_monitor.h" |
| 13 | #include "core/core.h" | 13 | #include "core/core.h" |
| 14 | #include "core/core_cpu.h" | 14 | #include "core/core_manager.h" |
| 15 | #include "core/core_timing.h" | 15 | #include "core/core_timing.h" |
| 16 | #include "core/cpu_core_manager.h" | 16 | #include "core/cpu_manager.h" |
| 17 | #include "core/file_sys/bis_factory.h" | 17 | #include "core/file_sys/bis_factory.h" |
| 18 | #include "core/file_sys/card_image.h" | 18 | #include "core/file_sys/card_image.h" |
| 19 | #include "core/file_sys/mode.h" | 19 | #include "core/file_sys/mode.h" |
| @@ -114,14 +114,14 @@ FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs, | |||
| 114 | struct System::Impl { | 114 | struct System::Impl { |
| 115 | explicit Impl(System& system) | 115 | explicit Impl(System& system) |
| 116 | : kernel{system}, fs_controller{system}, memory{system}, | 116 | : kernel{system}, fs_controller{system}, memory{system}, |
| 117 | cpu_core_manager{system}, reporter{system}, applet_manager{system} {} | 117 | cpu_manager{system}, reporter{system}, applet_manager{system} {} |
| 118 | 118 | ||
| 119 | Cpu& CurrentCpuCore() { | 119 | CoreManager& CurrentCoreManager() { |
| 120 | return cpu_core_manager.GetCurrentCore(); | 120 | return cpu_manager.GetCurrentCoreManager(); |
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | Kernel::PhysicalCore& CurrentPhysicalCore() { | 123 | Kernel::PhysicalCore& CurrentPhysicalCore() { |
| 124 | const auto i = cpu_core_manager.GetCurrentCoreIndex(); | 124 | const auto i = cpu_manager.GetActiveCoreIndex(); |
| 125 | return kernel.PhysicalCore(i); | 125 | return kernel.PhysicalCore(i); |
| 126 | } | 126 | } |
| 127 | 127 | ||
| @@ -132,7 +132,7 @@ struct System::Impl { | |||
| 132 | ResultStatus RunLoop(bool tight_loop) { | 132 | ResultStatus RunLoop(bool tight_loop) { |
| 133 | status = ResultStatus::Success; | 133 | status = ResultStatus::Success; |
| 134 | 134 | ||
| 135 | cpu_core_manager.RunLoop(tight_loop); | 135 | cpu_manager.RunLoop(tight_loop); |
| 136 | 136 | ||
| 137 | return status; | 137 | return status; |
| 138 | } | 138 | } |
| @@ -142,7 +142,7 @@ struct System::Impl { | |||
| 142 | 142 | ||
| 143 | core_timing.Initialize(); | 143 | core_timing.Initialize(); |
| 144 | kernel.Initialize(); | 144 | kernel.Initialize(); |
| 145 | cpu_core_manager.Initialize(); | 145 | cpu_manager.Initialize(); |
| 146 | 146 | ||
| 147 | const auto current_time = std::chrono::duration_cast<std::chrono::seconds>( | 147 | const auto current_time = std::chrono::duration_cast<std::chrono::seconds>( |
| 148 | std::chrono::system_clock::now().time_since_epoch()); | 148 | std::chrono::system_clock::now().time_since_epoch()); |
| @@ -281,7 +281,7 @@ struct System::Impl { | |||
| 281 | gpu_core.reset(); | 281 | gpu_core.reset(); |
| 282 | 282 | ||
| 283 | // Close all CPU/threading state | 283 | // Close all CPU/threading state |
| 284 | cpu_core_manager.Shutdown(); | 284 | cpu_manager.Shutdown(); |
| 285 | 285 | ||
| 286 | // Shutdown kernel and core timing | 286 | // Shutdown kernel and core timing |
| 287 | kernel.Shutdown(); | 287 | kernel.Shutdown(); |
| @@ -351,7 +351,7 @@ struct System::Impl { | |||
| 351 | std::unique_ptr<Tegra::GPU> gpu_core; | 351 | std::unique_ptr<Tegra::GPU> gpu_core; |
| 352 | std::unique_ptr<Hardware::InterruptManager> interrupt_manager; | 352 | std::unique_ptr<Hardware::InterruptManager> interrupt_manager; |
| 353 | Memory::Memory memory; | 353 | Memory::Memory memory; |
| 354 | CpuCoreManager cpu_core_manager; | 354 | CpuManager cpu_manager; |
| 355 | bool is_powered_on = false; | 355 | bool is_powered_on = false; |
| 356 | bool exit_lock = false; | 356 | bool exit_lock = false; |
| 357 | 357 | ||
| @@ -386,12 +386,12 @@ struct System::Impl { | |||
| 386 | System::System() : impl{std::make_unique<Impl>(*this)} {} | 386 | System::System() : impl{std::make_unique<Impl>(*this)} {} |
| 387 | System::~System() = default; | 387 | System::~System() = default; |
| 388 | 388 | ||
| 389 | Cpu& System::CurrentCpuCore() { | 389 | CoreManager& System::CurrentCoreManager() { |
| 390 | return impl->CurrentCpuCore(); | 390 | return impl->CurrentCoreManager(); |
| 391 | } | 391 | } |
| 392 | 392 | ||
| 393 | const Cpu& System::CurrentCpuCore() const { | 393 | const CoreManager& System::CurrentCoreManager() const { |
| 394 | return impl->CurrentCpuCore(); | 394 | return impl->CurrentCoreManager(); |
| 395 | } | 395 | } |
| 396 | 396 | ||
| 397 | System::ResultStatus System::RunLoop(bool tight_loop) { | 397 | System::ResultStatus System::RunLoop(bool tight_loop) { |
| @@ -415,13 +415,11 @@ bool System::IsPoweredOn() const { | |||
| 415 | } | 415 | } |
| 416 | 416 | ||
| 417 | void System::PrepareReschedule() { | 417 | void System::PrepareReschedule() { |
| 418 | CurrentCpuCore().PrepareReschedule(); | 418 | CurrentCoreManager().PrepareReschedule(); |
| 419 | } | 419 | } |
| 420 | 420 | ||
| 421 | void System::PrepareReschedule(const u32 core_index) { | 421 | void System::PrepareReschedule(const u32 core_index) { |
| 422 | if (core_index < GlobalScheduler().CpuCoresCount()) { | 422 | impl->kernel.PrepareReschedule(core_index); |
| 423 | CpuCore(core_index).PrepareReschedule(); | ||
| 424 | } | ||
| 425 | } | 423 | } |
| 426 | 424 | ||
| 427 | PerfStatsResults System::GetAndResetPerfStats() { | 425 | PerfStatsResults System::GetAndResetPerfStats() { |
| @@ -445,7 +443,7 @@ const ARM_Interface& System::CurrentArmInterface() const { | |||
| 445 | } | 443 | } |
| 446 | 444 | ||
| 447 | std::size_t System::CurrentCoreIndex() const { | 445 | std::size_t System::CurrentCoreIndex() const { |
| 448 | return CurrentCpuCore().CoreIndex(); | 446 | return impl->cpu_manager.GetActiveCoreIndex(); |
| 449 | } | 447 | } |
| 450 | 448 | ||
| 451 | Kernel::Scheduler& System::CurrentScheduler() { | 449 | Kernel::Scheduler& System::CurrentScheduler() { |
| @@ -490,13 +488,13 @@ const ARM_Interface& System::ArmInterface(std::size_t core_index) const { | |||
| 490 | return impl->GetPhysicalCore(core_index).ArmInterface(); | 488 | return impl->GetPhysicalCore(core_index).ArmInterface(); |
| 491 | } | 489 | } |
| 492 | 490 | ||
| 493 | Cpu& System::CpuCore(std::size_t core_index) { | 491 | CoreManager& System::GetCoreManager(std::size_t core_index) { |
| 494 | return impl->cpu_core_manager.GetCore(core_index); | 492 | return impl->cpu_manager.GetCoreManager(core_index); |
| 495 | } | 493 | } |
| 496 | 494 | ||
| 497 | const Cpu& System::CpuCore(std::size_t core_index) const { | 495 | const CoreManager& System::GetCoreManager(std::size_t core_index) const { |
| 498 | ASSERT(core_index < NUM_CPU_CORES); | 496 | ASSERT(core_index < NUM_CPU_CORES); |
| 499 | return impl->cpu_core_manager.GetCore(core_index); | 497 | return impl->cpu_manager.GetCoreManager(core_index); |
| 500 | } | 498 | } |
| 501 | 499 | ||
| 502 | ExclusiveMonitor& System::Monitor() { | 500 | ExclusiveMonitor& System::Monitor() { |
diff --git a/src/core/core.h b/src/core/core.h index e240c5c58..e69d68fcf 100644 --- a/src/core/core.h +++ b/src/core/core.h | |||
| @@ -93,7 +93,7 @@ class Memory; | |||
| 93 | namespace Core { | 93 | namespace Core { |
| 94 | 94 | ||
| 95 | class ARM_Interface; | 95 | class ARM_Interface; |
| 96 | class Cpu; | 96 | class CoreManager; |
| 97 | class ExclusiveMonitor; | 97 | class ExclusiveMonitor; |
| 98 | class FrameLimiter; | 98 | class FrameLimiter; |
| 99 | class PerfStats; | 99 | class PerfStats; |
| @@ -218,10 +218,10 @@ public: | |||
| 218 | const ARM_Interface& ArmInterface(std::size_t core_index) const; | 218 | const ARM_Interface& ArmInterface(std::size_t core_index) const; |
| 219 | 219 | ||
| 220 | /// Gets a CPU interface to the CPU core with the specified index | 220 | /// Gets a CPU interface to the CPU core with the specified index |
| 221 | Cpu& CpuCore(std::size_t core_index); | 221 | CoreManager& GetCoreManager(std::size_t core_index); |
| 222 | 222 | ||
| 223 | /// Gets a CPU interface to the CPU core with the specified index | 223 | /// Gets a CPU interface to the CPU core with the specified index |
| 224 | const Cpu& CpuCore(std::size_t core_index) const; | 224 | const CoreManager& GetCoreManager(std::size_t core_index) const; |
| 225 | 225 | ||
| 226 | /// Gets a reference to the exclusive monitor | 226 | /// Gets a reference to the exclusive monitor |
| 227 | ExclusiveMonitor& Monitor(); | 227 | ExclusiveMonitor& Monitor(); |
| @@ -364,10 +364,10 @@ private: | |||
| 364 | System(); | 364 | System(); |
| 365 | 365 | ||
| 366 | /// Returns the currently running CPU core | 366 | /// Returns the currently running CPU core |
| 367 | Cpu& CurrentCpuCore(); | 367 | CoreManager& CurrentCoreManager(); |
| 368 | 368 | ||
| 369 | /// Returns the currently running CPU core | 369 | /// Returns the currently running CPU core |
| 370 | const Cpu& CurrentCpuCore() const; | 370 | const CoreManager& CurrentCoreManager() const; |
| 371 | 371 | ||
| 372 | /** | 372 | /** |
| 373 | * Initialize the emulated system. | 373 | * Initialize the emulated system. |
diff --git a/src/core/core_cpu.cpp b/src/core/core_manager.cpp index bcfdf0198..bb03857d5 100644 --- a/src/core/core_cpu.cpp +++ b/src/core/core_manager.cpp | |||
| @@ -12,7 +12,7 @@ | |||
| 12 | #include "core/arm/exclusive_monitor.h" | 12 | #include "core/arm/exclusive_monitor.h" |
| 13 | #include "core/arm/unicorn/arm_unicorn.h" | 13 | #include "core/arm/unicorn/arm_unicorn.h" |
| 14 | #include "core/core.h" | 14 | #include "core/core.h" |
| 15 | #include "core/core_cpu.h" | 15 | #include "core/core_manager.h" |
| 16 | #include "core/core_timing.h" | 16 | #include "core/core_timing.h" |
| 17 | #include "core/hle/kernel/kernel.h" | 17 | #include "core/hle/kernel/kernel.h" |
| 18 | #include "core/hle/kernel/physical_core.h" | 18 | #include "core/hle/kernel/physical_core.h" |
| @@ -23,15 +23,15 @@ | |||
| 23 | 23 | ||
| 24 | namespace Core { | 24 | namespace Core { |
| 25 | 25 | ||
| 26 | Cpu::Cpu(System& system, std::size_t core_index) | 26 | CoreManager::CoreManager(System& system, std::size_t core_index) |
| 27 | : global_scheduler{system.GlobalScheduler()}, | 27 | : global_scheduler{system.GlobalScheduler()}, |
| 28 | physical_core{system.Kernel().PhysicalCore(core_index)}, core_timing{system.CoreTiming()}, | 28 | physical_core{system.Kernel().PhysicalCore(core_index)}, core_timing{system.CoreTiming()}, |
| 29 | core_index{core_index} { | 29 | core_index{core_index} { |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | Cpu::~Cpu() = default; | 32 | CoreManager::~CoreManager() = default; |
| 33 | 33 | ||
| 34 | void Cpu::RunLoop(bool tight_loop) { | 34 | void CoreManager::RunLoop(bool tight_loop) { |
| 35 | Reschedule(); | 35 | Reschedule(); |
| 36 | 36 | ||
| 37 | // If we don't have a currently active thread then don't execute instructions, | 37 | // If we don't have a currently active thread then don't execute instructions, |
| @@ -51,15 +51,15 @@ void Cpu::RunLoop(bool tight_loop) { | |||
| 51 | Reschedule(); | 51 | Reschedule(); |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | void Cpu::SingleStep() { | 54 | void CoreManager::SingleStep() { |
| 55 | return RunLoop(false); | 55 | return RunLoop(false); |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | void Cpu::PrepareReschedule() { | 58 | void CoreManager::PrepareReschedule() { |
| 59 | physical_core.Stop(); | 59 | physical_core.Stop(); |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | void Cpu::Reschedule() { | 62 | void CoreManager::Reschedule() { |
| 63 | // Lock the global kernel mutex when we manipulate the HLE state | 63 | // Lock the global kernel mutex when we manipulate the HLE state |
| 64 | std::lock_guard lock(HLE::g_hle_lock); | 64 | std::lock_guard lock(HLE::g_hle_lock); |
| 65 | 65 | ||
diff --git a/src/core/core_cpu.h b/src/core/core_manager.h index 6f7aec8f9..7bc9679c1 100644 --- a/src/core/core_cpu.h +++ b/src/core/core_manager.h | |||
| @@ -32,10 +32,10 @@ namespace Core { | |||
| 32 | 32 | ||
| 33 | constexpr unsigned NUM_CPU_CORES{4}; | 33 | constexpr unsigned NUM_CPU_CORES{4}; |
| 34 | 34 | ||
| 35 | class Cpu { | 35 | class CoreManager { |
| 36 | public: | 36 | public: |
| 37 | Cpu(System& system, std::size_t core_index); | 37 | CoreManager(System& system, std::size_t core_index); |
| 38 | ~Cpu(); | 38 | ~CoreManager(); |
| 39 | 39 | ||
| 40 | void RunLoop(bool tight_loop = true); | 40 | void RunLoop(bool tight_loop = true); |
| 41 | 41 | ||
diff --git a/src/core/cpu_core_manager.h b/src/core/cpu_core_manager.h deleted file mode 100644 index 2a7f84d5c..000000000 --- a/src/core/cpu_core_manager.h +++ /dev/null | |||
| @@ -1,52 +0,0 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <array> | ||
| 8 | #include <map> | ||
| 9 | #include <memory> | ||
| 10 | #include <thread> | ||
| 11 | |||
| 12 | namespace Core { | ||
| 13 | |||
| 14 | class Cpu; | ||
| 15 | class System; | ||
| 16 | |||
| 17 | class CpuCoreManager { | ||
| 18 | public: | ||
| 19 | explicit CpuCoreManager(System& system); | ||
| 20 | CpuCoreManager(const CpuCoreManager&) = delete; | ||
| 21 | CpuCoreManager(CpuCoreManager&&) = delete; | ||
| 22 | |||
| 23 | ~CpuCoreManager(); | ||
| 24 | |||
| 25 | CpuCoreManager& operator=(const CpuCoreManager&) = delete; | ||
| 26 | CpuCoreManager& operator=(CpuCoreManager&&) = delete; | ||
| 27 | |||
| 28 | void Initialize(); | ||
| 29 | void Shutdown(); | ||
| 30 | |||
| 31 | Cpu& GetCore(std::size_t index); | ||
| 32 | const Cpu& GetCore(std::size_t index) const; | ||
| 33 | |||
| 34 | Cpu& GetCurrentCore(); | ||
| 35 | const Cpu& GetCurrentCore() const; | ||
| 36 | |||
| 37 | std::size_t GetCurrentCoreIndex() const { | ||
| 38 | return active_core; | ||
| 39 | } | ||
| 40 | |||
| 41 | void RunLoop(bool tight_loop); | ||
| 42 | |||
| 43 | private: | ||
| 44 | static constexpr std::size_t NUM_CPU_CORES = 4; | ||
| 45 | |||
| 46 | std::array<std::unique_ptr<Cpu>, NUM_CPU_CORES> cores; | ||
| 47 | std::size_t active_core{}; ///< Active core, only used in single thread mode | ||
| 48 | |||
| 49 | System& system; | ||
| 50 | }; | ||
| 51 | |||
| 52 | } // namespace Core | ||
diff --git a/src/core/cpu_core_manager.cpp b/src/core/cpu_manager.cpp index ab03e8fdf..abc8aad9e 100644 --- a/src/core/cpu_core_manager.cpp +++ b/src/core/cpu_manager.cpp | |||
| @@ -5,56 +5,49 @@ | |||
| 5 | #include "common/assert.h" | 5 | #include "common/assert.h" |
| 6 | #include "core/arm/exclusive_monitor.h" | 6 | #include "core/arm/exclusive_monitor.h" |
| 7 | #include "core/core.h" | 7 | #include "core/core.h" |
| 8 | #include "core/core_cpu.h" | 8 | #include "core/core_manager.h" |
| 9 | #include "core/core_timing.h" | 9 | #include "core/core_timing.h" |
| 10 | #include "core/cpu_core_manager.h" | 10 | #include "core/cpu_manager.h" |
| 11 | #include "core/gdbstub/gdbstub.h" | 11 | #include "core/gdbstub/gdbstub.h" |
| 12 | #include "core/settings.h" | 12 | #include "core/settings.h" |
| 13 | 13 | ||
| 14 | namespace Core { | 14 | namespace Core { |
| 15 | namespace { | ||
| 16 | void RunCpuCore(const System& system, Cpu& cpu_state) { | ||
| 17 | while (system.IsPoweredOn()) { | ||
| 18 | cpu_state.RunLoop(true); | ||
| 19 | } | ||
| 20 | } | ||
| 21 | } // Anonymous namespace | ||
| 22 | 15 | ||
| 23 | CpuCoreManager::CpuCoreManager(System& system) : system{system} {} | 16 | CpuManager::CpuManager(System& system) : system{system} {} |
| 24 | CpuCoreManager::~CpuCoreManager() = default; | 17 | CpuManager::~CpuManager() = default; |
| 25 | 18 | ||
| 26 | void CpuCoreManager::Initialize() { | 19 | void CpuManager::Initialize() { |
| 27 | 20 | ||
| 28 | for (std::size_t index = 0; index < cores.size(); ++index) { | 21 | for (std::size_t index = 0; index < core_managers.size(); ++index) { |
| 29 | cores[index] = std::make_unique<Cpu>(system, index); | 22 | core_managers[index] = std::make_unique<CoreManager>(system, index); |
| 30 | } | 23 | } |
| 31 | } | 24 | } |
| 32 | 25 | ||
| 33 | void CpuCoreManager::Shutdown() { | 26 | void CpuManager::Shutdown() { |
| 34 | for (auto& cpu_core : cores) { | 27 | for (auto& cpu_core : core_managers) { |
| 35 | cpu_core.reset(); | 28 | cpu_core.reset(); |
| 36 | } | 29 | } |
| 37 | } | 30 | } |
| 38 | 31 | ||
| 39 | Cpu& CpuCoreManager::GetCore(std::size_t index) { | 32 | CoreManager& CpuManager::GetCoreManager(std::size_t index) { |
| 40 | return *cores.at(index); | 33 | return *core_managers.at(index); |
| 41 | } | 34 | } |
| 42 | 35 | ||
| 43 | const Cpu& CpuCoreManager::GetCore(std::size_t index) const { | 36 | const CoreManager& CpuManager::GetCoreManager(std::size_t index) const { |
| 44 | return *cores.at(index); | 37 | return *core_managers.at(index); |
| 45 | } | 38 | } |
| 46 | 39 | ||
| 47 | Cpu& CpuCoreManager::GetCurrentCore() { | 40 | CoreManager& CpuManager::GetCurrentCoreManager() { |
| 48 | // Otherwise, use single-threaded mode active_core variable | 41 | // Otherwise, use single-threaded mode active_core variable |
| 49 | return *cores[active_core]; | 42 | return *core_managers[active_core]; |
| 50 | } | 43 | } |
| 51 | 44 | ||
| 52 | const Cpu& CpuCoreManager::GetCurrentCore() const { | 45 | const CoreManager& CpuManager::GetCurrentCoreManager() const { |
| 53 | // Otherwise, use single-threaded mode active_core variable | 46 | // Otherwise, use single-threaded mode active_core variable |
| 54 | return *cores[active_core]; | 47 | return *core_managers[active_core]; |
| 55 | } | 48 | } |
| 56 | 49 | ||
| 57 | void CpuCoreManager::RunLoop(bool tight_loop) { | 50 | void CpuManager::RunLoop(bool tight_loop) { |
| 58 | if (GDBStub::IsServerEnabled()) { | 51 | if (GDBStub::IsServerEnabled()) { |
| 59 | GDBStub::HandlePacket(); | 52 | GDBStub::HandlePacket(); |
| 60 | 53 | ||
| @@ -77,7 +70,7 @@ void CpuCoreManager::RunLoop(bool tight_loop) { | |||
| 77 | for (active_core = 0; active_core < NUM_CPU_CORES; ++active_core) { | 70 | for (active_core = 0; active_core < NUM_CPU_CORES; ++active_core) { |
| 78 | core_timing.SwitchContext(active_core); | 71 | core_timing.SwitchContext(active_core); |
| 79 | if (core_timing.CanCurrentContextRun()) { | 72 | if (core_timing.CanCurrentContextRun()) { |
| 80 | cores[active_core]->RunLoop(tight_loop); | 73 | core_managers[active_core]->RunLoop(tight_loop); |
| 81 | } | 74 | } |
| 82 | keep_running |= core_timing.CanCurrentContextRun(); | 75 | keep_running |= core_timing.CanCurrentContextRun(); |
| 83 | } | 76 | } |
diff --git a/src/core/cpu_manager.h b/src/core/cpu_manager.h new file mode 100644 index 000000000..5371d448e --- /dev/null +++ b/src/core/cpu_manager.h | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <array> | ||
| 8 | #include <map> | ||
| 9 | #include <memory> | ||
| 10 | #include <thread> | ||
| 11 | |||
| 12 | namespace Core { | ||
| 13 | |||
| 14 | class CoreManager; | ||
| 15 | class System; | ||
| 16 | |||
| 17 | class CpuManager { | ||
| 18 | public: | ||
| 19 | explicit CpuManager(System& system); | ||
| 20 | CpuManager(const CpuManager&) = delete; | ||
| 21 | CpuManager(CpuManager&&) = delete; | ||
| 22 | |||
| 23 | ~CpuManager(); | ||
| 24 | |||
| 25 | CpuManager& operator=(const CpuManager&) = delete; | ||
| 26 | CpuManager& operator=(CpuManager&&) = delete; | ||
| 27 | |||
| 28 | void Initialize(); | ||
| 29 | void Shutdown(); | ||
| 30 | |||
| 31 | CoreManager& GetCoreManager(std::size_t index); | ||
| 32 | const CoreManager& GetCoreManager(std::size_t index) const; | ||
| 33 | |||
| 34 | CoreManager& GetCurrentCoreManager(); | ||
| 35 | const CoreManager& GetCurrentCoreManager() const; | ||
| 36 | |||
| 37 | std::size_t GetActiveCoreIndex() const { | ||
| 38 | return active_core; | ||
| 39 | } | ||
| 40 | |||
| 41 | void RunLoop(bool tight_loop); | ||
| 42 | |||
| 43 | private: | ||
| 44 | static constexpr std::size_t NUM_CPU_CORES = 4; | ||
| 45 | |||
| 46 | std::array<std::unique_ptr<CoreManager>, NUM_CPU_CORES> core_managers; | ||
| 47 | std::size_t active_core{}; ///< Active core, only used in single thread mode | ||
| 48 | |||
| 49 | System& system; | ||
| 50 | }; | ||
| 51 | |||
| 52 | } // namespace Core | ||
diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp index 37cb28848..67e95999d 100644 --- a/src/core/gdbstub/gdbstub.cpp +++ b/src/core/gdbstub/gdbstub.cpp | |||
| @@ -35,7 +35,7 @@ | |||
| 35 | #include "common/swap.h" | 35 | #include "common/swap.h" |
| 36 | #include "core/arm/arm_interface.h" | 36 | #include "core/arm/arm_interface.h" |
| 37 | #include "core/core.h" | 37 | #include "core/core.h" |
| 38 | #include "core/core_cpu.h" | 38 | #include "core/core_manager.h" |
| 39 | #include "core/gdbstub/gdbstub.h" | 39 | #include "core/gdbstub/gdbstub.h" |
| 40 | #include "core/hle/kernel/process.h" | 40 | #include "core/hle/kernel/process.h" |
| 41 | #include "core/hle/kernel/scheduler.h" | 41 | #include "core/hle/kernel/scheduler.h" |
diff --git a/src/core/hle/kernel/address_arbiter.cpp b/src/core/hle/kernel/address_arbiter.cpp index db189c8e3..2ea3dcb61 100644 --- a/src/core/hle/kernel/address_arbiter.cpp +++ b/src/core/hle/kernel/address_arbiter.cpp | |||
| @@ -8,7 +8,6 @@ | |||
| 8 | #include "common/assert.h" | 8 | #include "common/assert.h" |
| 9 | #include "common/common_types.h" | 9 | #include "common/common_types.h" |
| 10 | #include "core/core.h" | 10 | #include "core/core.h" |
| 11 | #include "core/core_cpu.h" | ||
| 12 | #include "core/hle/kernel/address_arbiter.h" | 11 | #include "core/hle/kernel/address_arbiter.h" |
| 13 | #include "core/hle/kernel/errors.h" | 12 | #include "core/hle/kernel/errors.h" |
| 14 | #include "core/hle/kernel/scheduler.h" | 13 | #include "core/hle/kernel/scheduler.h" |
diff --git a/src/core/hle/kernel/scheduler.cpp b/src/core/hle/kernel/scheduler.cpp index d36fcd7d9..eb196a690 100644 --- a/src/core/hle/kernel/scheduler.cpp +++ b/src/core/hle/kernel/scheduler.cpp | |||
| @@ -14,7 +14,6 @@ | |||
| 14 | #include "common/logging/log.h" | 14 | #include "common/logging/log.h" |
| 15 | #include "core/arm/arm_interface.h" | 15 | #include "core/arm/arm_interface.h" |
| 16 | #include "core/core.h" | 16 | #include "core/core.h" |
| 17 | #include "core/core_cpu.h" | ||
| 18 | #include "core/core_timing.h" | 17 | #include "core/core_timing.h" |
| 19 | #include "core/hle/kernel/kernel.h" | 18 | #include "core/hle/kernel/kernel.h" |
| 20 | #include "core/hle/kernel/process.h" | 19 | #include "core/hle/kernel/process.h" |
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index dbcdb0b88..1d99bf7a2 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp | |||
| @@ -15,7 +15,7 @@ | |||
| 15 | #include "common/string_util.h" | 15 | #include "common/string_util.h" |
| 16 | #include "core/arm/exclusive_monitor.h" | 16 | #include "core/arm/exclusive_monitor.h" |
| 17 | #include "core/core.h" | 17 | #include "core/core.h" |
| 18 | #include "core/core_cpu.h" | 18 | #include "core/core_manager.h" |
| 19 | #include "core/core_timing.h" | 19 | #include "core/core_timing.h" |
| 20 | #include "core/core_timing_util.h" | 20 | #include "core/core_timing_util.h" |
| 21 | #include "core/hle/kernel/address_arbiter.h" | 21 | #include "core/hle/kernel/address_arbiter.h" |
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index e84e5ce0d..278e46bad 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp | |||
| @@ -13,7 +13,6 @@ | |||
| 13 | #include "common/thread_queue_list.h" | 13 | #include "common/thread_queue_list.h" |
| 14 | #include "core/arm/arm_interface.h" | 14 | #include "core/arm/arm_interface.h" |
| 15 | #include "core/core.h" | 15 | #include "core/core.h" |
| 16 | #include "core/core_cpu.h" | ||
| 17 | #include "core/core_timing.h" | 16 | #include "core/core_timing.h" |
| 18 | #include "core/core_timing_util.h" | 17 | #include "core/core_timing_util.h" |
| 19 | #include "core/hle/kernel/errors.h" | 18 | #include "core/hle/kernel/errors.h" |
| @@ -356,7 +355,7 @@ void Thread::SetActivity(ThreadActivity value) { | |||
| 356 | // Set status if not waiting | 355 | // Set status if not waiting |
| 357 | if (status == ThreadStatus::Ready || status == ThreadStatus::Running) { | 356 | if (status == ThreadStatus::Ready || status == ThreadStatus::Running) { |
| 358 | SetStatus(ThreadStatus::Paused); | 357 | SetStatus(ThreadStatus::Paused); |
| 359 | Core::System::GetInstance().CpuCore(processor_id).PrepareReschedule(); | 358 | Core::System::GetInstance().PrepareReschedule(processor_id); |
| 360 | } | 359 | } |
| 361 | } else if (status == ThreadStatus::Paused) { | 360 | } else if (status == ThreadStatus::Paused) { |
| 362 | // Ready to reschedule | 361 | // Ready to reschedule |
diff --git a/src/core/hle/kernel/wait_object.cpp b/src/core/hle/kernel/wait_object.cpp index 745f2c4e8..aa72889df 100644 --- a/src/core/hle/kernel/wait_object.cpp +++ b/src/core/hle/kernel/wait_object.cpp | |||
| @@ -7,7 +7,6 @@ | |||
| 7 | #include "common/common_types.h" | 7 | #include "common/common_types.h" |
| 8 | #include "common/logging/log.h" | 8 | #include "common/logging/log.h" |
| 9 | #include "core/core.h" | 9 | #include "core/core.h" |
| 10 | #include "core/core_cpu.h" | ||
| 11 | #include "core/hle/kernel/kernel.h" | 10 | #include "core/hle/kernel/kernel.h" |
| 12 | #include "core/hle/kernel/object.h" | 11 | #include "core/hle/kernel/object.h" |
| 13 | #include "core/hle/kernel/process.h" | 12 | #include "core/hle/kernel/process.h" |