From cba0d8ef11300d9a152c60c3d32d23c5d0c60778 Mon Sep 17 00:00:00 2001 From: TeYuan Wang Date: Mon, 9 Mar 2020 19:17:56 +0800 Subject: [PATCH] thermal: Optimize uevent monitor timeout mechanism If non-thermal uevents keep triggered, thermalhal will not hit uevent timeout to update temperature. Bug: 138257706 Test: pts-tradefed run pts -m PtsThermalHalTestCases Change-Id: I8470b95f34ff3867e1a9c677e3712d8c8deb3a3c Signed-off-by: TeYuan Wang --- hidl/thermal/utils/thermal_watcher.cpp | 7 ++++++- hidl/thermal/utils/thermal_watcher.h | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/hidl/thermal/utils/thermal_watcher.cpp b/hidl/thermal/utils/thermal_watcher.cpp index 19e76280..02982160 100644 --- a/hidl/thermal/utils/thermal_watcher.cpp +++ b/hidl/thermal/utils/thermal_watcher.cpp @@ -67,6 +67,7 @@ void ThermalWatcher::registerFilesToWatch(const std::set &sensors_t looper_->addFd(uevent_fd_.get(), 0, Looper::EVENT_INPUT, nullptr, nullptr); is_polling_ = false; thermal_triggered_ = true; + last_update_time_ = boot_clock::now(); } bool ThermalWatcher::startWatchingDeviceFiles() { @@ -147,8 +148,11 @@ bool ThermalWatcher::threadLoop() { int fd; std::set sensors; + auto time_elapsed_ms = std::chrono::duration_cast(boot_clock::now() - + last_update_time_) + .count(); int timeout = (thermal_triggered_ || is_polling_) ? kMinPollIntervalMs : kUeventPollTimeoutMs; - if (looper_->pollOnce(timeout, &fd, nullptr, nullptr) >= 0) { + if (time_elapsed_ms < timeout && looper_->pollOnce(timeout, &fd, nullptr, nullptr) >= 0) { if (fd != uevent_fd_.get()) { return true; } @@ -159,6 +163,7 @@ bool ThermalWatcher::threadLoop() { } } thermal_triggered_ = cb_(sensors); + last_update_time_ = boot_clock::now(); return true; } diff --git a/hidl/thermal/utils/thermal_watcher.h b/hidl/thermal/utils/thermal_watcher.h index 45c2a737..be94ab09 100644 --- a/hidl/thermal/utils/thermal_watcher.h +++ b/hidl/thermal/utils/thermal_watcher.h @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -37,6 +38,7 @@ namespace thermal { namespace V2_0 { namespace implementation { +using android::base::boot_clock; using android::base::unique_fd; using WatcherCallback = std::function &name)>; @@ -92,6 +94,8 @@ class ThermalWatcher : public ::android::Thread { bool thermal_triggered_; // Flag to point out if device can support uevent notify. bool is_polling_; + // Timestamp for last thermal update + boot_clock::time_point last_update_time_; }; } // namespace implementation