From ff2c255af5bb2fc2e5cd3b3685f0c6283117ce73 Mon Sep 17 00:00:00 2001 From: Robert Guo Date: Fri, 2 Mar 2018 06:22:03 -0500 Subject: [PATCH] Use STCK to get the CPU clock on s390x (#540) --- AUTHORS | 1 + CONTRIBUTORS | 1 + src/cycleclock.h | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/AUTHORS b/AUTHORS index 4e4c4ed4..e574b23b 100644 --- a/AUTHORS +++ b/AUTHORS @@ -31,6 +31,7 @@ Kishan Kumar Lei Xu Matt Clarkson Maxim Vafin +MongoDB Inc. Nick Hutchinson Oleksandr Sochka Paul Redmond diff --git a/CONTRIBUTORS b/CONTRIBUTORS index c59134b9..b942722e 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -53,6 +53,7 @@ Pierre Phaneuf Radoslav Yovchev Raul Marin Ray Glover +Robert Guo Roman Lebedev Shuo Chen Tobias Ulvgård diff --git a/src/cycleclock.h b/src/cycleclock.h index 4251fe4c..3b376ac5 100644 --- a/src/cycleclock.h +++ b/src/cycleclock.h @@ -159,6 +159,11 @@ 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(__s390__) // Covers both s390 and s390x. + // Return the CPU clock. + uint64_t tsc; + asm("stck %0" : "=Q" (tsc) : : "cc"); + return tsc; #else // The soft failover to a generic implementation is automatic only for ARM. // For other platforms the developer is expected to make an attempt to create