From 649994706bdd41949a9a4680ef81decedd3678b4 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Wed, 12 Aug 2020 16:48:36 +0200 Subject: [PATCH] Use clock monotonic raw on Linux. Because Linux kernel interfaces are fucking stupid. --- client/TracyProfiler.cpp | 9 --------- client/TracyProfiler.hpp | 21 +++++++++++---------- client/TracySysTrace.cpp | 8 -------- 3 files changed, 11 insertions(+), 27 deletions(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 042f0d94..8525cc7a 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -84,11 +84,6 @@ # endif #endif -#if defined TRACY_HW_TIMER && __ARM_ARCH >= 6 && !defined TARGET_OS_IOS -# include -# include -#endif - #if defined _WIN32 || defined __CYGWIN__ # include extern "C" typedef LONG (WINAPI *t_RtlGetVersion)( PRTL_OSVERSIONINFOW ); @@ -2585,9 +2580,6 @@ void Profiler::HandleDisconnect() void Profiler::CalibrateTimer() { #ifdef TRACY_HW_TIMER -# if !defined TARGET_OS_IOS && __ARM_ARCH >= 6 - m_timerMul = 1.; -# else std::atomic_signal_fence( std::memory_order_acq_rel ); const auto t0 = std::chrono::high_resolution_clock::now(); const auto r0 = GetTime(); @@ -2602,7 +2594,6 @@ void Profiler::CalibrateTimer() const auto dr = r1 - r0; m_timerMul = double( dt ) / double( dr ); -# endif #else m_timerMul = 1.; #endif diff --git a/client/TracyProfiler.hpp b/client/TracyProfiler.hpp index 465946b2..cf1a1c8c 100644 --- a/client/TracyProfiler.hpp +++ b/client/TracyProfiler.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "tracy_concurrentqueue.h" #include "TracyCallstack.hpp" @@ -24,11 +25,11 @@ # include #endif -#if defined _WIN32 || defined __CYGWIN__ || ( ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 ) && !defined __ANDROID__ ) || __ARM_ARCH >= 6 +#if defined _WIN32 || defined __CYGWIN__ || ( ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 ) && !defined __linux__ ) || ( defined TARGET_OS_IOS && TARGET_OS_IOS == 1 ) # define TRACY_HW_TIMER #endif -#if !defined TRACY_HW_TIMER || ( defined __ARM_ARCH && __ARM_ARCH >= 6 && !defined CLOCK_MONOTONIC_RAW ) +#if !defined TRACY_HW_TIMER #include #endif @@ -130,14 +131,6 @@ public: #ifdef TRACY_HW_TIMER # if defined TARGET_OS_IOS && TARGET_OS_IOS == 1 return mach_absolute_time(); -# elif defined __ARM_ARCH && __ARM_ARCH >= 6 -# ifdef CLOCK_MONOTONIC_RAW - struct timespec ts; - clock_gettime( CLOCK_MONOTONIC_RAW, &ts ); - return int64_t( ts.tv_sec ) * 1000000000ll + int64_t( ts.tv_nsec ); -# else - return std::chrono::duration_cast( std::chrono::high_resolution_clock::now().time_since_epoch() ).count(); -# endif # elif defined _WIN32 || defined __CYGWIN__ # ifdef TRACY_TIMER_QPC return GetTimeQpc(); @@ -152,9 +145,17 @@ public: uint64_t rax, rdx; asm volatile ( "rdtsc" : "=a" (rax), "=d" (rdx) ); return ( rdx << 32 ) + rax; +# else +# error "TRACY_HW_TIMER detection logic needs fixing" # endif #else +# if defined __linux__ && defined CLOCK_MONOTONIC_RAW + struct timespec ts; + clock_gettime( CLOCK_MONOTONIC_RAW, &ts ); + return int64_t( ts.tv_sec ) * 1000000000ll + int64_t( ts.tv_nsec ); +# else return std::chrono::duration_cast( std::chrono::high_resolution_clock::now().time_since_epoch() ).count(); +# endif #endif } diff --git a/client/TracySysTrace.cpp b/client/TracySysTrace.cpp index bec85bc4..21df70f6 100644 --- a/client/TracySysTrace.cpp +++ b/client/TracySysTrace.cpp @@ -827,11 +827,7 @@ bool SysTraceStart( int64_t& samplingPeriod ) TraceWrite( TraceOptions, sizeof( TraceOptions ), "norecord-tgid", 14 ); TraceWrite( TraceOptions, sizeof( TraceOptions ), "noirq-info", 11 ); TraceWrite( TraceOptions, sizeof( TraceOptions ), "noannotate", 11 ); -#if defined TRACY_HW_TIMER && ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 ) - if( !TraceWrite( TraceClock, sizeof( TraceClock ), "x86-tsc", 8 ) ) return false; -#elif __ARM_ARCH >= 6 if( !TraceWrite( TraceClock, sizeof( TraceClock ), "mono_raw", 9 ) ) return false; -#endif if( !TraceWrite( SchedSwitch, sizeof( SchedSwitch ), "1", 2 ) ) return false; if( !TraceWrite( SchedWakeup, sizeof( SchedWakeup ), "1", 2 ) ) return false; if( !TraceWrite( BufferSizeKb, sizeof( BufferSizeKb ), "4096", 5 ) ) return false; @@ -975,14 +971,10 @@ static void HandleTraceLine( const char* line ) line++; // ']' while( *line == ' ' ) line++; -#if defined TRACY_HW_TIMER && ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 ) - const auto time = ReadNumber( line ); -#elif __ARM_ARCH >= 6 const auto ts = ReadNumber( line ); line++; // '.' const auto tus = ReadNumber( line ); const auto time = ts * 1000000000ll + tus * 1000ll; -#endif line += 2; // ': ' if( memcmp( line, "sched_switch", 12 ) == 0 )