summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/kernel.cpp
diff options
context:
space:
mode:
authorGravatar Fernando S2022-06-16 02:41:12 +0200
committerGravatar GitHub2022-06-16 02:41:12 +0200
commitf86b770ff75efff029fa82b959b3f33eca1750fe (patch)
tree8c1aa046c96d7f943288ecb3455f4091cdc31a09 /src/core/hle/kernel/kernel.cpp
parentMerge pull request #8460 from Morph1984/bounded-q (diff)
parentkernel: implement KProcess suspension (diff)
downloadyuzu-f86b770ff75efff029fa82b959b3f33eca1750fe.tar.gz
yuzu-f86b770ff75efff029fa82b959b3f33eca1750fe.tar.xz
yuzu-f86b770ff75efff029fa82b959b3f33eca1750fe.zip
Merge pull request #8457 from liamwhite/kprocess-suspend
kernel: implement KProcess suspension
Diffstat (limited to 'src/core/hle/kernel/kernel.cpp')
-rw-r--r--src/core/hle/kernel/kernel.cpp49
1 files changed, 29 insertions, 20 deletions
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index b2c4f12b4..73593c7a0 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -76,7 +76,7 @@ struct KernelCore::Impl {
76 InitializeMemoryLayout(); 76 InitializeMemoryLayout();
77 Init::InitializeKPageBufferSlabHeap(system); 77 Init::InitializeKPageBufferSlabHeap(system);
78 InitializeSchedulers(); 78 InitializeSchedulers();
79 InitializeSuspendThreads(); 79 InitializeShutdownThreads();
80 InitializePreemption(kernel); 80 InitializePreemption(kernel);
81 81
82 RegisterHostThread(); 82 RegisterHostThread();
@@ -143,9 +143,9 @@ struct KernelCore::Impl {
143 CleanupObject(system_resource_limit); 143 CleanupObject(system_resource_limit);
144 144
145 for (u32 core_id = 0; core_id < Core::Hardware::NUM_CPU_CORES; core_id++) { 145 for (u32 core_id = 0; core_id < Core::Hardware::NUM_CPU_CORES; core_id++) {
146 if (suspend_threads[core_id]) { 146 if (shutdown_threads[core_id]) {
147 suspend_threads[core_id]->Close(); 147 shutdown_threads[core_id]->Close();
148 suspend_threads[core_id] = nullptr; 148 shutdown_threads[core_id] = nullptr;
149 } 149 }
150 150
151 schedulers[core_id]->Finalize(); 151 schedulers[core_id]->Finalize();
@@ -247,14 +247,14 @@ struct KernelCore::Impl {
247 system.CoreTiming().ScheduleEvent(time_interval, preemption_event); 247 system.CoreTiming().ScheduleEvent(time_interval, preemption_event);
248 } 248 }
249 249
250 void InitializeSuspendThreads() { 250 void InitializeShutdownThreads() {
251 for (u32 core_id = 0; core_id < Core::Hardware::NUM_CPU_CORES; core_id++) { 251 for (u32 core_id = 0; core_id < Core::Hardware::NUM_CPU_CORES; core_id++) {
252 suspend_threads[core_id] = KThread::Create(system.Kernel()); 252 shutdown_threads[core_id] = KThread::Create(system.Kernel());
253 ASSERT(KThread::InitializeHighPriorityThread(system, suspend_threads[core_id], {}, {}, 253 ASSERT(KThread::InitializeHighPriorityThread(system, shutdown_threads[core_id], {}, {},
254 core_id) 254 core_id)
255 .IsSuccess()); 255 .IsSuccess());
256 suspend_threads[core_id]->SetName(fmt::format("SuspendThread:{}", core_id)); 256 shutdown_threads[core_id]->SetName(fmt::format("SuspendThread:{}", core_id));
257 suspend_threads[core_id]->DisableDispatch(); 257 shutdown_threads[core_id]->DisableDispatch();
258 } 258 }
259 } 259 }
260 260
@@ -769,7 +769,7 @@ struct KernelCore::Impl {
769 std::weak_ptr<ServiceThread> default_service_thread; 769 std::weak_ptr<ServiceThread> default_service_thread;
770 Common::ThreadWorker service_threads_manager; 770 Common::ThreadWorker service_threads_manager;
771 771
772 std::array<KThread*, Core::Hardware::NUM_CPU_CORES> suspend_threads; 772 std::array<KThread*, Core::Hardware::NUM_CPU_CORES> shutdown_threads;
773 std::array<Core::CPUInterruptHandler, Core::Hardware::NUM_CPU_CORES> interrupts{}; 773 std::array<Core::CPUInterruptHandler, Core::Hardware::NUM_CPU_CORES> interrupts{};
774 std::array<std::unique_ptr<Kernel::KScheduler>, Core::Hardware::NUM_CPU_CORES> schedulers{}; 774 std::array<std::unique_ptr<Kernel::KScheduler>, Core::Hardware::NUM_CPU_CORES> schedulers{};
775 775
@@ -920,6 +920,12 @@ const KAutoObjectWithListContainer& KernelCore::ObjectListContainer() const {
920 return *impl->global_object_list_container; 920 return *impl->global_object_list_container;
921} 921}
922 922
923void KernelCore::InterruptAllPhysicalCores() {
924 for (auto& physical_core : impl->cores) {
925 physical_core.Interrupt();
926 }
927}
928
923void KernelCore::InvalidateAllInstructionCaches() { 929void KernelCore::InvalidateAllInstructionCaches() {
924 for (auto& physical_core : impl->cores) { 930 for (auto& physical_core : impl->cores) {
925 physical_core.ArmInterface().ClearInstructionCache(); 931 physical_core.ArmInterface().ClearInstructionCache();
@@ -1067,17 +1073,20 @@ const Kernel::KSharedMemory& KernelCore::GetHidBusSharedMem() const {
1067 return *impl->hidbus_shared_mem; 1073 return *impl->hidbus_shared_mem;
1068} 1074}
1069 1075
1070void KernelCore::Suspend(bool in_suspention) { 1076void KernelCore::Suspend(bool suspended) {
1071 const bool should_suspend = exception_exited || in_suspention; 1077 const bool should_suspend{exception_exited || suspended};
1072 { 1078 const auto activity = should_suspend ? ProcessActivity::Paused : ProcessActivity::Runnable;
1073 KScopedSchedulerLock lock(*this); 1079
1074 const auto state = should_suspend ? ThreadState::Runnable : ThreadState::Waiting; 1080 for (auto* process : GetProcessList()) {
1075 for (u32 core_id = 0; core_id < Core::Hardware::NUM_CPU_CORES; core_id++) { 1081 process->SetActivity(activity);
1076 impl->suspend_threads[core_id]->SetState(state); 1082 }
1077 impl->suspend_threads[core_id]->SetWaitReasonForDebugging( 1083}
1078 ThreadWaitReasonForDebugging::Suspended); 1084
1079 } 1085void KernelCore::ShutdownCores() {
1086 for (auto* thread : impl->shutdown_threads) {
1087 void(thread->Run());
1080 } 1088 }
1089 InterruptAllPhysicalCores();
1081} 1090}
1082 1091
1083bool KernelCore::IsMulticore() const { 1092bool KernelCore::IsMulticore() const {