Index: source/lib/sysdep/arch/x86_x64/x86_x64.h =================================================================== --- source/lib/sysdep/arch/x86_x64/x86_x64.h +++ source/lib/sysdep/arch/x86_x64/x86_x64.h @@ -169,14 +169,6 @@ **/ LIB_API void DebugBreak(); -/** - * measure the CPU clock frequency via rdtsc and timer_Time. - * (it follows that this must not be called from WHRT init.) - * this takes several milliseconds (i.e. much longer than - * os_cpu_ClockFrequency) but delivers accurate measurements. - **/ -LIB_API double ClockFrequency(); - } // namespace x86_x64 #endif // #ifndef INCLUDED_X86_X64 Index: source/lib/sysdep/arch/x86_x64/x86_x64.cpp =================================================================== --- source/lib/sysdep/arch/x86_x64/x86_x64.cpp +++ source/lib/sysdep/arch/x86_x64/x86_x64.cpp @@ -33,7 +33,6 @@ #include #include -#include "lib/posix/posix_pthread.h" #include "lib/bits.h" #include "lib/timer.h" #include "lib/module_init.h" @@ -403,116 +402,6 @@ __asm__ __volatile__ ("int $3"); #endif } - - -//----------------------------------------------------------------------------- -// CPU frequency - -// set scheduling priority and restore when going out of scope. -class ScopedSetPriority -{ -public: - ScopedSetPriority(int newPriority) - { - // get current scheduling policy and priority - pthread_getschedparam(pthread_self(), &m_oldPolicy, &m_oldParam); - - // set new priority - sched_param newParam = {0}; - newParam.sched_priority = newPriority; - pthread_setschedparam(pthread_self(), SCHED_FIFO, &newParam); - } - - ~ScopedSetPriority() - { - // restore previous policy and priority. - pthread_setschedparam(pthread_self(), m_oldPolicy, &m_oldParam); - } - -private: - int m_oldPolicy; - sched_param m_oldParam; -}; - -// note: this function uses timer.cpp!timer_Time, which is implemented via -// whrt.cpp on Windows. -double ClockFrequency() -{ - // if the TSC isn't available, there's really no good way to count the - // actual CPU clocks per known time interval, so bail. - // note: loop iterations ("bogomips") are not a reliable measure due - // to differing IPC and compiler optimizations. - if(!Cap(x86_x64::CAP_TSC)) - return -1.0; // impossible value - - // increase priority to reduce interference while measuring. - const int priority = sched_get_priority_max(SCHED_FIFO)-1; - ScopedSetPriority ssp(priority); - - // note: no need to "warm up" cpuid - it will already have been - // called several times by the time this code is reached. - // (background: it's used in rdtsc() to serialize instruction flow; - // the first call is documented to be slower on Intel CPUs) - - size_t numSamples = 16; - // if clock is low-res, do less samples so it doesn't take too long. - // balance measuring time (~ 10 ms) and accuracy (< 0.1% error - - // ok for using the TSC as a time reference) - if(timer_Resolution() >= 1e-3) - numSamples = 8; - std::vector samples(numSamples); - - for(size_t i = 0; i < numSamples; i++) - { - double dt; - i64 dc; // (i64 instead of u64 for faster conversion to double) - - // count # of clocks in max{1 tick, 1 ms}: - // .. wait for start of tick. - const double t0 = timer_Time(); - u64 c1; double t1; - do - { - // note: timer_Time effectively has a long delay (up to 5 us) - // before returning the time. we call it before rdtsc to - // minimize the delay between actually sampling time / TSC, - // thus decreasing the chance for interference. - // (if unavoidable background activity, e.g. interrupts, - // delays the second reading, inaccuracy is introduced). - t1 = timer_Time(); - c1 = rdtsc(); - } - while(t1 == t0); - // .. wait until start of next tick and at least 1 ms elapsed. - do - { - const double t2 = timer_Time(); - const u64 c2 = rdtsc(); - dc = (i64)(c2 - c1); - dt = t2 - t1; - } - while(dt < 1e-3); - - // .. freq = (delta_clocks) / (delta_seconds); - // rdtsc/timer overhead is negligible. - const double freq = dc / dt; - samples[i] = freq; - } - - std::sort(samples.begin(), samples.end()); - - // median filter (remove upper and lower 25% and average the rest). - // note: don't just take the lowest value! it could conceivably be - // too low, if background processing delays reading c1 (see above). - double sum = 0.0; - const size_t lo = numSamples/4, hi = 3*numSamples/4; - for(size_t i = lo; i < hi; i++) - sum += samples[i]; - - const double clockFrequency = sum / (hi-lo); - return clockFrequency; -} - } // namespace x86_x64 Index: source/lib/sysdep/os_cpu.h =================================================================== --- source/lib/sysdep/os_cpu.h +++ source/lib/sysdep/os_cpu.h @@ -74,12 +74,6 @@ //----------------------------------------------------------------------------- // CPU and memory characteristics -/** - * @return a rough estimate of the CPU clock frequency. - * this is usually accurate to a few MHz and is faster than measurement loops. - **/ -LIB_API double os_cpu_ClockFrequency(); - /** * @return the size [bytes] of a MMU page (4096 on most IA-32 systems) **/ Index: source/lib/sysdep/os_cpu.cpp =================================================================== --- source/lib/sysdep/os_cpu.cpp +++ source/lib/sysdep/os_cpu.cpp @@ -39,27 +39,6 @@ }; STATUS_ADD_DEFINITIONS(osCpuStatusDefinitions); - -double os_cpu_ClockFrequency() -{ - static double clockFrequency; - if(clockFrequency != 0.0) // already initialized - return clockFrequency; - -#if OS_WIN - u32 freqMhz; - if(wcpu_ReadFrequencyFromRegistry(freqMhz) == INFO::OK) - return clockFrequency = freqMhz * 1e6; -#endif - - const SMBIOS::Structures* structures = SMBIOS::GetStructures(); - if(structures->Processor_) - return clockFrequency = structures->Processor_->maxFrequency * 1e6; - - return clockFrequency = -1.0; // unknown -} - - size_t os_cpu_MemorySize() { static size_t memorySize; Index: source/lib/timer.h =================================================================== --- source/lib/timer.h +++ source/lib/timer.h @@ -30,7 +30,6 @@ #include "lib/config2.h" // CONFIG2_TIMER_ALLOW_RDTSC #include "lib/sysdep/cpu.h" // cpu_AtomicAdd #if ARCH_X86_X64 && CONFIG2_TIMER_ALLOW_RDTSC -# include "lib/sysdep/os_cpu.h" // os_cpu_ClockFrequency # include "lib/sysdep/arch/x86_x64/x86_x64.h" // x86_x64::rdtsc #endif @@ -204,11 +203,6 @@ return StringForCycles(m_cycles); } - double ToSeconds() const - { - return (double)m_cycles / os_cpu_ClockFrequency(); - } - private: Cycles m_cycles; }; @@ -258,11 +252,6 @@ return StringForSeconds(m_seconds); } - double ToSeconds() const - { - return m_seconds; - } - private: double m_seconds; }; Index: source/ps/GameSetup/HWDetect.cpp =================================================================== --- source/ps/GameSetup/HWDetect.cpp +++ source/ps/GameSetup/HWDetect.cpp @@ -233,7 +233,6 @@ #endif scriptInterface.SetProperty(settings, "cpu_identifier", std::string(cpu_IdentifierString())); - scriptInterface.SetProperty(settings, "cpu_frequency", os_cpu_ClockFrequency()); scriptInterface.SetProperty(settings, "cpu_pagesize", (u32)os_cpu_PageSize()); scriptInterface.SetProperty(settings, "cpu_largepagesize", (u32)os_cpu_LargePageSize()); scriptInterface.SetProperty(settings, "cpu_numprocs", (u32)os_cpu_NumProcessors()); Index: source/ps/Util.cpp =================================================================== --- source/ps/Util.cpp +++ source/ps/Util.cpp @@ -110,20 +110,6 @@ #if ARCH_X86_X64 fprintf(f, " (%dx%dx%d)", (int)topology::NumPackages(), (int)topology::CoresPerPackage(), (int)topology::LogicalPerCore()); #endif - double cpuClock = os_cpu_ClockFrequency(); // query OS (may fail) -#if ARCH_X86_X64 - if(cpuClock <= 0.0) - cpuClock = x86_x64::ClockFrequency(); // measure (takes a few ms) -#endif - if(cpuClock > 0.0) - { - if(cpuClock < 1e9) - fprintf(f, ", %.2f MHz\n", cpuClock*1e-6); - else - fprintf(f, ", %.2f GHz\n", cpuClock*1e-9); - } - else - fprintf(f, "\n"); // memory fprintf(f, "Memory : %u MiB; %u MiB free\n", (unsigned)os_cpu_MemorySize(), (unsigned)os_cpu_MemoryAvailable());