1*9356374aSAndroid Build Coastguard Worker // Copyright 2022 The Abseil Authors 2*9356374aSAndroid Build Coastguard Worker // 3*9356374aSAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License"); 4*9356374aSAndroid Build Coastguard Worker // you may not use this file except in compliance with the License. 5*9356374aSAndroid Build Coastguard Worker // You may obtain a copy of the License at 6*9356374aSAndroid Build Coastguard Worker // 7*9356374aSAndroid Build Coastguard Worker // https://www.apache.org/licenses/LICENSE-2.0 8*9356374aSAndroid Build Coastguard Worker // 9*9356374aSAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software 10*9356374aSAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS, 11*9356374aSAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*9356374aSAndroid Build Coastguard Worker // See the License for the specific language governing permissions and 13*9356374aSAndroid Build Coastguard Worker // limitations under the License. 14*9356374aSAndroid Build Coastguard Worker 15*9356374aSAndroid Build Coastguard Worker #ifndef ABSL_BASE_INTERNAL_UNSCALEDCYCLECLOCK_CONFIG_H_ 16*9356374aSAndroid Build Coastguard Worker #define ABSL_BASE_INTERNAL_UNSCALEDCYCLECLOCK_CONFIG_H_ 17*9356374aSAndroid Build Coastguard Worker 18*9356374aSAndroid Build Coastguard Worker #if defined(__APPLE__) 19*9356374aSAndroid Build Coastguard Worker #include <TargetConditionals.h> 20*9356374aSAndroid Build Coastguard Worker #endif 21*9356374aSAndroid Build Coastguard Worker 22*9356374aSAndroid Build Coastguard Worker // The following platforms have an implementation of a hardware counter. 23*9356374aSAndroid Build Coastguard Worker #if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__) || \ 24*9356374aSAndroid Build Coastguard Worker defined(__powerpc__) || defined(__ppc__) || defined(_M_IX86) || \ 25*9356374aSAndroid Build Coastguard Worker (defined(_M_X64) && !defined(_M_ARM64EC)) 26*9356374aSAndroid Build Coastguard Worker #define ABSL_HAVE_UNSCALED_CYCLECLOCK_IMPLEMENTATION 1 27*9356374aSAndroid Build Coastguard Worker #else 28*9356374aSAndroid Build Coastguard Worker #define ABSL_HAVE_UNSCALED_CYCLECLOCK_IMPLEMENTATION 0 29*9356374aSAndroid Build Coastguard Worker #endif 30*9356374aSAndroid Build Coastguard Worker 31*9356374aSAndroid Build Coastguard Worker // The following platforms often disable access to the hardware 32*9356374aSAndroid Build Coastguard Worker // counter (through a sandbox) even if the underlying hardware has a 33*9356374aSAndroid Build Coastguard Worker // usable counter. The CycleTimer interface also requires a *scaled* 34*9356374aSAndroid Build Coastguard Worker // CycleClock that runs at atleast 1 MHz. We've found some Android 35*9356374aSAndroid Build Coastguard Worker // ARM64 devices where this is not the case, so we disable it by 36*9356374aSAndroid Build Coastguard Worker // default on Android ARM64. 37*9356374aSAndroid Build Coastguard Worker #if defined(__native_client__) || (defined(__APPLE__)) || \ 38*9356374aSAndroid Build Coastguard Worker (defined(__ANDROID__) && defined(__aarch64__)) 39*9356374aSAndroid Build Coastguard Worker #define ABSL_USE_UNSCALED_CYCLECLOCK_DEFAULT 0 40*9356374aSAndroid Build Coastguard Worker #else 41*9356374aSAndroid Build Coastguard Worker #define ABSL_USE_UNSCALED_CYCLECLOCK_DEFAULT 1 42*9356374aSAndroid Build Coastguard Worker #endif 43*9356374aSAndroid Build Coastguard Worker 44*9356374aSAndroid Build Coastguard Worker // UnscaledCycleClock is an optional internal feature. 45*9356374aSAndroid Build Coastguard Worker // Use "#if ABSL_USE_UNSCALED_CYCLECLOCK" to test for its presence. 46*9356374aSAndroid Build Coastguard Worker // Can be overridden at compile-time via -DABSL_USE_UNSCALED_CYCLECLOCK=0|1 47*9356374aSAndroid Build Coastguard Worker #if !defined(ABSL_USE_UNSCALED_CYCLECLOCK) 48*9356374aSAndroid Build Coastguard Worker #define ABSL_USE_UNSCALED_CYCLECLOCK \ 49*9356374aSAndroid Build Coastguard Worker (ABSL_HAVE_UNSCALED_CYCLECLOCK_IMPLEMENTATION && \ 50*9356374aSAndroid Build Coastguard Worker ABSL_USE_UNSCALED_CYCLECLOCK_DEFAULT) 51*9356374aSAndroid Build Coastguard Worker #endif 52*9356374aSAndroid Build Coastguard Worker 53*9356374aSAndroid Build Coastguard Worker #if ABSL_USE_UNSCALED_CYCLECLOCK 54*9356374aSAndroid Build Coastguard Worker // This macro can be used to test if UnscaledCycleClock::Frequency() 55*9356374aSAndroid Build Coastguard Worker // is NominalCPUFrequency() on a particular platform. 56*9356374aSAndroid Build Coastguard Worker #if (defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || \ 57*9356374aSAndroid Build Coastguard Worker defined(_M_X64)) 58*9356374aSAndroid Build Coastguard Worker #define ABSL_INTERNAL_UNSCALED_CYCLECLOCK_FREQUENCY_IS_CPU_FREQUENCY 59*9356374aSAndroid Build Coastguard Worker #endif 60*9356374aSAndroid Build Coastguard Worker #endif 61*9356374aSAndroid Build Coastguard Worker 62*9356374aSAndroid Build Coastguard Worker #endif // ABSL_BASE_INTERNAL_UNSCALEDCYCLECLOCK_CONFIG_H_ 63