• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <android/hardware/thermal/2.0/IThermal.h>
20 
21 #include <string>
22 #include <unordered_map>
23 
24 namespace android {
25 namespace hardware {
26 namespace thermal {
27 namespace V2_0 {
28 namespace implementation {
29 
30 using ::android::hardware::hidl_enum_range;
31 using CoolingType_2_0 = ::android::hardware::thermal::V2_0::CoolingType;
32 using TemperatureType_2_0 = ::android::hardware::thermal::V2_0::TemperatureType;
33 using ::android::hardware::thermal::V2_0::ThrottlingSeverity;
34 constexpr size_t kThrottlingSeverityCount = std::distance(
35         hidl_enum_range<ThrottlingSeverity>().begin(), hidl_enum_range<ThrottlingSeverity>().end());
36 using ThrottlingArray = std::array<float, static_cast<size_t>(kThrottlingSeverityCount)>;
37 using CdevArray = std::array<int, static_cast<size_t>(kThrottlingSeverityCount)>;
38 constexpr std::chrono::milliseconds kMinPollIntervalMs = std::chrono::milliseconds(2000);
39 constexpr std::chrono::milliseconds kUeventPollTimeoutMs = std::chrono::milliseconds(300000);
40 
41 enum FormulaOption : uint32_t {
42     COUNT_THRESHOLD = 0,
43     WEIGHTED_AVG,
44     MAXIMUM,
45     MINIMUM,
46 };
47 
48 struct VirtualSensorInfo {
49     std::vector<std::string> linked_sensors;
50     std::vector<float> coefficients;
51     float offset;
52     std::vector<std::string> trigger_sensors;
53     FormulaOption formula;
54 };
55 
56 struct VirtualPowerRailInfo {
57     std::vector<std::string> linked_power_rails;
58     std::vector<float> coefficients;
59     float offset;
60     FormulaOption formula;
61 };
62 
63 // The method when the ODPM power is lower than threshold
64 enum ReleaseLogic : uint32_t {
65     INCREASE = 0,      // Increase throttling by step
66     DECREASE,          // Decrease throttling by step
67     STEPWISE,          // Support both increase and decrease logix
68     RELEASE_TO_FLOOR,  // Release throttling to floor directly
69     NONE,
70 };
71 
72 struct BindedCdevInfo {
73     CdevArray limit_info;
74     ThrottlingArray power_thresholds;
75     ReleaseLogic release_logic;
76     ThrottlingArray cdev_weight_for_pid;
77     CdevArray cdev_ceiling;
78     int max_release_step;
79     int max_throttle_step;
80     CdevArray cdev_floor_with_power_link;
81     std::string power_rail;
82     // The flag for activate release logic when power is higher than power threshold
83     bool high_power_check;
84     // The flag for only triggering throttling until all power samples are collected
85     bool throttling_with_power_link;
86 };
87 
88 struct ThrottlingInfo {
89     ThrottlingArray k_po;
90     ThrottlingArray k_pu;
91     ThrottlingArray k_i;
92     ThrottlingArray k_d;
93     ThrottlingArray i_max;
94     ThrottlingArray max_alloc_power;
95     ThrottlingArray min_alloc_power;
96     ThrottlingArray s_power;
97     ThrottlingArray i_cutoff;
98     float i_default;
99     int tran_cycle;
100     std::unordered_map<std::string, ThrottlingArray> excluded_power_info_map;
101     std::unordered_map<std::string, BindedCdevInfo> binded_cdev_info_map;
102 };
103 
104 struct SensorInfo {
105     TemperatureType_2_0 type;
106     ThrottlingArray hot_thresholds;
107     ThrottlingArray cold_thresholds;
108     ThrottlingArray hot_hysteresis;
109     ThrottlingArray cold_hysteresis;
110     std::string temp_path;
111     float vr_threshold;
112     float multiplier;
113     std::chrono::milliseconds polling_delay;
114     std::chrono::milliseconds passive_delay;
115     std::chrono::milliseconds time_resolution;
116     bool send_cb;
117     bool send_powerhint;
118     bool is_watch;
119     bool is_hidden;
120     std::unique_ptr<VirtualSensorInfo> virtual_sensor_info;
121     std::shared_ptr<ThrottlingInfo> throttling_info;
122 };
123 
124 struct CdevInfo {
125     CoolingType_2_0 type;
126     std::string read_path;
127     std::string write_path;
128     std::vector<float> state2power;
129     int max_state;
130 };
131 
132 struct PowerRailInfo {
133     std::string rail;
134     int power_sample_count;
135     std::chrono::milliseconds power_sample_delay;
136     std::unique_ptr<VirtualPowerRailInfo> virtual_power_rail_info;
137 };
138 
139 bool ParseSensorInfo(std::string_view config_path,
140                      std::unordered_map<std::string, SensorInfo> *sensors_parsed);
141 bool ParseCoolingDevice(std::string_view config_path,
142                         std::unordered_map<std::string, CdevInfo> *cooling_device_parsed);
143 bool ParsePowerRailInfo(std::string_view config_path,
144                         std::unordered_map<std::string, PowerRailInfo> *power_rail_parsed);
145 
146 }  // namespace implementation
147 }  // namespace V2_0
148 }  // namespace thermal
149 }  // namespace hardware
150 }  // namespace android
151