1
0
mirror of https://github.com/google/benchmark.git synced 2025-03-31 14:40:29 +08:00

Improve compatibility with Hexagon hardware

The customization done via BENCHMARK_OS_QURT works just fine with the Hexagon simulator, but on at least some Hexagon hardware, both `qurt_timer_get_ticks()` and `std::chrono::now()` are broken and always return 0. This fixes the former by using the better-supported (and essentially identical `qurt_sysclock_get_hw_ticks()` call, and the latter by reading a 19.2MHz hardware counter (per suggestion from Qualcomm). Local testing seems to indicate these changes are just as robust under the simulator as before.
This commit is contained in:
Steven Johnson 2024-05-14 11:29:56 -07:00
parent bc946b919c
commit 5ca92d18e4
2 changed files with 19 additions and 2 deletions

View File

@ -127,7 +127,7 @@ double ProcessCPUUsage() {
DiagnoseAndExit("GetProccessTimes() failed");
#elif defined(BENCHMARK_OS_QURT)
return static_cast<double>(
qurt_timer_timetick_to_us(qurt_timer_get_ticks())) *
qurt_timer_timetick_to_us(qurt_sysclock_get_hw_ticks())) *
1.0e-6;
#elif defined(BENCHMARK_OS_EMSCRIPTEN)
// clock_gettime(CLOCK_PROCESS_CPUTIME_ID, ...) returns 0 on Emscripten.
@ -161,7 +161,7 @@ double ThreadCPUUsage() {
return MakeTime(kernel_time, user_time);
#elif defined(BENCHMARK_OS_QURT)
return static_cast<double>(
qurt_timer_timetick_to_us(qurt_timer_get_ticks())) *
qurt_timer_timetick_to_us(qurt_sysclock_get_hw_ticks())) *
1.0e-6;
#elif defined(BENCHMARK_OS_MACOSX)
// FIXME We want to use clock_gettime, but its not available in MacOS 10.11.

View File

@ -15,6 +15,21 @@ double ChildrenCPUUsage();
// Return the CPU usage of the current thread
double ThreadCPUUsage();
#if defined(BENCHMARK_OS_QURT)
// std::chrono::now() can return 0 on some Hexagon devices;
// this reads the value of a 56-bit, 19.2MHz hardware counter
// and converts it to seconds. Unlike std::chrono, this doesn't
// return an absolute time, but since ChronoClockNow() is only used
// to compute elapsed time, this shouldn't matter.
inline double ChronoClockNow() {
unsigned long long count;
asm volatile (" %0 = c31:30 " : "=r"(count));
return (double)count / 19200000.0;
}
#else
#if defined(HAVE_STEADY_CLOCK)
template <bool HighResIsSteady = std::chrono::high_resolution_clock::is_steady>
struct ChooseSteadyClock {
@ -41,6 +56,8 @@ inline double ChronoClockNow() {
return FpSeconds(ClockType::now().time_since_epoch()).count();
}
#endif
std::string LocalDateTimeString();
} // end namespace benchmark