diff options
| author | 2020-06-28 12:37:50 -0400 | |
|---|---|---|
| committer | 2020-06-28 12:37:50 -0400 | |
| commit | b05795d704e0c194215f815a5703db09e524b59a (patch) | |
| tree | ecf4023b4ee0c91555c1d8263762fcb9dcb04a17 /src/core/cpu_manager.h | |
| parent | Merge pull request #4196 from ogniK5377/nrr-nro-fixes (diff) | |
| parent | Core/Common: Address Feedback. (diff) | |
| download | yuzu-b05795d704e0c194215f815a5703db09e524b59a.tar.gz yuzu-b05795d704e0c194215f815a5703db09e524b59a.tar.xz yuzu-b05795d704e0c194215f815a5703db09e524b59a.zip | |
Merge pull request #3955 from FernandoS27/prometheus-2b
Remake Kernel Scheduling, CPU Management & Boot Management (Prometheus)
Diffstat (limited to 'src/core/cpu_manager.h')
| -rw-r--r-- | src/core/cpu_manager.h | 80 |
1 files changed, 69 insertions, 11 deletions
diff --git a/src/core/cpu_manager.h b/src/core/cpu_manager.h index 97554d1bb..35929ed94 100644 --- a/src/core/cpu_manager.h +++ b/src/core/cpu_manager.h | |||
| @@ -5,12 +5,19 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <array> | 7 | #include <array> |
| 8 | #include <atomic> | ||
| 9 | #include <functional> | ||
| 8 | #include <memory> | 10 | #include <memory> |
| 11 | #include <thread> | ||
| 9 | #include "core/hardware_properties.h" | 12 | #include "core/hardware_properties.h" |
| 10 | 13 | ||
| 14 | namespace Common { | ||
| 15 | class Event; | ||
| 16 | class Fiber; | ||
| 17 | } // namespace Common | ||
| 18 | |||
| 11 | namespace Core { | 19 | namespace Core { |
| 12 | 20 | ||
| 13 | class CoreManager; | ||
| 14 | class System; | 21 | class System; |
| 15 | 22 | ||
| 16 | class CpuManager { | 23 | class CpuManager { |
| @@ -24,24 +31,75 @@ public: | |||
| 24 | CpuManager& operator=(const CpuManager&) = delete; | 31 | CpuManager& operator=(const CpuManager&) = delete; |
| 25 | CpuManager& operator=(CpuManager&&) = delete; | 32 | CpuManager& operator=(CpuManager&&) = delete; |
| 26 | 33 | ||
| 34 | /// Sets if emulation is multicore or single core, must be set before Initialize | ||
| 35 | void SetMulticore(bool is_multicore) { | ||
| 36 | this->is_multicore = is_multicore; | ||
| 37 | } | ||
| 38 | |||
| 39 | /// Sets if emulation is using an asynchronous GPU. | ||
| 40 | void SetAsyncGpu(bool is_async_gpu) { | ||
| 41 | this->is_async_gpu = is_async_gpu; | ||
| 42 | } | ||
| 43 | |||
| 27 | void Initialize(); | 44 | void Initialize(); |
| 28 | void Shutdown(); | 45 | void Shutdown(); |
| 29 | 46 | ||
| 30 | CoreManager& GetCoreManager(std::size_t index); | 47 | void Pause(bool paused); |
| 31 | const CoreManager& GetCoreManager(std::size_t index) const; | ||
| 32 | 48 | ||
| 33 | CoreManager& GetCurrentCoreManager(); | 49 | std::function<void(void*)> GetGuestThreadStartFunc(); |
| 34 | const CoreManager& GetCurrentCoreManager() const; | 50 | std::function<void(void*)> GetIdleThreadStartFunc(); |
| 51 | std::function<void(void*)> GetSuspendThreadStartFunc(); | ||
| 52 | void* GetStartFuncParamater(); | ||
| 35 | 53 | ||
| 36 | std::size_t GetActiveCoreIndex() const { | 54 | void PreemptSingleCore(bool from_running_enviroment = true); |
| 37 | return active_core; | ||
| 38 | } | ||
| 39 | 55 | ||
| 40 | void RunLoop(bool tight_loop); | 56 | std::size_t CurrentCore() const { |
| 57 | return current_core.load(); | ||
| 58 | } | ||
| 41 | 59 | ||
| 42 | private: | 60 | private: |
| 43 | std::array<std::unique_ptr<CoreManager>, Hardware::NUM_CPU_CORES> core_managers; | 61 | static void GuestThreadFunction(void* cpu_manager); |
| 44 | std::size_t active_core{}; ///< Active core, only used in single thread mode | 62 | static void GuestRewindFunction(void* cpu_manager); |
| 63 | static void IdleThreadFunction(void* cpu_manager); | ||
| 64 | static void SuspendThreadFunction(void* cpu_manager); | ||
| 65 | |||
| 66 | void MultiCoreRunGuestThread(); | ||
| 67 | void MultiCoreRunGuestLoop(); | ||
| 68 | void MultiCoreRunIdleThread(); | ||
| 69 | void MultiCoreRunSuspendThread(); | ||
| 70 | void MultiCorePause(bool paused); | ||
| 71 | |||
| 72 | void SingleCoreRunGuestThread(); | ||
| 73 | void SingleCoreRunGuestLoop(); | ||
| 74 | void SingleCoreRunIdleThread(); | ||
| 75 | void SingleCoreRunSuspendThread(); | ||
| 76 | void SingleCorePause(bool paused); | ||
| 77 | |||
| 78 | static void ThreadStart(CpuManager& cpu_manager, std::size_t core); | ||
| 79 | |||
| 80 | void RunThread(std::size_t core); | ||
| 81 | |||
| 82 | struct CoreData { | ||
| 83 | std::shared_ptr<Common::Fiber> host_context; | ||
| 84 | std::unique_ptr<Common::Event> enter_barrier; | ||
| 85 | std::unique_ptr<Common::Event> exit_barrier; | ||
| 86 | std::atomic<bool> is_running; | ||
| 87 | std::atomic<bool> is_paused; | ||
| 88 | std::atomic<bool> initialized; | ||
| 89 | std::unique_ptr<std::thread> host_thread; | ||
| 90 | }; | ||
| 91 | |||
| 92 | std::atomic<bool> running_mode{}; | ||
| 93 | std::atomic<bool> paused_state{}; | ||
| 94 | |||
| 95 | std::array<CoreData, Core::Hardware::NUM_CPU_CORES> core_data{}; | ||
| 96 | |||
| 97 | bool is_async_gpu{}; | ||
| 98 | bool is_multicore{}; | ||
| 99 | std::atomic<std::size_t> current_core{}; | ||
| 100 | std::size_t preemption_count{}; | ||
| 101 | std::size_t idle_count{}; | ||
| 102 | static constexpr std::size_t max_cycle_runs = 5; | ||
| 45 | 103 | ||
| 46 | System& system; | 104 | System& system; |
| 47 | }; | 105 | }; |