Skip to content

Commit 4c2413d

Browse files
Helge Dellerhdeller
authored andcommitted
Add clock counter for hppa architecture
Add support for time measurements on hppa, otherwise build breaks with this compiler error: You need to define CycleTimer for your OS and CPU
1 parent ff239db commit 4c2413d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

third-party/benchmark/src/cycleclock.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,16 @@ inline BENCHMARK_ALWAYS_INLINE int64_t Now() {
228228
struct timeval tv;
229229
gettimeofday(&tv, nullptr);
230230
return static_cast<int64_t>(tv.tv_sec) * 1000000 + tv.tv_usec;
231+
#elif defined(__hppa__)
232+
// HP PA-RISC provides a user-readable clock counter (cr16), but
233+
// it's not syncronized across CPUs and only 32-bit wide when programs
234+
// are built as 32-bit binaries.
235+
// Use clock_gettime(CLOCK_MONOTONIC, ...) instead of gettimeofday
236+
// because is provides nanosecond resolution.
237+
// Initialize to always return 0 if clock_gettime fails.
238+
struct timespec ts = {0, 0};
239+
clock_gettime(CLOCK_MONOTONIC, &ts);
240+
return static_cast<int64_t>(ts.tv_sec) * 1000000000 + ts.tv_nsec;
231241
#else
232242
// The soft failover to a generic implementation is automatic only for ARM.
233243
// For other platforms the developer is expected to make an attempt to create

0 commit comments

Comments
 (0)