From 4a1ca5f39b1c72255078d7517dbd559269bf8967 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Fri, 17 Sep 2021 14:57:08 -0700 Subject: [PATCH] kern: update GetInfo logic for tick count InfoTypes --- .../source/svc/kern_svc_info.cpp | 42 ++++++++++--------- .../include/vapours/svc/svc_types_common.hpp | 3 +- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/libraries/libmesosphere/source/svc/kern_svc_info.cpp b/libraries/libmesosphere/source/svc/kern_svc_info.cpp index e16fdcd37..c5424095f 100644 --- a/libraries/libmesosphere/source/svc/kern_svc_info.cpp +++ b/libraries/libmesosphere/source/svc/kern_svc_info.cpp @@ -181,6 +181,9 @@ namespace ams::kern::svc { /* Verify the input handle is invalid. */ R_UNLESS(handle == ams::svc::InvalidHandle, svc::ResultInvalidHandle()); + /* Disable dispatch while we get the tick count. */ + KScopedDisableDispatch dd; + /* Verify the requested core is valid. */ const bool core_valid = (info_subtype == static_cast(-1ul)) || (info_subtype == static_cast(GetCurrentCoreId())); R_UNLESS(core_valid, svc::ResultInvalidCombination()); @@ -223,28 +226,27 @@ namespace ams::kern::svc { KScopedAutoObject thread = GetCurrentProcess().GetHandleTable().GetObject(handle); R_UNLESS(thread.IsNotNull(), svc::ResultInvalidHandle()); - /* Disable interrupts while we get the tick count. */ + /* Disable dispatch while we get the tick count. */ + KScopedDisableDispatch dd; + + /* Determine the tick count. */ s64 tick_count; - { - KScopedInterruptDisable di; + if (info_subtype == static_cast(-1ul)) { + tick_count = thread->GetCpuTime(); + if (GetCurrentThreadPointer() == thread.GetPointerUnsafe()) { + const s64 cur_tick = KHardwareTimer::GetTick(); + const s64 prev_switch = Kernel::GetScheduler().GetLastContextSwitchTime(); + tick_count += (cur_tick - prev_switch); + } + } else { + const s32 phys_core = cpu::VirtualToPhysicalCoreMap[info_subtype]; + MESOSPHERE_ABORT_UNLESS(phys_core < static_cast(cpu::NumCores)); - if (info_subtype == static_cast(-1ul)) { - tick_count = thread->GetCpuTime(); - if (GetCurrentThreadPointer() == thread.GetPointerUnsafe()) { - const s64 cur_tick = KHardwareTimer::GetTick(); - const s64 prev_switch = Kernel::GetScheduler().GetLastContextSwitchTime(); - tick_count += (cur_tick - prev_switch); - } - } else { - const s32 phys_core = cpu::VirtualToPhysicalCoreMap[info_subtype]; - MESOSPHERE_ABORT_UNLESS(phys_core < static_cast(cpu::NumCores)); - - tick_count = thread->GetCpuTime(phys_core); - if (GetCurrentThreadPointer() == thread.GetPointerUnsafe() && phys_core == GetCurrentCoreId()) { - const s64 cur_tick = KHardwareTimer::GetTick(); - const s64 prev_switch = Kernel::GetScheduler().GetLastContextSwitchTime(); - tick_count += (cur_tick - prev_switch); - } + tick_count = thread->GetCpuTime(phys_core); + if (GetCurrentThreadPointer() == thread.GetPointerUnsafe() && phys_core == GetCurrentCoreId()) { + const s64 cur_tick = KHardwareTimer::GetTick(); + const s64 prev_switch = Kernel::GetScheduler().GetLastContextSwitchTime(); + tick_count += (cur_tick - prev_switch); } } diff --git a/libraries/libvapours/include/vapours/svc/svc_types_common.hpp b/libraries/libvapours/include/vapours/svc/svc_types_common.hpp index 06355d34c..a42a6c033 100644 --- a/libraries/libvapours/include/vapours/svc/svc_types_common.hpp +++ b/libraries/libvapours/include/vapours/svc/svc_types_common.hpp @@ -157,11 +157,10 @@ namespace ams::svc { InfoType_UsedNonSystemMemorySize = 22, InfoType_IsApplication = 23, InfoType_FreeThreadCount = 24, + InfoType_ThreadTickCount = 25, InfoType_MesosphereMeta = 65000, InfoType_MesosphereCurrentProcess = 65001, - - InfoType_ThreadTickCount = 0xF0000002, }; enum TickCountInfo : u64 {