summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Lioncash2019-10-27 22:01:45 -0400
committerGravatar Lioncash2019-10-27 22:12:32 -0400
commit2dc469cebac90462fcc48edcf5c1b77148825957 (patch)
treec22a32ed1a1990d9bfac0b49f013a2a4ac4ba0b4
parentMerge pull request #2971 from FernandoS27/new-scheduler-v2 (diff)
downloadyuzu-2dc469cebac90462fcc48edcf5c1b77148825957.tar.gz
yuzu-2dc469cebac90462fcc48edcf5c1b77148825957.tar.xz
yuzu-2dc469cebac90462fcc48edcf5c1b77148825957.zip
scheduler: Amend documentation comments
Adjusts the formatting of a few of the comments an ensures they get recognized as proper Doxygen comments.
-rw-r--r--src/core/hle/kernel/scheduler.cpp29
-rw-r--r--src/core/hle/kernel/scheduler.h105
2 files changed, 59 insertions, 75 deletions
diff --git a/src/core/hle/kernel/scheduler.cpp b/src/core/hle/kernel/scheduler.cpp
index e6dcb9639..53281cc6c 100644
--- a/src/core/hle/kernel/scheduler.cpp
+++ b/src/core/hle/kernel/scheduler.cpp
@@ -35,24 +35,11 @@ void GlobalScheduler::RemoveThread(const Thread* thread) {
35 thread_list.end()); 35 thread_list.end());
36} 36}
37 37
38/*
39 * UnloadThread selects a core and forces it to unload its current thread's context
40 */
41void GlobalScheduler::UnloadThread(s32 core) { 38void GlobalScheduler::UnloadThread(s32 core) {
42 Scheduler& sched = system.Scheduler(core); 39 Scheduler& sched = system.Scheduler(core);
43 sched.UnloadThread(); 40 sched.UnloadThread();
44} 41}
45 42
46/*
47 * SelectThread takes care of selecting the new scheduled thread.
48 * It does it in 3 steps:
49 * - First a thread is selected from the top of the priority queue. If no thread
50 * is obtained then we move to step two, else we are done.
51 * - Second we try to get a suggested thread that's not assigned to any core or
52 * that is not the top thread in that core.
53 * - Third is no suggested thread is found, we do a second pass and pick a running
54 * thread in another core and swap it with its current thread.
55 */
56void GlobalScheduler::SelectThread(u32 core) { 43void GlobalScheduler::SelectThread(u32 core) {
57 const auto update_thread = [](Thread* thread, Scheduler& sched) { 44 const auto update_thread = [](Thread* thread, Scheduler& sched) {
58 if (thread != sched.selected_thread) { 45 if (thread != sched.selected_thread) {
@@ -114,10 +101,6 @@ void GlobalScheduler::SelectThread(u32 core) {
114 update_thread(current_thread, sched); 101 update_thread(current_thread, sched);
115} 102}
116 103
117/*
118 * YieldThread takes a thread and moves it to the back of the it's priority list
119 * This operation can be redundant and no scheduling is changed if marked as so.
120 */
121bool GlobalScheduler::YieldThread(Thread* yielding_thread) { 104bool GlobalScheduler::YieldThread(Thread* yielding_thread) {
122 // Note: caller should use critical section, etc. 105 // Note: caller should use critical section, etc.
123 const u32 core_id = static_cast<u32>(yielding_thread->GetProcessorID()); 106 const u32 core_id = static_cast<u32>(yielding_thread->GetProcessorID());
@@ -132,12 +115,6 @@ bool GlobalScheduler::YieldThread(Thread* yielding_thread) {
132 return AskForReselectionOrMarkRedundant(yielding_thread, winner); 115 return AskForReselectionOrMarkRedundant(yielding_thread, winner);
133} 116}
134 117
135/*
136 * YieldThreadAndBalanceLoad takes a thread and moves it to the back of the it's priority list.
137 * Afterwards, tries to pick a suggested thread from the suggested queue that has worse time or
138 * a better priority than the next thread in the core.
139 * This operation can be redundant and no scheduling is changed if marked as so.
140 */
141bool GlobalScheduler::YieldThreadAndBalanceLoad(Thread* yielding_thread) { 118bool GlobalScheduler::YieldThreadAndBalanceLoad(Thread* yielding_thread) {
142 // Note: caller should check if !thread.IsSchedulerOperationRedundant and use critical section, 119 // Note: caller should check if !thread.IsSchedulerOperationRedundant and use critical section,
143 // etc. 120 // etc.
@@ -189,12 +166,6 @@ bool GlobalScheduler::YieldThreadAndBalanceLoad(Thread* yielding_thread) {
189 return AskForReselectionOrMarkRedundant(yielding_thread, winner); 166 return AskForReselectionOrMarkRedundant(yielding_thread, winner);
190} 167}
191 168
192/*
193 * YieldThreadAndWaitForLoadBalancing takes a thread and moves it out of the scheduling queue
194 * and into the suggested queue. If no thread can be squeduled afterwards in that core,
195 * a suggested thread is obtained instead.
196 * This operation can be redundant and no scheduling is changed if marked as so.
197 */
198bool GlobalScheduler::YieldThreadAndWaitForLoadBalancing(Thread* yielding_thread) { 169bool GlobalScheduler::YieldThreadAndWaitForLoadBalancing(Thread* yielding_thread) {
199 // Note: caller should check if !thread.IsSchedulerOperationRedundant and use critical section, 170 // Note: caller should check if !thread.IsSchedulerOperationRedundant and use critical section,
200 // etc. 171 // etc.
diff --git a/src/core/hle/kernel/scheduler.h b/src/core/hle/kernel/scheduler.h
index fcae28e0a..8f1f39c59 100644
--- a/src/core/hle/kernel/scheduler.h
+++ b/src/core/hle/kernel/scheduler.h
@@ -26,6 +26,7 @@ public:
26 26
27 explicit GlobalScheduler(Core::System& system); 27 explicit GlobalScheduler(Core::System& system);
28 ~GlobalScheduler(); 28 ~GlobalScheduler();
29
29 /// Adds a new thread to the scheduler 30 /// Adds a new thread to the scheduler
30 void AddThread(SharedPtr<Thread> thread); 31 void AddThread(SharedPtr<Thread> thread);
31 32
@@ -37,47 +38,57 @@ public:
37 return thread_list; 38 return thread_list;
38 } 39 }
39 40
40 // Add a thread to the suggested queue of a cpu core. Suggested threads may be 41 /**
41 // picked if no thread is scheduled to run on the core. 42 * Add a thread to the suggested queue of a cpu core. Suggested threads may be
43 * picked if no thread is scheduled to run on the core.
44 */
42 void Suggest(u32 priority, u32 core, Thread* thread); 45 void Suggest(u32 priority, u32 core, Thread* thread);
43 46
44 // Remove a thread to the suggested queue of a cpu core. Suggested threads may be 47 /**
45 // picked if no thread is scheduled to run on the core. 48 * Remove a thread to the suggested queue of a cpu core. Suggested threads may be
49 * picked if no thread is scheduled to run on the core.
50 */
46 void Unsuggest(u32 priority, u32 core, Thread* thread); 51 void Unsuggest(u32 priority, u32 core, Thread* thread);
47 52
48 // Add a thread to the scheduling queue of a cpu core. The thread is added at the 53 /**
49 // back the queue in its priority level 54 * Add a thread to the scheduling queue of a cpu core. The thread is added at the
55 * back the queue in its priority level.
56 */
50 void Schedule(u32 priority, u32 core, Thread* thread); 57 void Schedule(u32 priority, u32 core, Thread* thread);
51 58
52 // Add a thread to the scheduling queue of a cpu core. The thread is added at the 59 /**
53 // front the queue in its priority level 60 * Add a thread to the scheduling queue of a cpu core. The thread is added at the
61 * front the queue in its priority level.
62 */
54 void SchedulePrepend(u32 priority, u32 core, Thread* thread); 63 void SchedulePrepend(u32 priority, u32 core, Thread* thread);
55 64
56 // Reschedule an already scheduled thread based on a new priority 65 /// Reschedule an already scheduled thread based on a new priority
57 void Reschedule(u32 priority, u32 core, Thread* thread); 66 void Reschedule(u32 priority, u32 core, Thread* thread);
58 67
59 // Unschedule a thread. 68 /// Unschedules a thread.
60 void Unschedule(u32 priority, u32 core, Thread* thread); 69 void Unschedule(u32 priority, u32 core, Thread* thread);
61 70
62 // Transfers a thread into an specific core. If the destination_core is -1 71 /**
63 // it will be unscheduled from its source code and added into its suggested 72 * Transfers a thread into an specific core. If the destination_core is -1
64 // queue. 73 * it will be unscheduled from its source code and added into its suggested
74 * queue.
75 */
65 void TransferToCore(u32 priority, s32 destination_core, Thread* thread); 76 void TransferToCore(u32 priority, s32 destination_core, Thread* thread);
66 77
67 /* 78 /// Selects a core and forces it to unload its current thread's context
68 * UnloadThread selects a core and forces it to unload its current thread's context
69 */
70 void UnloadThread(s32 core); 79 void UnloadThread(s32 core);
71 80
72 /* 81 /**
73 * SelectThread takes care of selecting the new scheduled thread. 82 * Takes care of selecting the new scheduled thread in three steps:
74 * It does it in 3 steps: 83 *
75 * - First a thread is selected from the top of the priority queue. If no thread 84 * 1. First a thread is selected from the top of the priority queue. If no thread
76 * is obtained then we move to step two, else we are done. 85 * is obtained then we move to step two, else we are done.
77 * - Second we try to get a suggested thread that's not assigned to any core or 86 *
78 * that is not the top thread in that core. 87 * 2. Second we try to get a suggested thread that's not assigned to any core or
79 * - Third is no suggested thread is found, we do a second pass and pick a running 88 * that is not the top thread in that core.
80 * thread in another core and swap it with its current thread. 89 *
90 * 3. Third is no suggested thread is found, we do a second pass and pick a running
91 * thread in another core and swap it with its current thread.
81 */ 92 */
82 void SelectThread(u32 core); 93 void SelectThread(u32 core);
83 94
@@ -85,33 +96,37 @@ public:
85 return !scheduled_queue[core_id].empty(); 96 return !scheduled_queue[core_id].empty();
86 } 97 }
87 98
88 /* 99 /**
89 * YieldThread takes a thread and moves it to the back of the it's priority list 100 * Takes a thread and moves it to the back of the it's priority list.
90 * This operation can be redundant and no scheduling is changed if marked as so. 101 *
102 * @note This operation can be redundant and no scheduling is changed if marked as so.
91 */ 103 */
92 bool YieldThread(Thread* thread); 104 bool YieldThread(Thread* thread);
93 105
94 /* 106 /**
95 * YieldThreadAndBalanceLoad takes a thread and moves it to the back of the it's priority list. 107 * Takes a thread and moves it to the back of the it's priority list.
96 * Afterwards, tries to pick a suggested thread from the suggested queue that has worse time or 108 * Afterwards, tries to pick a suggested thread from the suggested queue that has worse time or
97 * a better priority than the next thread in the core. 109 * a better priority than the next thread in the core.
98 * This operation can be redundant and no scheduling is changed if marked as so. 110 *
111 * @note This operation can be redundant and no scheduling is changed if marked as so.
99 */ 112 */
100 bool YieldThreadAndBalanceLoad(Thread* thread); 113 bool YieldThreadAndBalanceLoad(Thread* thread);
101 114
102 /* 115 /**
103 * YieldThreadAndWaitForLoadBalancing takes a thread and moves it out of the scheduling queue 116 * Takes a thread and moves it out of the scheduling queue.
104 * and into the suggested queue. If no thread can be squeduled afterwards in that core, 117 * and into the suggested queue. If no thread can be scheduled afterwards in that core,
105 * a suggested thread is obtained instead. 118 * a suggested thread is obtained instead.
106 * This operation can be redundant and no scheduling is changed if marked as so. 119 *
120 * @note This operation can be redundant and no scheduling is changed if marked as so.
107 */ 121 */
108 bool YieldThreadAndWaitForLoadBalancing(Thread* thread); 122 bool YieldThreadAndWaitForLoadBalancing(Thread* thread);
109 123
110 /* 124 /**
111 * PreemptThreads this operation rotates the scheduling queues of threads at 125 * Rotates the scheduling queues of threads at a preemption priority and then does
112 * a preemption priority and then does some core rebalancing. Preemption priorities 126 * some core rebalancing. Preemption priorities can be found in the array
113 * can be found in the array 'preemption_priorities'. This operation happens 127 * 'preemption_priorities'.
114 * every 10ms. 128 *
129 * @note This operation happens every 10ms.
115 */ 130 */
116 void PreemptThreads(); 131 void PreemptThreads();
117 132
@@ -137,8 +152,8 @@ private:
137 std::array<Common::MultiLevelQueue<Thread*, THREADPRIO_COUNT>, NUM_CPU_CORES> suggested_queue; 152 std::array<Common::MultiLevelQueue<Thread*, THREADPRIO_COUNT>, NUM_CPU_CORES> suggested_queue;
138 std::atomic<bool> is_reselection_pending; 153 std::atomic<bool> is_reselection_pending;
139 154
140 // `preemption_priorities` are the priority levels at which the global scheduler 155 // The priority levels at which the global scheduler preempts threads every 10 ms. They are
141 // preempts threads every 10 ms. They are ordered from Core 0 to Core 3 156 // ordered from Core 0 to Core 3.
142 std::array<u32, NUM_CPU_CORES> preemption_priorities = {59, 59, 59, 62}; 157 std::array<u32, NUM_CPU_CORES> preemption_priorities = {59, 59, 59, 62};
143 158
144 /// Lists all thread ids that aren't deleted/etc. 159 /// Lists all thread ids that aren't deleted/etc.
@@ -181,10 +196,8 @@ public:
181 196
182private: 197private:
183 friend class GlobalScheduler; 198 friend class GlobalScheduler;
184 /** 199
185 * Switches the CPU's active thread context to that of the specified thread 200 /// Switches the CPU's active thread context to that of the specified thread
186 * @param new_thread The thread to switch to
187 */
188 void SwitchContext(); 201 void SwitchContext();
189 202
190 /** 203 /**