diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/kernel/init/init_slab_setup.cpp | 54 | ||||
| -rw-r--r-- | src/core/hle/kernel/init/init_slab_setup.h | 9 | ||||
| -rw-r--r-- | src/core/hle/kernel/kernel.cpp | 12 | ||||
| -rw-r--r-- | src/core/hle/kernel/kernel.h | 10 |
4 files changed, 52 insertions, 33 deletions
diff --git a/src/core/hle/kernel/init/init_slab_setup.cpp b/src/core/hle/kernel/init/init_slab_setup.cpp index 2dd792e71..69ae405e6 100644 --- a/src/core/hle/kernel/init/init_slab_setup.cpp +++ b/src/core/hle/kernel/init/init_slab_setup.cpp | |||
| @@ -25,7 +25,7 @@ | |||
| 25 | 25 | ||
| 26 | namespace Kernel::Init { | 26 | namespace Kernel::Init { |
| 27 | 27 | ||
| 28 | #define SLAB_COUNT(CLASS) g_slab_resource_counts.num_##CLASS | 28 | #define SLAB_COUNT(CLASS) kernel.SlabResourceCounts().num_##CLASS |
| 29 | 29 | ||
| 30 | #define FOREACH_SLAB_TYPE(HANDLER, ...) \ | 30 | #define FOREACH_SLAB_TYPE(HANDLER, ...) \ |
| 31 | HANDLER(KProcess, (SLAB_COUNT(KProcess)), ##__VA_ARGS__) \ | 31 | HANDLER(KProcess, (SLAB_COUNT(KProcess)), ##__VA_ARGS__) \ |
| @@ -67,26 +67,6 @@ constexpr size_t SlabCountKBeta = 6; | |||
| 67 | 67 | ||
| 68 | constexpr size_t SlabCountExtraKThread = 160; | 68 | constexpr size_t SlabCountExtraKThread = 160; |
| 69 | 69 | ||
| 70 | // Global to hold our resource counts. | ||
| 71 | KSlabResourceCounts g_slab_resource_counts = { | ||
| 72 | .num_KProcess = SlabCountKProcess, | ||
| 73 | .num_KThread = SlabCountKThread, | ||
| 74 | .num_KEvent = SlabCountKEvent, | ||
| 75 | .num_KInterruptEvent = SlabCountKInterruptEvent, | ||
| 76 | .num_KPort = SlabCountKPort, | ||
| 77 | .num_KSharedMemory = SlabCountKSharedMemory, | ||
| 78 | .num_KTransferMemory = SlabCountKTransferMemory, | ||
| 79 | .num_KCodeMemory = SlabCountKCodeMemory, | ||
| 80 | .num_KDeviceAddressSpace = SlabCountKDeviceAddressSpace, | ||
| 81 | .num_KSession = SlabCountKSession, | ||
| 82 | .num_KLightSession = SlabCountKLightSession, | ||
| 83 | .num_KObjectName = SlabCountKObjectName, | ||
| 84 | .num_KResourceLimit = SlabCountKResourceLimit, | ||
| 85 | .num_KDebug = SlabCountKDebug, | ||
| 86 | .num_KAlpha = SlabCountKAlpha, | ||
| 87 | .num_KBeta = SlabCountKBeta, | ||
| 88 | }; | ||
| 89 | |||
| 90 | template <typename T> | 70 | template <typename T> |
| 91 | VAddr InitializeSlabHeap(Core::System& system, KMemoryLayout& memory_layout, VAddr address, | 71 | VAddr InitializeSlabHeap(Core::System& system, KMemoryLayout& memory_layout, VAddr address, |
| 92 | size_t num_objects) { | 72 | size_t num_objects) { |
| @@ -105,19 +85,35 @@ VAddr InitializeSlabHeap(Core::System& system, KMemoryLayout& memory_layout, VAd | |||
| 105 | 85 | ||
| 106 | } // namespace | 86 | } // namespace |
| 107 | 87 | ||
| 108 | const KSlabResourceCounts& GetSlabResourceCounts() { | 88 | KSlabResourceCounts KSlabResourceCounts::CreateDefault() { |
| 109 | return g_slab_resource_counts; | 89 | return { |
| 90 | .num_KProcess = SlabCountKProcess, | ||
| 91 | .num_KThread = SlabCountKThread, | ||
| 92 | .num_KEvent = SlabCountKEvent, | ||
| 93 | .num_KInterruptEvent = SlabCountKInterruptEvent, | ||
| 94 | .num_KPort = SlabCountKPort, | ||
| 95 | .num_KSharedMemory = SlabCountKSharedMemory, | ||
| 96 | .num_KTransferMemory = SlabCountKTransferMemory, | ||
| 97 | .num_KCodeMemory = SlabCountKCodeMemory, | ||
| 98 | .num_KDeviceAddressSpace = SlabCountKDeviceAddressSpace, | ||
| 99 | .num_KSession = SlabCountKSession, | ||
| 100 | .num_KLightSession = SlabCountKLightSession, | ||
| 101 | .num_KObjectName = SlabCountKObjectName, | ||
| 102 | .num_KResourceLimit = SlabCountKResourceLimit, | ||
| 103 | .num_KDebug = SlabCountKDebug, | ||
| 104 | .num_KAlpha = SlabCountKAlpha, | ||
| 105 | .num_KBeta = SlabCountKBeta, | ||
| 106 | }; | ||
| 110 | } | 107 | } |
| 111 | 108 | ||
| 112 | void InitializeSlabResourceCounts() { | 109 | void InitializeSlabResourceCounts(KernelCore& kernel) { |
| 113 | // Note: Nintendo initializes all fields here, but we initialize all constants at compile-time. | 110 | kernel.SlabResourceCounts() = KSlabResourceCounts::CreateDefault(); |
| 114 | |||
| 115 | if (KSystemControl::Init::ShouldIncreaseThreadResourceLimit()) { | 111 | if (KSystemControl::Init::ShouldIncreaseThreadResourceLimit()) { |
| 116 | g_slab_resource_counts.num_KThread += SlabCountExtraKThread; | 112 | kernel.SlabResourceCounts().num_KThread += SlabCountExtraKThread; |
| 117 | } | 113 | } |
| 118 | } | 114 | } |
| 119 | 115 | ||
| 120 | size_t CalculateTotalSlabHeapSize() { | 116 | size_t CalculateTotalSlabHeapSize(const KernelCore& kernel) { |
| 121 | size_t size = 0; | 117 | size_t size = 0; |
| 122 | 118 | ||
| 123 | #define ADD_SLAB_SIZE(NAME, COUNT, ...) \ | 119 | #define ADD_SLAB_SIZE(NAME, COUNT, ...) \ |
| @@ -138,6 +134,8 @@ size_t CalculateTotalSlabHeapSize() { | |||
| 138 | } | 134 | } |
| 139 | 135 | ||
| 140 | void InitializeSlabHeaps(Core::System& system, KMemoryLayout& memory_layout) { | 136 | void InitializeSlabHeaps(Core::System& system, KMemoryLayout& memory_layout) { |
| 137 | auto& kernel = system.Kernel(); | ||
| 138 | |||
| 141 | // Get the start of the slab region, since that's where we'll be working. | 139 | // Get the start of the slab region, since that's where we'll be working. |
| 142 | VAddr address = memory_layout.GetSlabRegionAddress(); | 140 | VAddr address = memory_layout.GetSlabRegionAddress(); |
| 143 | 141 | ||
diff --git a/src/core/hle/kernel/init/init_slab_setup.h b/src/core/hle/kernel/init/init_slab_setup.h index 6418b97ac..a8f7e0918 100644 --- a/src/core/hle/kernel/init/init_slab_setup.h +++ b/src/core/hle/kernel/init/init_slab_setup.h | |||
| @@ -9,12 +9,15 @@ class System; | |||
| 9 | } // namespace Core | 9 | } // namespace Core |
| 10 | 10 | ||
| 11 | namespace Kernel { | 11 | namespace Kernel { |
| 12 | class KernelCore; | ||
| 12 | class KMemoryLayout; | 13 | class KMemoryLayout; |
| 13 | } // namespace Kernel | 14 | } // namespace Kernel |
| 14 | 15 | ||
| 15 | namespace Kernel::Init { | 16 | namespace Kernel::Init { |
| 16 | 17 | ||
| 17 | struct KSlabResourceCounts { | 18 | struct KSlabResourceCounts { |
| 19 | static KSlabResourceCounts CreateDefault(); | ||
| 20 | |||
| 18 | size_t num_KProcess; | 21 | size_t num_KProcess; |
| 19 | size_t num_KThread; | 22 | size_t num_KThread; |
| 20 | size_t num_KEvent; | 23 | size_t num_KEvent; |
| @@ -33,10 +36,8 @@ struct KSlabResourceCounts { | |||
| 33 | size_t num_KBeta; | 36 | size_t num_KBeta; |
| 34 | }; | 37 | }; |
| 35 | 38 | ||
| 36 | void InitializeSlabResourceCounts(); | 39 | void InitializeSlabResourceCounts(KernelCore& kernel); |
| 37 | const KSlabResourceCounts& GetSlabResourceCounts(); | 40 | size_t CalculateTotalSlabHeapSize(const KernelCore& kernel); |
| 38 | |||
| 39 | size_t CalculateTotalSlabHeapSize(); | ||
| 40 | void InitializeSlabHeaps(Core::System& system, KMemoryLayout& memory_layout); | 41 | void InitializeSlabHeaps(Core::System& system, KMemoryLayout& memory_layout); |
| 41 | 42 | ||
| 42 | } // namespace Kernel::Init | 43 | } // namespace Kernel::Init |
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 5ebd47e49..32bbf2d9b 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp | |||
| @@ -69,6 +69,7 @@ struct KernelCore::Impl { | |||
| 69 | InitializePhysicalCores(); | 69 | InitializePhysicalCores(); |
| 70 | 70 | ||
| 71 | // Derive the initial memory layout from the emulated board | 71 | // Derive the initial memory layout from the emulated board |
| 72 | Init::InitializeSlabResourceCounts(kernel); | ||
| 72 | KMemoryLayout memory_layout; | 73 | KMemoryLayout memory_layout; |
| 73 | DeriveInitialMemoryLayout(memory_layout); | 74 | DeriveInitialMemoryLayout(memory_layout); |
| 74 | Init::InitializeSlabHeaps(system, memory_layout); | 75 | Init::InitializeSlabHeaps(system, memory_layout); |
| @@ -395,7 +396,7 @@ struct KernelCore::Impl { | |||
| 395 | 396 | ||
| 396 | // Determine the size of the slab region. | 397 | // Determine the size of the slab region. |
| 397 | const size_t slab_region_size = | 398 | const size_t slab_region_size = |
| 398 | Common::AlignUp(Init::CalculateTotalSlabHeapSize(), PageSize); | 399 | Common::AlignUp(Init::CalculateTotalSlabHeapSize(system.Kernel()), PageSize); |
| 399 | ASSERT(slab_region_size <= resource_region_size); | 400 | ASSERT(slab_region_size <= resource_region_size); |
| 400 | 401 | ||
| 401 | // Setup the slab region. | 402 | // Setup the slab region. |
| @@ -642,6 +643,7 @@ struct KernelCore::Impl { | |||
| 642 | std::unique_ptr<Kernel::GlobalSchedulerContext> global_scheduler_context; | 643 | std::unique_ptr<Kernel::GlobalSchedulerContext> global_scheduler_context; |
| 643 | Kernel::TimeManager time_manager; | 644 | Kernel::TimeManager time_manager; |
| 644 | 645 | ||
| 646 | Init::KSlabResourceCounts slab_resource_counts{}; | ||
| 645 | KResourceLimit* system_resource_limit{}; | 647 | KResourceLimit* system_resource_limit{}; |
| 646 | 648 | ||
| 647 | std::shared_ptr<Core::Timing::EventType> preemption_event; | 649 | std::shared_ptr<Core::Timing::EventType> preemption_event; |
| @@ -995,6 +997,14 @@ void KernelCore::ReleaseServiceThread(std::weak_ptr<Kernel::ServiceThread> servi | |||
| 995 | }); | 997 | }); |
| 996 | } | 998 | } |
| 997 | 999 | ||
| 1000 | Init::KSlabResourceCounts& KernelCore::SlabResourceCounts() { | ||
| 1001 | return impl->slab_resource_counts; | ||
| 1002 | } | ||
| 1003 | |||
| 1004 | const Init::KSlabResourceCounts& KernelCore::SlabResourceCounts() const { | ||
| 1005 | return impl->slab_resource_counts; | ||
| 1006 | } | ||
| 1007 | |||
| 998 | bool KernelCore::IsPhantomModeForSingleCore() const { | 1008 | bool KernelCore::IsPhantomModeForSingleCore() const { |
| 999 | return impl->IsPhantomModeForSingleCore(); | 1009 | return impl->IsPhantomModeForSingleCore(); |
| 1000 | } | 1010 | } |
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index 7c46aa997..51aaccbc7 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h | |||
| @@ -51,6 +51,10 @@ class ServiceThread; | |||
| 51 | class Synchronization; | 51 | class Synchronization; |
| 52 | class TimeManager; | 52 | class TimeManager; |
| 53 | 53 | ||
| 54 | namespace Init { | ||
| 55 | struct KSlabResourceCounts; | ||
| 56 | } | ||
| 57 | |||
| 54 | template <typename T> | 58 | template <typename T> |
| 55 | class KSlabHeap; | 59 | class KSlabHeap; |
| 56 | 60 | ||
| @@ -292,6 +296,12 @@ public: | |||
| 292 | } | 296 | } |
| 293 | } | 297 | } |
| 294 | 298 | ||
| 299 | /// Gets the current slab resource counts. | ||
| 300 | Init::KSlabResourceCounts& SlabResourceCounts(); | ||
| 301 | |||
| 302 | /// Gets the current slab resource counts. | ||
| 303 | const Init::KSlabResourceCounts& SlabResourceCounts() const; | ||
| 304 | |||
| 295 | private: | 305 | private: |
| 296 | friend class KProcess; | 306 | friend class KProcess; |
| 297 | friend class KThread; | 307 | friend class KThread; |