diff options
| author | TreeHugger Robot <treehugger-gerrit@google.com> | 2018-11-09 00:41:35 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2018-11-09 00:41:35 +0000 |
| commit | 34aa431c18ba8d0caf78199675ebf9d29a39d34d (patch) | |
| tree | 97f7f296ed1540d3a9500823c34811ecf1ec020b | |
| parent | 170b01fbee999d083fbf407ece5b8ba1c774a9b7 (diff) | |
| parent | d1cab37d764b3df4ff62042824abd116f1a5b1e5 (diff) | |
Merge "Revert "thermal: recommend throttling at low temps"" into pi-dev
| -rw-r--r-- | thermal/Android.bp | 1 | ||||
| -rw-r--r-- | thermal/Thermal.cpp | 3 | ||||
| -rw-r--r-- | thermal/thermal-helper.cpp | 10 | ||||
| -rw-r--r-- | thermal/thermal-helper.h | 3 | ||||
| -rw-r--r-- | thermal/utils/battery_threshold.cpp | 249 | ||||
| -rw-r--r-- | thermal/utils/battery_threshold.h | 66 |
6 files changed, 0 insertions, 332 deletions
diff --git a/thermal/Android.bp b/thermal/Android.bp index 9e90b84..eaac77d 100644 --- a/thermal/Android.bp +++ b/thermal/Android.bp @@ -12,7 +12,6 @@ cc_binary { "service.cpp", "Thermal.cpp", "thermal-helper.cpp", - "utils/battery_threshold.cpp", "utils/cooling_devices.cpp", "utils/device_file_watcher.cpp", "utils/sensors.cpp", diff --git a/thermal/Thermal.cpp b/thermal/Thermal.cpp index 37edb13..70ac1d2 100644 --- a/thermal/Thermal.cpp +++ b/thermal/Thermal.cpp @@ -218,9 +218,6 @@ Return<void> Thermal::debug( << std::endl; } - if (!thermal_helper_.fillBatteryThresholdDebugInfo(dump_buf)) { - dump_buf << "error while filling BatteryThresholdDebugInfo." << std::endl; - } } std::string buf = dump_buf.str(); if (!android::base::WriteStringToFd(buf, fd)) { diff --git a/thermal/thermal-helper.cpp b/thermal/thermal-helper.cpp index 3d7debe..6e8e1f9 100644 --- a/thermal/thermal-helper.cpp +++ b/thermal/thermal-helper.cpp @@ -250,11 +250,6 @@ bool ThermalHelper::readTemperature( out->name = sensor_name; out->currentValue = std::stoi(temp) * sensor_info.multiplier; out->throttlingThreshold = getThresholdFromType(sensor_info.type, thresholds_); - if (sensor_info.type == TemperatureType::SKIN) { - out->throttlingThreshold = low_temp_threshold_adjuster_.adjustThreshold( - out->throttlingThreshold, out->currentValue); - } - out->shutdownThreshold = getThresholdFromType( sensor_info.type, shutdown_thresholds_); out->vrThrottlingThreshold = getThresholdFromType( @@ -416,11 +411,6 @@ bool ThermalHelper::checkThrottlingData( return false; } -bool ThermalHelper::fillBatteryThresholdDebugInfo(std::ostringstream& dump_buf) -{ - return low_temp_threshold_adjuster_.fillBatteryThresholdDebugInfo(dump_buf); -} - std::string ThermalHelper::getSkinSensorType() { // The skin sensor is checked dynamically, since -evt uses quiet-therm-adc // and -prod uses fps-therm-adc. diff --git a/thermal/thermal-helper.h b/thermal/thermal-helper.h index 670cc3b..c864931 100644 --- a/thermal/thermal-helper.h +++ b/thermal/thermal-helper.h @@ -39,7 +39,6 @@ #include <fnmatch.h> #include <android/hardware/thermal/1.0/IThermal.h> -#include "utils/battery_threshold.h" #include "utils/cooling_devices.h" #include "utils/sensors.h" @@ -77,7 +76,6 @@ class ThermalHelper { bool fillTemperatures(hidl_vec<Temperature>* temperatures); bool fillCpuUsages(hidl_vec<CpuUsage>* cpu_usages); - bool fillBatteryThresholdDebugInfo(std::ostringstream& dump_buf); // Dissallow copy and assign. ThermalHelper(const ThermalHelper&) = delete; @@ -132,7 +130,6 @@ class ThermalHelper { ThrottlingThresholds vr_thresholds_; ThrottlingThresholds shutdown_thresholds_; const bool is_initialized_; - const BatteryThresholdLUT low_temp_threshold_adjuster_; }; } // namespace implementation diff --git a/thermal/utils/battery_threshold.cpp b/thermal/utils/battery_threshold.cpp deleted file mode 100644 index 8dc196c..0000000 --- a/thermal/utils/battery_threshold.cpp +++ /dev/null @@ -1,249 +0,0 @@ -/* - * Copyright (C) 2018 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <android-base/file.h> -#include <android-base/logging.h> -#include <android-base/strings.h> -#include "battery_threshold.h" - -namespace android { -namespace hardware { -namespace thermal { -namespace V1_1 { -namespace implementation { - -enum class AgeRange -{ - Fresh, - Above200, - Above400, - Above600, - Above900 -}; -enum class TempRange -{ - AboveZero, - ZeroToNegFive, - NegFiveToNegTen, - BelowNegTen -}; - -namespace { - -TempRange rangeFromTemp(float current_temp) -{ - if (current_temp >= 0.0) { - return TempRange::AboveZero; - } - if ((current_temp >= -5.0) && (current_temp < 0.0)) { - return TempRange::ZeroToNegFive; - } - if ((current_temp >= -10.0) && (current_temp < -5.0)) { - return TempRange::NegFiveToNegTen; - } - if ((current_temp < -10.0)) { - return TempRange::BelowNegTen; - } - return TempRange::AboveZero; -} - -AgeRange ageFromCC(int cycle_count) -{ - if ( cycle_count < 200) { - return AgeRange::Fresh; - } - if (( cycle_count >= 200) && (cycle_count < 400)) { - return AgeRange::Above200; - } - if (( cycle_count >= 400) && (cycle_count < 600)) { - return AgeRange::Above400; - } - if (( cycle_count >= 600) && (cycle_count < 900)) { - return AgeRange::Above600; - } - return AgeRange::Above900; -} - -std::ostream& operator<<(std::ostream& os, const AgeRange& age) -{ - switch (age) { - case AgeRange::Fresh: - os << "Fresh"; - break; - case AgeRange::Above200: - os << "Above200"; - break; - case AgeRange::Above400: - os << "Above400"; - break; - case AgeRange::Above600: - os << "Above600"; - break; - case AgeRange::Above900: - os << "Above900"; - break; - default: - break; - } - return os; -} - -std::ostream& operator<<(std::ostream& os, const TempRange& temp) -{ - switch (temp) { - case TempRange::AboveZero: - os << "AboveZero"; - break; - case TempRange::ZeroToNegFive: - os << "ZeroToNegFive"; - break; - case TempRange::NegFiveToNegTen: - os << "NegFiveToNegTen"; - break; - case TempRange::BelowNegTen: - os << "BelowNegTen"; - break; - default: - break; - } - return os; -} -} // namespace - -bool BatteryThresholdLUT::readCycleCount(int& cycle_count) const -{ - std::string contents; - if (!android::base::ReadFileToString(cycle_count_filename_, &contents)) { - return false; - } - cycle_count = std::stoi(android::base::Trim(contents)); - return true; -} - -bool BatteryThresholdLUT::readSoC(int& soc) const -{ - std::string contents; - if (!android::base::ReadFileToString( - state_of_charge_filename_, &contents)) { - return false; - } - soc = std::stoi(android::base::Trim(contents)); - return true; -} - -bool BatteryThresholdLUT::readStatus(std::string& status) const -{ - if (!android::base::ReadFileToString(status_filename_, &status)) { - return false; - } - status = android::base::Trim(status); - return true; -} - -constexpr float kThresholdDecrease = 5.0; -float BatteryThresholdLUT::adjustThreshold( - float configured_threshold, float current_temperature) const -{ - int current_soc = 100; - int cycle_count = 0; - std::string status; - bool rc = readStatus(status); - if (!rc || status != "Discharging") { - return configured_threshold; - } - - TempRange temp_range = rangeFromTemp(current_temperature); - - if (!readCycleCount(cycle_count)) { - return configured_threshold; - } - AgeRange age = ageFromCC(cycle_count); - - auto it = battery_conditions_lut_.find({temp_range, age}); - if (it == battery_conditions_lut_.end()) { - return configured_threshold; - } - int low_soc = it->second; - - if (!readSoC(current_soc) || (low_soc <= current_soc)) { - return configured_threshold; - } - - //TODO: We should expand the semantics of the Thermal Hal so that the - // temperature thresholds have a max and a min. For now, just set the - // threshold below the actual value. - float low_temp_threshold = current_temperature - kThresholdDecrease; - LOG(DEBUG) << "Low temp and battery conditions present." - << " (cycle_count: " << cycle_count - << " SoC: " << current_soc - << " temperature: " << current_temperature << ")\n" - << " Recommending threshold : " << low_temp_threshold; - return low_temp_threshold; -} - -BatteryThresholdLUT::BatteryThresholdLUT() : - battery_conditions_lut_ { - {{ TempRange::ZeroToNegFive, AgeRange::Above900 }, 40 }, - {{ TempRange::NegFiveToNegTen, AgeRange::Above400 }, 5 }, - {{ TempRange::NegFiveToNegTen, AgeRange::Above600 }, 15 }, - {{ TempRange::NegFiveToNegTen, AgeRange::Above900 }, 50 }, - {{ TempRange::BelowNegTen, AgeRange::Fresh }, 5 }, - {{ TempRange::BelowNegTen, AgeRange::Above200 }, 12 }, - {{ TempRange::BelowNegTen, AgeRange::Above400 }, 45 }, - {{ TempRange::BelowNegTen, AgeRange::Above600 }, 60 }, - {{ TempRange::BelowNegTen, AgeRange::Above900 }, 100 } - }, - cycle_count_filename_{"/sys/class/power_supply/battery/cycle_count"}, - state_of_charge_filename_{"/sys/class/power_supply/battery/capacity"}, - status_filename_{"/sys/class/power_supply/battery/status"} -{ -} - -bool BatteryThresholdLUT::fillBatteryThresholdDebugInfo( - std::ostringstream& dump_buf) const -{ - int soc = -1; - int cycle_count = -1; - std::string status; - bool rc = readSoC(soc); - rc |= readCycleCount(cycle_count); - rc |= readStatus(status); - - dump_buf << "ThermalBattery: Status: " << status - << " SoC: " << soc - << " Cycle count: " << cycle_count << std::endl; - dump_buf << "ThermalBattery: LookupTable: " << std::endl; - - for (const auto & entry : battery_conditions_lut_) { - dump_buf << "\t(Temp: " << entry.first.first - << ", Age: " << entry.first.second - << ") -> " << entry.second << " SoC Level" << std::endl; - } - return rc; - -} - -size_t BatteryThresholdLUT::TempAgeHash::operator()( - const std::pair<TempRange, AgeRange>& k) const -{ - return static_cast<size_t>(k.first) << 16 | static_cast<size_t>(k.second); -} - -} // namespace implementation -} // namespace V1_1 -} // namespace thermal -} // namespace hardware -} // namespace android diff --git a/thermal/utils/battery_threshold.h b/thermal/utils/battery_threshold.h deleted file mode 100644 index 47249b1..0000000 --- a/thermal/utils/battery_threshold.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2018 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __BATTERY_THRESHOLD_H__ -#define __BATTERY_THRESHOLD_H__ - -#include <android/hardware/thermal/1.0/IThermal.h> -#include <string> -#include <unordered_map> -#include <utility> - -namespace android { -namespace hardware { -namespace thermal { -namespace V1_1 { -namespace implementation { -using ::android::hardware::hidl_vec; -using ::android::hardware::thermal::V1_0::CpuUsage; -using ::android::hardware::thermal::V1_0::Temperature; -using ::android::hardware::thermal::V1_0::TemperatureType; - -enum class AgeRange; -enum class TempRange; -class BatteryThresholdLUT -{ -public: - BatteryThresholdLUT(); - float adjustThreshold( - float configured_threshold, float current_temperature) const; - bool fillBatteryThresholdDebugInfo(std::ostringstream& dump_buf) const; -private: - bool readCycleCount(int& cycle_count) const; - bool readSoC(int& soc) const; - bool readStatus(std::string& status) const; - - struct TempAgeHash - { - size_t operator()(const std::pair<TempRange, AgeRange>& key) const; - }; - const std::unordered_map<std::pair<TempRange, AgeRange>, int, TempAgeHash> - battery_conditions_lut_; - const char* cycle_count_filename_; - const char* state_of_charge_filename_; - const char* status_filename_; -}; - -} // namespace implementation -} // namespace V1_1 -} // namespace thermal -} // namespace hardware -} // namespace android - -#endif // __THERMAL_HELPER_H__ |
