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_cpu.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/core/core_cpu.h (limited to 'src/core/core_cpu.h') diff --git a/src/core/core_cpu.h b/src/core/core_cpu.h new file mode 100644 index 000000000..312db1655 --- /dev/null +++ b/src/core/core_cpu.h @@ -0,0 +1,46 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include "common/common_types.h" + +class ARM_Interface; + +namespace Kernel { +class Scheduler; +} + +namespace Core { + +class Cpu { +public: + Cpu(); + + void RunLoop(bool tight_loop = true); + + void SingleStep(); + + void PrepareReschedule(); + + ARM_Interface& CPU() { + return *arm_interface; + } + + Kernel::Scheduler& Scheduler() { + return *scheduler; + } + +private: + void Reschedule(); + + std::shared_ptr arm_interface; + std::unique_ptr scheduler; + + bool reschedule_pending{}; +}; + +} // namespace Core -- 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_cpu.h | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'src/core/core_cpu.h') diff --git a/src/core/core_cpu.h b/src/core/core_cpu.h index 312db1655..e6ed698cc 100644 --- a/src/core/core_cpu.h +++ b/src/core/core_cpu.h @@ -4,7 +4,9 @@ #pragma once +#include #include +#include #include #include "common/common_types.h" @@ -16,9 +18,32 @@ class Scheduler; namespace Core { +constexpr unsigned NUM_CPU_CORES{4}; + +class CpuBarrier { +public: + void Rendezvous() { + std::unique_lock lock(mutex); + + --cores_waiting; + if (!cores_waiting) { + cores_waiting = NUM_CPU_CORES; + condition.notify_all(); + return; + } + + condition.wait(lock); + } + +private: + unsigned cores_waiting{NUM_CPU_CORES}; + std::mutex mutex; + std::condition_variable condition; +}; + class Cpu { public: - Cpu(); + Cpu(std::shared_ptr cpu_barrier, size_t core_index); void RunLoop(bool tight_loop = true); @@ -34,13 +59,19 @@ public: return *scheduler; } + bool IsMainCore() const { + return core_index == 0; + } + private: void Reschedule(); std::shared_ptr arm_interface; + std::shared_ptr cpu_barrier; std::unique_ptr scheduler; bool reschedule_pending{}; + size_t core_index; }; } // namespace Core -- 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_cpu.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/core/core_cpu.h') diff --git a/src/core/core_cpu.h b/src/core/core_cpu.h index e6ed698cc..06784c4ab 100644 --- a/src/core/core_cpu.h +++ b/src/core/core_cpu.h @@ -51,12 +51,16 @@ public: void PrepareReschedule(); - ARM_Interface& CPU() { + ARM_Interface& ArmInterface() { return *arm_interface; } - Kernel::Scheduler& Scheduler() { - return *scheduler; + const ARM_Interface& ArmInterface() const { + return *arm_interface; + } + + const std::shared_ptr& Scheduler() const { + return scheduler; } bool IsMainCore() const { @@ -68,7 +72,7 @@ private: std::shared_ptr arm_interface; std::shared_ptr cpu_barrier; - std::unique_ptr scheduler; + std::shared_ptr scheduler; bool reschedule_pending{}; size_t core_index; -- 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_cpu.h | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'src/core/core_cpu.h') diff --git a/src/core/core_cpu.h b/src/core/core_cpu.h index 06784c4ab..243f0b5e7 100644 --- a/src/core/core_cpu.h +++ b/src/core/core_cpu.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include #include @@ -22,23 +23,19 @@ constexpr unsigned NUM_CPU_CORES{4}; class CpuBarrier { public: - void Rendezvous() { - std::unique_lock lock(mutex); + bool IsAlive() const { + return !end; + } - --cores_waiting; - if (!cores_waiting) { - cores_waiting = NUM_CPU_CORES; - condition.notify_all(); - return; - } + void NotifyEnd(); - condition.wait(lock); - } + bool Rendezvous(); private: unsigned cores_waiting{NUM_CPU_CORES}; std::mutex mutex; std::condition_variable condition; + std::atomic end{}; }; class Cpu { -- cgit v1.2.3