summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/process.h
diff options
context:
space:
mode:
authorGravatar bunnei2021-01-29 23:06:40 -0800
committerGravatar GitHub2021-01-29 23:06:40 -0800
commita4526c4e1acb50808bbe205952101142288e1c60 (patch)
tree7109edf89606c43352da9de40d0e3a920a08b659 /src/core/hle/kernel/process.h
parentMerge pull request #5795 from ReinUsesLisp/bytes-to-map-end (diff)
parenthle: kernel: KLightLock: Fix several bugs. (diff)
downloadyuzu-a4526c4e1acb50808bbe205952101142288e1c60.tar.gz
yuzu-a4526c4e1acb50808bbe205952101142288e1c60.tar.xz
yuzu-a4526c4e1acb50808bbe205952101142288e1c60.zip
Merge pull request #5779 from bunnei/kthread-rewrite
Rewrite KThread to be more accurate
Diffstat (limited to 'src/core/hle/kernel/process.h')
-rw-r--r--src/core/hle/kernel/process.h88
1 files changed, 82 insertions, 6 deletions
diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h
index 564e1f27d..26e647743 100644
--- a/src/core/hle/kernel/process.h
+++ b/src/core/hle/kernel/process.h
@@ -30,7 +30,7 @@ namespace Kernel {
30 30
31class KernelCore; 31class KernelCore;
32class ResourceLimit; 32class ResourceLimit;
33class Thread; 33class KThread;
34class TLSPage; 34class TLSPage;
35 35
36struct CodeSet; 36struct CodeSet;
@@ -173,10 +173,15 @@ public:
173 std::shared_ptr<ResourceLimit> GetResourceLimit() const; 173 std::shared_ptr<ResourceLimit> GetResourceLimit() const;
174 174
175 /// Gets the ideal CPU core ID for this process 175 /// Gets the ideal CPU core ID for this process
176 u8 GetIdealCore() const { 176 u8 GetIdealCoreId() const {
177 return ideal_core; 177 return ideal_core;
178 } 178 }
179 179
180 /// Checks if the specified thread priority is valid.
181 bool CheckThreadPriority(s32 prio) const {
182 return ((1ULL << prio) & GetPriorityMask()) != 0;
183 }
184
180 /// Gets the bitmask of allowed cores that this process' threads can run on. 185 /// Gets the bitmask of allowed cores that this process' threads can run on.
181 u64 GetCoreMask() const { 186 u64 GetCoreMask() const {
182 return capabilities.GetCoreMask(); 187 return capabilities.GetCoreMask();
@@ -212,6 +217,14 @@ public:
212 return is_64bit_process; 217 return is_64bit_process;
213 } 218 }
214 219
220 [[nodiscard]] bool IsSuspended() const {
221 return is_suspended;
222 }
223
224 void SetSuspended(bool suspended) {
225 is_suspended = suspended;
226 }
227
215 /// Gets the total running time of the process instance in ticks. 228 /// Gets the total running time of the process instance in ticks.
216 u64 GetCPUTimeTicks() const { 229 u64 GetCPUTimeTicks() const {
217 return total_process_running_time_ticks; 230 return total_process_running_time_ticks;
@@ -232,6 +245,33 @@ public:
232 ++schedule_count; 245 ++schedule_count;
233 } 246 }
234 247
248 void IncrementThreadCount();
249 void DecrementThreadCount();
250
251 void SetRunningThread(s32 core, KThread* thread, u64 idle_count) {
252 running_threads[core] = thread;
253 running_thread_idle_counts[core] = idle_count;
254 }
255
256 void ClearRunningThread(KThread* thread) {
257 for (size_t i = 0; i < running_threads.size(); ++i) {
258 if (running_threads[i] == thread) {
259 running_threads[i] = nullptr;
260 }
261 }
262 }
263
264 [[nodiscard]] KThread* GetRunningThread(s32 core) const {
265 return running_threads[core];
266 }
267
268 bool ReleaseUserException(KThread* thread);
269
270 [[nodiscard]] KThread* GetPinnedThread(s32 core_id) const {
271 ASSERT(0 <= core_id && core_id < static_cast<s32>(Core::Hardware::NUM_CPU_CORES));
272 return pinned_threads[core_id];
273 }
274
235 /// Gets 8 bytes of random data for svcGetInfo RandomEntropy 275 /// Gets 8 bytes of random data for svcGetInfo RandomEntropy
236 u64 GetRandomEntropy(std::size_t index) const { 276 u64 GetRandomEntropy(std::size_t index) const {
237 return random_entropy.at(index); 277 return random_entropy.at(index);
@@ -252,17 +292,17 @@ public:
252 u64 GetTotalPhysicalMemoryUsedWithoutSystemResource() const; 292 u64 GetTotalPhysicalMemoryUsedWithoutSystemResource() const;
253 293
254 /// Gets the list of all threads created with this process as their owner. 294 /// Gets the list of all threads created with this process as their owner.
255 const std::list<const Thread*>& GetThreadList() const { 295 const std::list<const KThread*>& GetThreadList() const {
256 return thread_list; 296 return thread_list;
257 } 297 }
258 298
259 /// Registers a thread as being created under this process, 299 /// Registers a thread as being created under this process,
260 /// adding it to this process' thread list. 300 /// adding it to this process' thread list.
261 void RegisterThread(const Thread* thread); 301 void RegisterThread(const KThread* thread);
262 302
263 /// Unregisters a thread from this process, removing it 303 /// Unregisters a thread from this process, removing it
264 /// from this process' thread list. 304 /// from this process' thread list.
265 void UnregisterThread(const Thread* thread); 305 void UnregisterThread(const KThread* thread);
266 306
267 /// Clears the signaled state of the process if and only if it's signaled. 307 /// Clears the signaled state of the process if and only if it's signaled.
268 /// 308 ///
@@ -303,6 +343,15 @@ public:
303 343
304 bool IsSignaled() const override; 344 bool IsSignaled() const override;
305 345
346 void Finalize() override {}
347
348 void PinCurrentThread();
349 void UnpinCurrentThread();
350
351 KLightLock& GetStateLock() {
352 return state_lock;
353 }
354
306 /////////////////////////////////////////////////////////////////////////////////////////////// 355 ///////////////////////////////////////////////////////////////////////////////////////////////
307 // Thread-local storage management 356 // Thread-local storage management
308 357
@@ -313,6 +362,20 @@ public:
313 void FreeTLSRegion(VAddr tls_address); 362 void FreeTLSRegion(VAddr tls_address);
314 363
315private: 364private:
365 void PinThread(s32 core_id, KThread* thread) {
366 ASSERT(0 <= core_id && core_id < static_cast<s32>(Core::Hardware::NUM_CPU_CORES));
367 ASSERT(thread != nullptr);
368 ASSERT(pinned_threads[core_id] == nullptr);
369 pinned_threads[core_id] = thread;
370 }
371
372 void UnpinThread(s32 core_id, KThread* thread) {
373 ASSERT(0 <= core_id && core_id < static_cast<s32>(Core::Hardware::NUM_CPU_CORES));
374 ASSERT(thread != nullptr);
375 ASSERT(pinned_threads[core_id] == thread);
376 pinned_threads[core_id] = nullptr;
377 }
378
316 /// Changes the process status. If the status is different 379 /// Changes the process status. If the status is different
317 /// from the current process status, then this will trigger 380 /// from the current process status, then this will trigger
318 /// a process signal. 381 /// a process signal.
@@ -380,7 +443,7 @@ private:
380 std::array<u64, RANDOM_ENTROPY_SIZE> random_entropy{}; 443 std::array<u64, RANDOM_ENTROPY_SIZE> random_entropy{};
381 444
382 /// List of threads that are running with this process as their owner. 445 /// List of threads that are running with this process as their owner.
383 std::list<const Thread*> thread_list; 446 std::list<const KThread*> thread_list;
384 447
385 /// Address of the top of the main thread's stack 448 /// Address of the top of the main thread's stack
386 VAddr main_thread_stack_top{}; 449 VAddr main_thread_stack_top{};
@@ -401,6 +464,19 @@ private:
401 s64 schedule_count{}; 464 s64 schedule_count{};
402 465
403 bool is_signaled{}; 466 bool is_signaled{};
467 bool is_suspended{};
468
469 std::atomic<s32> num_created_threads{};
470 std::atomic<u16> num_threads{};
471 u16 peak_num_threads{};
472
473 std::array<KThread*, Core::Hardware::NUM_CPU_CORES> running_threads{};
474 std::array<u64, Core::Hardware::NUM_CPU_CORES> running_thread_idle_counts{};
475 std::array<KThread*, Core::Hardware::NUM_CPU_CORES> pinned_threads{};
476
477 KThread* exception_thread{};
478
479 KLightLock state_lock;
404 480
405 /// System context 481 /// System context
406 Core::System& system; 482 Core::System& system;