diff options
author | David Chao <davidchao@google.com> | 2021-06-09 11:08:18 +0800 |
---|---|---|
committer | David Chao <davidchao@google.com> | 2021-08-05 17:29:08 +0800 |
commit | d774cbb949e98627e4172bf8fc11e8d954599aa7 (patch) | |
tree | d2cc010dbde0794e40b0d0ef85cd70c82159c970 | |
parent | 0e73536681c59ef1dca9dc7fc289935c9ff83dc3 (diff) | |
download | pixel-d774cbb949e98627e4172bf8fc11e8d954599aa7.tar.gz |
thermal: Dynamically read State2Power from setting
Dynamically read the state2power from setting and ensure
the number of State2Power matches with max_state in
thermal HAL initialization.
Bug: 189488358
Test: boot and local test.
Change-Id: Id95175325c34686b6414362858f19f6445b61a65
Signed-off-by: David Chao <davidchao@google.com>
-rw-r--r-- | thermal/thermal-helper.cpp | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/thermal/thermal-helper.cpp b/thermal/thermal-helper.cpp index b6c374fe..cbd63939 100644 --- a/thermal/thermal-helper.cpp +++ b/thermal/thermal-helper.cpp @@ -51,6 +51,7 @@ constexpr std::string_view kSensorTripPointHystZeroFile("trip_point_0_hyst"); constexpr std::string_view kUserSpaceSuffix("user_space"); constexpr std::string_view kCoolingDeviceCurStateSuffix("cur_state"); constexpr std::string_view kCoolingDeviceMaxStateSuffix("max_state"); +constexpr std::string_view kCoolingDeviceState2powerSuffix("state2power_table"); constexpr std::string_view kConfigProperty("vendor.thermal.config"); constexpr std::string_view kConfigDefaultFileName("thermal_info_config.json"); constexpr std::string_view kThermalGenlProperty("persist.vendor.enable.thermal.genl"); @@ -848,6 +849,26 @@ bool ThermalHelper::initializeCoolingDevices( continue; } + std::string state2power_path = android::base::StringPrintf( + "%s/%s", path.data(), kCoolingDeviceState2powerSuffix.data()); + std::string state2power_str; + if (android::base::ReadFileToString(state2power_path, &state2power_str)) { + LOG(INFO) << "Cooling device " << cooling_device_info_pair.first + << " use state2power read from sysfs"; + cooling_device_info_pair.second.state2power.clear(); + + std::stringstream power(state2power_str); + unsigned int power_number; + int i = 0; + while (power >> power_number) { + cooling_device_info_pair.second.state2power.push_back( + static_cast<float>(power_number)); + LOG(INFO) << "Cooling device " << cooling_device_info_pair.first << " state:" << i + << " power: " << power_number; + i++; + } + } + // Get max cooling device request state std::string max_state; std::string max_state_path = android::base::StringPrintf( @@ -859,7 +880,17 @@ bool ThermalHelper::initializeCoolingDevices( } else { cooling_device_info_pair.second.max_state = std::stoi(android::base::Trim(max_state)); LOG(INFO) << "Cooling device " << cooling_device_info_pair.first - << " max state: " << cooling_device_info_pair.second.max_state; + << " max state: " << cooling_device_info_pair.second.max_state + << " state2power number: " + << cooling_device_info_pair.second.state2power.size(); + if (cooling_device_info_pair.second.state2power.size() > 0 && + cooling_device_info_pair.second.state2power.size() != + (size_t)cooling_device_info_pair.second.max_state + 1) { + LOG(ERROR) << "Invalid state2power number: " + << cooling_device_info_pair.second.state2power.size() + << ", number should be " << cooling_device_info_pair.second.max_state + 1 + << " (max_state + 1)"; + } } // Add cooling device path for thermalHAL to request state |