diff options
| author | 2021-02-13 01:29:32 -0800 | |
|---|---|---|
| committer | 2021-03-21 14:45:02 -0700 | |
| commit | 5872561077e8b671ee9a80ecd5d116100458a28f (patch) | |
| tree | cdb8736a1fdd7d1f8b88c3091b96045356ece5b3 /src | |
| parent | hle: kernel: Add initial KMemoryRegionType module. (diff) | |
| download | yuzu-5872561077e8b671ee9a80ecd5d116100458a28f.tar.gz yuzu-5872561077e8b671ee9a80ecd5d116100458a28f.tar.xz yuzu-5872561077e8b671ee9a80ecd5d116100458a28f.zip | |
hle: kernel: Migrate some code from Common::SpinLock to KSpinLock.
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/kernel/k_scheduler.cpp | 22 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_scheduler.h | 7 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_scheduler_lock.h | 11 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_spin_lock.h | 6 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_thread.h | 4 |
5 files changed, 25 insertions, 25 deletions
diff --git a/src/core/hle/kernel/k_scheduler.cpp b/src/core/hle/kernel/k_scheduler.cpp index e7de48476..d1df97305 100644 --- a/src/core/hle/kernel/k_scheduler.cpp +++ b/src/core/hle/kernel/k_scheduler.cpp | |||
| @@ -62,7 +62,7 @@ void KScheduler::RescheduleCores(KernelCore& kernel, u64 cores_pending_reschedul | |||
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | u64 KScheduler::UpdateHighestPriorityThread(KThread* highest_thread) { | 64 | u64 KScheduler::UpdateHighestPriorityThread(KThread* highest_thread) { |
| 65 | std::scoped_lock lock{guard}; | 65 | KScopedSpinLock lk{guard}; |
| 66 | if (KThread* prev_highest_thread = state.highest_priority_thread; | 66 | if (KThread* prev_highest_thread = state.highest_priority_thread; |
| 67 | prev_highest_thread != highest_thread) { | 67 | prev_highest_thread != highest_thread) { |
| 68 | if (prev_highest_thread != nullptr) { | 68 | if (prev_highest_thread != nullptr) { |
| @@ -637,11 +637,11 @@ void KScheduler::RescheduleCurrentCore() { | |||
| 637 | if (phys_core.IsInterrupted()) { | 637 | if (phys_core.IsInterrupted()) { |
| 638 | phys_core.ClearInterrupt(); | 638 | phys_core.ClearInterrupt(); |
| 639 | } | 639 | } |
| 640 | guard.lock(); | 640 | guard.Lock(); |
| 641 | if (state.needs_scheduling.load()) { | 641 | if (state.needs_scheduling.load()) { |
| 642 | Schedule(); | 642 | Schedule(); |
| 643 | } else { | 643 | } else { |
| 644 | guard.unlock(); | 644 | guard.Unlock(); |
| 645 | } | 645 | } |
| 646 | } | 646 | } |
| 647 | 647 | ||
| @@ -669,7 +669,7 @@ void KScheduler::Unload(KThread* thread) { | |||
| 669 | } else { | 669 | } else { |
| 670 | prev_thread = nullptr; | 670 | prev_thread = nullptr; |
| 671 | } | 671 | } |
| 672 | thread->context_guard.unlock(); | 672 | thread->context_guard.Unlock(); |
| 673 | } | 673 | } |
| 674 | } | 674 | } |
| 675 | 675 | ||
| @@ -713,7 +713,7 @@ void KScheduler::ScheduleImpl() { | |||
| 713 | 713 | ||
| 714 | // If we're not actually switching thread, there's nothing to do. | 714 | // If we're not actually switching thread, there's nothing to do. |
| 715 | if (next_thread == current_thread.load()) { | 715 | if (next_thread == current_thread.load()) { |
| 716 | guard.unlock(); | 716 | guard.Unlock(); |
| 717 | return; | 717 | return; |
| 718 | } | 718 | } |
| 719 | 719 | ||
| @@ -732,7 +732,7 @@ void KScheduler::ScheduleImpl() { | |||
| 732 | } else { | 732 | } else { |
| 733 | old_context = &idle_thread->GetHostContext(); | 733 | old_context = &idle_thread->GetHostContext(); |
| 734 | } | 734 | } |
| 735 | guard.unlock(); | 735 | guard.Unlock(); |
| 736 | 736 | ||
| 737 | Common::Fiber::YieldTo(*old_context, *switch_fiber); | 737 | Common::Fiber::YieldTo(*old_context, *switch_fiber); |
| 738 | /// When a thread wakes up, the scheduler may have changed to other in another core. | 738 | /// When a thread wakes up, the scheduler may have changed to other in another core. |
| @@ -748,24 +748,24 @@ void KScheduler::OnSwitch(void* this_scheduler) { | |||
| 748 | void KScheduler::SwitchToCurrent() { | 748 | void KScheduler::SwitchToCurrent() { |
| 749 | while (true) { | 749 | while (true) { |
| 750 | { | 750 | { |
| 751 | std::scoped_lock lock{guard}; | 751 | KScopedSpinLock lk{guard}; |
| 752 | current_thread.store(state.highest_priority_thread); | 752 | current_thread.store(state.highest_priority_thread); |
| 753 | state.needs_scheduling.store(false); | 753 | state.needs_scheduling.store(false); |
| 754 | } | 754 | } |
| 755 | const auto is_switch_pending = [this] { | 755 | const auto is_switch_pending = [this] { |
| 756 | std::scoped_lock lock{guard}; | 756 | KScopedSpinLock lk{guard}; |
| 757 | return state.needs_scheduling.load(); | 757 | return state.needs_scheduling.load(); |
| 758 | }; | 758 | }; |
| 759 | do { | 759 | do { |
| 760 | auto next_thread = current_thread.load(); | 760 | auto next_thread = current_thread.load(); |
| 761 | if (next_thread != nullptr) { | 761 | if (next_thread != nullptr) { |
| 762 | next_thread->context_guard.lock(); | 762 | next_thread->context_guard.Lock(); |
| 763 | if (next_thread->GetRawState() != ThreadState::Runnable) { | 763 | if (next_thread->GetRawState() != ThreadState::Runnable) { |
| 764 | next_thread->context_guard.unlock(); | 764 | next_thread->context_guard.Unlock(); |
| 765 | break; | 765 | break; |
| 766 | } | 766 | } |
| 767 | if (next_thread->GetActiveCore() != core_id) { | 767 | if (next_thread->GetActiveCore() != core_id) { |
| 768 | next_thread->context_guard.unlock(); | 768 | next_thread->context_guard.Unlock(); |
| 769 | break; | 769 | break; |
| 770 | } | 770 | } |
| 771 | } | 771 | } |
diff --git a/src/core/hle/kernel/k_scheduler.h b/src/core/hle/kernel/k_scheduler.h index f595b9a5c..f1cca51dc 100644 --- a/src/core/hle/kernel/k_scheduler.h +++ b/src/core/hle/kernel/k_scheduler.h | |||
| @@ -2,19 +2,16 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | // This file references various implementation details from Atmosphere, an open-source firmware for | ||
| 6 | // the Nintendo Switch. Copyright 2018-2020 Atmosphere-NX. | ||
| 7 | |||
| 8 | #pragma once | 5 | #pragma once |
| 9 | 6 | ||
| 10 | #include <atomic> | 7 | #include <atomic> |
| 11 | 8 | ||
| 12 | #include "common/common_types.h" | 9 | #include "common/common_types.h" |
| 13 | #include "common/spin_lock.h" | ||
| 14 | #include "core/hle/kernel/global_scheduler_context.h" | 10 | #include "core/hle/kernel/global_scheduler_context.h" |
| 15 | #include "core/hle/kernel/k_priority_queue.h" | 11 | #include "core/hle/kernel/k_priority_queue.h" |
| 16 | #include "core/hle/kernel/k_scheduler_lock.h" | 12 | #include "core/hle/kernel/k_scheduler_lock.h" |
| 17 | #include "core/hle/kernel/k_scoped_lock.h" | 13 | #include "core/hle/kernel/k_scoped_lock.h" |
| 14 | #include "core/hle/kernel/k_spin_lock.h" | ||
| 18 | 15 | ||
| 19 | namespace Common { | 16 | namespace Common { |
| 20 | class Fiber; | 17 | class Fiber; |
| @@ -195,7 +192,7 @@ private: | |||
| 195 | u64 last_context_switch_time{}; | 192 | u64 last_context_switch_time{}; |
| 196 | const s32 core_id; | 193 | const s32 core_id; |
| 197 | 194 | ||
| 198 | Common::SpinLock guard{}; | 195 | KSpinLock guard{}; |
| 199 | }; | 196 | }; |
| 200 | 197 | ||
| 201 | class KScopedSchedulerLock : KScopedLock<GlobalSchedulerContext::LockType> { | 198 | class KScopedSchedulerLock : KScopedLock<GlobalSchedulerContext::LockType> { |
diff --git a/src/core/hle/kernel/k_scheduler_lock.h b/src/core/hle/kernel/k_scheduler_lock.h index 169455d18..47e315555 100644 --- a/src/core/hle/kernel/k_scheduler_lock.h +++ b/src/core/hle/kernel/k_scheduler_lock.h | |||
| @@ -2,14 +2,11 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | // This file references various implementation details from Atmosphere, an open-source firmware for | ||
| 6 | // the Nintendo Switch. Copyright 2018-2020 Atmosphere-NX. | ||
| 7 | |||
| 8 | #pragma once | 5 | #pragma once |
| 9 | 6 | ||
| 10 | #include "common/assert.h" | 7 | #include "common/assert.h" |
| 11 | #include "common/spin_lock.h" | ||
| 12 | #include "core/hardware_properties.h" | 8 | #include "core/hardware_properties.h" |
| 9 | #include "core/hle/kernel/k_spin_lock.h" | ||
| 13 | #include "core/hle/kernel/k_thread.h" | 10 | #include "core/hle/kernel/k_thread.h" |
| 14 | #include "core/hle/kernel/kernel.h" | 11 | #include "core/hle/kernel/kernel.h" |
| 15 | 12 | ||
| @@ -34,7 +31,7 @@ public: | |||
| 34 | } else { | 31 | } else { |
| 35 | // Otherwise, we want to disable scheduling and acquire the spinlock. | 32 | // Otherwise, we want to disable scheduling and acquire the spinlock. |
| 36 | SchedulerType::DisableScheduling(kernel); | 33 | SchedulerType::DisableScheduling(kernel); |
| 37 | spin_lock.lock(); | 34 | spin_lock.Lock(); |
| 38 | 35 | ||
| 39 | // For debug, ensure that our state is valid. | 36 | // For debug, ensure that our state is valid. |
| 40 | ASSERT(lock_count == 0); | 37 | ASSERT(lock_count == 0); |
| @@ -58,7 +55,7 @@ public: | |||
| 58 | 55 | ||
| 59 | // Note that we no longer hold the lock, and unlock the spinlock. | 56 | // Note that we no longer hold the lock, and unlock the spinlock. |
| 60 | owner_thread = nullptr; | 57 | owner_thread = nullptr; |
| 61 | spin_lock.unlock(); | 58 | spin_lock.Unlock(); |
| 62 | 59 | ||
| 63 | // Enable scheduling, and perform a rescheduling operation. | 60 | // Enable scheduling, and perform a rescheduling operation. |
| 64 | SchedulerType::EnableScheduling(kernel, cores_needing_scheduling); | 61 | SchedulerType::EnableScheduling(kernel, cores_needing_scheduling); |
| @@ -67,7 +64,7 @@ public: | |||
| 67 | 64 | ||
| 68 | private: | 65 | private: |
| 69 | KernelCore& kernel; | 66 | KernelCore& kernel; |
| 70 | Common::SpinLock spin_lock{}; | 67 | KAlignedSpinLock spin_lock{}; |
| 71 | s32 lock_count{}; | 68 | s32 lock_count{}; |
| 72 | KThread* owner_thread{}; | 69 | KThread* owner_thread{}; |
| 73 | }; | 70 | }; |
diff --git a/src/core/hle/kernel/k_spin_lock.h b/src/core/hle/kernel/k_spin_lock.h index 12c4b2e88..4d87d006a 100644 --- a/src/core/hle/kernel/k_spin_lock.h +++ b/src/core/hle/kernel/k_spin_lock.h | |||
| @@ -28,6 +28,12 @@ private: | |||
| 28 | std::atomic_flag lck = ATOMIC_FLAG_INIT; | 28 | std::atomic_flag lck = ATOMIC_FLAG_INIT; |
| 29 | }; | 29 | }; |
| 30 | 30 | ||
| 31 | // TODO(bunnei): Alias for now, in case we want to implement these accurately in the future. | ||
| 32 | using KAlignedSpinLock = KSpinLock; | ||
| 33 | using KNotAlignedSpinLock = KSpinLock; | ||
| 34 | |||
| 31 | using KScopedSpinLock = KScopedLock<KSpinLock>; | 35 | using KScopedSpinLock = KScopedLock<KSpinLock>; |
| 36 | using KScopedAlignedSpinLock = KScopedLock<KAlignedSpinLock>; | ||
| 37 | using KScopedNotAlignedSpinLock = KScopedLock<KNotAlignedSpinLock>; | ||
| 32 | 38 | ||
| 33 | } // namespace Kernel | 39 | } // namespace Kernel |
diff --git a/src/core/hle/kernel/k_thread.h b/src/core/hle/kernel/k_thread.h index 1c19b23dc..1c86fdd20 100644 --- a/src/core/hle/kernel/k_thread.h +++ b/src/core/hle/kernel/k_thread.h | |||
| @@ -14,10 +14,10 @@ | |||
| 14 | 14 | ||
| 15 | #include "common/common_types.h" | 15 | #include "common/common_types.h" |
| 16 | #include "common/intrusive_red_black_tree.h" | 16 | #include "common/intrusive_red_black_tree.h" |
| 17 | #include "common/spin_lock.h" | ||
| 18 | #include "core/arm/arm_interface.h" | 17 | #include "core/arm/arm_interface.h" |
| 19 | #include "core/hle/kernel/k_affinity_mask.h" | 18 | #include "core/hle/kernel/k_affinity_mask.h" |
| 20 | #include "core/hle/kernel/k_light_lock.h" | 19 | #include "core/hle/kernel/k_light_lock.h" |
| 20 | #include "core/hle/kernel/k_spin_lock.h" | ||
| 21 | #include "core/hle/kernel/k_synchronization_object.h" | 21 | #include "core/hle/kernel/k_synchronization_object.h" |
| 22 | #include "core/hle/kernel/object.h" | 22 | #include "core/hle/kernel/object.h" |
| 23 | #include "core/hle/kernel/svc_common.h" | 23 | #include "core/hle/kernel/svc_common.h" |
| @@ -732,7 +732,7 @@ private: | |||
| 732 | s8 priority_inheritance_count{}; | 732 | s8 priority_inheritance_count{}; |
| 733 | bool resource_limit_release_hint{}; | 733 | bool resource_limit_release_hint{}; |
| 734 | StackParameters stack_parameters{}; | 734 | StackParameters stack_parameters{}; |
| 735 | Common::SpinLock context_guard{}; | 735 | KSpinLock context_guard{}; |
| 736 | 736 | ||
| 737 | // For emulation | 737 | // For emulation |
| 738 | std::shared_ptr<Common::Fiber> host_context{}; | 738 | std::shared_ptr<Common::Fiber> host_context{}; |