From 98f909f9915448d49cd7fe83d044fdc490fc6003 Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Wed, 18 Nov 2009 23:08:01 -0600 Subject: SNOW-108: Fast timers fail on non i386 systems Patch by Robin Cornelius --- ChangeLog.txt | 8 ++++++++ linden/doc/contributions.txt | 1 + linden/indra/llcommon/llfasttimer.cpp | 35 +++++++++++++++++++++++++---------- linden/indra/llcommon/llfasttimer.h | 1 + 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 492d353..cc20925 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,5 +1,13 @@ 2009-11-18 Jacek Antonelli + * SNOW-108: Fast timers fail on non i386 systems + Patch by Robin Cornelius + + modified: doc/contributions.txt + modified: indra/llcommon/llfasttimer.cpp + modified: indra/llcommon/llfasttimer.h + + * Added "File > Export Selected Objects..." modified: linden/indra/newview/skins/default/xui/en-us/menu_viewer.xml diff --git a/linden/doc/contributions.txt b/linden/doc/contributions.txt index 64304dc..e99bd78 100644 --- a/linden/doc/contributions.txt +++ b/linden/doc/contributions.txt @@ -347,6 +347,7 @@ princess niven Renault Clio VWR-1976 Robin Cornelius + SNOW-108 VWR-2488 Ryozu Kojima VWR-287 diff --git a/linden/indra/llcommon/llfasttimer.cpp b/linden/indra/llcommon/llfasttimer.cpp index 3304528..9253f2b 100644 --- a/linden/indra/llcommon/llfasttimer.cpp +++ b/linden/indra/llcommon/llfasttimer.cpp @@ -63,6 +63,12 @@ int LLFastTimer::sResetHistory = 0; F64 LLFastTimer::sCPUClockFrequency = 0.0; +#if LL_LINUX || LL_SOLARIS +U64 LLFastTimer::sClockResolution = 1e9; // Nanosecond resolution +#else +U64 LLFastTimer::sClockResolution = 1e6; // Microsecond resolution +#endif + ////////////////////////////////////////////////////////////////////////////// // @@ -90,17 +96,26 @@ U64 get_cpu_clock_count() #endif // LL_WINDOWS - -#if (LL_LINUX || LL_SOLARIS) && (defined(__i386__) || defined(__amd64__)) +#if LL_LINUX || LL_SOLARIS +// Try to use the MONOTONIC clock if available, this is a constant time counter +// with nanosecond resolution (but not necessarily accuracy) and attempts are made +// to synchronize this value between cores at kernel start. It should not be effected +// by CPU frequency. If not available use the REALTIME clock, but this may be effected by +// NTP adjustments or other user activity effecting the system time. U64 get_cpu_clock_count() { - U64 x; - __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x)); - return x; -} + struct timespec tp; + +#ifdef CLOCK_MONOTONIC + clock_gettime(CLOCK_MONOTONIC,&tp); +#else + clock_gettime(CLOCK_REALTIME,&tp); #endif + return (tp.tv_sec*LLFastTimer::sClockResolution)+tp.tv_nsec; +} +#endif // (LL_LINUX || LL_SOLARIS)) -#if LL_DARWIN || (LL_SOLARIS && defined(__sparc__)) +#if LL_DARWIN // // Mac implementation of CPU clock // @@ -115,13 +130,13 @@ U64 get_cpu_clock_count() ////////////////////////////////////////////////////////////////////////////// //static -#if LL_LINUX || LL_DARWIN || LL_SOLARIS +#if LL_DARWIN || LL_LINUX || LL_SOLARIS // Both Linux and Mac use gettimeofday for accurate time U64 LLFastTimer::countsPerSecond() { - return 1000000; // microseconds, so 1 Mhz. + return sClockResolution; // microseconds, so 1 Mhz. } -#else +#else U64 LLFastTimer::countsPerSecond() { if (!sCPUClockFrequency) diff --git a/linden/indra/llcommon/llfasttimer.h b/linden/indra/llcommon/llfasttimer.h index a32da18..2e66496 100644 --- a/linden/indra/llcommon/llfasttimer.h +++ b/linden/indra/llcommon/llfasttimer.h @@ -238,6 +238,7 @@ public: static int sPauseHistory; static int sResetHistory; static F64 sCPUClockFrequency; + static U64 sClockResolution; private: EFastTimerType mType; -- cgit v1.1