From 559024593086d04e24a99a9f77490a3f97cf952d Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 1 May 2018 22:21:38 -0400 Subject: core: Move common CPU core things to its own class. --- src/core/core.h | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'src/core/core.h') diff --git a/src/core/core.h b/src/core/core.h index f81cbfb3c..6e6cc7579 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -4,9 +4,11 @@ #pragma once +#include #include #include #include "common/common_types.h" +#include "core/core_cpu.h" #include "core/hle/kernel/kernel.h" #include "core/hle/kernel/scheduler.h" #include "core/loader/loader.h" @@ -89,7 +91,7 @@ public: * @returns True if the emulated system is powered on, otherwise false. */ bool IsPoweredOn() const { - return cpu_core != nullptr; + return cpu_cores[0] != nullptr; } /** @@ -110,7 +112,7 @@ public: * @returns A reference to the emulated CPU. */ ARM_Interface& CPU() { - return *cpu_core; + return cpu_cores[0]->CPU(); } Tegra::GPU& GPU() { @@ -118,7 +120,7 @@ public: } Kernel::Scheduler& Scheduler() { - return *scheduler; + return cpu_cores[0]->Scheduler(); } Kernel::SharedPtr& CurrentProcess() { @@ -163,18 +165,12 @@ private: */ ResultStatus Init(EmuWindow* emu_window, u32 system_mode); - /// Reschedule the core emulation - void Reschedule(); - /// AppLoader used to load the current executing application std::unique_ptr app_loader; - std::shared_ptr cpu_core; - std::unique_ptr scheduler; + std::array, 4> cpu_cores; std::unique_ptr gpu_core; - std::shared_ptr debug_context; - Kernel::SharedPtr current_process; /// When true, signals that a reschedule should happen -- cgit v1.2.3 From 9776ff91797423a9cf19571faafe4648fb5a1d1d Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 2 May 2018 21:26:14 -0400 Subject: core: Create a thread for each CPU core, keep in lock-step with a barrier. --- src/core/core.h | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'src/core/core.h') diff --git a/src/core/core.h b/src/core/core.h index 6e6cc7579..21a0b074b 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -7,6 +7,7 @@ #include #include #include +#include #include "common/common_types.h" #include "core/core_cpu.h" #include "core/hle/kernel/kernel.h" @@ -112,7 +113,7 @@ public: * @returns A reference to the emulated CPU. */ ARM_Interface& CPU() { - return cpu_cores[0]->CPU(); + return CurrentCpuCore().CPU(); } Tegra::GPU& GPU() { @@ -120,7 +121,7 @@ public: } Kernel::Scheduler& Scheduler() { - return cpu_cores[0]->Scheduler(); + return CurrentCpuCore().Scheduler(); } Kernel::SharedPtr& CurrentProcess() { @@ -157,6 +158,14 @@ public: } private: + /// Returns the current CPU core based on the calling host thread + Cpu& CurrentCpuCore() { + const auto& search = thread_to_cpu.find(std::this_thread::get_id()); + ASSERT(search != thread_to_cpu.end()); + ASSERT(search->second); + return *search->second; + } + /** * Initialize the emulated system. * @param emu_window Pointer to the host-system window used for video output and keyboard input. @@ -167,14 +176,12 @@ private: /// AppLoader used to load the current executing application std::unique_ptr app_loader; - - std::array, 4> cpu_cores; std::unique_ptr gpu_core; std::shared_ptr debug_context; Kernel::SharedPtr current_process; - - /// When true, signals that a reschedule should happen - bool reschedule_pending{}; + std::shared_ptr cpu_barrier; + std::array, NUM_CPU_CORES> cpu_cores; + std::array, NUM_CPU_CORES - 1> cpu_core_threads; /// Service manager std::shared_ptr service_manager; @@ -186,6 +193,9 @@ private: ResultStatus status = ResultStatus::Success; std::string status_details = ""; + + /// Map of guest threads to CPU cores + std::map> thread_to_cpu; }; inline ARM_Interface& CPU() { -- cgit v1.2.3 From a434fdcb102e96ddf564dc0973d7073d49bf19fc Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 2 May 2018 22:36:51 -0400 Subject: core: Implement multicore support. --- src/core/core.h | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'src/core/core.h') diff --git a/src/core/core.h b/src/core/core.h index 21a0b074b..3e0a7e6a7 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -108,20 +108,26 @@ public: PerfStats::Results GetAndResetPerfStats(); - /** - * Gets a reference to the emulated CPU. - * @returns A reference to the emulated CPU. - */ - ARM_Interface& CPU() { - return CurrentCpuCore().CPU(); + ARM_Interface& CurrentArmInterface() { + return CurrentCpuCore().ArmInterface(); + } + + ARM_Interface& ArmInterface(size_t core_index) { + ASSERT(core_index < NUM_CPU_CORES); + return cpu_cores[core_index]->ArmInterface(); } Tegra::GPU& GPU() { return *gpu_core; } - Kernel::Scheduler& Scheduler() { - return CurrentCpuCore().Scheduler(); + Kernel::Scheduler& CurrentScheduler() { + return *CurrentCpuCore().Scheduler(); + } + + const std::shared_ptr& Scheduler(size_t core_index) { + ASSERT(core_index < NUM_CPU_CORES); + return cpu_cores[core_index]->Scheduler(); } Kernel::SharedPtr& CurrentProcess() { @@ -198,8 +204,8 @@ private: std::map> thread_to_cpu; }; -inline ARM_Interface& CPU() { - return System::GetInstance().CPU(); +inline ARM_Interface& CurrentArmInterface() { + return System::GetInstance().CurrentArmInterface(); } inline TelemetrySession& Telemetry() { -- cgit v1.2.3 From cba69fdcd439c5f225bbddf1dad70e6326edd0dc Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 3 May 2018 00:16:12 -0400 Subject: core: Support session close with multicore. --- src/core/core.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/core.h') diff --git a/src/core/core.h b/src/core/core.h index 3e0a7e6a7..561e7b48f 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -92,7 +92,7 @@ public: * @returns True if the emulated system is powered on, otherwise false. */ bool IsPoweredOn() const { - return cpu_cores[0] != nullptr; + return cpu_barrier && cpu_barrier->IsAlive(); } /** -- cgit v1.2.3 From 9bf2a428f9e9359763be1bfd90c32371044c711e Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 3 May 2018 00:34:54 -0400 Subject: core: Add a configuration setting for use_multi_core. --- src/core/core.h | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'src/core/core.h') diff --git a/src/core/core.h b/src/core/core.h index 561e7b48f..115061932 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -112,10 +112,7 @@ public: return CurrentCpuCore().ArmInterface(); } - ARM_Interface& ArmInterface(size_t core_index) { - ASSERT(core_index < NUM_CPU_CORES); - return cpu_cores[core_index]->ArmInterface(); - } + ARM_Interface& ArmInterface(size_t core_index); Tegra::GPU& GPU() { return *gpu_core; @@ -125,10 +122,7 @@ public: return *CurrentCpuCore().Scheduler(); } - const std::shared_ptr& Scheduler(size_t core_index) { - ASSERT(core_index < NUM_CPU_CORES); - return cpu_cores[core_index]->Scheduler(); - } + const std::shared_ptr& Scheduler(size_t core_index); Kernel::SharedPtr& CurrentProcess() { return current_process; -- cgit v1.2.3 From 8aa5d25f826c8969a1e9938d8c8e12fa6df8be82 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 5 May 2018 23:54:43 -0400 Subject: threading: Reschedule only on cores that are necessary. --- src/core/core.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/core/core.h') diff --git a/src/core/core.h b/src/core/core.h index 115061932..5740e858b 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -114,6 +114,8 @@ public: ARM_Interface& ArmInterface(size_t core_index); + Cpu& CpuCore(size_t core_index); + Tegra::GPU& GPU() { return *gpu_core; } -- cgit v1.2.3 From edc52250b8157a9d2b8c909225114c98c7ea609e Mon Sep 17 00:00:00 2001 From: bunnei Date: Mon, 7 May 2018 22:57:39 -0400 Subject: core: Run all CPU cores separately, even in single-thread mode. --- src/core/core.h | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'src/core/core.h') diff --git a/src/core/core.h b/src/core/core.h index 5740e858b..6de707271 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -160,13 +160,8 @@ public: } private: - /// Returns the current CPU core based on the calling host thread - Cpu& CurrentCpuCore() { - const auto& search = thread_to_cpu.find(std::this_thread::get_id()); - ASSERT(search != thread_to_cpu.end()); - ASSERT(search->second); - return *search->second; - } + /// Returns the currently running CPU core + Cpu& CurrentCpuCore(); /** * Initialize the emulated system. @@ -184,6 +179,7 @@ private: std::shared_ptr cpu_barrier; std::array, NUM_CPU_CORES> cpu_cores; std::array, NUM_CPU_CORES - 1> cpu_core_threads; + size_t active_core{}; ///< Active core, only used in single thread mode /// Service manager std::shared_ptr service_manager; -- cgit v1.2.3 From 811dae12f9e1c0eb5c19f6c6a8e75b1e6260abb2 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 10 May 2018 19:34:21 -0400 Subject: core: Add several missing docstrings. --- src/core/core.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/core/core.h') diff --git a/src/core/core.h b/src/core/core.h index 6de707271..f90f085ad 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -106,26 +106,34 @@ public: /// Prepare the core emulation for a reschedule void PrepareReschedule(); + /// Gets and resets core performance statistics PerfStats::Results GetAndResetPerfStats(); + /// Gets an ARM interface to the CPU core that is currently running ARM_Interface& CurrentArmInterface() { return CurrentCpuCore().ArmInterface(); } + /// Gets an ARM interface to the CPU core with the specified index ARM_Interface& ArmInterface(size_t core_index); + /// Gets a CPU interface to the CPU core with the specified index Cpu& CpuCore(size_t core_index); + /// Gets the GPU interface Tegra::GPU& GPU() { return *gpu_core; } + /// Gets the scheduler for the CPU core that is currently running Kernel::Scheduler& CurrentScheduler() { return *CurrentCpuCore().Scheduler(); } + /// Gets the scheduler for the CPU core with the specified index const std::shared_ptr& Scheduler(size_t core_index); + /// Gets the current process Kernel::SharedPtr& CurrentProcess() { return current_process; } -- cgit v1.2.3