From e2737f7c4ed085358c50dbe2a5603e1c5c96cf56 Mon Sep 17 00:00:00 2001 From: TeYuan Wang Date: Thu, 19 Mar 2020 21:24:00 +0800 Subject: [PATCH] thermal: remove redundant cdev_to_watch registration cdev_to_watch fd causes pollOnce function return immediatly. Because thermalhal does not monitor cdev status now, so remove cdev_to_watch fd to avoid threadLoop busy problem. Bug: 151897840 Test: Verified thermalhal notifythrottling via emul_temp thermalhal will not keep busy. Change-Id: I999c9b843dde5870d83d8305d5517196188fa819 Signed-off-by: TeYuan Wang --- hidl/thermal/thermal-helper.cpp | 13 +------------ hidl/thermal/utils/thermal_watcher.cpp | 13 ------------- hidl/thermal/utils/thermal_watcher.h | 4 +--- 3 files changed, 2 insertions(+), 28 deletions(-) diff --git a/hidl/thermal/thermal-helper.cpp b/hidl/thermal/thermal-helper.cpp index dff45c29..269b1de7 100644 --- a/hidl/thermal/thermal-helper.cpp +++ b/hidl/thermal/thermal-helper.cpp @@ -199,17 +199,6 @@ ThermalHelper::ThermalHelper(const NotificationCallback &cb) if (!is_initialized_) { LOG(FATAL) << "ThermalHAL could not be initialized properly."; } - std::set cdev_paths; - std::transform(cooling_device_info_map_.cbegin(), cooling_device_info_map_.cend(), - std::inserter(cdev_paths, cdev_paths.begin()), - [this](std::pair const &cdev) { - std::string path = - cooling_devices_.getThermalFilePath(std::string_view(cdev.first)); - if (!path.empty()) - return path; - else - return std::string(); - }); std::set monitored_sensors; std::transform(sensor_info_map_.cbegin(), sensor_info_map_.cend(), std::inserter(monitored_sensors, monitored_sensors.begin()), @@ -220,7 +209,7 @@ ThermalHelper::ThermalHelper(const NotificationCallback &cb) return std::string(); }); - thermal_watcher_->registerFilesToWatch(monitored_sensors, cdev_paths, initializeTrip(tz_map)); + thermal_watcher_->registerFilesToWatch(monitored_sensors, initializeTrip(tz_map)); // Need start watching after status map initialized is_initialized_ = thermal_watcher_->startWatchingDeviceFiles(); diff --git a/hidl/thermal/utils/thermal_watcher.cpp b/hidl/thermal/utils/thermal_watcher.cpp index 08a7e390..31a89a05 100644 --- a/hidl/thermal/utils/thermal_watcher.cpp +++ b/hidl/thermal/utils/thermal_watcher.cpp @@ -36,20 +36,7 @@ namespace implementation { using std::chrono_literals::operator""ms; void ThermalWatcher::registerFilesToWatch(const std::set &sensors_to_watch, - const std::set &cdev_to_watch, bool uevent_monitor) { - int flags = O_RDONLY | O_CLOEXEC | O_BINARY; - - for (const auto &path : cdev_to_watch) { - android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(path.c_str(), flags))); - if (fd == -1) { - PLOG(ERROR) << "failed to watch: " << path; - continue; - } - watch_to_file_path_map_.emplace(fd.get(), path); - looper_->addFd(fd.get(), 0, Looper::EVENT_INPUT, nullptr, nullptr); - fds_.emplace_back(std::move(fd)); - } monitored_sensors_.insert(sensors_to_watch.begin(), sensors_to_watch.end()); if (!uevent_monitor) { is_polling_ = true; diff --git a/hidl/thermal/utils/thermal_watcher.h b/hidl/thermal/utils/thermal_watcher.h index be94ab09..f8cd0449 100644 --- a/hidl/thermal/utils/thermal_watcher.h +++ b/hidl/thermal/utils/thermal_watcher.h @@ -58,8 +58,7 @@ class ThermalWatcher : public ::android::Thread { // Give the file watcher a list of files to start watching. This helper // class will by default wait for modifications to the file with a looper. // This should be called before starting watcher thread. - void registerFilesToWatch(const std::set &sensors_to_watch, - const std::set &cdev_to_watch, bool uevent_monitor); + void registerFilesToWatch(const std::set &sensors_to_watch, bool uevent_monitor); // Wake up the looper thus the worker thread, immediately. This can be called // in any thread. void wake(); @@ -76,7 +75,6 @@ class ThermalWatcher : public ::android::Thread { // Maps watcher filer descriptor to watched file path. std::unordered_map watch_to_file_path_map_; - std::vector fds_; // The callback function. Called whenever thermal uevent is seen. // The function passed in should expect a string in the form (type).