Core: Refactor CpuCoreManager to CpuManager and Cpu to Core Manager.

This commit instends on better naming the new purpose of this classes.
This commit is contained in:
Fernando Sahmkow 2020-01-26 14:07:22 -04:00
parent 450341b397
commit e4a1ead897
15 changed files with 115 additions and 128 deletions

View file

@ -15,14 +15,14 @@ add_library(core STATIC
constants.h constants.h
core.cpp core.cpp
core.h core.h
core_cpu.cpp core_manager.cpp
core_cpu.h core_manager.h
core_timing.cpp core_timing.cpp
core_timing.h core_timing.h
core_timing_util.cpp core_timing_util.cpp
core_timing_util.h core_timing_util.h
cpu_core_manager.cpp cpu_manager.cpp
cpu_core_manager.h cpu_manager.h
crypto/aes_util.cpp crypto/aes_util.cpp
crypto/aes_util.h crypto/aes_util.h
crypto/encryption_layer.cpp crypto/encryption_layer.cpp

View file

@ -10,7 +10,7 @@
#include "common/microprofile.h" #include "common/microprofile.h"
#include "core/arm/dynarmic/arm_dynarmic.h" #include "core/arm/dynarmic/arm_dynarmic.h"
#include "core/core.h" #include "core/core.h"
#include "core/core_cpu.h" #include "core/core_manager.h"
#include "core/core_timing.h" #include "core/core_timing.h"
#include "core/core_timing_util.h" #include "core/core_timing_util.h"
#include "core/gdbstub/gdbstub.h" #include "core/gdbstub/gdbstub.h"

View file

@ -11,9 +11,9 @@
#include "common/string_util.h" #include "common/string_util.h"
#include "core/arm/exclusive_monitor.h" #include "core/arm/exclusive_monitor.h"
#include "core/core.h" #include "core/core.h"
#include "core/core_cpu.h" #include "core/core_manager.h"
#include "core/core_timing.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/bis_factory.h"
#include "core/file_sys/card_image.h" #include "core/file_sys/card_image.h"
#include "core/file_sys/mode.h" #include "core/file_sys/mode.h"
@ -114,14 +114,14 @@ FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs,
struct System::Impl { struct System::Impl {
explicit Impl(System& system) explicit Impl(System& system)
: kernel{system}, fs_controller{system}, memory{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() { CoreManager& CurrentCoreManager() {
return cpu_core_manager.GetCurrentCore(); return cpu_manager.GetCurrentCoreManager();
} }
Kernel::PhysicalCore& CurrentPhysicalCore() { Kernel::PhysicalCore& CurrentPhysicalCore() {
const auto i = cpu_core_manager.GetCurrentCoreIndex(); const auto i = cpu_manager.GetActiveCoreIndex();
return kernel.PhysicalCore(i); return kernel.PhysicalCore(i);
} }
@ -132,7 +132,7 @@ struct System::Impl {
ResultStatus RunLoop(bool tight_loop) { ResultStatus RunLoop(bool tight_loop) {
status = ResultStatus::Success; status = ResultStatus::Success;
cpu_core_manager.RunLoop(tight_loop); cpu_manager.RunLoop(tight_loop);
return status; return status;
} }
@ -142,7 +142,7 @@ struct System::Impl {
core_timing.Initialize(); core_timing.Initialize();
kernel.Initialize(); kernel.Initialize();
cpu_core_manager.Initialize(); cpu_manager.Initialize();
const auto current_time = std::chrono::duration_cast<std::chrono::seconds>( const auto current_time = std::chrono::duration_cast<std::chrono::seconds>(
std::chrono::system_clock::now().time_since_epoch()); std::chrono::system_clock::now().time_since_epoch());
@ -281,7 +281,7 @@ struct System::Impl {
gpu_core.reset(); gpu_core.reset();
// Close all CPU/threading state // Close all CPU/threading state
cpu_core_manager.Shutdown(); cpu_manager.Shutdown();
// Shutdown kernel and core timing // Shutdown kernel and core timing
kernel.Shutdown(); kernel.Shutdown();
@ -351,7 +351,7 @@ struct System::Impl {
std::unique_ptr<Tegra::GPU> gpu_core; std::unique_ptr<Tegra::GPU> gpu_core;
std::unique_ptr<Hardware::InterruptManager> interrupt_manager; std::unique_ptr<Hardware::InterruptManager> interrupt_manager;
Memory::Memory memory; Memory::Memory memory;
CpuCoreManager cpu_core_manager; CpuManager cpu_manager;
bool is_powered_on = false; bool is_powered_on = false;
bool exit_lock = false; bool exit_lock = false;
@ -386,12 +386,12 @@ struct System::Impl {
System::System() : impl{std::make_unique<Impl>(*this)} {} System::System() : impl{std::make_unique<Impl>(*this)} {}
System::~System() = default; System::~System() = default;
Cpu& System::CurrentCpuCore() { CoreManager& System::CurrentCoreManager() {
return impl->CurrentCpuCore(); return impl->CurrentCoreManager();
} }
const Cpu& System::CurrentCpuCore() const { const CoreManager& System::CurrentCoreManager() const {
return impl->CurrentCpuCore(); return impl->CurrentCoreManager();
} }
System::ResultStatus System::RunLoop(bool tight_loop) { System::ResultStatus System::RunLoop(bool tight_loop) {
@ -415,13 +415,11 @@ bool System::IsPoweredOn() const {
} }
void System::PrepareReschedule() { void System::PrepareReschedule() {
CurrentCpuCore().PrepareReschedule(); CurrentCoreManager().PrepareReschedule();
} }
void System::PrepareReschedule(const u32 core_index) { void System::PrepareReschedule(const u32 core_index) {
if (core_index < GlobalScheduler().CpuCoresCount()) { impl->kernel.PrepareReschedule(core_index);
CpuCore(core_index).PrepareReschedule();
}
} }
PerfStatsResults System::GetAndResetPerfStats() { PerfStatsResults System::GetAndResetPerfStats() {
@ -445,7 +443,7 @@ const ARM_Interface& System::CurrentArmInterface() const {
} }
std::size_t System::CurrentCoreIndex() const { std::size_t System::CurrentCoreIndex() const {
return CurrentCpuCore().CoreIndex(); return impl->cpu_manager.GetActiveCoreIndex();
} }
Kernel::Scheduler& System::CurrentScheduler() { 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(); return impl->GetPhysicalCore(core_index).ArmInterface();
} }
Cpu& System::CpuCore(std::size_t core_index) { CoreManager& System::GetCoreManager(std::size_t core_index) {
return impl->cpu_core_manager.GetCore(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); ASSERT(core_index < NUM_CPU_CORES);
return impl->cpu_core_manager.GetCore(core_index); return impl->cpu_manager.GetCoreManager(core_index);
} }
ExclusiveMonitor& System::Monitor() { ExclusiveMonitor& System::Monitor() {

View file

@ -93,7 +93,7 @@ class Memory;
namespace Core { namespace Core {
class ARM_Interface; class ARM_Interface;
class Cpu; class CoreManager;
class ExclusiveMonitor; class ExclusiveMonitor;
class FrameLimiter; class FrameLimiter;
class PerfStats; class PerfStats;
@ -218,10 +218,10 @@ public:
const ARM_Interface& ArmInterface(std::size_t core_index) const; const ARM_Interface& ArmInterface(std::size_t core_index) const;
/// Gets a CPU interface to the CPU core with the specified index /// 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 /// 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 monitor /// Gets a reference to the exclusive monitor
ExclusiveMonitor& Monitor(); ExclusiveMonitor& Monitor();
@ -364,10 +364,10 @@ private:
System(); System();
/// Returns the currently running CPU core /// Returns the currently running CPU core
Cpu& CurrentCpuCore(); CoreManager& CurrentCoreManager();
/// Returns the currently running CPU core /// Returns the currently running CPU core
const Cpu& CurrentCpuCore() const; const CoreManager& CurrentCoreManager() const;
/** /**
* Initialize the emulated system. * Initialize the emulated system.

View file

@ -12,7 +12,7 @@
#include "core/arm/exclusive_monitor.h" #include "core/arm/exclusive_monitor.h"
#include "core/arm/unicorn/arm_unicorn.h" #include "core/arm/unicorn/arm_unicorn.h"
#include "core/core.h" #include "core/core.h"
#include "core/core_cpu.h" #include "core/core_manager.h"
#include "core/core_timing.h" #include "core/core_timing.h"
#include "core/hle/kernel/kernel.h" #include "core/hle/kernel/kernel.h"
#include "core/hle/kernel/physical_core.h" #include "core/hle/kernel/physical_core.h"
@ -23,15 +23,15 @@
namespace Core { namespace Core {
Cpu::Cpu(System& system, std::size_t core_index) CoreManager::CoreManager(System& system, std::size_t core_index)
: global_scheduler{system.GlobalScheduler()}, : global_scheduler{system.GlobalScheduler()},
physical_core{system.Kernel().PhysicalCore(core_index)}, core_timing{system.CoreTiming()}, physical_core{system.Kernel().PhysicalCore(core_index)}, core_timing{system.CoreTiming()},
core_index{core_index} { core_index{core_index} {
} }
Cpu::~Cpu() = default; CoreManager::~CoreManager() = default;
void Cpu::RunLoop(bool tight_loop) { void CoreManager::RunLoop(bool tight_loop) {
Reschedule(); Reschedule();
// If we don't have a currently active thread then don't execute instructions, // 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(); Reschedule();
} }
void Cpu::SingleStep() { void CoreManager::SingleStep() {
return RunLoop(false); return RunLoop(false);
} }
void Cpu::PrepareReschedule() { void CoreManager::PrepareReschedule() {
physical_core.Stop(); physical_core.Stop();
} }
void Cpu::Reschedule() { void CoreManager::Reschedule() {
// Lock the global kernel mutex when we manipulate the HLE state // Lock the global kernel mutex when we manipulate the HLE state
std::lock_guard lock(HLE::g_hle_lock); std::lock_guard lock(HLE::g_hle_lock);

View file

@ -32,10 +32,10 @@ namespace Core {
constexpr unsigned NUM_CPU_CORES{4}; constexpr unsigned NUM_CPU_CORES{4};
class Cpu { class CoreManager {
public: public:
Cpu(System& system, std::size_t core_index); CoreManager(System& system, std::size_t core_index);
~Cpu(); ~CoreManager();
void RunLoop(bool tight_loop = true); void RunLoop(bool tight_loop = true);

View file

@ -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 Core

View file

@ -5,56 +5,49 @@
#include "common/assert.h" #include "common/assert.h"
#include "core/arm/exclusive_monitor.h" #include "core/arm/exclusive_monitor.h"
#include "core/core.h" #include "core/core.h"
#include "core/core_cpu.h" #include "core/core_manager.h"
#include "core/core_timing.h" #include "core/core_timing.h"
#include "core/cpu_core_manager.h" #include "core/cpu_manager.h"
#include "core/gdbstub/gdbstub.h" #include "core/gdbstub/gdbstub.h"
#include "core/settings.h" #include "core/settings.h"
namespace Core { 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} {} CpuManager::CpuManager(System& system) : system{system} {}
CpuCoreManager::~CpuCoreManager() = default; CpuManager::~CpuManager() = default;
void CpuCoreManager::Initialize() { void CpuManager::Initialize() {
for (std::size_t index = 0; index < cores.size(); ++index) { for (std::size_t index = 0; index < core_managers.size(); ++index) {
cores[index] = std::make_unique<Cpu>(system, index); core_managers[index] = std::make_unique<CoreManager>(system, index);
} }
} }
void CpuCoreManager::Shutdown() { void CpuManager::Shutdown() {
for (auto& cpu_core : cores) { for (auto& cpu_core : core_managers) {
cpu_core.reset(); cpu_core.reset();
} }
} }
Cpu& CpuCoreManager::GetCore(std::size_t index) { CoreManager& CpuManager::GetCoreManager(std::size_t index) {
return *cores.at(index); return *core_managers.at(index);
} }
const Cpu& CpuCoreManager::GetCore(std::size_t index) const { const CoreManager& CpuManager::GetCoreManager(std::size_t index) const {
return *cores.at(index); return *core_managers.at(index);
} }
Cpu& CpuCoreManager::GetCurrentCore() { CoreManager& CpuManager::GetCurrentCoreManager() {
// Otherwise, use single-threaded mode active_core variable // 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 // 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()) { if (GDBStub::IsServerEnabled()) {
GDBStub::HandlePacket(); GDBStub::HandlePacket();
@ -77,7 +70,7 @@ void CpuCoreManager::RunLoop(bool tight_loop) {
for (active_core = 0; active_core < NUM_CPU_CORES; ++active_core) { for (active_core = 0; active_core < NUM_CPU_CORES; ++active_core) {
core_timing.SwitchContext(active_core); core_timing.SwitchContext(active_core);
if (core_timing.CanCurrentContextRun()) { if (core_timing.CanCurrentContextRun()) {
cores[active_core]->RunLoop(tight_loop); core_managers[active_core]->RunLoop(tight_loop);
} }
keep_running |= core_timing.CanCurrentContextRun(); keep_running |= core_timing.CanCurrentContextRun();
} }

52
src/core/cpu_manager.h Normal file
View file

@ -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 Core

View file

@ -35,7 +35,7 @@
#include "common/swap.h" #include "common/swap.h"
#include "core/arm/arm_interface.h" #include "core/arm/arm_interface.h"
#include "core/core.h" #include "core/core.h"
#include "core/core_cpu.h" #include "core/core_manager.h"
#include "core/gdbstub/gdbstub.h" #include "core/gdbstub/gdbstub.h"
#include "core/hle/kernel/process.h" #include "core/hle/kernel/process.h"
#include "core/hle/kernel/scheduler.h" #include "core/hle/kernel/scheduler.h"

View file

@ -8,7 +8,6 @@
#include "common/assert.h" #include "common/assert.h"
#include "common/common_types.h" #include "common/common_types.h"
#include "core/core.h" #include "core/core.h"
#include "core/core_cpu.h"
#include "core/hle/kernel/address_arbiter.h" #include "core/hle/kernel/address_arbiter.h"
#include "core/hle/kernel/errors.h" #include "core/hle/kernel/errors.h"
#include "core/hle/kernel/scheduler.h" #include "core/hle/kernel/scheduler.h"

View file

@ -14,7 +14,6 @@
#include "common/logging/log.h" #include "common/logging/log.h"
#include "core/arm/arm_interface.h" #include "core/arm/arm_interface.h"
#include "core/core.h" #include "core/core.h"
#include "core/core_cpu.h"
#include "core/core_timing.h" #include "core/core_timing.h"
#include "core/hle/kernel/kernel.h" #include "core/hle/kernel/kernel.h"
#include "core/hle/kernel/process.h" #include "core/hle/kernel/process.h"

View file

@ -15,7 +15,7 @@
#include "common/string_util.h" #include "common/string_util.h"
#include "core/arm/exclusive_monitor.h" #include "core/arm/exclusive_monitor.h"
#include "core/core.h" #include "core/core.h"
#include "core/core_cpu.h" #include "core/core_manager.h"
#include "core/core_timing.h" #include "core/core_timing.h"
#include "core/core_timing_util.h" #include "core/core_timing_util.h"
#include "core/hle/kernel/address_arbiter.h" #include "core/hle/kernel/address_arbiter.h"

View file

@ -13,7 +13,6 @@
#include "common/thread_queue_list.h" #include "common/thread_queue_list.h"
#include "core/arm/arm_interface.h" #include "core/arm/arm_interface.h"
#include "core/core.h" #include "core/core.h"
#include "core/core_cpu.h"
#include "core/core_timing.h" #include "core/core_timing.h"
#include "core/core_timing_util.h" #include "core/core_timing_util.h"
#include "core/hle/kernel/errors.h" #include "core/hle/kernel/errors.h"
@ -356,7 +355,7 @@ void Thread::SetActivity(ThreadActivity value) {
// Set status if not waiting // Set status if not waiting
if (status == ThreadStatus::Ready || status == ThreadStatus::Running) { if (status == ThreadStatus::Ready || status == ThreadStatus::Running) {
SetStatus(ThreadStatus::Paused); SetStatus(ThreadStatus::Paused);
Core::System::GetInstance().CpuCore(processor_id).PrepareReschedule(); Core::System::GetInstance().PrepareReschedule(processor_id);
} }
} else if (status == ThreadStatus::Paused) { } else if (status == ThreadStatus::Paused) {
// Ready to reschedule // Ready to reschedule

View file

@ -7,7 +7,6 @@
#include "common/common_types.h" #include "common/common_types.h"
#include "common/logging/log.h" #include "common/logging/log.h"
#include "core/core.h" #include "core/core.h"
#include "core/core_cpu.h"
#include "core/hle/kernel/kernel.h" #include "core/hle/kernel/kernel.h"
#include "core/hle/kernel/object.h" #include "core/hle/kernel/object.h"
#include "core/hle/kernel/process.h" #include "core/hle/kernel/process.h"