Codestyle fixes

This commit is contained in:
Daniil Brychikov 2022-02-19 11:44:15 +03:00
parent 73f6c66cde
commit a9ba1ce688
2 changed files with 15 additions and 27 deletions

View File

@ -322,13 +322,10 @@ static void InitFailure( const char* msg )
exit( 1 ); exit( 1 );
} }
static bool checkHardwareSupportsInvariantTSC() static bool CheckHardwareSupportsInvariantTSC()
{ {
const char* noCheck = GetEnvVar( "TRACY_NO_INVARIANT_CHECK" ); const char* noCheck = GetEnvVar( "TRACY_NO_INVARIANT_CHECK" );
if( noCheck && noCheck[0] == '1' ) if( noCheck && noCheck[0] == '1' ) return true;
{
return true;
}
uint32_t regs[4]; uint32_t regs[4];
CpuId( regs, 1 ); CpuId( regs, 1 );
@ -340,18 +337,15 @@ static bool checkHardwareSupportsInvariantTSC()
return false; return false;
} }
CpuId( regs, 0x80000007 ); CpuId( regs, 0x80000007 );
if( regs[3] & ( 1 << 8 ) ) if( regs[3] & ( 1 << 8 ) ) return true;
{
return true;
}
return false; return false;
} }
#if defined TRACY_TIMER_FALLBACK && defined TRACY_HW_TIMER #if defined TRACY_TIMER_FALLBACK && defined TRACY_HW_TIMER
bool hardwareSupportsInvariantTSC() bool HardwareSupportsInvariantTSC()
{ {
static bool cachedResult = checkHardwareSupportsInvariantTSC(); static bool cachedResult = CheckHardwareSupportsInvariantTSC();
return cachedResult; return cachedResult;
} }
#endif #endif
@ -359,7 +353,7 @@ bool hardwareSupportsInvariantTSC()
static int64_t SetupHwTimer() static int64_t SetupHwTimer()
{ {
#if !defined TRACY_TIMER_QPC && !defined TRACY_TIMER_FALLBACK #if !defined TRACY_TIMER_QPC && !defined TRACY_TIMER_FALLBACK
if(!checkHardwareSupportsInvariantTSC()) if( !CheckHardwareSupportsInvariantTSC() )
{ {
#if defined _WIN32 #if defined _WIN32
InitFailure( "CPU doesn't support invariant TSC.\nDefine TRACY_NO_INVARIANT_CHECK=1 to ignore this error, *if you know what you are doing*.\nAlternatively you may rebuild the application with the TRACY_TIMER_QPC or TRACY_TIMER_FALLBACK define to use lower resolution timer." ); InitFailure( "CPU doesn't support invariant TSC.\nDefine TRACY_NO_INVARIANT_CHECK=1 to ignore this error, *if you know what you are doing*.\nAlternatively you may rebuild the application with the TRACY_TIMER_QPC or TRACY_TIMER_FALLBACK define to use lower resolution timer." );
@ -3482,11 +3476,11 @@ void Profiler::CalibrateTimer()
#ifdef TRACY_HW_TIMER #ifdef TRACY_HW_TIMER
# if !defined TRACY_TIMER_QPC && defined TRACY_TIMER_FALLBACK # if !defined TRACY_TIMER_QPC && defined TRACY_TIMER_FALLBACK
const bool needCalibration = hardwareSupportsInvariantTSC(); const bool needCalibration = HardwareSupportsInvariantTSC();
# else # else
const bool needCalibration = true; const bool needCalibration = true;
# endif # endif
if (needCalibration) if( needCalibration )
{ {
std::atomic_signal_fence( std::memory_order_acq_rel ); std::atomic_signal_fence( std::memory_order_acq_rel );
const auto t0 = std::chrono::high_resolution_clock::now(); const auto t0 = std::chrono::high_resolution_clock::now();

View File

@ -68,15 +68,15 @@ TRACY_API bool ProfilerAvailable();
TRACY_API int64_t GetFrequencyQpc(); TRACY_API int64_t GetFrequencyQpc();
#if defined TRACY_TIMER_FALLBACK && defined TRACY_HW_TIMER && ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 ) #if defined TRACY_TIMER_FALLBACK && defined TRACY_HW_TIMER && ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 )
TRACY_API bool hardwareSupportsInvariantTSC(); // check, if we need fallback scenario TRACY_API bool HardwareSupportsInvariantTSC(); // check, if we need fallback scenario
#else #else
# if defined TRACY_HW_TIMER # if defined TRACY_HW_TIMER
tracy_force_inline bool hardwareSupportsInvariantTSC() tracy_force_inline bool HardwareSupportsInvariantTSC()
{ {
return true; // this is checked at startup return true; // this is checked at startup
} }
# else # else
tracy_force_inline bool hardwareSupportsInvariantTSC() tracy_force_inline bool HardwareSupportsInvariantTSC()
{ {
return false; return false;
} }
@ -183,28 +183,22 @@ public:
{ {
#ifdef TRACY_HW_TIMER #ifdef TRACY_HW_TIMER
# if defined TARGET_OS_IOS && TARGET_OS_IOS == 1 # if defined TARGET_OS_IOS && TARGET_OS_IOS == 1
if (hardwareSupportsInvariantTSC()) if( HardwareSupportsInvariantTSC() ) return mach_absolute_time();
{
return mach_absolute_time();
}
# elif defined _WIN32 # elif defined _WIN32
# ifdef TRACY_TIMER_QPC # ifdef TRACY_TIMER_QPC
return GetTimeQpc(); return GetTimeQpc();
# else # else
if (hardwareSupportsInvariantTSC()) if( HardwareSupportsInvariantTSC() ) return int64_t( __rdtsc() );
{
return int64_t( __rdtsc() );
}
# endif # endif
# elif defined __i386 || defined _M_IX86 # elif defined __i386 || defined _M_IX86
if (hardwareSupportsInvariantTSC()) if( HardwareSupportsInvariantTSC() )
{ {
uint32_t eax, edx; uint32_t eax, edx;
asm volatile ( "rdtsc" : "=a" (eax), "=d" (edx) ); asm volatile ( "rdtsc" : "=a" (eax), "=d" (edx) );
return ( uint64_t( edx ) << 32 ) + uint64_t( eax ); return ( uint64_t( edx ) << 32 ) + uint64_t( eax );
} }
# elif defined __x86_64__ || defined _M_X64 # elif defined __x86_64__ || defined _M_X64
if (hardwareSupportsInvariantTSC()) if( HardwareSupportsInvariantTSC() )
{ {
uint64_t rax, rdx; uint64_t rax, rdx;
asm volatile ( "rdtsc" : "=a" (rax), "=d" (rdx) ); asm volatile ( "rdtsc" : "=a" (rax), "=d" (rdx) );