Commit a46794fa authored by Yabin Cui's avatar Yabin Cui
Browse files

Simpleperf: don't use ioctl(PERF_EVENT_IOC_ENABLE).

Some android kernels(like bullhead/angler) can't handle
ioctl(PERF_EVENT_IOC_ENABLE) correctly when cpu-hotplug
happens. Instead of fixing all of them in kernel, we
can't simply don't use it.

Bug: 25193162
Change-Id: I9df1458045ffd2ccc2c7ba393e746ebba7c253de
parent dd7f62ed
......@@ -231,11 +231,6 @@ bool RecordCommand::Run(const std::vector<std::string>& args) {
}
// 5. Write records in mmap buffers of perf_event_files to output file while workload is running.
if (!event_selection_set_.GetEnableOnExec()) {
if (!event_selection_set_.EnableEvents()) {
return false;
}
}
if (workload != nullptr && !workload->Start()) {
return false;
}
......
......@@ -145,11 +145,6 @@ bool StatCommand::Run(const std::vector<std::string>& args) {
// 4. Count events while workload running.
auto start_time = std::chrono::steady_clock::now();
if (!event_selection_set_.GetEnableOnExec()) {
if (!event_selection_set_.EnableEvents()) {
return false;
}
}
if (workload != nullptr && !workload->Start()) {
return false;
}
......
......@@ -82,7 +82,7 @@ perf_event_attr CreateDefaultPerfEventAttr(const EventType& event_type) {
attr.config = event_type.config;
attr.mmap = 1;
attr.comm = 1;
attr.disabled = 1;
attr.disabled = 0;
// Changing read_format affects the layout of the data read from perf_event_file, namely
// PerfCounter in event_fd.h.
attr.read_format =
......
......@@ -95,24 +95,6 @@ uint64_t EventFd::Id() const {
return id_;
}
bool EventFd::EnableEvent() {
int result = ioctl(perf_event_fd_, PERF_EVENT_IOC_ENABLE, 0);
if (result < 0) {
PLOG(ERROR) << "ioctl(enable) " << Name() << " failed";
return false;
}
return true;
}
bool EventFd::DisableEvent() {
int result = ioctl(perf_event_fd_, PERF_EVENT_IOC_DISABLE, 0);
if (result < 0) {
PLOG(ERROR) << "ioctl(disable) " << Name() << " failed";
return false;
}
return true;
}
bool EventFd::ReadCounter(PerfCounter* counter) const {
CHECK(counter != nullptr);
if (!android::base::ReadFully(perf_event_fd_, counter, sizeof(*counter))) {
......
......@@ -53,12 +53,6 @@ class EventFd {
return cpu_;
}
// It tells the kernel to start counting and recording events specified by this file.
bool EnableEvent();
// It tells the kernel to stop counting and recording events specified by this file.
bool DisableEvent();
bool ReadCounter(PerfCounter* counter) const;
// Call mmap() for this perf_event_file, so we can read sampled records from mapped area.
......
......@@ -81,7 +81,17 @@ void EventSelectionSet::UnionSampleType() {
void EventSelectionSet::SetEnableOnExec(bool enable) {
for (auto& selection : selections_) {
selection.event_attr.enable_on_exec = (enable ? 1 : 0);
// If sampling is enabled on exec, then it is disabled at startup, otherwise
// it should be enabled at startup. Don't use ioctl(PERF_EVENT_IOC_ENABLE)
// to enable it after perf_event_open(). Because some android kernels can't
// handle ioctl() well when cpu-hotplug happens. See http://b/25193162.
if (enable) {
selection.event_attr.enable_on_exec = 1;
selection.event_attr.disabled = 1;
} else {
selection.event_attr.enable_on_exec = 0;
selection.event_attr.disabled = 0;
}
}
}
......@@ -218,17 +228,6 @@ bool EventSelectionSet::OpenEventFiles(const std::vector<pid_t>& threads,
return true;
}
bool EventSelectionSet::EnableEvents() {
for (auto& selection : selections_) {
for (auto& event_fd : selection.event_fds) {
if (!event_fd->EnableEvent()) {
return false;
}
}
}
return true;
}
bool EventSelectionSet::ReadCounters(std::vector<CountersInfo>* counters) {
counters->clear();
for (auto& selection : selections_) {
......
......@@ -70,7 +70,6 @@ class EventSelectionSet {
bool OpenEventFilesForCpus(const std::vector<int>& cpus);
bool OpenEventFilesForThreadsOnCpus(const std::vector<pid_t>& threads, std::vector<int> cpus);
bool EnableEvents();
bool ReadCounters(std::vector<CountersInfo>* counters);
void PreparePollForEventFiles(std::vector<pollfd>* pollfds);
bool MmapEventFiles(size_t mmap_pages);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment