summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Fernando S2022-11-09 14:50:49 +0100
committerGravatar GitHub2022-11-09 14:50:49 +0100
commit3161b34ff6e4773cce35f0e4efe94ffb670eb2af (patch)
tree524010a3d63edd86fa80f0af873a411359aa6b9f
parentMerge pull request #9199 from liamwhite/service-oops (diff)
parentEnsure correctness of atomic store ordering (diff)
downloadyuzu-3161b34ff6e4773cce35f0e4efe94ffb670eb2af.tar.gz
yuzu-3161b34ff6e4773cce35f0e4efe94ffb670eb2af.tar.xz
yuzu-3161b34ff6e4773cce35f0e4efe94ffb670eb2af.zip
Merge pull request #9215 from liamwhite/swordfight
Ensure correctness of atomic store ordering
-rw-r--r--src/core/hle/kernel/k_scheduler.cpp9
-rw-r--r--src/core/hle/kernel/k_scheduler_lock.h3
2 files changed, 9 insertions, 3 deletions
diff --git a/src/core/hle/kernel/k_scheduler.cpp b/src/core/hle/kernel/k_scheduler.cpp
index b1cabbca0..d6676904b 100644
--- a/src/core/hle/kernel/k_scheduler.cpp
+++ b/src/core/hle/kernel/k_scheduler.cpp
@@ -384,7 +384,8 @@ void KScheduler::SwitchThread(KThread* next_thread) {
384 384
385void KScheduler::ScheduleImpl() { 385void KScheduler::ScheduleImpl() {
386 // First, clear the needs scheduling bool. 386 // First, clear the needs scheduling bool.
387 m_state.needs_scheduling.store(false, std::memory_order_seq_cst); 387 m_state.needs_scheduling.store(false, std::memory_order_relaxed);
388 std::atomic_thread_fence(std::memory_order_seq_cst);
388 389
389 // Load the appropriate thread pointers for scheduling. 390 // Load the appropriate thread pointers for scheduling.
390 KThread* const cur_thread{GetCurrentThreadPointer(kernel)}; 391 KThread* const cur_thread{GetCurrentThreadPointer(kernel)};
@@ -400,7 +401,8 @@ void KScheduler::ScheduleImpl() {
400 // If there aren't, we want to check if the highest priority thread is the same as the current 401 // If there aren't, we want to check if the highest priority thread is the same as the current
401 // thread. 402 // thread.
402 if (highest_priority_thread == cur_thread) { 403 if (highest_priority_thread == cur_thread) {
403 // If they're the same, then we can just return. 404 // If they're the same, then we can just issue a memory barrier and return.
405 std::atomic_thread_fence(std::memory_order_seq_cst);
404 return; 406 return;
405 } 407 }
406 408
@@ -476,7 +478,8 @@ void KScheduler::ScheduleImplFiber() {
476 478
477 // We failed to successfully do the context switch, and need to retry. 479 // We failed to successfully do the context switch, and need to retry.
478 // Clear needs_scheduling. 480 // Clear needs_scheduling.
479 m_state.needs_scheduling.store(false, std::memory_order_seq_cst); 481 m_state.needs_scheduling.store(false, std::memory_order_relaxed);
482 std::atomic_thread_fence(std::memory_order_seq_cst);
480 483
481 // Refresh the highest priority thread. 484 // Refresh the highest priority thread.
482 highest_priority_thread = m_state.highest_priority_thread; 485 highest_priority_thread = m_state.highest_priority_thread;
diff --git a/src/core/hle/kernel/k_scheduler_lock.h b/src/core/hle/kernel/k_scheduler_lock.h
index 73314b45e..129d60472 100644
--- a/src/core/hle/kernel/k_scheduler_lock.h
+++ b/src/core/hle/kernel/k_scheduler_lock.h
@@ -60,6 +60,9 @@ public:
60 60
61 // Release an instance of the lock. 61 // Release an instance of the lock.
62 if ((--lock_count) == 0) { 62 if ((--lock_count) == 0) {
63 // Perform a memory barrier here.
64 std::atomic_thread_fence(std::memory_order_seq_cst);
65
63 // We're no longer going to hold the lock. Take note of what cores need scheduling. 66 // We're no longer going to hold the lock. Take note of what cores need scheduling.
64 const u64 cores_needing_scheduling = 67 const u64 cores_needing_scheduling =
65 SchedulerType::UpdateHighestPriorityThreads(kernel); 68 SchedulerType::UpdateHighestPriorityThreads(kernel);