summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2018-05-08 04:57:39 +0200
committerbunnei <bunneidev@gmail.com>2018-05-11 01:34:53 +0200
commitedc52250b8157a9d2b8c909225114c98c7ea609e (patch)
treeecef7f8e5405ccc6221de2ec713df1baac226eee
parentthread: Support core change on ResumeFromWait and improve ChangeCore. (diff)
downloadyuzu-edc52250b8157a9d2b8c909225114c98c7ea609e.tar
yuzu-edc52250b8157a9d2b8c909225114c98c7ea609e.tar.gz
yuzu-edc52250b8157a9d2b8c909225114c98c7ea609e.tar.bz2
yuzu-edc52250b8157a9d2b8c909225114c98c7ea609e.tar.lz
yuzu-edc52250b8157a9d2b8c909225114c98c7ea609e.tar.xz
yuzu-edc52250b8157a9d2b8c909225114c98c7ea609e.tar.zst
yuzu-edc52250b8157a9d2b8c909225114c98c7ea609e.zip
-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) {
}
}
+Cpu& System::CurrentCpuCore() {
+ // If multicore is enabled, use host thread to figure out the current CPU core
+ if (Settings::values.use_multi_core) {
+ const auto& search = thread_to_cpu.find(std::this_thread::get_id());
+ ASSERT(search != thread_to_cpu.end());
+ ASSERT(search->second);
+ return *search->second;
+ }
+
+ // Otherwise, use single-threaded mode active_core variable
+ return *cpu_cores[active_core];
+}
+
System::ResultStatus System::RunLoop(bool tight_loop) {
status = ResultStatus::Success;
@@ -55,7 +68,13 @@ System::ResultStatus System::RunLoop(bool tight_loop) {
}
}
- cpu_cores[0]->RunLoop(tight_loop);
+ for (active_core = 0; active_core < NUM_CPU_CORES; ++active_core) {
+ cpu_cores[active_core]->RunLoop(tight_loop);
+ if (Settings::values.use_multi_core) {
+ // Cores 1-3 are run on other threads in this mode
+ break;
+ }
+ }
return status;
}
@@ -127,11 +146,6 @@ PerfStats::Results System::GetAndResetPerfStats() {
}
const std::shared_ptr<Kernel::Scheduler>& System::Scheduler(size_t core_index) {
- if (!Settings::values.use_multi_core) {
- // Always use Core 0 scheduler when multicore is disabled
- return cpu_cores[0]->Scheduler();
- }
-
ASSERT(core_index < NUM_CPU_CORES);
return cpu_cores[core_index]->Scheduler();
}
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:
}
private:
- /// Returns the current CPU core based on the calling host thread
- Cpu& CurrentCpuCore() {
- const auto& search = thread_to_cpu.find(std::this_thread::get_id());
- ASSERT(search != thread_to_cpu.end());
- ASSERT(search->second);
- return *search->second;
- }
+ /// Returns the currently running CPU core
+ Cpu& CurrentCpuCore();
/**
* Initialize the emulated system.
@@ -184,6 +179,7 @@ private:
std::shared_ptr<CpuBarrier> cpu_barrier;
std::array<std::shared_ptr<Cpu>, NUM_CPU_CORES> cpu_cores;
std::array<std::unique_ptr<std::thread>, NUM_CPU_CORES - 1> cpu_core_threads;
+ size_t active_core{}; ///< Active core, only used in single thread mode
/// Service manager
std::shared_ptr<Service::SM::ServiceManager> service_manager;