diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2021-10-30 01:10:27 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2021-10-30 01:10:27 +0000 |
commit | a52257c77024d285582a5b585cd12ceba4d6be9c (patch) | |
tree | 07a7ac5ed1c66ac011ff4223421c51635deb59e0 | |
parent | ed692e3fc4f4eed26b6bce85cec1850fb5e928b6 (diff) | |
parent | 36c233be062c877f57495916b435be7ea8faeec4 (diff) | |
download | extras-a52257c77024d285582a5b585cd12ceba4d6be9c.tar.gz |
Snap for 7867461 from 36c233be062c877f57495916b435be7ea8faeec4 to sc-d2-release
Change-Id: I9a415383a4e3965684775c42b860f74af04115b7
-rw-r--r-- | simpleperf/test_util.cpp | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/simpleperf/test_util.cpp b/simpleperf/test_util.cpp index 547eaf90..d85294f5 100644 --- a/simpleperf/test_util.cpp +++ b/simpleperf/test_util.cpp @@ -48,7 +48,7 @@ bool IsInNativeAbi() { return in_native_abi == 1; } -#if defined(__arm__) +#if defined(__linux__) // Check if we can get a non-zero instruction event count by monitoring current thread. static bool HasNonZeroInstructionEventCount() { const simpleperf::EventType* type = simpleperf::FindEventTypeByName("instructions", false); @@ -70,32 +70,38 @@ static bool HasNonZeroInstructionEventCount() { } return false; } -#endif // defined(__arm__) bool HasHardwareCounter() { -#if defined(__linux__) static int has_hw_counter = -1; if (has_hw_counter == -1) { has_hw_counter = 1; -#if defined(__x86__) || defined(__x86_64__) - // On x86 and x86_64, it's likely to run on an emulator or vm without hardware perf counters. - // It's hard to enumerate them all. So check the support at runtime. - const simpleperf::EventType* type = simpleperf::FindEventTypeByName("cpu-cycles", false); - CHECK(type != nullptr); - perf_event_attr attr = CreateDefaultPerfEventAttr(*type); - has_hw_counter = IsEventAttrSupported(attr, "cpu-cycles") ? 1 : 0; -#elif defined(__arm__) - // For arm32 devices, external non-invasive debug signal controls PMU counters. Once it is - // disabled for security reason, we always get zero values for PMU counters. And we want to - // skip hardware counter tests once we detect it. - has_hw_counter &= HasNonZeroInstructionEventCount() ? 1 : 0; -#endif // defined(__arm__) + auto arch = GetBuildArch(); + std::string fingerprint = android::base::GetProperty("ro.system.build.fingerprint", ""); + bool is_emulator = android::base::StartsWith(fingerprint, "google/sdk_gphone") || + android::base::StartsWith(fingerprint, "generic/cf"); + + if (arch == ARCH_X86_64 || arch == ARCH_X86_32 || is_emulator) { + // On x86 and x86_64, it's likely to run on an emulator or vm without hardware perf + // counters. It's hard to enumerate them all. So check the support at runtime. + const simpleperf::EventType* type = simpleperf::FindEventTypeByName("cpu-cycles", false); + CHECK(type != nullptr); + perf_event_attr attr = CreateDefaultPerfEventAttr(*type); + has_hw_counter = IsEventAttrSupported(attr, "cpu-cycles") ? 1 : 0; + } else if (arch == ARCH_ARM) { + // For arm32 devices, external non-invasive debug signal controls PMU counters. Once it is + // disabled for security reason, we always get zero values for PMU counters. And we want to + // skip hardware counter tests once we detect it. + has_hw_counter &= HasNonZeroInstructionEventCount() ? 1 : 0; + } } return has_hw_counter == 1; -#else // defined(__linux__) +} + +#else // !defined(__linux__) +bool HasHardwareCounter() { return false; -#endif // defined(__linux__) } +#endif // !defined(__linux__) bool HasPmuCounter() { static int has_pmu_counter = -1; |