summaryrefslogtreecommitdiff
path: root/simpleperf/cmd_record_test.cpp
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2020-06-30 15:43:00 -0700
committerYabin Cui <yabinc@google.com>2020-07-01 09:41:26 -0700
commit5edf8458b1e718caeae4d04614b1b9c86bec7d74 (patch)
tree309d98e27c813d454cf57aaa6f3a6651d74cd821 /simpleperf/cmd_record_test.cpp
parent1f7cc3b43946e938bccc8b12f03f2edb8c97f1ba (diff)
downloadextras-5edf8458b1e718caeae4d04614b1b9c86bec7d74.tar.gz
simpleperf: replace chip list with runtime detection.
This is to avoid the need to expand chip list. Bug: none Test: run simpleperf_unit_test. Change-Id: Ia5bd0efe0342332b1511ffb436511db945199ad2
Diffstat (limited to 'simpleperf/cmd_record_test.cpp')
-rw-r--r--simpleperf/cmd_record_test.cpp40
1 files changed, 28 insertions, 12 deletions
diff --git a/simpleperf/cmd_record_test.cpp b/simpleperf/cmd_record_test.cpp
index 9517edf8..4b558309 100644
--- a/simpleperf/cmd_record_test.cpp
+++ b/simpleperf/cmd_record_test.cpp
@@ -291,24 +291,40 @@ bool HasTracepointEvents() {
return has_tracepoint_events == 1;
}
+#if defined(__arm__)
+// Check if we can get a non-zero instruction event count by monitoring current thread.
+static bool HasNonZeroInstructionEventCount() {
+ const EventType* type = FindEventTypeByName("instructions", false);
+ if (type == nullptr) {
+ return false;
+ }
+ perf_event_attr attr = CreateDefaultPerfEventAttr(*type);
+ std::unique_ptr<EventFd> event_fd =
+ EventFd::OpenEventFile(attr, gettid(), -1, nullptr, type->name, false);
+ if (!event_fd) {
+ return false;
+ }
+ // do some cpu work.
+ for (volatile int i = 0; i < 100000; ++i) {
+ }
+ PerfCounter counter;
+ if (event_fd->ReadCounter(&counter)) {
+ return counter.value != 0;
+ }
+ return false;
+}
+#endif // defined(__arm__)
+
bool HasHardwareCounter() {
static int has_hw_counter = -1;
if (has_hw_counter == -1) {
// Cloud Android doesn't have hardware counters.
has_hw_counter = InCloudAndroid() ? 0 : 1;
#if defined(__arm__)
- std::string cpu_info;
- if (android::base::ReadFileToString("/proc/cpuinfo", &cpu_info)) {
- std::string hardware = GetHardwareFromCpuInfo(cpu_info);
- if (std::regex_search(hardware, std::regex(R"(i\.MX6.*Quad)")) ||
- std::regex_search(hardware, std::regex(R"(SC7731e)")) ||
- std::regex_search(hardware, std::regex(R"(Qualcomm Technologies, Inc MSM8909)")) ||
- std::regex_search(hardware, std::regex(R"(Qualcomm Technologies, Inc MSM8909W)")) ||
- std::regex_search(hardware, std::regex(R"(Qualcomm Technologies, Inc APQ8009W)")) ||
- std::regex_search(hardware, std::regex(R"(Broadcom STB \(Flattened Device Tree\))"))) {
- has_hw_counter = 0;
- }
- }
+ // 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
}
return has_hw_counter == 1;