summaryrefslogtreecommitdiff
path: root/src/core/cpu_manager.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2020-01-30 18:13:59 -0500
committerGravatar GitHub2020-01-30 18:13:59 -0500
commit985d0f35e55f0752c6e147d0140b367708499cb4 (patch)
tree119249aee3acc2cc2ee6a5d391288b52c126765b /src/core/cpu_manager.cpp
parentMerge pull request #3151 from FearlessTobi/fix-korean (diff)
parentSystem: Address Feedback (diff)
downloadyuzu-985d0f35e55f0752c6e147d0140b367708499cb4.tar.gz
yuzu-985d0f35e55f0752c6e147d0140b367708499cb4.tar.xz
yuzu-985d0f35e55f0752c6e147d0140b367708499cb4.zip
Merge pull request #3353 from FernandoS27/aries
System: Refactor CPU Core management and move ARMInterface and Schedulers to Kernel
Diffstat (limited to 'src/core/cpu_manager.cpp')
-rw-r--r--src/core/cpu_manager.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp
new file mode 100644
index 000000000..752534868
--- /dev/null
+++ b/src/core/cpu_manager.cpp
@@ -0,0 +1,83 @@
1// Copyright 2018 yuzu emulator team
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include "common/assert.h"
6#include "core/arm/exclusive_monitor.h"
7#include "core/core.h"
8#include "core/core_manager.h"
9#include "core/core_timing.h"
10#include "core/cpu_manager.h"
11#include "core/gdbstub/gdbstub.h"
12#include "core/settings.h"
13
14namespace Core {
15
16CpuManager::CpuManager(System& system) : system{system} {}
17CpuManager::~CpuManager() = default;
18
19void CpuManager::Initialize() {
20 for (std::size_t index = 0; index < core_managers.size(); ++index) {
21 core_managers[index] = std::make_unique<CoreManager>(system, index);
22 }
23}
24
25void CpuManager::Shutdown() {
26 for (auto& cpu_core : core_managers) {
27 cpu_core.reset();
28 }
29}
30
31CoreManager& CpuManager::GetCoreManager(std::size_t index) {
32 return *core_managers.at(index);
33}
34
35const CoreManager& CpuManager::GetCoreManager(std::size_t index) const {
36 return *core_managers.at(index);
37}
38
39CoreManager& CpuManager::GetCurrentCoreManager() {
40 // Otherwise, use single-threaded mode active_core variable
41 return *core_managers[active_core];
42}
43
44const CoreManager& CpuManager::GetCurrentCoreManager() const {
45 // Otherwise, use single-threaded mode active_core variable
46 return *core_managers[active_core];
47}
48
49void CpuManager::RunLoop(bool tight_loop) {
50 if (GDBStub::IsServerEnabled()) {
51 GDBStub::HandlePacket();
52
53 // If the loop is halted and we want to step, use a tiny (1) number of instructions to
54 // execute. Otherwise, get out of the loop function.
55 if (GDBStub::GetCpuHaltFlag()) {
56 if (GDBStub::GetCpuStepFlag()) {
57 tight_loop = false;
58 } else {
59 return;
60 }
61 }
62 }
63
64 auto& core_timing = system.CoreTiming();
65 core_timing.ResetRun();
66 bool keep_running{};
67 do {
68 keep_running = false;
69 for (active_core = 0; active_core < NUM_CPU_CORES; ++active_core) {
70 core_timing.SwitchContext(active_core);
71 if (core_timing.CanCurrentContextRun()) {
72 core_managers[active_core]->RunLoop(tight_loop);
73 }
74 keep_running |= core_timing.CanCurrentContextRun();
75 }
76 } while (keep_running);
77
78 if (GDBStub::IsServerEnabled()) {
79 GDBStub::SetCpuStepFlag(false);
80 }
81}
82
83} // namespace Core