diff options
author | Jacek Antonelli | 2009-11-18 23:08:01 -0600 |
---|---|---|
committer | Jacek Antonelli | 2009-11-18 23:10:06 -0600 |
commit | 98f909f9915448d49cd7fe83d044fdc490fc6003 (patch) | |
tree | 1d037f14a57505638dbc9f5fbd8a950290629b73 /linden/indra/llcommon | |
parent | Added "File > Export Selected Objects..." (diff) | |
download | meta-impy-98f909f9915448d49cd7fe83d044fdc490fc6003.zip meta-impy-98f909f9915448d49cd7fe83d044fdc490fc6003.tar.gz meta-impy-98f909f9915448d49cd7fe83d044fdc490fc6003.tar.bz2 meta-impy-98f909f9915448d49cd7fe83d044fdc490fc6003.tar.xz |
SNOW-108: Fast timers fail on non i386 systems
Patch by Robin Cornelius
Diffstat (limited to 'linden/indra/llcommon')
-rw-r--r-- | linden/indra/llcommon/llfasttimer.cpp | 35 | ||||
-rw-r--r-- | linden/indra/llcommon/llfasttimer.h | 1 |
2 files changed, 26 insertions, 10 deletions
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; | |||
63 | 63 | ||
64 | F64 LLFastTimer::sCPUClockFrequency = 0.0; | 64 | F64 LLFastTimer::sCPUClockFrequency = 0.0; |
65 | 65 | ||
66 | #if LL_LINUX || LL_SOLARIS | ||
67 | U64 LLFastTimer::sClockResolution = 1e9; // Nanosecond resolution | ||
68 | #else | ||
69 | U64 LLFastTimer::sClockResolution = 1e6; // Microsecond resolution | ||
70 | #endif | ||
71 | |||
66 | ////////////////////////////////////////////////////////////////////////////// | 72 | ////////////////////////////////////////////////////////////////////////////// |
67 | 73 | ||
68 | // | 74 | // |
@@ -90,17 +96,26 @@ U64 get_cpu_clock_count() | |||
90 | 96 | ||
91 | #endif // LL_WINDOWS | 97 | #endif // LL_WINDOWS |
92 | 98 | ||
93 | 99 | #if LL_LINUX || LL_SOLARIS | |
94 | #if (LL_LINUX || LL_SOLARIS) && (defined(__i386__) || defined(__amd64__)) | 100 | // Try to use the MONOTONIC clock if available, this is a constant time counter |
101 | // with nanosecond resolution (but not necessarily accuracy) and attempts are made | ||
102 | // to synchronize this value between cores at kernel start. It should not be effected | ||
103 | // by CPU frequency. If not available use the REALTIME clock, but this may be effected by | ||
104 | // NTP adjustments or other user activity effecting the system time. | ||
95 | U64 get_cpu_clock_count() | 105 | U64 get_cpu_clock_count() |
96 | { | 106 | { |
97 | U64 x; | 107 | struct timespec tp; |
98 | __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x)); | 108 | |
99 | return x; | 109 | #ifdef CLOCK_MONOTONIC |
100 | } | 110 | clock_gettime(CLOCK_MONOTONIC,&tp); |
111 | #else | ||
112 | clock_gettime(CLOCK_REALTIME,&tp); | ||
101 | #endif | 113 | #endif |
114 | return (tp.tv_sec*LLFastTimer::sClockResolution)+tp.tv_nsec; | ||
115 | } | ||
116 | #endif // (LL_LINUX || LL_SOLARIS)) | ||
102 | 117 | ||
103 | #if LL_DARWIN || (LL_SOLARIS && defined(__sparc__)) | 118 | #if LL_DARWIN |
104 | // | 119 | // |
105 | // Mac implementation of CPU clock | 120 | // Mac implementation of CPU clock |
106 | // | 121 | // |
@@ -115,13 +130,13 @@ U64 get_cpu_clock_count() | |||
115 | ////////////////////////////////////////////////////////////////////////////// | 130 | ////////////////////////////////////////////////////////////////////////////// |
116 | 131 | ||
117 | //static | 132 | //static |
118 | #if LL_LINUX || LL_DARWIN || LL_SOLARIS | 133 | #if LL_DARWIN || LL_LINUX || LL_SOLARIS |
119 | // Both Linux and Mac use gettimeofday for accurate time | 134 | // Both Linux and Mac use gettimeofday for accurate time |
120 | U64 LLFastTimer::countsPerSecond() | 135 | U64 LLFastTimer::countsPerSecond() |
121 | { | 136 | { |
122 | return 1000000; // microseconds, so 1 Mhz. | 137 | return sClockResolution; // microseconds, so 1 Mhz. |
123 | } | 138 | } |
124 | #else | 139 | #else |
125 | U64 LLFastTimer::countsPerSecond() | 140 | U64 LLFastTimer::countsPerSecond() |
126 | { | 141 | { |
127 | if (!sCPUClockFrequency) | 142 | 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: | |||
238 | static int sPauseHistory; | 238 | static int sPauseHistory; |
239 | static int sResetHistory; | 239 | static int sResetHistory; |
240 | static F64 sCPUClockFrequency; | 240 | static F64 sCPUClockFrequency; |
241 | static U64 sClockResolution; | ||
241 | 242 | ||
242 | private: | 243 | private: |
243 | EFastTimerType mType; | 244 | EFastTimerType mType; |