summaryrefslogtreecommitdiff
path: root/thermalUtils.cpp
diff options
context:
space:
mode:
authorRam Chandrasekar <rkumbako@codeaurora.org>2020-11-17 13:57:40 -0800
committerRam Chandrasekar <rkumbako@codeaurora.org>2020-11-18 16:32:02 -0800
commitdbc52fc76e6a41e75fa7ad49b5343e855ea8a821 (patch)
treeb7f3b8b38801ba5c3fac1d31c15a5f5cd29c1677 /thermalUtils.cpp
parent7273761a6e729d63b8983adee08cac52c8adb3ba (diff)
thermal-hal: Update the common data object with the status
thermal-hal has a hash map storing all the sensor instances. Use the same instance to read and update the temperature, update the severity and determine the next threshold based on severity. Not using the same instance can lead to a situation where the information is updated in the local copy rather than in the global copy in the hash map. Also change the return signature of the estimateseverity function to return the new severity value if it is changed. Otherwise it will return -1. This provided a mechanism for the caller's to know if there is any change in severity for that sensor. Change-Id: I34c2a271b505fea969db6f4a04321e63c0181ea7
Diffstat (limited to 'thermalUtils.cpp')
-rw-r--r--thermalUtils.cpp39
1 files changed, 19 insertions, 20 deletions
diff --git a/thermalUtils.cpp b/thermalUtils.cpp
index 7aaada4..f057e75 100644
--- a/thermalUtils.cpp
+++ b/thermalUtils.cpp
@@ -54,19 +54,19 @@ ThermalUtils::ThermalUtils(const ueventCB &inp_cb):
{
int ret = 0;
std::vector<struct therm_sensor> sensorList;
- std::vector<struct therm_sensor>::iterator it;
+ std::vector<struct target_therm_cfg> therm_cfg = cfg.fetchConfig();
is_sensor_init = false;
is_cdev_init = false;
- ret = cmnInst.initThermalZones(cfg.fetchConfig());
+ ret = cmnInst.initThermalZones(therm_cfg);
if (ret > 0) {
is_sensor_init = true;
sensorList = cmnInst.fetch_sensor_list();
std::lock_guard<std::mutex> _lock(sens_cb_mutex);
- for (it = sensorList.begin(); it != sensorList.end(); it++) {
- thermalConfig[it->sensor_name] = *it;
- cmnInst.read_temperature(&(*it));
- cmnInst.initThreshold(*it);
+ for (struct therm_sensor sens: sensorList) {
+ thermalConfig[sens.sensor_name] = sens;
+ cmnInst.read_temperature(sens);
+ cmnInst.initThreshold(sens);
}
monitor.start();
}
@@ -79,23 +79,22 @@ ThermalUtils::ThermalUtils(const ueventCB &inp_cb):
void ThermalUtils::ueventParse(std::string sensor_name, int temp)
{
- std::unordered_map<std::string, struct therm_sensor>::iterator it;
- struct therm_sensor sens;
+ int severity = 0;
LOG(INFO) << "uevent triggered for sensor: " << sensor_name
<< std::endl;
- it = thermalConfig.find(sensor_name);
- if (it == thermalConfig.end()) {
+ if (thermalConfig.find(sensor_name) == thermalConfig.end()) {
LOG(DEBUG) << "sensor is not monitored:" << sensor_name
<< std::endl;
return;
}
- sens = it->second;
std::lock_guard<std::mutex> _lock(sens_cb_mutex);
+ struct therm_sensor& sens = thermalConfig[sensor_name];
sens.t.value = (float)temp / (float)sens.mulFactor;
- cmnInst.estimateSeverity(&sens);
- if (sens.lastThrottleStatus != sens.t.throttlingStatus) {
- LOG(INFO) << "sensor: " << sensor_name <<" old: " <<
+ severity = cmnInst.estimateSeverity(sens);
+ if (severity != -1) {
+ LOG(INFO) << "sensor: " << sensor_name <<" temperature: "
+ << sens.t.value << " old: " <<
(int)sens.lastThrottleStatus << " new: " <<
(int)sens.t.throttlingStatus << std::endl;
cb(sens.t);
@@ -113,13 +112,13 @@ int ThermalUtils::readTemperatures(hidl_vec<Temperature_1_0>& temp)
return 0;
for (it = thermalConfig.begin(); it != thermalConfig.end();
it++, idx++) {
- struct therm_sensor sens = it->second;
+ struct therm_sensor& sens = it->second;
Temperature_1_0 _temp;
/* v1 supports only CPU, GPU, Battery and SKIN */
if (sens.t.type > TemperatureType::SKIN)
continue;
- ret = cmnInst.read_temperature(&sens);
+ ret = cmnInst.read_temperature(sens);
if (ret < 0)
return ret;
_temp.currentValue = sens.t.value;
@@ -145,11 +144,11 @@ int ThermalUtils::readTemperatures(bool filterType, TemperatureType type,
std::vector<Temperature> _temp;
for (it = thermalConfig.begin(); it != thermalConfig.end(); it++) {
- struct therm_sensor sens = it->second;
+ struct therm_sensor& sens = it->second;
if (filterType && sens.t.type != type)
continue;
- ret = cmnInst.read_temperature(&sens);
+ ret = cmnInst.read_temperature(sens);
if (ret < 0)
return ret;
_temp.push_back(sens.t);
@@ -166,7 +165,7 @@ int ThermalUtils::readTemperatureThreshold(bool filterType, TemperatureType type
std::vector<TemperatureThreshold> _thresh;
for (it = thermalConfig.begin(); it != thermalConfig.end(); it++) {
- struct therm_sensor sens = it->second;
+ struct therm_sensor& sens = it->second;
if (filterType && sens.t.type != type)
continue;
@@ -187,7 +186,7 @@ int ThermalUtils::readCdevStates(bool filterType, cdevType type,
if (filterType && cdev.c.type != type)
continue;
- ret = cmnInst.read_cdev_state(&cdev);
+ ret = cmnInst.read_cdev_state(cdev);
if (ret < 0)
return ret;
_cdev.push_back(cdev.c);