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 <kamewang@google.com>
tirimbino
TeYuan Wang 5 years ago committed by Francescodario Cuzzocrea
parent 530ecc4dba
commit cba0d8ef11
  1. 7
      hidl/thermal/utils/thermal_watcher.cpp
  2. 4
      hidl/thermal/utils/thermal_watcher.h

@ -67,6 +67,7 @@ void ThermalWatcher::registerFilesToWatch(const std::set<std::string> &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<std::string> sensors;
auto time_elapsed_ms = std::chrono::duration_cast<std::chrono::milliseconds>(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;
}

@ -27,6 +27,7 @@
#include <unordered_map>
#include <vector>
#include <android-base/chrono_utils.h>
#include <android-base/unique_fd.h>
#include <utils/Looper.h>
#include <utils/Thread.h>
@ -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<bool(const std::set<std::string> &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

Loading…
Cancel
Save