From 37e2142ccac0b6ec411182511b1045ed82642540 Mon Sep 17 00:00:00 2001 From: tellowkrinkle Date: Thu, 4 Nov 2021 21:46:39 -0500 Subject: [PATCH] Common: Fix Darwin thread times MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Percentages will now actually be percentages instead of permille (units of 1/1000) Was caused by trying to match Windows's returns of 100ns units, but then reporting 1µs units from `GetThreadTicksPerSecond()` --- common/Darwin/DarwinThreads.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/common/Darwin/DarwinThreads.cpp b/common/Darwin/DarwinThreads.cpp index a9a74879f5..28ed4894eb 100644 --- a/common/Darwin/DarwinThreads.cpp +++ b/common/Darwin/DarwinThreads.cpp @@ -82,11 +82,7 @@ static u64 getthreadtime(thread_port_t thread) (u64)info.system_time.microseconds; } -// Returns the current timestamp (not relative to a real world clock) in -// units of 100 nanoseconds. The weird units are to mirror the Windows -// counterpart in WinThreads.cpp, which uses the GetThreadTimes() API. On -// OSX/Darwin, this is only accurate up until 1ms (and possibly less), so -// not very good. +// Returns the current timestamp (not relative to a real world clock) in microseconds u64 Threading::GetThreadCpuTime() { // we could also use mach_thread_self() and mach_port_deallocate(), but @@ -95,7 +91,7 @@ u64 Threading::GetThreadCpuTime() // to be user-space instead. In contract, // pthread_mach_thread_np(pthread_self()) is entirely in user-space. u64 us = getthreadtime(pthread_mach_thread_np(pthread_self())); - return us * 10ULL; + return us; } u64 Threading::pxThread::GetCpuTime() const @@ -109,7 +105,7 @@ u64 Threading::pxThread::GetCpuTime() const return 0; } - return getthreadtime((thread_port_t)m_native_id) * 10ULL; + return getthreadtime((thread_port_t)m_native_id); } void Threading::pxThread::_platform_specific_OnStartInThread()