summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2019-03-29 17:09:10 -0400
committerGravatar FernandoS272019-10-15 11:55:07 -0400
commit47c6c78c031b33af877a64aa1da2705558ab02c2 (patch)
tree9e04faeaf19f5f7b2c50664b9d4a5a4e47e4f4e6 /src
parentAdd interfacing to the Global Scheduler (diff)
downloadyuzu-47c6c78c031b33af877a64aa1da2705558ab02c2.tar.gz
yuzu-47c6c78c031b33af877a64aa1da2705558ab02c2.tar.xz
yuzu-47c6c78c031b33af877a64aa1da2705558ab02c2.zip
Redesign CPU Cores to work with the new scheduler
Diffstat (limited to 'src')
-rw-r--r--src/core/core_cpu.cpp23
-rw-r--r--src/core/core_cpu.h2
2 files changed, 12 insertions, 13 deletions
diff --git a/src/core/core_cpu.cpp b/src/core/core_cpu.cpp
index 6bd9639c6..2a7c3af24 100644
--- a/src/core/core_cpu.cpp
+++ b/src/core/core_cpu.cpp
@@ -52,7 +52,8 @@ bool CpuBarrier::Rendezvous() {
52 52
53Cpu::Cpu(System& system, ExclusiveMonitor& exclusive_monitor, CpuBarrier& cpu_barrier, 53Cpu::Cpu(System& system, ExclusiveMonitor& exclusive_monitor, CpuBarrier& cpu_barrier,
54 std::size_t core_index) 54 std::size_t core_index)
55 : cpu_barrier{cpu_barrier}, core_timing{system.CoreTiming()}, core_index{core_index} { 55 : cpu_barrier{cpu_barrier}, global_scheduler{system.GlobalScheduler()},
56 core_timing{system.CoreTiming()}, core_index{core_index} {
56#ifdef ARCHITECTURE_x86_64 57#ifdef ARCHITECTURE_x86_64
57 arm_interface = std::make_unique<ARM_Dynarmic>(system, exclusive_monitor, core_index); 58 arm_interface = std::make_unique<ARM_Dynarmic>(system, exclusive_monitor, core_index);
58#else 59#else
@@ -60,7 +61,7 @@ Cpu::Cpu(System& system, ExclusiveMonitor& exclusive_monitor, CpuBarrier& cpu_ba
60 LOG_WARNING(Core, "CPU JIT requested, but Dynarmic not available"); 61 LOG_WARNING(Core, "CPU JIT requested, but Dynarmic not available");
61#endif 62#endif
62 63
63 scheduler = std::make_unique<Kernel::Scheduler>(system, *arm_interface); 64 scheduler = std::make_unique<Kernel::Scheduler>(system, *arm_interface, core_index);
64} 65}
65 66
66Cpu::~Cpu() = default; 67Cpu::~Cpu() = default;
@@ -81,21 +82,21 @@ void Cpu::RunLoop(bool tight_loop) {
81 return; 82 return;
82 } 83 }
83 84
85 Reschedule();
86
84 // If we don't have a currently active thread then don't execute instructions, 87 // If we don't have a currently active thread then don't execute instructions,
85 // instead advance to the next event and try to yield to the next thread 88 // instead advance to the next event and try to yield to the next thread
86 if (Kernel::GetCurrentThread() == nullptr) { 89 if (Kernel::GetCurrentThread() == nullptr) {
87 LOG_TRACE(Core, "Core-{} idling", core_index); 90 LOG_TRACE(Core, "Core-{} idling", core_index);
88 core_timing.Idle(); 91 core_timing.Idle();
89 core_timing.Advance();
90 PrepareReschedule();
91 } else { 92 } else {
92 if (tight_loop) { 93 if (tight_loop) {
93 arm_interface->Run(); 94 arm_interface->Run();
94 } else { 95 } else {
95 arm_interface->Step(); 96 arm_interface->Step();
96 } 97 }
97 core_timing.Advance();
98 } 98 }
99 core_timing.Advance();
99 100
100 Reschedule(); 101 Reschedule();
101} 102}
@@ -106,18 +107,14 @@ void Cpu::SingleStep() {
106 107
107void Cpu::PrepareReschedule() { 108void Cpu::PrepareReschedule() {
108 arm_interface->PrepareReschedule(); 109 arm_interface->PrepareReschedule();
109 reschedule_pending = true;
110} 110}
111 111
112void Cpu::Reschedule() { 112void Cpu::Reschedule() {
113 if (!reschedule_pending) {
114 return;
115 }
116
117 reschedule_pending = false;
118 // Lock the global kernel mutex when we manipulate the HLE state 113 // Lock the global kernel mutex when we manipulate the HLE state
119 std::lock_guard lock{HLE::g_hle_lock}; 114 std::lock_guard<std::recursive_mutex> lock(HLE::g_hle_lock);
120 scheduler->Reschedule(); 115
116 global_scheduler.SelectThread(core_index);
117 scheduler->TryDoContextSwitch();
121} 118}
122 119
123} // namespace Core 120} // namespace Core
diff --git a/src/core/core_cpu.h b/src/core/core_cpu.h
index 7589beb8c..5dde2994c 100644
--- a/src/core/core_cpu.h
+++ b/src/core/core_cpu.h
@@ -13,6 +13,7 @@
13 13
14namespace Kernel { 14namespace Kernel {
15class Scheduler; 15class Scheduler;
16class GlobalScheduler;
16} 17}
17 18
18namespace Core { 19namespace Core {
@@ -90,6 +91,7 @@ private:
90 91
91 std::unique_ptr<ARM_Interface> arm_interface; 92 std::unique_ptr<ARM_Interface> arm_interface;
92 CpuBarrier& cpu_barrier; 93 CpuBarrier& cpu_barrier;
94 Kernel::GlobalScheduler& global_scheduler;
93 std::unique_ptr<Kernel::Scheduler> scheduler; 95 std::unique_ptr<Kernel::Scheduler> scheduler;
94 Timing::CoreTiming& core_timing; 96 Timing::CoreTiming& core_timing;
95 97