From 81a524f8b187c77e517b7c6e4e29ec028807a01d Mon Sep 17 00:00:00 2001 From: Helge Deller Date: Wed, 8 Jan 2025 17:26:44 +0100 Subject: [PATCH] cycleclock: Use cock_gettime() as fallback for any Linux architecture The Linux kernel provides the clock_gettime() functions since a long time already, so it's possible to use it as a generic fallback option for any architecture if no other (better) possibility has been provided instead. I noticed the benchmark package failed to build on debian on the SH-4 architecture, so with this change SH-4 is now the first user of this fallback option. --- src/cycleclock.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cycleclock.h b/src/cycleclock.h index 7852f3df52..03e02f8055 100644 --- a/src/cycleclock.h +++ b/src/cycleclock.h @@ -229,10 +229,12 @@ inline BENCHMARK_ALWAYS_INLINE int64_t Now() { struct timeval tv; gettimeofday(&tv, nullptr); return static_cast(tv.tv_sec) * 1000000 + tv.tv_usec; -#elif defined(__hppa__) +#elif defined(__hppa__) || defined(__linux__) + // Fallback for all other architectures with a recent Linux kernel, e.g.: // HP PA-RISC provides a user-readable clock counter (cr16), but // it's not syncronized across CPUs and only 32-bit wide when programs // are built as 32-bit binaries. + // Same for SH-4 and possibly others. // Use clock_gettime(CLOCK_MONOTONIC, ...) instead of gettimeofday // because is provides nanosecond resolution. // Initialize to always return 0 if clock_gettime fails.