summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/hle/kernel/init/init_slab_setup.cpp54
-rw-r--r--src/core/hle/kernel/init/init_slab_setup.h9
-rw-r--r--src/core/hle/kernel/kernel.cpp12
-rw-r--r--src/core/hle/kernel/kernel.h10
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
26namespace Kernel::Init { 26namespace 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
68constexpr size_t SlabCountExtraKThread = 160; 68constexpr size_t SlabCountExtraKThread = 160;
69 69
70// Global to hold our resource counts.
71KSlabResourceCounts 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
90template <typename T> 70template <typename T>
91VAddr InitializeSlabHeap(Core::System& system, KMemoryLayout& memory_layout, VAddr address, 71VAddr 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
108const KSlabResourceCounts& GetSlabResourceCounts() { 88KSlabResourceCounts 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
112void InitializeSlabResourceCounts() { 109void 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
120size_t CalculateTotalSlabHeapSize() { 116size_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
140void InitializeSlabHeaps(Core::System& system, KMemoryLayout& memory_layout) { 136void 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
11namespace Kernel { 11namespace Kernel {
12class KernelCore;
12class KMemoryLayout; 13class KMemoryLayout;
13} // namespace Kernel 14} // namespace Kernel
14 15
15namespace Kernel::Init { 16namespace Kernel::Init {
16 17
17struct KSlabResourceCounts { 18struct 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
36void InitializeSlabResourceCounts(); 39void InitializeSlabResourceCounts(KernelCore& kernel);
37const KSlabResourceCounts& GetSlabResourceCounts(); 40size_t CalculateTotalSlabHeapSize(const KernelCore& kernel);
38
39size_t CalculateTotalSlabHeapSize();
40void InitializeSlabHeaps(Core::System& system, KMemoryLayout& memory_layout); 41void 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
1000Init::KSlabResourceCounts& KernelCore::SlabResourceCounts() {
1001 return impl->slab_resource_counts;
1002}
1003
1004const Init::KSlabResourceCounts& KernelCore::SlabResourceCounts() const {
1005 return impl->slab_resource_counts;
1006}
1007
998bool KernelCore::IsPhantomModeForSingleCore() const { 1008bool 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;
51class Synchronization; 51class Synchronization;
52class TimeManager; 52class TimeManager;
53 53
54namespace Init {
55struct KSlabResourceCounts;
56}
57
54template <typename T> 58template <typename T>
55class KSlabHeap; 59class 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
295private: 305private:
296 friend class KProcess; 306 friend class KProcess;
297 friend class KThread; 307 friend class KThread;