From fae92a2df852992216eb24418a1dd0b676696bee Mon Sep 17 00:00:00 2001 From: Tofu Linden Date: Thu, 15 Apr 2010 16:55:34 +0100 Subject: some clean-up of lllfsthread to help me understand it, remove one extraneous close(). to be reviewed by bao. (transplanted from 17c6af7a2396f9890aab8226356a556b4d58a7d8) --- indra/llcommon/llapr.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llapr.h b/indra/llcommon/llapr.h index b05a222b33..c1ad0bfed1 100644 --- a/indra/llcommon/llapr.h +++ b/indra/llcommon/llapr.h @@ -182,7 +182,7 @@ typedef LLAtomic32 LLAtomicU32; typedef LLAtomic32 LLAtomicS32; // File IO convenience functions. -// Returns NULL if the file fails to openm sets *sizep to file size of not NULL +// Returns NULL if the file fails to open, sets *sizep to file size if not NULL // abbreviated flags #define LL_APR_R (APR_READ) // "r" #define LL_APR_W (APR_CREATE|APR_TRUNCATE|APR_WRITE) // "w" @@ -200,7 +200,7 @@ typedef LLAtomic32 LLAtomicS32; // especially do not put some time-costly operations between open() and close(). // otherwise it might lock the APRFilePool. //there are two different apr_pools the APRFile can use: -// 1, a temperary pool passed to an APRFile function, which is used within this function and only once. +// 1, a temporary pool passed to an APRFile function, which is used within this function and only once. // 2, a global pool. // -- cgit v1.2.3 From 1c638961543909e897bc343d260f300202687723 Mon Sep 17 00:00:00 2001 From: Tofu Linden Date: Thu, 15 Apr 2010 18:00:00 +0100 Subject: Supporting 'read from the end' doesn't make sense (to me), unlike 'write from the end'. Also, more comments. Also, try to avoid a seek when offset==0 in read. To be reviewed by Bao. (transplanted from 60eb013221a83ff76054ab7dcb1d07c108f51a9d) --- indra/llcommon/llapr.cpp | 11 +++++------ indra/llcommon/llapr.h | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llapr.cpp b/indra/llcommon/llapr.cpp index ed70b1d9f2..7330b00bcf 100644 --- a/indra/llcommon/llapr.cpp +++ b/indra/llcommon/llapr.cpp @@ -543,14 +543,13 @@ S32 LLAPRFile::readEx(const std::string& filename, void *buf, S32 offset, S32 nb return 0; } - S32 off; - if (offset < 0) - off = LLAPRFile::seek(file_handle, APR_END, 0); - else - off = LLAPRFile::seek(file_handle, APR_SET, offset); + llassert(offset >= 0); + + if (offset > 0) + offset = LLAPRFile::seek(file_handle, APR_SET, offset); apr_size_t bytes_read; - if (off < 0) + if (offset < 0) { bytes_read = 0; } diff --git a/indra/llcommon/llapr.h b/indra/llcommon/llapr.h index c1ad0bfed1..08cf11e593 100644 --- a/indra/llcommon/llapr.h +++ b/indra/llcommon/llapr.h @@ -255,12 +255,12 @@ public: // Returns bytes read/written, 0 if read/write fails: static S32 readEx(const std::string& filename, void *buf, S32 offset, S32 nbytes, LLVolatileAPRPool* pool = NULL); - static S32 writeEx(const std::string& filename, void *buf, S32 offset, S32 nbytes, LLVolatileAPRPool* pool = NULL); + static S32 writeEx(const std::string& filename, void *buf, S32 offset, S32 nbytes, LLVolatileAPRPool* pool = NULL); // offset<0 means append //******************************************************************************************************************************* }; /** - * @brief Function which approprately logs error or remains quiet on + * @brief Function which appropriately logs error or remains quiet on * APR_SUCCESS. * @return Returns true if status is an error condition. */ -- cgit v1.2.3 From 59446d550522660c47065622812308da190d6a89 Mon Sep 17 00:00:00 2001 From: Tofu Linden Date: Thu, 15 Apr 2010 19:40:58 +0100 Subject: be gentler on negative-offset reads - just do nothing instead of asserting. from bao's review. (transplanted from 061b8b55838634425455ebc4ac046462dfc0e5f1) --- indra/llcommon/llapr.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llapr.cpp b/indra/llcommon/llapr.cpp index 7330b00bcf..f030867ec4 100644 --- a/indra/llcommon/llapr.cpp +++ b/indra/llcommon/llapr.cpp @@ -535,6 +535,11 @@ S32 LLAPRFile::seek(apr_file_t* file_handle, apr_seek_where_t where, S32 offset) //static S32 LLAPRFile::readEx(const std::string& filename, void *buf, S32 offset, S32 nbytes, LLVolatileAPRPool* pool) { + if (offset < 0) + { + return 0; // do nothing, negative offsets don't make sense for reads + } + //***************************************** apr_file_t* file_handle = open(filename, pool, APR_READ|APR_BINARY); //***************************************** @@ -543,10 +548,10 @@ S32 LLAPRFile::readEx(const std::string& filename, void *buf, S32 offset, S32 nb return 0; } - llassert(offset >= 0); - if (offset > 0) + { offset = LLAPRFile::seek(file_handle, APR_SET, offset); + } apr_size_t bytes_read; if (offset < 0) -- cgit v1.2.3 From 799e014f2a16d5031d976e9662d3333d65cfc94c Mon Sep 17 00:00:00 2001 From: Tofu Linden Date: Thu, 15 Apr 2010 20:31:56 +0100 Subject: Backed out changeset eaac19489aa6 Bao agreed with my initial version after all. --- indra/llcommon/llapr.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llapr.cpp b/indra/llcommon/llapr.cpp index f030867ec4..7330b00bcf 100644 --- a/indra/llcommon/llapr.cpp +++ b/indra/llcommon/llapr.cpp @@ -535,11 +535,6 @@ S32 LLAPRFile::seek(apr_file_t* file_handle, apr_seek_where_t where, S32 offset) //static S32 LLAPRFile::readEx(const std::string& filename, void *buf, S32 offset, S32 nbytes, LLVolatileAPRPool* pool) { - if (offset < 0) - { - return 0; // do nothing, negative offsets don't make sense for reads - } - //***************************************** apr_file_t* file_handle = open(filename, pool, APR_READ|APR_BINARY); //***************************************** @@ -548,10 +543,10 @@ S32 LLAPRFile::readEx(const std::string& filename, void *buf, S32 offset, S32 nb return 0; } + llassert(offset >= 0); + if (offset > 0) - { offset = LLAPRFile::seek(file_handle, APR_SET, offset); - } apr_size_t bytes_read; if (offset < 0) -- cgit v1.2.3 From 7462911bddd9b5e4033d7108ffc1b6716068f489 Mon Sep 17 00:00:00 2001 From: Tofu Linden Date: Mon, 19 Apr 2010 12:49:15 +0100 Subject: Change Linux fasttimer implementation back to RDTSC - using a reliable syscall was REALLY chewing CPU time. Sigh. I didn't realize how incredibly often this gets called. So, back to the assembly. But be more careful with CPU clock count on linux, so the fasttimer values are much more accurate than they were the last time we were with RDTSC, in absolute terms - back in the right order of magnitude anyway. Also change many instances of Mhz to MHz. Also some minor comment fixes. --- indra/llcommon/llfasttimer.h | 24 +++++++++++++++--------- indra/llcommon/llfasttimer_class.cpp | 6 +++--- indra/llcommon/llprocessor.cpp | 11 ++++++++++- indra/llcommon/llsys.cpp | 14 +++++++------- indra/llcommon/llsys.h | 4 ++-- indra/llcommon/lltimer.cpp | 2 +- 6 files changed, 38 insertions(+), 23 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llfasttimer.h b/indra/llcommon/llfasttimer.h index 48461df6ae..840d09d970 100644 --- a/indra/llcommon/llfasttimer.h +++ b/indra/llcommon/llfasttimer.h @@ -36,6 +36,10 @@ // pull in the actual class definition #include "llfasttimer_class.h" +// +// Important note: These implementations must be FAST! +// + #if LL_WINDOWS // // Windows implementation of CPU clock @@ -99,15 +103,17 @@ inline U64 LLFastTimer::getCPUClockCount64() #endif -#if LL_LINUX || LL_SOLARIS +#if (LL_LINUX || LL_SOLARIS) && !(defined(__i386__) || defined(__amd64__)) // -// Linux and Solaris implementation of CPU clock - all architectures. +// Linux and Solaris implementation of CPU clock - non-x86. +// This is accurate but SLOW! Only use out of desperation. // // 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 affected -// by CPU frequency. If not available use the REALTIME clock, but this may be affected by -// NTP adjustments or other user activity affecting the system time. +// with nanosecond resolution (but not necessarily accuracy) and attempts are +// made to synchronize this value between cores at kernel start. It should not +// be affected by CPU frequency. If not available use the REALTIME clock, but +// this may be affected by NTP adjustments or other user activity affecting +// the system time. inline U64 LLFastTimer::getCPUClockCount64() { struct timespec tp; @@ -124,12 +130,12 @@ inline U32 LLFastTimer::getCPUClockCount32() { return (U32)(LLFastTimer::getCPUClockCount64() >> 8); } -#endif // (LL_LINUX || LL_SOLARIS)) +#endif // (LL_LINUX || LL_SOLARIS) && !(defined(__i386__) || defined(__amd64__)) -#if (LL_DARWIN) && (defined(__i386__) || defined(__amd64__)) +#if (LL_LINUX || LL_SOLARIS || LL_DARWIN) && (defined(__i386__) || defined(__amd64__)) // -// Mac x86 implementation of CPU clock +// Mac+Linux+Solaris FAST x86 implementation of CPU clock inline U32 LLFastTimer::getCPUClockCount32() { U64 x; diff --git a/indra/llcommon/llfasttimer_class.cpp b/indra/llcommon/llfasttimer_class.cpp index 2e5edb1f3b..f39a4e6619 100644 --- a/indra/llcommon/llfasttimer_class.cpp +++ b/indra/llcommon/llfasttimer_class.cpp @@ -230,17 +230,17 @@ void LLFastTimer::DeclareTimer::updateCachedPointers() } //static -#if LL_LINUX || LL_SOLARIS || ( LL_DARWIN && !(defined(__i386__) || defined(__amd64__)) ) +#if (LL_DARWIN || LL_LINUX || LL_SOLARIS) && !(defined(__i386__) || defined(__amd64__)) U64 LLFastTimer::countsPerSecond() // counts per second for the *32-bit* timer { return sClockResolution >> 8; } -#else // windows or x86-mac +#else // windows or x86-mac or x86-linux or x86-solaris U64 LLFastTimer::countsPerSecond() // counts per second for the *32-bit* timer { static U64 sCPUClockFrequency = U64(CProcessor().GetCPUFrequency(50)); - // we drop the low-order byte in out timers, so report a lower frequency + // we drop the low-order byte in our timers, so report a lower frequency return sCPUClockFrequency >> 8; } #endif diff --git a/indra/llcommon/llprocessor.cpp b/indra/llcommon/llprocessor.cpp index 8a4a4a8f9a..f6ab55a6b5 100644 --- a/indra/llcommon/llprocessor.cpp +++ b/indra/llcommon/llprocessor.cpp @@ -60,6 +60,10 @@ # include #endif +#if LL_LINUX +#include "llsys.h" +#endif // LL_LINUX + #if !LL_DARWIN && !LL_SOLARIS #ifdef PROCESSOR_FREQUENCY_MEASURE_AVAILABLE @@ -116,6 +120,11 @@ CProcessor::CProcessor() //////////////////////////////////////////////////////////////////////////// F64 CProcessor::GetCPUFrequency(unsigned int uiMeasureMSecs) { +#if LL_LINUX + // use the shinier LLCPUInfo interface + return 1000000.0F * gSysCPU.getMHz(); +#endif + #ifndef PROCESSOR_FREQUENCY_MEASURE_AVAILABLE return 0; #else @@ -781,7 +790,7 @@ bool CProcessor::AnalyzeAMDProcessor() case 5: // Family = 5: K5 / K6 processor family switch (CPUInfo.uiModel) { - case 0: // Model = 0: K5 SSA 5 (Pentium Rating *ggg* 75, 90 and 100 Mhz) + case 0: // Model = 0: K5 SSA 5 (Pentium Rating *ggg* 75, 90 and 100 MHz) strcpy(CPUInfo.strModel, "AMD K5 SSA5 (PR75, PR90, PR100)"); /* Flawfinder: ignore */ strncat(strCPUName, "AMD K5 SSA5 (PR75, PR90, PR100)", sizeof(strCPUName) - strlen(strCPUName) -1); /* Flawfinder: ignore */ break; diff --git a/indra/llcommon/llsys.cpp b/indra/llcommon/llsys.cpp index 0272c55db2..52b1b63209 100644 --- a/indra/llcommon/llsys.cpp +++ b/indra/llcommon/llsys.cpp @@ -519,15 +519,15 @@ LLCPUInfo::LLCPUInfo() mHasSSE = info->_Ext.SSE_StreamingSIMD_Extensions; mHasSSE2 = info->_Ext.SSE2_StreamingSIMD2_Extensions; mHasAltivec = info->_Ext.Altivec_Extensions; - mCPUMhz = (S32)(proc.GetCPUFrequency(50)/1000000.0); + mCPUMHz = (F64)(proc.GetCPUFrequency(50)/1000000.0F); mFamily.assign( info->strFamily ); mCPUString = "Unknown"; #if LL_WINDOWS || LL_DARWIN || LL_SOLARIS out << proc.strCPUName; - if (200 < mCPUMhz && mCPUMhz < 10000) // *NOTE: cpu speed is often way wrong, do a sanity check + if (200 < mCPUMHz && mCPUMHz < 10000) // *NOTE: cpu speed is often way wrong, do a sanity check { - out << " (" << mCPUMhz << " MHz)"; + out << " (" << mCPUMHz << " MHz)"; } mCPUString = out.str(); @@ -572,7 +572,7 @@ LLCPUInfo::LLCPUInfo() if (LLStringUtil::convertToF64(cpuinfo["cpu mhz"], mhz) && 200.0 < mhz && mhz < 10000.0) { - mCPUMhz = (S32)llrint(mhz); + mCPUMHz = (F64)(mhz); } if (!cpuinfo["model name"].empty()) mCPUString = cpuinfo["model name"]; @@ -595,9 +595,9 @@ bool LLCPUInfo::hasSSE2() const return mHasSSE2; } -S32 LLCPUInfo::getMhz() const +F64 LLCPUInfo::getMHz() const { - return mCPUMhz; + return mCPUMHz; } std::string LLCPUInfo::getCPUString() const @@ -644,7 +644,7 @@ void LLCPUInfo::stream(std::ostream& s) const s << "->mHasSSE: " << (U32)mHasSSE << std::endl; s << "->mHasSSE2: " << (U32)mHasSSE2 << std::endl; s << "->mHasAltivec: " << (U32)mHasAltivec << std::endl; - s << "->mCPUMhz: " << mCPUMhz << std::endl; + s << "->mCPUMHz: " << mCPUMHz << std::endl; s << "->mCPUString: " << mCPUString << std::endl; } diff --git a/indra/llcommon/llsys.h b/indra/llcommon/llsys.h index c2c45bec9a..0b34951149 100644 --- a/indra/llcommon/llsys.h +++ b/indra/llcommon/llsys.h @@ -81,7 +81,7 @@ public: bool hasAltivec() const; bool hasSSE() const; bool hasSSE2() const; - S32 getMhz() const; + F64 getMHz() const; // Family is "AMD Duron" or "Intel Pentium Pro" const std::string& getFamily() const { return mFamily; } @@ -90,7 +90,7 @@ private: bool mHasSSE; bool mHasSSE2; bool mHasAltivec; - S32 mCPUMhz; + F64 mCPUMHz; std::string mFamily; std::string mCPUString; }; diff --git a/indra/llcommon/lltimer.cpp b/indra/llcommon/lltimer.cpp index 25b768079b..6111db2bfa 100644 --- a/indra/llcommon/lltimer.cpp +++ b/indra/llcommon/lltimer.cpp @@ -209,7 +209,7 @@ F64 calc_clock_frequency(U32 uiMeasureMSecs) // Both Linux and Mac use gettimeofday for accurate time F64 calc_clock_frequency(unsigned int uiMeasureMSecs) { - return 1000000.0; // microseconds, so 1 Mhz. + return 1000000.0; // microseconds, so 1 MHz. } U64 get_clock_count() -- cgit v1.2.3