mirror of
https://github.com/google/benchmark.git
synced 2025-03-29 21:51:06 +08:00
Remove tunable estimate for cycles per second
This commit is contained in:
parent
9d230ffb47
commit
dc5b533adb
@ -20,21 +20,18 @@
|
|||||||
|
|
||||||
namespace benchmark {
|
namespace benchmark {
|
||||||
namespace {
|
namespace {
|
||||||
|
const int64_t estimate_time_ms = 1000;
|
||||||
pthread_once_t cpuinfo_init = PTHREAD_ONCE_INIT;
|
pthread_once_t cpuinfo_init = PTHREAD_ONCE_INIT;
|
||||||
double cpuinfo_cycles_per_second = 1.0;
|
double cpuinfo_cycles_per_second = 1.0;
|
||||||
int cpuinfo_num_cpus = 1; // Conservative guess
|
int cpuinfo_num_cpus = 1; // Conservative guess
|
||||||
static pthread_mutex_t cputimens_mutex;
|
pthread_mutex_t cputimens_mutex;
|
||||||
|
|
||||||
// Helper function estimates cycles/sec by observing cycles elapsed during
|
// Helper function estimates cycles/sec by observing cycles elapsed during
|
||||||
// sleep(). Using small sleep time decreases accuracy significantly.
|
// sleep(). Using small sleep time decreases accuracy significantly.
|
||||||
int64_t EstimateCyclesPerSecond(const int estimate_time_ms) {
|
int64_t EstimateCyclesPerSecond() {
|
||||||
CHECK(estimate_time_ms > 0);
|
|
||||||
double multiplier = 1000.0 / (double)estimate_time_ms; // scale by this much
|
|
||||||
|
|
||||||
const int64_t start_ticks = cycleclock::Now();
|
const int64_t start_ticks = cycleclock::Now();
|
||||||
SleepForMilliseconds(estimate_time_ms);
|
SleepForMilliseconds(estimate_time_ms);
|
||||||
const int64_t guess = int64_t(multiplier * (cycleclock::Now() - start_ticks));
|
return cycleclock::Now() - start_ticks;
|
||||||
return guess;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function for reading an int from a file. Returns true if successful
|
// Helper function for reading an int from a file. Returns true if successful
|
||||||
@ -99,9 +96,9 @@ void InitializeSystemInfo() {
|
|||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
perror(pname);
|
perror(pname);
|
||||||
if (!saw_mhz) {
|
if (!saw_mhz) {
|
||||||
cpuinfo_cycles_per_second = EstimateCyclesPerSecond(1000);
|
cpuinfo_cycles_per_second = EstimateCyclesPerSecond();
|
||||||
}
|
}
|
||||||
return; // TODO: use generic tester instead?
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
double bogo_clock = 1.0;
|
double bogo_clock = 1.0;
|
||||||
@ -166,7 +163,7 @@ void InitializeSystemInfo() {
|
|||||||
cpuinfo_cycles_per_second = bogo_clock;
|
cpuinfo_cycles_per_second = bogo_clock;
|
||||||
} else {
|
} else {
|
||||||
// If we don't even have bogomips, we'll use the slow estimation.
|
// If we don't even have bogomips, we'll use the slow estimation.
|
||||||
cpuinfo_cycles_per_second = EstimateCyclesPerSecond(1000);
|
cpuinfo_cycles_per_second = EstimateCyclesPerSecond();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (num_cpus == 0) {
|
if (num_cpus == 0) {
|
||||||
@ -202,7 +199,7 @@ void InitializeSystemInfo() {
|
|||||||
if ( sysctlbyname(sysctl_path, &hz, &sz, NULL, 0) != 0 ) {
|
if ( sysctlbyname(sysctl_path, &hz, &sz, NULL, 0) != 0 ) {
|
||||||
fprintf(stderr, "Unable to determine clock rate from sysctl: %s: %s\n",
|
fprintf(stderr, "Unable to determine clock rate from sysctl: %s: %s\n",
|
||||||
sysctl_path, strerror(errno));
|
sysctl_path, strerror(errno));
|
||||||
cpuinfo_cycles_per_second = EstimateCyclesPerSecond(1000);
|
cpuinfo_cycles_per_second = EstimateCyclesPerSecond();
|
||||||
} else {
|
} else {
|
||||||
cpuinfo_cycles_per_second = hz;
|
cpuinfo_cycles_per_second = hz;
|
||||||
}
|
}
|
||||||
@ -222,7 +219,7 @@ void InitializeSystemInfo() {
|
|||||||
"~MHz", NULL, &data, &data_size)))
|
"~MHz", NULL, &data, &data_size)))
|
||||||
cpuinfo_cycles_per_second = (int64)data * (int64)(1000 * 1000); // was mhz
|
cpuinfo_cycles_per_second = (int64)data * (int64)(1000 * 1000); // was mhz
|
||||||
else
|
else
|
||||||
cpuinfo_cycles_per_second = EstimateCyclesPerSecond(500); // TODO <500?
|
cpuinfo_cycles_per_second = EstimateCyclesPerSecond();
|
||||||
// TODO: also figure out cpuinfo_num_cpus
|
// TODO: also figure out cpuinfo_num_cpus
|
||||||
|
|
||||||
#elif defined OS_MACOSX
|
#elif defined OS_MACOSX
|
||||||
@ -251,7 +248,7 @@ void InitializeSystemInfo() {
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
// Generic cycles per second counter
|
// Generic cycles per second counter
|
||||||
cpuinfo_cycles_per_second = EstimateCyclesPerSecond(1000);
|
cpuinfo_cycles_per_second = EstimateCyclesPerSecond();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
} // end namespace
|
} // end namespace
|
||||||
|
Loading…
Reference in New Issue
Block a user