diff options
Diffstat (limited to 'src/core/hle/kernel/kernel.cpp')
| -rw-r--r-- | src/core/hle/kernel/kernel.cpp | 57 |
1 files changed, 29 insertions, 28 deletions
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 8fdab44e4..bea945301 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp | |||
| @@ -85,9 +85,8 @@ struct KernelCore::Impl { | |||
| 85 | } | 85 | } |
| 86 | 86 | ||
| 87 | void InitializeCores() { | 87 | void InitializeCores() { |
| 88 | for (u32 core_id = 0; core_id < Core::Hardware::NUM_CPU_CORES; core_id++) { | 88 | for (auto& core : cores) { |
| 89 | cores[core_id].Initialize(current_process->Is64BitProcess()); | 89 | core.Initialize(current_process->Is64BitProcess()); |
| 90 | system.Memory().SetCurrentPageTable(*current_process, core_id); | ||
| 91 | } | 90 | } |
| 92 | } | 91 | } |
| 93 | 92 | ||
| @@ -132,6 +131,15 @@ struct KernelCore::Impl { | |||
| 132 | next_user_process_id = KProcess::ProcessIDMin; | 131 | next_user_process_id = KProcess::ProcessIDMin; |
| 133 | next_thread_id = 1; | 132 | next_thread_id = 1; |
| 134 | 133 | ||
| 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 | |||
| 135 | cores.clear(); | 143 | cores.clear(); |
| 136 | 144 | ||
| 137 | global_handle_table->Finalize(); | 145 | global_handle_table->Finalize(); |
| @@ -159,16 +167,6 @@ struct KernelCore::Impl { | |||
| 159 | CleanupObject(time_shared_mem); | 167 | CleanupObject(time_shared_mem); |
| 160 | CleanupObject(system_resource_limit); | 168 | CleanupObject(system_resource_limit); |
| 161 | 169 | ||
| 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 | |||
| 172 | // Next host thead ID to use, 0-3 IDs represent core threads, >3 represent others | 170 | // Next host thead ID to use, 0-3 IDs represent core threads, >3 represent others |
| 173 | next_host_thread_id = Core::Hardware::NUM_CPU_CORES; | 171 | next_host_thread_id = Core::Hardware::NUM_CPU_CORES; |
| 174 | 172 | ||
| @@ -259,6 +257,14 @@ struct KernelCore::Impl { | |||
| 259 | 257 | ||
| 260 | void MakeCurrentProcess(KProcess* process) { | 258 | void MakeCurrentProcess(KProcess* process) { |
| 261 | current_process = process; | 259 | 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 | } | ||
| 262 | } | 268 | } |
| 263 | 269 | ||
| 264 | static inline thread_local u32 host_thread_id = UINT32_MAX; | 270 | static inline thread_local u32 host_thread_id = UINT32_MAX; |
| @@ -821,20 +827,16 @@ const Kernel::PhysicalCore& KernelCore::PhysicalCore(std::size_t id) const { | |||
| 821 | return impl->cores[id]; | 827 | return impl->cores[id]; |
| 822 | } | 828 | } |
| 823 | 829 | ||
| 824 | size_t KernelCore::CurrentPhysicalCoreIndex() const { | ||
| 825 | const u32 core_id = impl->GetCurrentHostThreadID(); | ||
| 826 | if (core_id >= Core::Hardware::NUM_CPU_CORES) { | ||
| 827 | return Core::Hardware::NUM_CPU_CORES - 1; | ||
| 828 | } | ||
| 829 | return core_id; | ||
| 830 | } | ||
| 831 | |||
| 832 | Kernel::PhysicalCore& KernelCore::CurrentPhysicalCore() { | 830 | Kernel::PhysicalCore& KernelCore::CurrentPhysicalCore() { |
| 833 | return impl->cores[CurrentPhysicalCoreIndex()]; | 831 | u32 core_id = impl->GetCurrentHostThreadID(); |
| 832 | ASSERT(core_id < Core::Hardware::NUM_CPU_CORES); | ||
| 833 | return impl->cores[core_id]; | ||
| 834 | } | 834 | } |
| 835 | 835 | ||
| 836 | const Kernel::PhysicalCore& KernelCore::CurrentPhysicalCore() const { | 836 | const Kernel::PhysicalCore& KernelCore::CurrentPhysicalCore() const { |
| 837 | return impl->cores[CurrentPhysicalCoreIndex()]; | 837 | u32 core_id = impl->GetCurrentHostThreadID(); |
| 838 | ASSERT(core_id < Core::Hardware::NUM_CPU_CORES); | ||
| 839 | return impl->cores[core_id]; | ||
| 838 | } | 840 | } |
| 839 | 841 | ||
| 840 | Kernel::KScheduler* KernelCore::CurrentScheduler() { | 842 | Kernel::KScheduler* KernelCore::CurrentScheduler() { |
| @@ -1027,9 +1029,6 @@ void KernelCore::Suspend(bool in_suspention) { | |||
| 1027 | impl->suspend_threads[core_id]->SetState(state); | 1029 | impl->suspend_threads[core_id]->SetState(state); |
| 1028 | impl->suspend_threads[core_id]->SetWaitReasonForDebugging( | 1030 | impl->suspend_threads[core_id]->SetWaitReasonForDebugging( |
| 1029 | ThreadWaitReasonForDebugging::Suspended); | 1031 | ThreadWaitReasonForDebugging::Suspended); |
| 1030 | if (!should_suspend) { | ||
| 1031 | impl->suspend_threads[core_id]->DisableDispatch(); | ||
| 1032 | } | ||
| 1033 | } | 1032 | } |
| 1034 | } | 1033 | } |
| 1035 | } | 1034 | } |
| @@ -1044,11 +1043,13 @@ void KernelCore::ExceptionalExit() { | |||
| 1044 | } | 1043 | } |
| 1045 | 1044 | ||
| 1046 | void KernelCore::EnterSVCProfile() { | 1045 | void KernelCore::EnterSVCProfile() { |
| 1047 | impl->svc_ticks[CurrentPhysicalCoreIndex()] = MicroProfileEnter(MICROPROFILE_TOKEN(Kernel_SVC)); | 1046 | std::size_t core = impl->GetCurrentHostThreadID(); |
| 1047 | impl->svc_ticks[core] = MicroProfileEnter(MICROPROFILE_TOKEN(Kernel_SVC)); | ||
| 1048 | } | 1048 | } |
| 1049 | 1049 | ||
| 1050 | void KernelCore::ExitSVCProfile() { | 1050 | void KernelCore::ExitSVCProfile() { |
| 1051 | MicroProfileLeave(MICROPROFILE_TOKEN(Kernel_SVC), impl->svc_ticks[CurrentPhysicalCoreIndex()]); | 1051 | std::size_t core = impl->GetCurrentHostThreadID(); |
| 1052 | MicroProfileLeave(MICROPROFILE_TOKEN(Kernel_SVC), impl->svc_ticks[core]); | ||
| 1052 | } | 1053 | } |
| 1053 | 1054 | ||
| 1054 | std::weak_ptr<Kernel::ServiceThread> KernelCore::CreateServiceThread(const std::string& name) { | 1055 | std::weak_ptr<Kernel::ServiceThread> KernelCore::CreateServiceThread(const std::string& name) { |