summaryrefslogtreecommitdiff
path: root/thermal
diff options
context:
space:
mode:
authorTeYuan Wang <kamewang@google.com>2021-02-02 16:57:19 +0800
committerTeYuan Wang <kamewang@google.com>2021-02-08 22:04:32 +0800
commit6326082f3c95a57b1e4af8cdb25e75772fbea0ac (patch)
tree2e3d21b4375147808cc37b212154acfe7a16b099 /thermal
parentc9045e3e02e915ee4deace06b684c484d619d62c (diff)
downloadpixel-6326082f3c95a57b1e4af8cdb25e75772fbea0ac.tar.gz
thermal: support user vote in thermalHAL
Bug: 170672151 Bug: 175267191 Test: verified with emul_temp Change-Id: Ib082103a5a0bbe6cc500a54c90e9c3ceb0393f94
Diffstat (limited to 'thermal')
-rw-r--r--thermal/android.hardware.thermal@2.0-service.pixel.rc7
-rw-r--r--thermal/thermal-helper.cpp59
-rw-r--r--thermal/thermal-helper.h2
-rw-r--r--thermal/utils/config_parser.cpp46
-rw-r--r--thermal/utils/config_parser.h5
-rw-r--r--thermal/utils/thermal_files.cpp4
6 files changed, 95 insertions, 28 deletions
diff --git a/thermal/android.hardware.thermal@2.0-service.pixel.rc b/thermal/android.hardware.thermal@2.0-service.pixel.rc
index a3febb31..fca222ff 100644
--- a/thermal/android.hardware.thermal@2.0-service.pixel.rc
+++ b/thermal/android.hardware.thermal@2.0-service.pixel.rc
@@ -28,6 +28,13 @@ on property:vendor.thermal.link_ready=1
chown system system /dev/thermal/tz-by-name/soft_ocp_gpu/trip_point_0_temp
chown system system /dev/thermal/tz-by-name/soft_ocp_gpu/trip_point_0_hyst
chown system system /dev/thermal/tz-by-name/soc/mode
+ # thermal
+ chown system system /dev/thermal/tz-by-name/neutral_therm/trip_point_0_temp
+ chown system system /dev/thermal/tz-by-name/neutral_therm/trip_point_0_hyst
+ chown system system /dev/thermal/cdev-by-name/thermal-cpufreq-0/user_vote
+ chown system system /dev/thermal/cdev-by-name/thermal-cpufreq-1/user_vote
+ chown system system /dev/thermal/cdev-by-name/thermal-cpufreq-2/user_vote
+ chown system system /dev/thermal/cdev-by-name/thermal-gpufreq-0/user_vote
start vendor.thermal-hal-2-0
service vendor.thermal-hal-2-0 /vendor/bin/hw/android.hardware.thermal@2.0-service.pixel
diff --git a/thermal/thermal-helper.cpp b/thermal/thermal-helper.cpp
index c00199c6..4d2496cb 100644
--- a/thermal/thermal-helper.cpp
+++ b/thermal/thermal-helper.cpp
@@ -323,11 +323,12 @@ ThermalHelper::ThermalHelper(const NotificationCallback &cb)
LOG(FATAL) << "ThermalHAL could not be initialized properly.";
}
- std::set<std::string> monitored_sensors;
- initializeTrip(tz_map, &monitored_sensors);
-
const bool thermal_genl_enabled =
android::base::GetBoolProperty(kThermalGenlProperty.data(), false);
+
+ std::set<std::string> monitored_sensors;
+ initializeTrip(tz_map, &monitored_sensors, thermal_genl_enabled);
+
if (thermal_genl_enabled) {
thermal_watcher_->registerFilesToWatchNl(monitored_sensors);
} else {
@@ -583,10 +584,12 @@ bool ThermalHelper::requestCdevByPower(std::string_view sensor_name, SensorStatu
cdev_power_budget = total_power_budget *
((sensor_info.throttling_info->cdev_weight[i]) / total_weight);
+ int cdev_ceiling = sensor_info.throttling_info->cdev_ceiling[i];
const CdevInfo &cdev_info_pair =
cooling_device_info_map_.at(sensor_info.throttling_info->cdev_request[i]);
- for (j = 0; j < cdev_info_pair.power2state.size() - 1; ++j) {
- if (cdev_power_budget > cdev_info_pair.power2state[j]) {
+ for (j = 0; j < cdev_info_pair.state2power.size() - 1; ++j) {
+ if (cdev_power_budget > cdev_info_pair.state2power[j] ||
+ (cdev_ceiling && static_cast<int>(j) >= cdev_ceiling)) {
break;
}
}
@@ -702,21 +705,45 @@ bool ThermalHelper::initializeSensorMap(const std::map<std::string, std::string>
bool ThermalHelper::initializeCoolingDevices(const std::map<std::string, std::string> &path_map) {
for (const auto &cooling_device_info_pair : cooling_device_info_map_) {
- std::string_view cooling_device_name = cooling_device_info_pair.first;
- if (!path_map.count(cooling_device_name.data())) {
+ std::string cooling_device_name = cooling_device_info_pair.first;
+ if (!path_map.count(cooling_device_name)) {
LOG(ERROR) << "Could not find " << cooling_device_name << " in sysfs";
continue;
}
- std::string path = android::base::StringPrintf(
- "%s/%s", path_map.at(cooling_device_name.data()).c_str(),
- kCoolingDeviceCurStateSuffix.data());
- if (!cooling_devices_.addThermalFile(cooling_device_name, path)) {
- LOG(ERROR) << "Could not add " << cooling_device_name << "to cooling device map";
+ // Add cooling device path for thermalHAL to get current state
+ std::string_view path = path_map.at(cooling_device_name);
+ std::string read_path;
+ if (!cooling_device_info_pair.second.read_path.empty()) {
+ read_path = cooling_device_info_pair.second.read_path.data();
+ } else {
+ read_path = android::base::StringPrintf("%s/%s", path.data(),
+ kCoolingDeviceCurStateSuffix.data());
+ }
+ if (!cooling_devices_.addThermalFile(cooling_device_name, read_path)) {
+ LOG(ERROR) << "Could not add " << cooling_device_name
+ << " read path to cooling device map";
+ continue;
+ }
+
+ // Add cooling device path for thermalHAL to request state
+ cooling_device_name =
+ android::base::StringPrintf("%s_%s", cooling_device_name.c_str(), "w");
+ std::string write_path;
+ if (!cooling_device_info_pair.second.write_path.empty()) {
+ write_path = cooling_device_info_pair.second.write_path.data();
+ } else {
+ write_path = android::base::StringPrintf("%s/%s", path.data(),
+ kCoolingDeviceCurStateSuffix.data());
+ }
+
+ if (!cooling_devices_.addThermalFile(cooling_device_name, write_path)) {
+ LOG(ERROR) << "Could not add " << cooling_device_name
+ << " write path to cooling device map";
continue;
}
}
- if (cooling_device_info_map_.size() == cooling_devices_.getNumThermalFiles()) {
+ if (cooling_device_info_map_.size() * 2 == cooling_devices_.getNumThermalFiles()) {
return true;
}
return false;
@@ -728,7 +755,8 @@ void ThermalHelper::setMinTimeout(SensorInfo *sensor_info) {
}
void ThermalHelper::initializeTrip(const std::map<std::string, std::string> &path_map,
- std::set<std::string> *monitored_sensors) {
+ std::set<std::string> *monitored_sensors,
+ bool thermal_genl_enabled) {
for (auto &sensor_info : sensor_info_map_) {
if (!sensor_info.second.is_monitor || (sensor_info.second.virtual_sensor_info != nullptr)) {
continue;
@@ -787,7 +815,8 @@ void ThermalHelper::initializeTrip(const std::map<std::string, std::string> &pat
}
}
}
- if (support_uevent) {
+
+ if (support_uevent || thermal_genl_enabled) {
monitored_sensors->insert(sensor_info.first);
} else {
LOG(INFO) << "config Sensor: " << sensor_info.first
diff --git a/thermal/thermal-helper.h b/thermal/thermal-helper.h
index 178f3466..51a52b56 100644
--- a/thermal/thermal-helper.h
+++ b/thermal/thermal-helper.h
@@ -150,7 +150,7 @@ class ThermalHelper {
bool initializeCoolingDevices(const std::map<std::string, std::string> &path_map);
void setMinTimeout(SensorInfo *sensor_info);
void initializeTrip(const std::map<std::string, std::string> &path_map,
- std::set<std::string> *monitored_sensors);
+ std::set<std::string> *monitored_sensors, bool thermal_genl_enabled);
// For thermal_watcher_'s polling thread, return the sleep interval
std::chrono::milliseconds thermalWatcherCallbackFunc(
diff --git a/thermal/utils/config_parser.cpp b/thermal/utils/config_parser.cpp
index 85b2b718..fc123bb2 100644
--- a/thermal/utils/config_parser.cpp
+++ b/thermal/utils/config_parser.cpp
@@ -389,6 +389,7 @@ std::map<std::string, SensorInfo> ParseSensorInfo(std::string_view config_path)
i_cutoff.fill(NAN);
std::vector<std::string> cdev_request;
std::vector<float> cdev_weight;
+ std::vector<int> cdev_ceiling;
if (support_pid) {
LOG(INFO) << "Start to parse K_Po";
@@ -468,7 +469,7 @@ std::map<std::string, SensorInfo> ParseSensorInfo(std::string_view config_path)
}
values = sensors[i]["CdevWeight"];
- if (values.size()) {
+ if (values.size() == cdev_request.size()) {
cdev_weight.reserve(values.size());
for (Json::Value::ArrayIndex j = 0; j < values.size(); ++j) {
cdev_weight.emplace_back(getFloatFromValue(values[j]));
@@ -476,8 +477,25 @@ std::map<std::string, SensorInfo> ParseSensorInfo(std::string_view config_path)
<< "]: " << cdev_weight[j];
}
} else {
- sensors_parsed.clear();
- return sensors_parsed;
+ cdev_weight.reserve(cdev_request.size());
+ for (size_t j = 0; j < cdev_request.size(); ++j) {
+ cdev_weight.emplace_back(1);
+ }
+ }
+
+ values = sensors[i]["CdevCeiling"];
+ if (values.size() == cdev_request.size()) {
+ cdev_ceiling.reserve(values.size());
+ for (Json::Value::ArrayIndex j = 0; j < values.size(); ++j) {
+ cdev_ceiling.emplace_back(getIntFromValue(values[j]));
+ LOG(INFO) << "Sensor[" << name << "]'s cdev_ceiling[" << j
+ << "]: " << cdev_ceiling[j];
+ }
+ } else {
+ cdev_ceiling.reserve(cdev_request.size());
+ for (size_t j = 0; j < cdev_request.size(); ++j) {
+ cdev_ceiling.emplace_back(0);
+ }
}
for (Json::Value::ArrayIndex j = 0; j < kThrottlingSeverityCount; ++j) {
@@ -519,7 +537,7 @@ std::map<std::string, SensorInfo> ParseSensorInfo(std::string_view config_path)
std::unique_ptr<ThrottlingInfo> throttling_info(new ThrottlingInfo{
k_po, k_pu, k_i, k_d, i_max, max_alloc_power, min_alloc_power, s_power, i_cutoff,
- throttle_type, cdev_request, cdev_weight, limit_info});
+ throttle_type, cdev_request, cdev_weight, cdev_ceiling, limit_info});
sensors_parsed[name] = {
.type = sensor_type,
@@ -593,14 +611,20 @@ std::map<std::string, CdevInfo> ParseCoolingDevice(std::string_view config_path)
return cooling_devices_parsed;
}
- std::vector<float> power2state;
- Json::Value values = cooling_devices[i]["Power2State"];
+ const std::string &read_path = cooling_devices[i]["ReadPath"].asString();
+ LOG(INFO) << "Cdev Read Path: " << (read_path.empty() ? "default" : read_path);
+
+ const std::string &write_path = cooling_devices[i]["WritePath"].asString();
+ LOG(INFO) << "Cdev Write Path: " << (write_path.empty() ? "default" : write_path);
+
+ std::vector<float> state2power;
+ Json::Value values = cooling_devices[i]["State2Power"];
if (values.size()) {
- power2state.reserve(values.size());
+ state2power.reserve(values.size());
for (Json::Value::ArrayIndex j = 0; j < values.size(); ++j) {
- power2state.emplace_back(getFloatFromValue(values[j]));
+ state2power.emplace_back(getFloatFromValue(values[j]));
LOG(INFO) << "Cooling device[" << name << "]'s Power2State[" << j
- << "]: " << power2state[j];
+ << "]: " << state2power[j];
}
} else {
LOG(INFO) << "CoolingDevice[" << i << "]'s Name: " << name
@@ -609,7 +633,9 @@ std::map<std::string, CdevInfo> ParseCoolingDevice(std::string_view config_path)
cooling_devices_parsed[name] = {
.type = cooling_device_type,
- .power2state = power2state,
+ .read_path = read_path,
+ .write_path = write_path,
+ .state2power = state2power,
};
++total_parsed;
}
diff --git a/thermal/utils/config_parser.h b/thermal/utils/config_parser.h
index 3b099761..075084b2 100644
--- a/thermal/utils/config_parser.h
+++ b/thermal/utils/config_parser.h
@@ -73,6 +73,7 @@ struct ThrottlingInfo {
ThrottlingTypeArray throttle_type;
std::vector<std::string> cdev_request;
std::vector<float> cdev_weight;
+ std::vector<int> cdev_ceiling;
std::map<std::string, ThrottlingArray> limit_info;
};
@@ -95,7 +96,9 @@ struct SensorInfo {
struct CdevInfo {
CoolingType_2_0 type;
- std::vector<float> power2state;
+ std::string read_path;
+ std::string write_path;
+ std::vector<float> state2power;
};
std::map<std::string, SensorInfo> ParseSensorInfo(std::string_view config_path);
diff --git a/thermal/utils/thermal_files.cpp b/thermal/utils/thermal_files.cpp
index 6f56af98..e5eb6be2 100644
--- a/thermal/utils/thermal_files.cpp
+++ b/thermal/utils/thermal_files.cpp
@@ -19,6 +19,7 @@
#include <android-base/file.h>
#include <android-base/logging.h>
+#include <android-base/stringprintf.h>
#include <android-base/strings.h>
#include "thermal_files.h"
@@ -60,7 +61,8 @@ bool ThermalFiles::readThermalFile(std::string_view thermal_name, std::string *d
}
bool ThermalFiles::writeCdevFile(std::string_view cdev_name, std::string_view data) {
- std::string file_path = getThermalFilePath(std::string_view(cdev_name.data()));
+ std::string file_path =
+ getThermalFilePath(android::base::StringPrintf("%s_%s", cdev_name.data(), "w"));
if (!android::base::WriteStringToFile(data.data(), file_path)) {
PLOG(WARNING) << "Failed to write cdev: " << cdev_name << " to " << data.data();