summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/thread.h
diff options
context:
space:
mode:
authorGravatar David2019-10-28 10:53:27 +1100
committerGravatar GitHub2019-10-28 10:53:27 +1100
commit4c5731c34f0915457a31c60c9f70a2f169ea575d (patch)
tree7f03a7f892370b59e56ae06c6c74514f1cc44998 /src/core/hle/kernel/thread.h
parentMerge pull request #3034 from ReinUsesLisp/w4244-maxwell3d (diff)
parentKernel Thread: Cleanup THREADPROCESSORID_DONT_UPDATE. (diff)
downloadyuzu-4c5731c34f0915457a31c60c9f70a2f169ea575d.tar.gz
yuzu-4c5731c34f0915457a31c60c9f70a2f169ea575d.tar.xz
yuzu-4c5731c34f0915457a31c60c9f70a2f169ea575d.zip
Merge pull request #2971 from FernandoS27/new-scheduler-v2
Kernel: Implement a New Thread Scheduler V2
Diffstat (limited to 'src/core/hle/kernel/thread.h')
-rw-r--r--src/core/hle/kernel/thread.h74
1 files changed, 73 insertions, 1 deletions
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h
index 07e989637..c9870873d 100644
--- a/src/core/hle/kernel/thread.h
+++ b/src/core/hle/kernel/thread.h
@@ -75,6 +75,26 @@ enum class ThreadActivity : u32 {
75 Paused = 1, 75 Paused = 1,
76}; 76};
77 77
78enum class ThreadSchedStatus : u32 {
79 None = 0,
80 Paused = 1,
81 Runnable = 2,
82 Exited = 3,
83};
84
85enum class ThreadSchedFlags : u32 {
86 ProcessPauseFlag = 1 << 4,
87 ThreadPauseFlag = 1 << 5,
88 ProcessDebugPauseFlag = 1 << 6,
89 KernelInitPauseFlag = 1 << 8,
90};
91
92enum class ThreadSchedMasks : u32 {
93 LowMask = 0x000f,
94 HighMask = 0xfff0,
95 ForcePauseMask = 0x0070,
96};
97
78class Thread final : public WaitObject { 98class Thread final : public WaitObject {
79public: 99public:
80 using MutexWaitingThreads = std::vector<SharedPtr<Thread>>; 100 using MutexWaitingThreads = std::vector<SharedPtr<Thread>>;
@@ -278,6 +298,10 @@ public:
278 return processor_id; 298 return processor_id;
279 } 299 }
280 300
301 void SetProcessorID(s32 new_core) {
302 processor_id = new_core;
303 }
304
281 Process* GetOwnerProcess() { 305 Process* GetOwnerProcess() {
282 return owner_process; 306 return owner_process;
283 } 307 }
@@ -295,6 +319,9 @@ public:
295 } 319 }
296 320
297 void ClearWaitObjects() { 321 void ClearWaitObjects() {
322 for (const auto& waiting_object : wait_objects) {
323 waiting_object->RemoveWaitingThread(this);
324 }
298 wait_objects.clear(); 325 wait_objects.clear();
299 } 326 }
300 327
@@ -383,11 +410,47 @@ public:
383 /// Sleeps this thread for the given amount of nanoseconds. 410 /// Sleeps this thread for the given amount of nanoseconds.
384 void Sleep(s64 nanoseconds); 411 void Sleep(s64 nanoseconds);
385 412
413 /// Yields this thread without rebalancing loads.
414 bool YieldSimple();
415
416 /// Yields this thread and does a load rebalancing.
417 bool YieldAndBalanceLoad();
418
419 /// Yields this thread and if the core is left idle, loads are rebalanced
420 bool YieldAndWaitForLoadBalancing();
421
422 void IncrementYieldCount() {
423 yield_count++;
424 }
425
426 u64 GetYieldCount() const {
427 return yield_count;
428 }
429
430 ThreadSchedStatus GetSchedulingStatus() const {
431 return static_cast<ThreadSchedStatus>(scheduling_state &
432 static_cast<u32>(ThreadSchedMasks::LowMask));
433 }
434
435 bool IsRunning() const {
436 return is_running;
437 }
438
439 void SetIsRunning(bool value) {
440 is_running = value;
441 }
442
386private: 443private:
387 explicit Thread(KernelCore& kernel); 444 explicit Thread(KernelCore& kernel);
388 ~Thread() override; 445 ~Thread() override;
389 446
390 void ChangeScheduler(); 447 void SetSchedulingStatus(ThreadSchedStatus new_status);
448 void SetCurrentPriority(u32 new_priority);
449 ResultCode SetCoreAndAffinityMask(s32 new_core, u64 new_affinity_mask);
450
451 void AdjustSchedulingOnStatus(u32 old_flags);
452 void AdjustSchedulingOnPriority(u32 old_priority);
453 void AdjustSchedulingOnAffinity(u64 old_affinity_mask, s32 old_core);
391 454
392 Core::ARM_Interface::ThreadContext context{}; 455 Core::ARM_Interface::ThreadContext context{};
393 456
@@ -409,6 +472,8 @@ private:
409 472
410 u64 total_cpu_time_ticks = 0; ///< Total CPU running ticks. 473 u64 total_cpu_time_ticks = 0; ///< Total CPU running ticks.
411 u64 last_running_ticks = 0; ///< CPU tick when thread was last running 474 u64 last_running_ticks = 0; ///< CPU tick when thread was last running
475 u64 yield_count = 0; ///< Number of redundant yields carried by this thread.
476 ///< a redundant yield is one where no scheduling is changed
412 477
413 s32 processor_id = 0; 478 s32 processor_id = 0;
414 479
@@ -453,6 +518,13 @@ private:
453 518
454 ThreadActivity activity = ThreadActivity::Normal; 519 ThreadActivity activity = ThreadActivity::Normal;
455 520
521 s32 ideal_core_override = -1;
522 u64 affinity_mask_override = 0x1;
523 u32 affinity_override_count = 0;
524
525 u32 scheduling_state = 0;
526 bool is_running = false;
527
456 std::string name; 528 std::string name;
457}; 529};
458 530