aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llcommon
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llcommon')
-rw-r--r--linden/indra/llcommon/llfasttimer.cpp35
-rw-r--r--linden/indra/llcommon/llfasttimer.h1
2 files changed, 26 insertions, 10 deletions
diff --git a/linden/indra/llcommon/llfasttimer.cpp b/linden/indra/llcommon/llfasttimer.cpp
index cdaadb0..4aa23bb 100644
--- a/linden/indra/llcommon/llfasttimer.cpp
+++ b/linden/indra/llcommon/llfasttimer.cpp
@@ -66,6 +66,12 @@ int LLFastTimer::sResetHistory = 0;
66 66
67F64 LLFastTimer::sCPUClockFrequency = 0.0; 67F64 LLFastTimer::sCPUClockFrequency = 0.0;
68 68
69#if LL_LINUX || LL_SOLARIS
70U64 LLFastTimer::sClockResolution = 1e9; // Nanosecond resolution
71#else
72U64 LLFastTimer::sClockResolution = 1e6; // Microsecond resolution
73#endif
74
69////////////////////////////////////////////////////////////////////////////// 75//////////////////////////////////////////////////////////////////////////////
70 76
71// 77//
@@ -93,17 +99,26 @@ U64 get_cpu_clock_count()
93 99
94#endif // LL_WINDOWS 100#endif // LL_WINDOWS
95 101
96 102#if LL_LINUX || LL_SOLARIS
97#if (LL_LINUX || LL_SOLARIS) && (defined(__i386__) || defined(__amd64__)) 103// Try to use the MONOTONIC clock if available, this is a constant time counter
104// with nanosecond resolution (but not necessarily accuracy) and attempts are made
105// to synchronize this value between cores at kernel start. It should not be effected
106// by CPU frequency. If not available use the REALTIME clock, but this may be effected by
107// NTP adjustments or other user activity effecting the system time.
98U64 get_cpu_clock_count() 108U64 get_cpu_clock_count()
99{ 109{
100 U64 x; 110 struct timespec tp;
101 __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x)); 111
102 return x; 112#ifdef CLOCK_MONOTONIC
103} 113 clock_gettime(CLOCK_MONOTONIC,&tp);
114#else
115 clock_gettime(CLOCK_REALTIME,&tp);
104#endif 116#endif
117 return (tp.tv_sec*LLFastTimer::sClockResolution)+tp.tv_nsec;
118}
119#endif // (LL_LINUX || LL_SOLARIS))
105 120
106#if LL_DARWIN || (LL_SOLARIS && defined(__sparc__)) 121#if LL_DARWIN
107// 122//
108// Mac implementation of CPU clock 123// Mac implementation of CPU clock
109// 124//
@@ -118,13 +133,13 @@ U64 get_cpu_clock_count()
118////////////////////////////////////////////////////////////////////////////// 133//////////////////////////////////////////////////////////////////////////////
119 134
120//static 135//static
121#if LL_LINUX || LL_DARWIN || LL_SOLARIS 136#if LL_DARWIN || LL_LINUX || LL_SOLARIS
122// Both Linux and Mac use gettimeofday for accurate time 137// Both Linux and Mac use gettimeofday for accurate time
123U64 LLFastTimer::countsPerSecond() 138U64 LLFastTimer::countsPerSecond()
124{ 139{
125 return 1000000; // microseconds, so 1 Mhz. 140 return sClockResolution; // microseconds, so 1 Mhz.
126} 141}
127#else 142#else
128U64 LLFastTimer::countsPerSecond() 143U64 LLFastTimer::countsPerSecond()
129{ 144{
130 if (!sCPUClockFrequency) 145 if (!sCPUClockFrequency)
diff --git a/linden/indra/llcommon/llfasttimer.h b/linden/indra/llcommon/llfasttimer.h
index 94b5111..60281fd 100644
--- a/linden/indra/llcommon/llfasttimer.h
+++ b/linden/indra/llcommon/llfasttimer.h
@@ -249,6 +249,7 @@ public:
249 static int sPauseHistory; 249 static int sPauseHistory;
250 static int sResetHistory; 250 static int sResetHistory;
251 static F64 sCPUClockFrequency; 251 static F64 sCPUClockFrequency;
252 static U64 sClockResolution;
252 253
253private: 254private:
254 EFastTimerType mType; 255 EFastTimerType mType;