diff options
| author | 2021-08-18 15:42:46 -0700 | |
|---|---|---|
| committer | 2021-08-18 15:42:46 -0700 | |
| commit | aa40084c241129ef08081bae72bd5de1b4c86348 (patch) | |
| tree | b4f406cbf0f230cf9064040992ce3ef8bf54e5a7 /src/core/hle/kernel/kernel.cpp | |
| parent | Merge pull request #6863 from spholz/fix-lan-play (diff) | |
| parent | core: hle: kernel: Disable dispatch count tracking on single core. (diff) | |
| download | yuzu-aa40084c241129ef08081bae72bd5de1b4c86348.tar.gz yuzu-aa40084c241129ef08081bae72bd5de1b4c86348.tar.xz yuzu-aa40084c241129ef08081bae72bd5de1b4c86348.zip | |
Merge pull request #6832 from bunnei/scheduler-improvements
kernel: Various improvements to scheduler
Diffstat (limited to 'src/core/hle/kernel/kernel.cpp')
| -rw-r--r-- | src/core/hle/kernel/kernel.cpp | 57 |
1 files changed, 28 insertions, 29 deletions
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 92fbc5532..8673384ee 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp | |||
| @@ -85,8 +85,9 @@ struct KernelCore::Impl { | |||
| 85 | } | 85 | } |
| 86 | 86 | ||
| 87 | void InitializeCores() { | 87 | void InitializeCores() { |
| 88 | for (auto& core : cores) { | 88 | for (u32 core_id = 0; core_id < Core::Hardware::NUM_CPU_CORES; core_id++) { |
| 89 | core.Initialize(current_process->Is64BitProcess()); | 89 | cores[core_id].Initialize(current_process->Is64BitProcess()); |
| 90 | system.Memory().SetCurrentPageTable(*current_process, core_id); | ||
| 90 | } | 91 | } |
| 91 | } | 92 | } |
| 92 | 93 | ||
| @@ -131,15 +132,6 @@ struct KernelCore::Impl { | |||
| 131 | next_user_process_id = KProcess::ProcessIDMin; | 132 | next_user_process_id = KProcess::ProcessIDMin; |
| 132 | next_thread_id = 1; | 133 | next_thread_id = 1; |
| 133 | 134 | ||
| 134 | for (u32 core_id = 0; core_id < Core::Hardware::NUM_CPU_CORES; core_id++) { | ||
| 135 | if (suspend_threads[core_id]) { | ||
| 136 | suspend_threads[core_id]->Close(); | ||
| 137 | suspend_threads[core_id] = nullptr; | ||
| 138 | } | ||
| 139 | |||
| 140 | schedulers[core_id].reset(); | ||
| 141 | } | ||
| 142 | |||
| 143 | cores.clear(); | 135 | cores.clear(); |
| 144 | 136 | ||
| 145 | global_handle_table->Finalize(); | 137 | global_handle_table->Finalize(); |
| @@ -167,6 +159,16 @@ struct KernelCore::Impl { | |||
| 167 | CleanupObject(time_shared_mem); | 159 | CleanupObject(time_shared_mem); |
| 168 | CleanupObject(system_resource_limit); | 160 | CleanupObject(system_resource_limit); |
| 169 | 161 | ||
| 162 | for (u32 core_id = 0; core_id < Core::Hardware::NUM_CPU_CORES; core_id++) { | ||
| 163 | if (suspend_threads[core_id]) { | ||
| 164 | suspend_threads[core_id]->Close(); | ||
| 165 | suspend_threads[core_id] = nullptr; | ||
| 166 | } | ||
| 167 | |||
| 168 | schedulers[core_id]->Finalize(); | ||
| 169 | schedulers[core_id].reset(); | ||
| 170 | } | ||
| 171 | |||
| 170 | // Next host thead ID to use, 0-3 IDs represent core threads, >3 represent others | 172 | // Next host thead ID to use, 0-3 IDs represent core threads, >3 represent others |
| 171 | next_host_thread_id = Core::Hardware::NUM_CPU_CORES; | 173 | next_host_thread_id = Core::Hardware::NUM_CPU_CORES; |
| 172 | 174 | ||
| @@ -257,14 +259,6 @@ struct KernelCore::Impl { | |||
| 257 | 259 | ||
| 258 | void MakeCurrentProcess(KProcess* process) { | 260 | void MakeCurrentProcess(KProcess* process) { |
| 259 | current_process = process; | 261 | current_process = process; |
| 260 | if (process == nullptr) { | ||
| 261 | return; | ||
| 262 | } | ||
| 263 | |||
| 264 | const u32 core_id = GetCurrentHostThreadID(); | ||
| 265 | if (core_id < Core::Hardware::NUM_CPU_CORES) { | ||
| 266 | system.Memory().SetCurrentPageTable(*process, core_id); | ||
| 267 | } | ||
| 268 | } | 262 | } |
| 269 | 263 | ||
| 270 | /// Creates a new host thread ID, should only be called by GetHostThreadId | 264 | /// Creates a new host thread ID, should only be called by GetHostThreadId |
| @@ -824,16 +818,20 @@ const Kernel::PhysicalCore& KernelCore::PhysicalCore(std::size_t id) const { | |||
| 824 | return impl->cores[id]; | 818 | return impl->cores[id]; |
| 825 | } | 819 | } |
| 826 | 820 | ||
| 821 | size_t KernelCore::CurrentPhysicalCoreIndex() const { | ||
| 822 | const u32 core_id = impl->GetCurrentHostThreadID(); | ||
| 823 | if (core_id >= Core::Hardware::NUM_CPU_CORES) { | ||
| 824 | return Core::Hardware::NUM_CPU_CORES - 1; | ||
| 825 | } | ||
| 826 | return core_id; | ||
| 827 | } | ||
| 828 | |||
| 827 | Kernel::PhysicalCore& KernelCore::CurrentPhysicalCore() { | 829 | Kernel::PhysicalCore& KernelCore::CurrentPhysicalCore() { |
| 828 | u32 core_id = impl->GetCurrentHostThreadID(); | 830 | return impl->cores[CurrentPhysicalCoreIndex()]; |
| 829 | ASSERT(core_id < Core::Hardware::NUM_CPU_CORES); | ||
| 830 | return impl->cores[core_id]; | ||
| 831 | } | 831 | } |
| 832 | 832 | ||
| 833 | const Kernel::PhysicalCore& KernelCore::CurrentPhysicalCore() const { | 833 | const Kernel::PhysicalCore& KernelCore::CurrentPhysicalCore() const { |
| 834 | u32 core_id = impl->GetCurrentHostThreadID(); | 834 | return impl->cores[CurrentPhysicalCoreIndex()]; |
| 835 | ASSERT(core_id < Core::Hardware::NUM_CPU_CORES); | ||
| 836 | return impl->cores[core_id]; | ||
| 837 | } | 835 | } |
| 838 | 836 | ||
| 839 | Kernel::KScheduler* KernelCore::CurrentScheduler() { | 837 | Kernel::KScheduler* KernelCore::CurrentScheduler() { |
| @@ -1026,6 +1024,9 @@ void KernelCore::Suspend(bool in_suspention) { | |||
| 1026 | impl->suspend_threads[core_id]->SetState(state); | 1024 | impl->suspend_threads[core_id]->SetState(state); |
| 1027 | impl->suspend_threads[core_id]->SetWaitReasonForDebugging( | 1025 | impl->suspend_threads[core_id]->SetWaitReasonForDebugging( |
| 1028 | ThreadWaitReasonForDebugging::Suspended); | 1026 | ThreadWaitReasonForDebugging::Suspended); |
| 1027 | if (!should_suspend) { | ||
| 1028 | impl->suspend_threads[core_id]->DisableDispatch(); | ||
| 1029 | } | ||
| 1029 | } | 1030 | } |
| 1030 | } | 1031 | } |
| 1031 | } | 1032 | } |
| @@ -1040,13 +1041,11 @@ void KernelCore::ExceptionalExit() { | |||
| 1040 | } | 1041 | } |
| 1041 | 1042 | ||
| 1042 | void KernelCore::EnterSVCProfile() { | 1043 | void KernelCore::EnterSVCProfile() { |
| 1043 | std::size_t core = impl->GetCurrentHostThreadID(); | 1044 | impl->svc_ticks[CurrentPhysicalCoreIndex()] = MicroProfileEnter(MICROPROFILE_TOKEN(Kernel_SVC)); |
| 1044 | impl->svc_ticks[core] = MicroProfileEnter(MICROPROFILE_TOKEN(Kernel_SVC)); | ||
| 1045 | } | 1045 | } |
| 1046 | 1046 | ||
| 1047 | void KernelCore::ExitSVCProfile() { | 1047 | void KernelCore::ExitSVCProfile() { |
| 1048 | std::size_t core = impl->GetCurrentHostThreadID(); | 1048 | MicroProfileLeave(MICROPROFILE_TOKEN(Kernel_SVC), impl->svc_ticks[CurrentPhysicalCoreIndex()]); |
| 1049 | MicroProfileLeave(MICROPROFILE_TOKEN(Kernel_SVC), impl->svc_ticks[core]); | ||
| 1050 | } | 1049 | } |
| 1051 | 1050 | ||
| 1052 | std::weak_ptr<Kernel::ServiceThread> KernelCore::CreateServiceThread(const std::string& name) { | 1051 | std::weak_ptr<Kernel::ServiceThread> KernelCore::CreateServiceThread(const std::string& name) { |