diff options
| author | 2021-11-10 23:02:45 -0800 | |
|---|---|---|
| committer | 2021-12-06 16:39:17 -0800 | |
| commit | 316a2dd22a25e4cfb31b364ab6595d8bb054411c (patch) | |
| tree | 3d5077bf251a5bd0d08b9ae3d014b0742475c876 /src/core | |
| parent | hle: kernel: KThreadQueue: Remove deprecated code. (diff) | |
| download | yuzu-316a2dd22a25e4cfb31b364ab6595d8bb054411c.tar.gz yuzu-316a2dd22a25e4cfb31b364ab6595d8bb054411c.tar.xz yuzu-316a2dd22a25e4cfb31b364ab6595d8bb054411c.zip | |
hle: kernel: KProcess: Improvements for thread pinning.
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/hle/kernel/k_process.cpp | 27 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_process.h | 7 |
2 files changed, 26 insertions, 8 deletions
diff --git a/src/core/hle/kernel/k_process.cpp b/src/core/hle/kernel/k_process.cpp index 7cc2061ea..90dda40dc 100644 --- a/src/core/hle/kernel/k_process.cpp +++ b/src/core/hle/kernel/k_process.cpp | |||
| @@ -228,12 +228,15 @@ void KProcess::PinCurrentThread() { | |||
| 228 | const s32 core_id = GetCurrentCoreId(kernel); | 228 | const s32 core_id = GetCurrentCoreId(kernel); |
| 229 | KThread* cur_thread = GetCurrentThreadPointer(kernel); | 229 | KThread* cur_thread = GetCurrentThreadPointer(kernel); |
| 230 | 230 | ||
| 231 | // Pin it. | 231 | // If the thread isn't terminated, pin it. |
| 232 | PinThread(core_id, cur_thread); | 232 | if (!cur_thread->IsTerminationRequested()) { |
| 233 | cur_thread->Pin(); | 233 | // Pin it. |
| 234 | PinThread(core_id, cur_thread); | ||
| 235 | cur_thread->Pin(); | ||
| 234 | 236 | ||
| 235 | // An update is needed. | 237 | // An update is needed. |
| 236 | KScheduler::SetSchedulerUpdateNeeded(kernel); | 238 | KScheduler::SetSchedulerUpdateNeeded(kernel); |
| 239 | } | ||
| 237 | } | 240 | } |
| 238 | 241 | ||
| 239 | void KProcess::UnpinCurrentThread() { | 242 | void KProcess::UnpinCurrentThread() { |
| @@ -251,6 +254,20 @@ void KProcess::UnpinCurrentThread() { | |||
| 251 | KScheduler::SetSchedulerUpdateNeeded(kernel); | 254 | KScheduler::SetSchedulerUpdateNeeded(kernel); |
| 252 | } | 255 | } |
| 253 | 256 | ||
| 257 | void KProcess::UnpinThread(KThread* thread) { | ||
| 258 | ASSERT(kernel.GlobalSchedulerContext().IsLocked()); | ||
| 259 | |||
| 260 | // Get the thread's core id. | ||
| 261 | const auto core_id = thread->GetActiveCore(); | ||
| 262 | |||
| 263 | // Unpin it. | ||
| 264 | UnpinThread(core_id, thread); | ||
| 265 | thread->Unpin(); | ||
| 266 | |||
| 267 | // An update is needed. | ||
| 268 | KScheduler::SetSchedulerUpdateNeeded(kernel); | ||
| 269 | } | ||
| 270 | |||
| 254 | ResultCode KProcess::AddSharedMemory(KSharedMemory* shmem, [[maybe_unused]] VAddr address, | 271 | ResultCode KProcess::AddSharedMemory(KSharedMemory* shmem, [[maybe_unused]] VAddr address, |
| 255 | [[maybe_unused]] size_t size) { | 272 | [[maybe_unused]] size_t size) { |
| 256 | // Lock ourselves, to prevent concurrent access. | 273 | // Lock ourselves, to prevent concurrent access. |
diff --git a/src/core/hle/kernel/k_process.h b/src/core/hle/kernel/k_process.h index 8a8c1fcbb..d972c9de0 100644 --- a/src/core/hle/kernel/k_process.h +++ b/src/core/hle/kernel/k_process.h | |||
| @@ -259,7 +259,7 @@ public: | |||
| 259 | 259 | ||
| 260 | [[nodiscard]] KThread* GetPinnedThread(s32 core_id) const { | 260 | [[nodiscard]] KThread* GetPinnedThread(s32 core_id) const { |
| 261 | ASSERT(0 <= core_id && core_id < static_cast<s32>(Core::Hardware::NUM_CPU_CORES)); | 261 | ASSERT(0 <= core_id && core_id < static_cast<s32>(Core::Hardware::NUM_CPU_CORES)); |
| 262 | return pinned_threads[core_id]; | 262 | return pinned_threads.at(core_id); |
| 263 | } | 263 | } |
| 264 | 264 | ||
| 265 | /// Gets 8 bytes of random data for svcGetInfo RandomEntropy | 265 | /// Gets 8 bytes of random data for svcGetInfo RandomEntropy |
| @@ -347,6 +347,7 @@ public: | |||
| 347 | 347 | ||
| 348 | void PinCurrentThread(); | 348 | void PinCurrentThread(); |
| 349 | void UnpinCurrentThread(); | 349 | void UnpinCurrentThread(); |
| 350 | void UnpinThread(KThread* thread); | ||
| 350 | 351 | ||
| 351 | KLightLock& GetStateLock() { | 352 | KLightLock& GetStateLock() { |
| 352 | return state_lock; | 353 | return state_lock; |
| @@ -368,14 +369,14 @@ private: | |||
| 368 | void PinThread(s32 core_id, KThread* thread) { | 369 | void PinThread(s32 core_id, KThread* thread) { |
| 369 | ASSERT(0 <= core_id && core_id < static_cast<s32>(Core::Hardware::NUM_CPU_CORES)); | 370 | ASSERT(0 <= core_id && core_id < static_cast<s32>(Core::Hardware::NUM_CPU_CORES)); |
| 370 | ASSERT(thread != nullptr); | 371 | ASSERT(thread != nullptr); |
| 371 | ASSERT(pinned_threads[core_id] == nullptr); | 372 | ASSERT(pinned_threads.at(core_id) == nullptr); |
| 372 | pinned_threads[core_id] = thread; | 373 | pinned_threads[core_id] = thread; |
| 373 | } | 374 | } |
| 374 | 375 | ||
| 375 | void UnpinThread(s32 core_id, KThread* thread) { | 376 | void UnpinThread(s32 core_id, KThread* thread) { |
| 376 | ASSERT(0 <= core_id && core_id < static_cast<s32>(Core::Hardware::NUM_CPU_CORES)); | 377 | ASSERT(0 <= core_id && core_id < static_cast<s32>(Core::Hardware::NUM_CPU_CORES)); |
| 377 | ASSERT(thread != nullptr); | 378 | ASSERT(thread != nullptr); |
| 378 | ASSERT(pinned_threads[core_id] == thread); | 379 | ASSERT(pinned_threads.at(core_id) == thread); |
| 379 | pinned_threads[core_id] = nullptr; | 380 | pinned_threads[core_id] = nullptr; |
| 380 | } | 381 | } |
| 381 | 382 | ||