diff options
| author | 2018-05-02 21:26:14 -0400 | |
|---|---|---|
| committer | 2018-05-10 19:34:46 -0400 | |
| commit | 9776ff91797423a9cf19571faafe4648fb5a1d1d (patch) | |
| tree | 46a7c94c53faee26b805f6290a09c45d33f7bf11 /src/core/core_cpu.h | |
| parent | core: Move common CPU core things to its own class. (diff) | |
| download | yuzu-9776ff91797423a9cf19571faafe4648fb5a1d1d.tar.gz yuzu-9776ff91797423a9cf19571faafe4648fb5a1d1d.tar.xz yuzu-9776ff91797423a9cf19571faafe4648fb5a1d1d.zip | |
core: Create a thread for each CPU core, keep in lock-step with a barrier.
Diffstat (limited to 'src/core/core_cpu.h')
| -rw-r--r-- | src/core/core_cpu.h | 33 |
1 files changed, 32 insertions, 1 deletions
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 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <condition_variable> | ||
| 7 | #include <memory> | 8 | #include <memory> |
| 9 | #include <mutex> | ||
| 8 | #include <string> | 10 | #include <string> |
| 9 | #include "common/common_types.h" | 11 | #include "common/common_types.h" |
| 10 | 12 | ||
| @@ -16,9 +18,32 @@ class Scheduler; | |||
| 16 | 18 | ||
| 17 | namespace Core { | 19 | namespace Core { |
| 18 | 20 | ||
| 21 | constexpr unsigned NUM_CPU_CORES{4}; | ||
| 22 | |||
| 23 | class CpuBarrier { | ||
| 24 | public: | ||
| 25 | void Rendezvous() { | ||
| 26 | std::unique_lock<std::mutex> lock(mutex); | ||
| 27 | |||
| 28 | --cores_waiting; | ||
| 29 | if (!cores_waiting) { | ||
| 30 | cores_waiting = NUM_CPU_CORES; | ||
| 31 | condition.notify_all(); | ||
| 32 | return; | ||
| 33 | } | ||
| 34 | |||
| 35 | condition.wait(lock); | ||
| 36 | } | ||
| 37 | |||
| 38 | private: | ||
| 39 | unsigned cores_waiting{NUM_CPU_CORES}; | ||
| 40 | std::mutex mutex; | ||
| 41 | std::condition_variable condition; | ||
| 42 | }; | ||
| 43 | |||
| 19 | class Cpu { | 44 | class Cpu { |
| 20 | public: | 45 | public: |
| 21 | Cpu(); | 46 | Cpu(std::shared_ptr<CpuBarrier> cpu_barrier, size_t core_index); |
| 22 | 47 | ||
| 23 | void RunLoop(bool tight_loop = true); | 48 | void RunLoop(bool tight_loop = true); |
| 24 | 49 | ||
| @@ -34,13 +59,19 @@ public: | |||
| 34 | return *scheduler; | 59 | return *scheduler; |
| 35 | } | 60 | } |
| 36 | 61 | ||
| 62 | bool IsMainCore() const { | ||
| 63 | return core_index == 0; | ||
| 64 | } | ||
| 65 | |||
| 37 | private: | 66 | private: |
| 38 | void Reschedule(); | 67 | void Reschedule(); |
| 39 | 68 | ||
| 40 | std::shared_ptr<ARM_Interface> arm_interface; | 69 | std::shared_ptr<ARM_Interface> arm_interface; |
| 70 | std::shared_ptr<CpuBarrier> cpu_barrier; | ||
| 41 | std::unique_ptr<Kernel::Scheduler> scheduler; | 71 | std::unique_ptr<Kernel::Scheduler> scheduler; |
| 42 | 72 | ||
| 43 | bool reschedule_pending{}; | 73 | bool reschedule_pending{}; |
| 74 | size_t core_index; | ||
| 44 | }; | 75 | }; |
| 45 | 76 | ||
| 46 | } // namespace Core | 77 | } // namespace Core |