OS X fix: if os_cpu_ClockFrequency reports an unknown/invalid value, measure the frequency instead; also avoid reporting invalid freqs in system_info

This was SVN commit r9886.
This commit is contained in:
janwas 2011-07-20 08:10:36 +00:00
parent ce42cd611a
commit 15df4aa4be
2 changed files with 8 additions and 6 deletions

View File

@ -479,7 +479,7 @@ double x86_x64_ClockFrequency()
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 (< 1 0/00 error -
// 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;

View File

@ -100,13 +100,15 @@ void WriteSystemInfo()
// CPU
fprintf(f, "CPU : %s, %s (%dx%dx%d)", un.machine, cpu_IdentifierString(), (int)cpu_topology_NumPackages(), (int)cpu_topology_CoresPerPackage(), (int)cpu_topology_LogicalPerCore());
const double cpu_freq = os_cpu_ClockFrequency();
if(cpu_freq != 0.0f)
double cpuClock = os_cpu_ClockFrequency(); // query OS (may fail)
if(cpuClock <= 0.0)
cpuClock = x86_x64_ClockFrequency(); // measure (takes a few ms)
if(cpuClock > 0.0)
{
if(cpu_freq < 1e9)
fprintf(f, ", %.2f MHz\n", cpu_freq*1e-6);
if(cpuClock < 1e9)
fprintf(f, ", %.2f MHz\n", cpuClock*1e-6);
else
fprintf(f, ", %.2f GHz\n", cpu_freq*1e-9);
fprintf(f, ", %.2f GHz\n", cpuClock*1e-9);
}
else
fprintf(f, "\n");