summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar bunnei2018-05-07 22:57:39 -0400
committerGravatar bunnei2018-05-10 19:34:53 -0400
commitedc52250b8157a9d2b8c909225114c98c7ea609e (patch)
treeecef7f8e5405ccc6221de2ec713df1baac226eee
parentthread: Support core change on ResumeFromWait and improve ChangeCore. (diff)
downloadyuzu-edc52250b8157a9d2b8c909225114c98c7ea609e.tar.gz
yuzu-edc52250b8157a9d2b8c909225114c98c7ea609e.tar.xz
yuzu-edc52250b8157a9d2b8c909225114c98c7ea609e.zip
core: Run all CPU cores separately, even in single-thread mode.
-rw-r--r--src/core/core.cpp26
-rw-r--r--src/core/core.h10
2 files changed, 23 insertions, 13 deletions
diff --git a/src/core/core.cpp b/src/core/core.cpp
index 6cbfc3035..84ab876cc 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -34,6 +34,19 @@ static void RunCpuCore(std::shared_ptr<Cpu> cpu_state) {
34 } 34 }
35} 35}
36 36
37Cpu& System::CurrentCpuCore() {
38 // If multicore is enabled, use host thread to figure out the current CPU core
39 if (Settings::values.use_multi_core) {
40 const auto& search = thread_to_cpu.find(std::this_thread::get_id());
41 ASSERT(search != thread_to_cpu.end());
42 ASSERT(search->second);
43 return *search->second;
44 }
45
46 // Otherwise, use single-threaded mode active_core variable
47 return *cpu_cores[active_core];
48}
49
37System::ResultStatus System::RunLoop(bool tight_loop) { 50System::ResultStatus System::RunLoop(bool tight_loop) {
38 status = ResultStatus::Success; 51 status = ResultStatus::Success;
39 52
@@ -55,7 +68,13 @@ System::ResultStatus System::RunLoop(bool tight_loop) {
55 } 68 }
56 } 69 }
57 70
58 cpu_cores[0]->RunLoop(tight_loop); 71 for (active_core = 0; active_core < NUM_CPU_CORES; ++active_core) {
72 cpu_cores[active_core]->RunLoop(tight_loop);
73 if (Settings::values.use_multi_core) {
74 // Cores 1-3 are run on other threads in this mode
75 break;
76 }
77 }
59 78
60 return status; 79 return status;
61} 80}
@@ -127,11 +146,6 @@ PerfStats::Results System::GetAndResetPerfStats() {
127} 146}
128 147
129const std::shared_ptr<Kernel::Scheduler>& System::Scheduler(size_t core_index) { 148const std::shared_ptr<Kernel::Scheduler>& System::Scheduler(size_t core_index) {
130 if (!Settings::values.use_multi_core) {
131 // Always use Core 0 scheduler when multicore is disabled
132 return cpu_cores[0]->Scheduler();
133 }
134
135 ASSERT(core_index < NUM_CPU_CORES); 149 ASSERT(core_index < NUM_CPU_CORES);
136 return cpu_cores[core_index]->Scheduler(); 150 return cpu_cores[core_index]->Scheduler();
137} 151}
diff --git a/src/core/core.h b/src/core/core.h
index 5740e858b..6de707271 100644
--- a/src/core/core.h
+++ b/src/core/core.h
@@ -160,13 +160,8 @@ public:
160 } 160 }
161 161
162private: 162private:
163 /// Returns the current CPU core based on the calling host thread 163 /// Returns the currently running CPU core
164 Cpu& CurrentCpuCore() { 164 Cpu& CurrentCpuCore();
165 const auto& search = thread_to_cpu.find(std::this_thread::get_id());
166 ASSERT(search != thread_to_cpu.end());
167 ASSERT(search->second);
168 return *search->second;
169 }
170 165
171 /** 166 /**
172 * Initialize the emulated system. 167 * Initialize the emulated system.
@@ -184,6 +179,7 @@ private:
184 std::shared_ptr<CpuBarrier> cpu_barrier; 179 std::shared_ptr<CpuBarrier> cpu_barrier;
185 std::array<std::shared_ptr<Cpu>, NUM_CPU_CORES> cpu_cores; 180 std::array<std::shared_ptr<Cpu>, NUM_CPU_CORES> cpu_cores;
186 std::array<std::unique_ptr<std::thread>, NUM_CPU_CORES - 1> cpu_core_threads; 181 std::array<std::unique_ptr<std::thread>, NUM_CPU_CORES - 1> cpu_core_threads;
182 size_t active_core{}; ///< Active core, only used in single thread mode
187 183
188 /// Service manager 184 /// Service manager
189 std::shared_ptr<Service::SM::ServiceManager> service_manager; 185 std::shared_ptr<Service::SM::ServiceManager> service_manager;