From d2a888d9e8c297040bd370170bf3c57ab23a9058 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Fri, 21 Feb 2020 13:05:16 -0800 Subject: [PATCH] kern: minor fixes to prevent core0-2 panics during boot --- .../mesosphere/kern_k_priority_queue.hpp | 4 ++-- .../include/mesosphere/kern_k_scheduler.hpp | 3 ++- .../include/mesosphere/kern_k_thread.hpp | 2 ++ .../source/kern_k_interrupt_task_manager.cpp | 4 +++- .../libmesosphere/source/kern_k_thread.cpp | 18 +++++++++++++++++- 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/libraries/libmesosphere/include/mesosphere/kern_k_priority_queue.hpp b/libraries/libmesosphere/include/mesosphere/kern_k_priority_queue.hpp index 28fc26e2f..3b471b4d0 100644 --- a/libraries/libmesosphere/include/mesosphere/kern_k_priority_queue.hpp +++ b/libraries/libmesosphere/include/mesosphere/kern_k_priority_queue.hpp @@ -306,7 +306,7 @@ namespace ams::kern { } constexpr ALWAYS_INLINE Member *GetScheduledFront(s32 core, s32 priority) const { - return this->scheduled_queue.GetFront(core, priority); + return this->scheduled_queue.GetFront(priority, core); } constexpr ALWAYS_INLINE Member *GetSuggestedFront(s32 core) const { @@ -314,7 +314,7 @@ namespace ams::kern { } constexpr ALWAYS_INLINE Member *GetSuggestedFront(s32 core, s32 priority) const { - return this->suggested_queue.GetFront(core, priority); + return this->suggested_queue.GetFront(priority, core); } constexpr ALWAYS_INLINE Member *GetScheduledNext(s32 core, const Member *member) const { diff --git a/libraries/libmesosphere/include/mesosphere/kern_k_scheduler.hpp b/libraries/libmesosphere/include/mesosphere/kern_k_scheduler.hpp index 4903b4f72..5fb57ad2f 100644 --- a/libraries/libmesosphere/include/mesosphere/kern_k_scheduler.hpp +++ b/libraries/libmesosphere/include/mesosphere/kern_k_scheduler.hpp @@ -88,7 +88,6 @@ namespace ams::kern { static ALWAYS_INLINE void SetSchedulerUpdateNeeded() { s_scheduler_update_needed = true; } static ALWAYS_INLINE void ClearSchedulerUpdateNeeded() { s_scheduler_update_needed = false; } static ALWAYS_INLINE KSchedulerPriorityQueue &GetPriorityQueue() { return s_priority_queue; } - static NOINLINE void SetInterruptTaskThreadRunnable(); static NOINLINE u64 UpdateHighestPriorityThreadsImpl(); public: @@ -96,6 +95,8 @@ namespace ams::kern { static ALWAYS_INLINE bool CanSchedule() { return GetCurrentThread().GetDisableDispatchCount() == 0; } static ALWAYS_INLINE bool IsSchedulerLockedByCurrentThread() { return s_scheduler_lock.IsLockedByCurrentThread(); } + static NOINLINE void SetInterruptTaskThreadRunnable(); + static ALWAYS_INLINE void DisableScheduling() { MESOSPHERE_ASSERT(GetCurrentThread().GetDisableDispatchCount() >= 0); GetCurrentThread().DisableDispatch(); diff --git a/libraries/libmesosphere/include/mesosphere/kern_k_thread.hpp b/libraries/libmesosphere/include/mesosphere/kern_k_thread.hpp index 7acd9a209..8e3ace54e 100644 --- a/libraries/libmesosphere/include/mesosphere/kern_k_thread.hpp +++ b/libraries/libmesosphere/include/mesosphere/kern_k_thread.hpp @@ -345,6 +345,8 @@ namespace ams::kern { } } + void Wakeup(); + Result SetPriorityToIdle(); Result Run(); diff --git a/libraries/libmesosphere/source/kern_k_interrupt_task_manager.cpp b/libraries/libmesosphere/source/kern_k_interrupt_task_manager.cpp index 5070830fe..83722e1b4 100644 --- a/libraries/libmesosphere/source/kern_k_interrupt_task_manager.cpp +++ b/libraries/libmesosphere/source/kern_k_interrupt_task_manager.cpp @@ -89,7 +89,9 @@ namespace ams::kern { void KInterruptTaskManager::EnqueueTask(KInterruptTask *task) { MESOSPHERE_ASSERT(!KInterruptManager::AreInterruptsEnabled()); - MESOSPHERE_TODO_IMPLEMENT(); + /* Enqueue the task and signal the scheduler. */ + this->task_queue.Enqueue(task); + Kernel::GetScheduler().SetInterruptTaskThreadRunnable(); } } diff --git a/libraries/libmesosphere/source/kern_k_thread.cpp b/libraries/libmesosphere/source/kern_k_thread.cpp index 0bef0856d..57218ae56 100644 --- a/libraries/libmesosphere/source/kern_k_thread.cpp +++ b/libraries/libmesosphere/source/kern_k_thread.cpp @@ -260,8 +260,24 @@ namespace ams::kern { return this->signaled; } + void KThread::Wakeup() { + MESOSPHERE_ASSERT_THIS(); + KScopedSchedulerLock sl; + + if (this->GetState() == ThreadState_Waiting) { + if (this->sleeping_queue != nullptr) { + this->sleeping_queue->WakeupThread(this); + } else { + this->SetState(ThreadState_Runnable); + } + } + } + void KThread::OnTimer() { - MESOSPHERE_TODO_IMPLEMENT(); + MESOSPHERE_ASSERT_THIS(); + MESOSPHERE_ASSERT(KScheduler::IsSchedulerLockedByCurrentThread()); + + this->Wakeup(); } void KThread::DoWorkerTask() {