summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-10-30 01:12:04 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-10-30 01:12:04 +0000
commitc68f47df0cdb22e6a091f68c96ab1c15d1d11ad2 (patch)
tree07a7ac5ed1c66ac011ff4223421c51635deb59e0
parent2194d5fb4701a3cf53dbfe85f4cce41bc0054b55 (diff)
parent36c233be062c877f57495916b435be7ea8faeec4 (diff)
downloadextras-c68f47df0cdb22e6a091f68c96ab1c15d1d11ad2.tar.gz
Snap for 7867461 from 36c233be062c877f57495916b435be7ea8faeec4 to sc-v2-release
Change-Id: I7db844ca1a4fd07ccb5c2bb5284c886a9d544f58
-rw-r--r--simpleperf/test_util.cpp42
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;