summaryrefslogtreecommitdiff
path: root/src/core/core_cpu.cpp
diff options
context:
space:
mode:
authorGravatar David2019-10-28 10:53:27 +1100
committerGravatar GitHub2019-10-28 10:53:27 +1100
commit4c5731c34f0915457a31c60c9f70a2f169ea575d (patch)
tree7f03a7f892370b59e56ae06c6c74514f1cc44998 /src/core/core_cpu.cpp
parentMerge pull request #3034 from ReinUsesLisp/w4244-maxwell3d (diff)
parentKernel Thread: Cleanup THREADPROCESSORID_DONT_UPDATE. (diff)
downloadyuzu-4c5731c34f0915457a31c60c9f70a2f169ea575d.tar.gz
yuzu-4c5731c34f0915457a31c60c9f70a2f169ea575d.tar.xz
yuzu-4c5731c34f0915457a31c60c9f70a2f169ea575d.zip
Merge pull request #2971 from FernandoS27/new-scheduler-v2
Kernel: Implement a New Thread Scheduler V2
Diffstat (limited to 'src/core/core_cpu.cpp')
-rw-r--r--src/core/core_cpu.cpp27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/core/core_cpu.cpp b/src/core/core_cpu.cpp
index 6bd9639c6..233ea572c 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,18 @@ 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 lock(HLE::g_hle_lock);
120 scheduler->Reschedule(); 115
116 global_scheduler.SelectThread(core_index);
117 scheduler->TryDoContextSwitch();
118}
119
120void Cpu::Shutdown() {
121 scheduler->Shutdown();
121} 122}
122 123
123} // namespace Core 124} // namespace Core