From 349a0881f2955a3233456728dd6a43a4e1f85cf7 Mon Sep 17 00:00:00 2001 From: Sidong-Wei Date: Mon, 29 Jun 2020 08:49:25 -0400 Subject: [PATCH] Add support for s390x cpu frequency --- absl/base/internal/unscaledcycleclock.cc | 12 ++++++++++++ absl/base/internal/unscaledcycleclock.h | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/absl/base/internal/unscaledcycleclock.cc b/absl/base/internal/unscaledcycleclock.cc index f1e7bbef844..caf6c950323 100644 --- a/absl/base/internal/unscaledcycleclock.cc +++ b/absl/base/internal/unscaledcycleclock.cc @@ -101,6 +101,18 @@ double UnscaledCycleClock::Frequency() { #endif } +#elif defined(__s390x__) + +int64_t UnscaledCycleClock::Now() { + int64_t tsc; + asm("stck %0" : "=Q" (tsc) : : "cc"); + return tsc; +} + +double UnscaledCycleClock::Frequency() { + return base_internal::NominalCPUFrequency(); +} + #elif defined(__aarch64__) // System timer of ARMv8 runs at a different frequency than the CPU's. diff --git a/absl/base/internal/unscaledcycleclock.h b/absl/base/internal/unscaledcycleclock.h index 82f2c87a95a..0331e517b5f 100644 --- a/absl/base/internal/unscaledcycleclock.h +++ b/absl/base/internal/unscaledcycleclock.h @@ -47,7 +47,7 @@ // The following platforms have an implementation of a hardware counter. #if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__) || \ defined(__powerpc__) || defined(__ppc__) || \ - defined(_M_IX86) || defined(_M_X64) + defined(_M_IX86) || defined(_M_X64) || defined(__s390x__) #define ABSL_HAVE_UNSCALED_CYCLECLOCK_IMPLEMENTATION 1 #else #define ABSL_HAVE_UNSCALED_CYCLECLOCK_IMPLEMENTATION 0 @@ -81,7 +81,7 @@ // This macro can be used to test if UnscaledCycleClock::Frequency() // is NominalCPUFrequency() on a particular platform. #if (defined(__i386__) || defined(__x86_64__) || \ - defined(_M_IX86) || defined(_M_X64)) + defined(_M_IX86) || defined(_M_X64)) || defined(__s390x__) #define ABSL_INTERNAL_UNSCALED_CYCLECLOCK_FREQUENCY_IS_CPU_FREQUENCY #endif