diff options
| author | 2021-04-03 19:11:46 -0700 | |
|---|---|---|
| committer | 2021-05-05 16:40:50 -0700 | |
| commit | da7e9553dea4b1eaefb71aca8642ccce7c7f50fb (patch) | |
| tree | 3da10a60005ddcc4237900eb5e7473fe7b006152 /src/core/hle/kernel/kernel.cpp | |
| parent | hle: kernel: svc: Migrate GetThreadPriority, StartThread, and ExitThread. (diff) | |
| download | yuzu-da7e9553dea4b1eaefb71aca8642ccce7c7f50fb.tar.gz yuzu-da7e9553dea4b1eaefb71aca8642ccce7c7f50fb.tar.xz yuzu-da7e9553dea4b1eaefb71aca8642ccce7c7f50fb.zip | |
hle: kernel: Migrate more of KThread to KAutoObject.
Diffstat (limited to 'src/core/hle/kernel/kernel.cpp')
| -rw-r--r-- | src/core/hle/kernel/kernel.cpp | 72 |
1 files changed, 48 insertions, 24 deletions
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 17fe1d59f..d1359e434 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp | |||
| @@ -28,6 +28,7 @@ | |||
| 28 | #include "core/hardware_properties.h" | 28 | #include "core/hardware_properties.h" |
| 29 | #include "core/hle/kernel/client_port.h" | 29 | #include "core/hle/kernel/client_port.h" |
| 30 | #include "core/hle/kernel/handle_table.h" | 30 | #include "core/hle/kernel/handle_table.h" |
| 31 | #include "core/hle/kernel/init/init_slab_setup.h" | ||
| 31 | #include "core/hle/kernel/k_memory_layout.h" | 32 | #include "core/hle/kernel/k_memory_layout.h" |
| 32 | #include "core/hle/kernel/k_memory_manager.h" | 33 | #include "core/hle/kernel/k_memory_manager.h" |
| 33 | #include "core/hle/kernel/k_resource_limit.h" | 34 | #include "core/hle/kernel/k_resource_limit.h" |
| @@ -51,7 +52,8 @@ namespace Kernel { | |||
| 51 | 52 | ||
| 52 | struct KernelCore::Impl { | 53 | struct KernelCore::Impl { |
| 53 | explicit Impl(Core::System& system, KernelCore& kernel) | 54 | explicit Impl(Core::System& system, KernelCore& kernel) |
| 54 | : time_manager{system}, global_handle_table{kernel}, system{system} {} | 55 | : time_manager{system}, global_handle_table{kernel}, |
| 56 | object_list_container{kernel}, system{system} {} | ||
| 55 | 57 | ||
| 56 | void SetMulticore(bool is_multicore) { | 58 | void SetMulticore(bool is_multicore) { |
| 57 | this->is_multicore = is_multicore; | 59 | this->is_multicore = is_multicore; |
| @@ -69,9 +71,12 @@ struct KernelCore::Impl { | |||
| 69 | // Derive the initial memory layout from the emulated board | 71 | // Derive the initial memory layout from the emulated board |
| 70 | KMemoryLayout memory_layout; | 72 | KMemoryLayout memory_layout; |
| 71 | DeriveInitialMemoryLayout(memory_layout); | 73 | DeriveInitialMemoryLayout(memory_layout); |
| 74 | Init::InitializeSlabHeaps(system, memory_layout); | ||
| 75 | |||
| 76 | // Initialize kernel memory and resources. | ||
| 72 | InitializeMemoryLayout(memory_layout); | 77 | InitializeMemoryLayout(memory_layout); |
| 73 | InitializeSystemResourceLimit(kernel, system.CoreTiming(), memory_layout); | 78 | InitializeSystemResourceLimit(kernel, system.CoreTiming(), memory_layout); |
| 74 | InitializeSlabHeaps(); | 79 | InitializePageSlab(); |
| 75 | InitializeSchedulers(); | 80 | InitializeSchedulers(); |
| 76 | InitializeSuspendThreads(); | 81 | InitializeSuspendThreads(); |
| 77 | InitializePreemption(kernel); | 82 | InitializePreemption(kernel); |
| @@ -99,7 +104,7 @@ struct KernelCore::Impl { | |||
| 99 | 104 | ||
| 100 | for (std::size_t i = 0; i < Core::Hardware::NUM_CPU_CORES; i++) { | 105 | for (std::size_t i = 0; i < Core::Hardware::NUM_CPU_CORES; i++) { |
| 101 | if (suspend_threads[i]) { | 106 | if (suspend_threads[i]) { |
| 102 | suspend_threads[i].reset(); | 107 | suspend_threads[i]->Close(); |
| 103 | } | 108 | } |
| 104 | } | 109 | } |
| 105 | 110 | ||
| @@ -189,15 +194,12 @@ struct KernelCore::Impl { | |||
| 189 | } | 194 | } |
| 190 | 195 | ||
| 191 | void InitializeSuspendThreads() { | 196 | void InitializeSuspendThreads() { |
| 192 | for (std::size_t i = 0; i < Core::Hardware::NUM_CPU_CORES; i++) { | 197 | for (s32 core_id = 0; core_id < Core::Hardware::NUM_CPU_CORES; core_id++) { |
| 193 | std::string name = "Suspend Thread Id:" + std::to_string(i); | 198 | suspend_threads[core_id] = KThread::CreateWithKernel(system.Kernel()); |
| 194 | std::function<void(void*)> init_func = Core::CpuManager::GetSuspendThreadStartFunc(); | 199 | ASSERT(KThread::InitializeHighPriorityThread(system, suspend_threads[core_id], {}, {}, |
| 195 | void* init_func_parameter = system.GetCpuManager().GetStartFuncParamater(); | 200 | core_id) |
| 196 | auto thread_res = KThread::CreateThread( | 201 | .IsSuccess()); |
| 197 | system, ThreadType::HighPriority, std::move(name), 0, 0, 0, static_cast<u32>(i), 0, | 202 | suspend_threads[core_id]->SetName(fmt::format("SuspendThread:{}", core_id)); |
| 198 | nullptr, std::move(init_func), init_func_parameter); | ||
| 199 | |||
| 200 | suspend_threads[i] = std::move(thread_res).Unwrap(); | ||
| 201 | } | 203 | } |
| 202 | } | 204 | } |
| 203 | 205 | ||
| @@ -232,12 +234,15 @@ struct KernelCore::Impl { | |||
| 232 | 234 | ||
| 233 | // Gets the dummy KThread for the caller, allocating a new one if this is the first time | 235 | // Gets the dummy KThread for the caller, allocating a new one if this is the first time |
| 234 | KThread* GetHostDummyThread() { | 236 | KThread* GetHostDummyThread() { |
| 235 | const thread_local auto thread = | 237 | auto make_thread = [this]() { |
| 236 | KThread::CreateThread( | 238 | KThread* thread = KThread::CreateWithKernel(system.Kernel()); |
| 237 | system, ThreadType::Main, fmt::format("DummyThread:{}", GetHostThreadId()), 0, | 239 | ASSERT(KThread::InitializeDummyThread(thread).IsSuccess()); |
| 238 | KThread::DefaultThreadPriority, 0, static_cast<u32>(3), 0, nullptr) | 240 | thread->SetName(fmt::format("DummyThread:{}", GetHostThreadId())); |
| 239 | .Unwrap(); | 241 | return thread; |
| 240 | return thread.get(); | 242 | }; |
| 243 | |||
| 244 | thread_local auto thread = make_thread(); | ||
| 245 | return thread; | ||
| 241 | } | 246 | } |
| 242 | 247 | ||
| 243 | /// Registers a CPU core thread by allocating a host thread ID for it | 248 | /// Registers a CPU core thread by allocating a host thread ID for it |
| @@ -371,7 +376,8 @@ struct KernelCore::Impl { | |||
| 371 | const size_t resource_region_size = memory_layout.GetResourceRegionSizeForInit(); | 376 | const size_t resource_region_size = memory_layout.GetResourceRegionSizeForInit(); |
| 372 | 377 | ||
| 373 | // Determine the size of the slab region. | 378 | // Determine the size of the slab region. |
| 374 | const size_t slab_region_size = Common::AlignUp(KernelSlabHeapSize, PageSize); | 379 | const size_t slab_region_size = |
| 380 | Common::AlignUp(Init::CalculateTotalSlabHeapSize(), PageSize); | ||
| 375 | ASSERT(slab_region_size <= resource_region_size); | 381 | ASSERT(slab_region_size <= resource_region_size); |
| 376 | 382 | ||
| 377 | // Setup the slab region. | 383 | // Setup the slab region. |
| @@ -587,7 +593,7 @@ struct KernelCore::Impl { | |||
| 587 | "Time:SharedMemory"); | 593 | "Time:SharedMemory"); |
| 588 | } | 594 | } |
| 589 | 595 | ||
| 590 | void InitializeSlabHeaps() { | 596 | void InitializePageSlab() { |
| 591 | // Allocate slab heaps | 597 | // Allocate slab heaps |
| 592 | user_slab_heap_pages = std::make_unique<KSlabHeap<Page>>(); | 598 | user_slab_heap_pages = std::make_unique<KSlabHeap<Page>>(); |
| 593 | 599 | ||
| @@ -596,7 +602,7 @@ struct KernelCore::Impl { | |||
| 596 | // Reserve slab heaps | 602 | // Reserve slab heaps |
| 597 | ASSERT( | 603 | ASSERT( |
| 598 | system_resource_limit->Reserve(LimitableResource::PhysicalMemory, user_slab_heap_size)); | 604 | system_resource_limit->Reserve(LimitableResource::PhysicalMemory, user_slab_heap_size)); |
| 599 | // Initialize slab heaps | 605 | // Initialize slab heap |
| 600 | user_slab_heap_pages->Initialize( | 606 | user_slab_heap_pages->Initialize( |
| 601 | system.DeviceMemory().GetPointer(Core::DramMemoryMap::SlabHeapBase), | 607 | system.DeviceMemory().GetPointer(Core::DramMemoryMap::SlabHeapBase), |
| 602 | user_slab_heap_size); | 608 | user_slab_heap_size); |
| @@ -621,6 +627,8 @@ struct KernelCore::Impl { | |||
| 621 | // stores all the objects in place. | 627 | // stores all the objects in place. |
| 622 | HandleTable global_handle_table; | 628 | HandleTable global_handle_table; |
| 623 | 629 | ||
| 630 | KAutoObjectWithListContainer object_list_container; | ||
| 631 | |||
| 624 | /// Map of named ports managed by the kernel, which can be retrieved using | 632 | /// Map of named ports managed by the kernel, which can be retrieved using |
| 625 | /// the ConnectToPort SVC. | 633 | /// the ConnectToPort SVC. |
| 626 | NamedPortTable named_ports; | 634 | NamedPortTable named_ports; |
| @@ -648,7 +656,7 @@ struct KernelCore::Impl { | |||
| 648 | // the release of itself | 656 | // the release of itself |
| 649 | std::unique_ptr<Common::ThreadWorker> service_thread_manager; | 657 | std::unique_ptr<Common::ThreadWorker> service_thread_manager; |
| 650 | 658 | ||
| 651 | std::array<std::shared_ptr<KThread>, Core::Hardware::NUM_CPU_CORES> suspend_threads{}; | 659 | std::array<KThread*, Core::Hardware::NUM_CPU_CORES> suspend_threads{}; |
| 652 | std::array<Core::CPUInterruptHandler, Core::Hardware::NUM_CPU_CORES> interrupts{}; | 660 | std::array<Core::CPUInterruptHandler, Core::Hardware::NUM_CPU_CORES> interrupts{}; |
| 653 | std::array<std::unique_ptr<Kernel::KScheduler>, Core::Hardware::NUM_CPU_CORES> schedulers{}; | 661 | std::array<std::unique_ptr<Kernel::KScheduler>, Core::Hardware::NUM_CPU_CORES> schedulers{}; |
| 654 | 662 | ||
| @@ -687,8 +695,8 @@ std::shared_ptr<KResourceLimit> KernelCore::GetSystemResourceLimit() const { | |||
| 687 | return impl->system_resource_limit; | 695 | return impl->system_resource_limit; |
| 688 | } | 696 | } |
| 689 | 697 | ||
| 690 | std::shared_ptr<KThread> KernelCore::RetrieveThreadFromGlobalHandleTable(Handle handle) const { | 698 | KScopedAutoObject<KThread> KernelCore::RetrieveThreadFromGlobalHandleTable(Handle handle) const { |
| 691 | return impl->global_handle_table.Get<KThread>(handle); | 699 | return impl->global_handle_table.GetObject<KThread>(handle); |
| 692 | } | 700 | } |
| 693 | 701 | ||
| 694 | void KernelCore::AppendNewProcess(std::shared_ptr<Process> process) { | 702 | void KernelCore::AppendNewProcess(std::shared_ptr<Process> process) { |
| @@ -781,6 +789,14 @@ const Core::ExclusiveMonitor& KernelCore::GetExclusiveMonitor() const { | |||
| 781 | return *impl->exclusive_monitor; | 789 | return *impl->exclusive_monitor; |
| 782 | } | 790 | } |
| 783 | 791 | ||
| 792 | KAutoObjectWithListContainer& KernelCore::ObjectListContainer() { | ||
| 793 | return impl->object_list_container; | ||
| 794 | } | ||
| 795 | |||
| 796 | const KAutoObjectWithListContainer& KernelCore::ObjectListContainer() const { | ||
| 797 | return impl->object_list_container; | ||
| 798 | } | ||
| 799 | |||
| 784 | void KernelCore::InvalidateAllInstructionCaches() { | 800 | void KernelCore::InvalidateAllInstructionCaches() { |
| 785 | for (auto& physical_core : impl->cores) { | 801 | for (auto& physical_core : impl->cores) { |
| 786 | physical_core.ArmInterface().ClearInstructionCache(); | 802 | physical_core.ArmInterface().ClearInstructionCache(); |
| @@ -960,4 +976,12 @@ void KernelCore::SetIsPhantomModeForSingleCore(bool value) { | |||
| 960 | impl->SetIsPhantomModeForSingleCore(value); | 976 | impl->SetIsPhantomModeForSingleCore(value); |
| 961 | } | 977 | } |
| 962 | 978 | ||
| 979 | Core::System& KernelCore::System() { | ||
| 980 | return impl->system; | ||
| 981 | } | ||
| 982 | |||
| 983 | const Core::System& KernelCore::System() const { | ||
| 984 | return impl->system; | ||
| 985 | } | ||
| 986 | |||
| 963 | } // namespace Kernel | 987 | } // namespace Kernel |