simpleperf: Fix event type for Intel Atom CPU
As shown in
https://github.com/torvalds/linux/blob/master/arch/x86/events/core.c#L2173,
Atom CPU uses a new event type instead of PERF_TYPE_RAW.
Bug: 345410289
Test: run simpleperf manually
Change-Id: I564fc821ce96063de0b4ff53fcf3171457d31c91
diff --git a/simpleperf/environment.cpp b/simpleperf/environment.cpp
index f636fe9..d101b43 100644
--- a/simpleperf/environment.cpp
+++ b/simpleperf/environment.cpp
@@ -1193,4 +1193,17 @@
return atom_cpus.has_value() ? atom_cpus.value() : std::set<int>();
}
+std::optional<uint32_t> GetX86IntelAtomCpuEventType() {
+ std::string data;
+ if (!android::base::ReadFileToString("/sys/bus/event_source/devices/cpu_atom/type", &data)) {
+ return std::nullopt;
+ }
+ data = android::base::Trim(data);
+ uint32_t result;
+ if (android::base::ParseUint(data, &result)) {
+ return result;
+ }
+ return std::nullopt;
+}
+
} // namespace simpleperf
diff --git a/simpleperf/environment.h b/simpleperf/environment.h
index 279f2ce..7200056 100644
--- a/simpleperf/environment.h
+++ b/simpleperf/environment.h
@@ -174,6 +174,7 @@
std::vector<CpuModel> GetCpuModels();
std::set<int> GetX86IntelAtomCpus();
+std::optional<uint32_t> GetX86IntelAtomCpuEventType();
#endif // defined(__linux__)
diff --git a/simpleperf/event_selection_set.cpp b/simpleperf/event_selection_set.cpp
index 0479303d..5945073 100644
--- a/simpleperf/event_selection_set.cpp
+++ b/simpleperf/event_selection_set.cpp
@@ -682,8 +682,13 @@
for (auto& selection : group.selections) {
#if defined(__i386__) || defined(__x86_64__)
perf_event_attr attr = selection.event_attr;
- std::set<int> atom_cpus = GetX86IntelAtomCpus();
- if (atom_cpus.count(cpu) > 0) {
+ if (attr.type == PERF_TYPE_RAW && GetX86IntelAtomCpus().count(cpu) > 0) {
+ std::optional<uint32_t> atom_type = GetX86IntelAtomCpuEventType();
+ if (!atom_type.has_value()) {
+ LOG(ERROR) << "Can't read pmu type for Intel Atom CPU";
+ return false;
+ }
+ attr.type = atom_type.value();
attr.config = selection.event_type_modifier.event_type.GetIntelAtomCpuConfig();
}
std::unique_ptr<EventFd> event_fd =