diff options
| author | 2015-04-03 18:40:16 -0400 | |
|---|---|---|
| committer | 2015-04-09 19:06:39 -0400 | |
| commit | 9c3419ebccf046e0a123e0516ea134547393e451 (patch) | |
| tree | 24073b71ade88e5f99db439b824228bdc6b2737d /src | |
| parent | Thread: Implement priority boost for starved threads. (diff) | |
| download | yuzu-9c3419ebccf046e0a123e0516ea134547393e451.tar.gz yuzu-9c3419ebccf046e0a123e0516ea134547393e451.tar.xz yuzu-9c3419ebccf046e0a123e0516ea134547393e451.zip | |
Kernel: Implemented priority inheritance for mutexes.
Diffstat (limited to '')
| -rw-r--r-- | src/core/hle/kernel/mutex.cpp | 10 | ||||
| -rw-r--r-- | src/core/hle/kernel/thread.cpp | 10 | ||||
| -rw-r--r-- | src/core/hle/kernel/thread.h | 6 |
3 files changed, 22 insertions, 4 deletions
diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp index be2c49706..ebc9e79d7 100644 --- a/src/core/hle/kernel/mutex.cpp +++ b/src/core/hle/kernel/mutex.cpp | |||
| @@ -56,7 +56,15 @@ SharedPtr<Mutex> Mutex::Create(bool initial_locked, std::string name) { | |||
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | bool Mutex::ShouldWait() { | 58 | bool Mutex::ShouldWait() { |
| 59 | return lock_count > 0 && holding_thread != GetCurrentThread();; | 59 | auto thread = GetCurrentThread(); |
| 60 | bool wait = lock_count > 0 && holding_thread != thread; | ||
| 61 | |||
| 62 | // If the holding thread of the mutex is lower priority than this thread, that thread should | ||
| 63 | // temporarily inherit this thread's priority | ||
| 64 | if (wait && thread->current_priority < holding_thread->current_priority) | ||
| 65 | holding_thread->BoostPriority(thread->current_priority); | ||
| 66 | |||
| 67 | return wait; | ||
| 60 | } | 68 | } |
| 61 | 69 | ||
| 62 | void Mutex::Acquire() { | 70 | void Mutex::Acquire() { |
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 3a1e15ac6..33d66b986 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp | |||
| @@ -156,9 +156,8 @@ static void PriorityBoostStarvedThreads() { | |||
| 156 | u64 delta = current_ticks - thread->last_running_ticks; | 156 | u64 delta = current_ticks - thread->last_running_ticks; |
| 157 | 157 | ||
| 158 | if (thread->status == THREADSTATUS_READY && delta > boost_timeout && !thread->idle) { | 158 | if (thread->status == THREADSTATUS_READY && delta > boost_timeout && !thread->idle) { |
| 159 | const s32 boost_priority = std::max(ready_queue.get_first()->current_priority - 1, 0); | 159 | const s32 priority = std::max(ready_queue.get_first()->current_priority - 1, 0); |
| 160 | ready_queue.move(thread, thread->current_priority, boost_priority); | 160 | thread->BoostPriority(priority); |
| 161 | thread->current_priority = boost_priority; | ||
| 162 | } | 161 | } |
| 163 | } | 162 | } |
| 164 | } | 163 | } |
| @@ -435,6 +434,11 @@ void Thread::SetPriority(s32 priority) { | |||
| 435 | nominal_priority = current_priority = priority; | 434 | nominal_priority = current_priority = priority; |
| 436 | } | 435 | } |
| 437 | 436 | ||
| 437 | void Thread::BoostPriority(s32 priority) { | ||
| 438 | ready_queue.move(this, current_priority, priority); | ||
| 439 | current_priority = priority; | ||
| 440 | } | ||
| 441 | |||
| 438 | SharedPtr<Thread> SetupIdleThread() { | 442 | SharedPtr<Thread> SetupIdleThread() { |
| 439 | // We need to pass a few valid values to get around parameter checking in Thread::Create. | 443 | // We need to pass a few valid values to get around parameter checking in Thread::Create. |
| 440 | auto thread = Thread::Create("idle", Memory::KERNEL_MEMORY_VADDR, THREADPRIO_LOWEST, 0, | 444 | auto thread = Thread::Create("idle", Memory::KERNEL_MEMORY_VADDR, THREADPRIO_LOWEST, 0, |
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index 92f2c423b..233bcbdbd 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h | |||
| @@ -90,6 +90,12 @@ public: | |||
| 90 | void SetPriority(s32 priority); | 90 | void SetPriority(s32 priority); |
| 91 | 91 | ||
| 92 | /** | 92 | /** |
| 93 | * Temporarily boosts the thread's priority until the next time it is scheduled | ||
| 94 | * @param priority The new priority | ||
| 95 | */ | ||
| 96 | void BoostPriority(s32 priority); | ||
| 97 | |||
| 98 | /** | ||
| 93 | * Gets the thread's thread ID | 99 | * Gets the thread's thread ID |
| 94 | * @return The thread's ID | 100 | * @return The thread's ID |
| 95 | */ | 101 | */ |