From 3e87b8ff17f2d7334596189a44a4f97a39b772aa Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Tue, 1 Dec 2020 13:03:44 -0800 Subject: [PATCH] kern: move scheduler/interrupt task manager out of core local region --- .../include/mesosphere/kern_k_core_local_region.hpp | 2 -- .../libmesosphere/include/mesosphere/kern_kernel.hpp | 8 +++++--- libraries/libmesosphere/source/kern_kernel.cpp | 4 ++-- mesosphere/kernel/source/kern_kernel_instantiations.cpp | 2 ++ 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/libraries/libmesosphere/include/mesosphere/kern_k_core_local_region.hpp b/libraries/libmesosphere/include/mesosphere/kern_k_core_local_region.hpp index 639bc631d..a70d886ab 100644 --- a/libraries/libmesosphere/include/mesosphere/kern_k_core_local_region.hpp +++ b/libraries/libmesosphere/include/mesosphere/kern_k_core_local_region.hpp @@ -27,8 +27,6 @@ namespace ams::kern { struct KCoreLocalContext { KCurrentContext current; - KScheduler scheduler; - KInterruptTaskManager interrupt_task_manager; /* Everything after this point is for debugging. */ /* Retail kernel doesn't even consistently update these fields. */ u64 num_sw_interrupts; diff --git a/libraries/libmesosphere/include/mesosphere/kern_kernel.hpp b/libraries/libmesosphere/include/mesosphere/kern_kernel.hpp index c5d8525fd..24adf4ea5 100644 --- a/libraries/libmesosphere/include/mesosphere/kern_kernel.hpp +++ b/libraries/libmesosphere/include/mesosphere/kern_kernel.hpp @@ -74,6 +74,8 @@ namespace ams::kern { static KUnsafeMemory s_unsafe_memory; static KWorkerTaskManager s_worker_task_managers[KWorkerTaskManager::WorkerType_Count]; static KInterruptManager s_interrupt_manager; + static KScheduler s_schedulers[cpu::NumCores]; + static KInterruptTaskManager s_interrupt_task_managers[cpu::NumCores]; static KHardwareTimer s_hardware_timers[cpu::NumCores]; private: static ALWAYS_INLINE KCoreLocalContext &GetCoreLocalContext() { @@ -99,15 +101,15 @@ namespace ams::kern { } static ALWAYS_INLINE KScheduler &GetScheduler() { - return GetCoreLocalContext().scheduler; + return s_schedulers[GetCurrentCoreId()]; } static ALWAYS_INLINE KScheduler &GetScheduler(s32 core_id) { - return GetCoreLocalContext(core_id).scheduler; + return s_schedulers[core_id]; } static ALWAYS_INLINE KInterruptTaskManager &GetInterruptTaskManager() { - return GetCoreLocalContext().interrupt_task_manager; + return s_interrupt_task_managers[GetCurrentCoreId()]; } static ALWAYS_INLINE KInterruptManager &GetInterruptManager() { diff --git a/libraries/libmesosphere/source/kern_kernel.cpp b/libraries/libmesosphere/source/kern_kernel.cpp index 750cc2a2f..e56321c71 100644 --- a/libraries/libmesosphere/source/kern_kernel.cpp +++ b/libraries/libmesosphere/source/kern_kernel.cpp @@ -49,8 +49,8 @@ namespace ams::kern { /* Initialize current context. */ clc->current.current_thread = nullptr; clc->current.current_process = nullptr; - clc->current.scheduler = std::addressof(clc->scheduler); - clc->current.interrupt_task_manager = std::addressof(clc->interrupt_task_manager); + clc->current.scheduler = std::addressof(Kernel::GetScheduler()); + clc->current.interrupt_task_manager = std::addressof(Kernel::GetInterruptTaskManager()); clc->current.core_id = core_id; clc->current.exception_stack_top = GetVoidPointer(KMemoryLayout::GetExceptionStackTopAddress(core_id) - sizeof(KThread::StackParameters)); diff --git a/mesosphere/kernel/source/kern_kernel_instantiations.cpp b/mesosphere/kernel/source/kern_kernel_instantiations.cpp index c5ffea0a4..e120b26f6 100644 --- a/mesosphere/kernel/source/kern_kernel_instantiations.cpp +++ b/mesosphere/kernel/source/kern_kernel_instantiations.cpp @@ -30,6 +30,8 @@ namespace ams::kern { constinit KUnsafeMemory Kernel::s_unsafe_memory; constinit KWorkerTaskManager Kernel::s_worker_task_managers[KWorkerTaskManager::WorkerType_Count]; constinit KInterruptManager Kernel::s_interrupt_manager; + constinit KScheduler Kernel::s_schedulers[cpu::NumCores]; + constinit KInterruptTaskManager Kernel::s_interrupt_task_managers[cpu::NumCores]; constinit KHardwareTimer Kernel::s_hardware_timers[cpu::NumCores]; namespace {