From 29a3bafb6f4a60d323763d999a9c31b3f7d0c30a Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Fri, 17 Jul 2020 22:10:50 -0700 Subject: [PATCH] kern: fix kscheduler interrupt api, adjust debug logging --- libmesosphere/include/mesosphere/kern_k_scheduler.hpp | 9 +++++++-- .../source/arch/arm64/kern_exception_handlers.cpp | 2 ++ libmesosphere/source/kern_k_interrupt_task_manager.cpp | 2 +- libmesosphere/source/kern_k_scheduler.cpp | 4 ++-- libmesosphere/source/kern_panic.cpp | 3 +++ 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/libmesosphere/include/mesosphere/kern_k_scheduler.hpp b/libmesosphere/include/mesosphere/kern_k_scheduler.hpp index c1048ef1..f555f783 100644 --- a/libmesosphere/include/mesosphere/kern_k_scheduler.hpp +++ b/libmesosphere/include/mesosphere/kern_k_scheduler.hpp @@ -70,6 +70,11 @@ namespace ams::kern { NOINLINE void Initialize(KThread *idle_thread); NOINLINE void Activate(); + ALWAYS_INLINE void SetInterruptTaskRunnable() { + this->state.interrupt_task_thread_runnable = true; + this->state.needs_scheduling = true; + } + ALWAYS_INLINE void RequestScheduleOnInterrupt() { SetSchedulerUpdateNeeded(); @@ -85,13 +90,13 @@ namespace ams::kern { static ALWAYS_INLINE KSchedulerPriorityQueue &GetPriorityQueue() { return s_priority_queue; } static NOINLINE u64 UpdateHighestPriorityThreadsImpl(); + + static NOINLINE void InterruptTaskThreadToRunnable(); public: /* Static public API. */ 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/libmesosphere/source/arch/arm64/kern_exception_handlers.cpp b/libmesosphere/source/arch/arm64/kern_exception_handlers.cpp index 37fefefb..b5694578 100644 --- a/libmesosphere/source/arch/arm64/kern_exception_handlers.cpp +++ b/libmesosphere/source/arch/arm64/kern_exception_handlers.cpp @@ -38,6 +38,8 @@ namespace ams::kern::arch::arm64 { KProcess *cur_process = GetCurrentProcessPointer(); bool should_process_user_exception = KTargetSystem::IsUserExceptionHandlersEnabled(); + MESOSPHERE_LOG("User Exception occurred in %s\n", cur_process->GetName()); + const u64 ec = (esr >> 26) & 0x3F; switch (ec) { case 0x0: /* Unknown */ diff --git a/libmesosphere/source/kern_k_interrupt_task_manager.cpp b/libmesosphere/source/kern_k_interrupt_task_manager.cpp index 83722e1b..492516a2 100644 --- a/libmesosphere/source/kern_k_interrupt_task_manager.cpp +++ b/libmesosphere/source/kern_k_interrupt_task_manager.cpp @@ -91,7 +91,7 @@ namespace ams::kern { /* Enqueue the task and signal the scheduler. */ this->task_queue.Enqueue(task); - Kernel::GetScheduler().SetInterruptTaskThreadRunnable(); + Kernel::GetScheduler().SetInterruptTaskRunnable(); } } diff --git a/libmesosphere/source/kern_k_scheduler.cpp b/libmesosphere/source/kern_k_scheduler.cpp index b98aa449..46bfc895 100644 --- a/libmesosphere/source/kern_k_scheduler.cpp +++ b/libmesosphere/source/kern_k_scheduler.cpp @@ -199,7 +199,7 @@ namespace ams::kern { return cores_needing_scheduling; } - void KScheduler::SetInterruptTaskThreadRunnable() { + void KScheduler::InterruptTaskThreadToRunnable() { MESOSPHERE_ASSERT(GetCurrentThread().GetDisableDispatchCount() == 1); KThread *task_thread = Kernel::GetInterruptTaskManager().GetThread(); @@ -252,7 +252,7 @@ namespace ams::kern { /* Switch the current process, if we're switching processes. */ if (KProcess *next_process = next_thread->GetOwnerProcess(); next_process != cur_process) { - MESOSPHERE_LOG("!!! PROCESS SWITCH !!! %s -> %s\n", cur_process != nullptr ? cur_process->GetName() : nullptr, next_process != nullptr ? next_process->GetName() : nullptr); + /* MESOSPHERE_LOG("!!! PROCESS SWITCH !!! %s -> %s\n", cur_process != nullptr ? cur_process->GetName() : nullptr, next_process != nullptr ? next_process->GetName() : nullptr); */ KProcess::Switch(cur_process, next_process); } diff --git a/libmesosphere/source/kern_panic.cpp b/libmesosphere/source/kern_panic.cpp index a60e8809..fc4322e7 100644 --- a/libmesosphere/source/kern_panic.cpp +++ b/libmesosphere/source/kern_panic.cpp @@ -120,6 +120,9 @@ namespace ams::kern { ::std::va_list vl; va_start(vl, format); MESOSPHERE_RELEASE_LOG("Core[%d]: Kernel Panic at %s:%d\n", GetCurrentCoreId(), file, line); + if (KProcess *cur_process = GetCurrentProcessPointer(); cur_process != nullptr) { + MESOSPHERE_RELEASE_LOG("Core[%d]: Current Process: %s\n", GetCurrentCoreId(), cur_process->GetName()); + } MESOSPHERE_RELEASE_VLOG(format, vl); MESOSPHERE_RELEASE_LOG("\n"); va_end(vl);