summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/thread.cpp
diff options
context:
space:
mode:
authorGravatar Subv2017-01-05 13:12:39 -0500
committerGravatar Subv2017-01-05 13:12:39 -0500
commit933df2606a34d4e609e890f45d0bef11e01da0ee (patch)
tree902f603a836ddc4679d86fd66da9db7ce9547ad4 /src/core/hle/kernel/thread.cpp
parentMerge pull request #2393 from Subv/synch (diff)
downloadyuzu-933df2606a34d4e609e890f45d0bef11e01da0ee.tar.gz
yuzu-933df2606a34d4e609e890f45d0bef11e01da0ee.tar.xz
yuzu-933df2606a34d4e609e890f45d0bef11e01da0ee.zip
Kernel: Removed the priority boost code for starved threads.
After hwtesting and reverse engineering the kernel, it was found that the CTROS scheduler performs no priority boosting for threads like this, although some other forms of scheduling priority-starved threads might take place. For example, it was found that hardware interrupts might cause low-priority threads to run if the CPU is preempted in the middle of an SVC handler that deschedules the current (high priority) thread before scheduling it again.
Diffstat (limited to 'src/core/hle/kernel/thread.cpp')
-rw-r--r--src/core/hle/kernel/thread.cpp27
1 files changed, 0 insertions, 27 deletions
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index 9109bd10b..5ff75803f 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -156,28 +156,6 @@ void ArbitrateAllThreads(u32 address) {
156 } 156 }
157} 157}
158 158
159/// Boost low priority threads (temporarily) that have been starved
160static void PriorityBoostStarvedThreads() {
161 u64 current_ticks = CoreTiming::GetTicks();
162
163 for (auto& thread : thread_list) {
164 // TODO(bunnei): Threads that have been waiting to be scheduled for `boost_ticks` (or
165 // longer) will have their priority temporarily adjusted to 1 higher than the highest
166 // priority thread to prevent thread starvation. This general behavior has been verified
167 // on hardware. However, this is almost certainly not perfect, and the real CTR OS scheduler
168 // should probably be reversed to verify this.
169
170 const u64 boost_timeout = 2000000; // Boost threads that have been ready for > this long
171
172 u64 delta = current_ticks - thread->last_running_ticks;
173
174 if (thread->status == THREADSTATUS_READY && delta > boost_timeout) {
175 const s32 priority = std::max(ready_queue.get_first()->current_priority - 1, 0);
176 thread->BoostPriority(priority);
177 }
178 }
179}
180
181/** 159/**
182 * Switches the CPU's active thread context to that of the specified thread 160 * Switches the CPU's active thread context to that of the specified thread
183 * @param new_thread The thread to switch to 161 * @param new_thread The thread to switch to
@@ -211,9 +189,6 @@ static void SwitchContext(Thread* new_thread) {
211 ready_queue.remove(new_thread->current_priority, new_thread); 189 ready_queue.remove(new_thread->current_priority, new_thread);
212 new_thread->status = THREADSTATUS_RUNNING; 190 new_thread->status = THREADSTATUS_RUNNING;
213 191
214 // Restores thread to its nominal priority if it has been temporarily changed
215 new_thread->current_priority = new_thread->nominal_priority;
216
217 Core::CPU().LoadContext(new_thread->context); 192 Core::CPU().LoadContext(new_thread->context);
218 Core::CPU().SetCP15Register(CP15_THREAD_URO, new_thread->GetTLSAddress()); 193 Core::CPU().SetCP15Register(CP15_THREAD_URO, new_thread->GetTLSAddress());
219 } else { 194 } else {
@@ -557,8 +532,6 @@ SharedPtr<Thread> SetupMainThread(u32 entry_point, s32 priority) {
557} 532}
558 533
559void Reschedule() { 534void Reschedule() {
560 PriorityBoostStarvedThreads();
561
562 Thread* cur = GetCurrentThread(); 535 Thread* cur = GetCurrentThread();
563 Thread* next = PopNextReadyThread(); 536 Thread* next = PopNextReadyThread();
564 537