1# 热策略定制开发指导 2 3## 概述 4 5### 简介 6 7OpenHarmony默认提供了热策略的特性。设备上发热的器件种类繁多,因此需要结合热等级和热场景,针对各类发热器件定制统一的管控策略。但是不同热等级下的管控动作在不同的产品上规格是不同的,产品希望根据产品的设计规格来定制此特性。OpenHarmony提供了热策略的定制方式,产品定制开发者可根据产品的设计规格来定制这些特性。 8 9### 约束与限制 10 11产品定制的配置路径,需要根据[配置策略](https://gitee.com/openharmony/customization_config_policy)决定。本开发指导中的定制路径以`/vendor`进行举例,请开发者根据具体的产品配置策略,修改定制路径。 12 13## 开发指导 14 15### 搭建环境 16 17设备要求: 18 19标准系统开发板,如DAYU200/Hi3516DV300开源套件。 20 21环境要求: 22 23Linux调测环境,相关要求和配置可参考《[快速入门](../quick-start/quickstart-overview.md)》。 24 25### 开发步骤 26 27本文以[DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568)为例介绍热策略的定制方法。 28 291. 在产品目录[(/vendor/hihope/rk3568)](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568)下创建thermal文件夹。 30 312. 参考[默认热策略的配置文件夹](https://gitee.com/openharmony/powermgr_thermal_manager/tree/master/services/native/profile)创建目标文件夹,并安装到`//vendor/hihope/rk3568/thermal`,文件格式如下: 32 33 ```text 34 profile 35 ├── BUILD.gn 36 ├── thermal_service_config.xml 37 ``` 38 393. 参考[默认热策略的配置文件夹中的thermal_service_config.xml](https://gitee.com/openharmony/powermgr_thermal_manager/blob/master/services/native/profile/thermal_service_config.xml)编写定制的thermal_service_config.xml。包含热策略配置说明及定制后的热策略配置如下,以其中两个热等级为例: 40 41 **表1** config配置说明 42 43 | 配置项名称 | 配置项描述 | 配置项类型 | 配置项范围 | 44 | -------- | -------- | -------- | -------- | 45 | name | 定义热策略对应的传感器集合名称 | string | 对应[热等级文档](../subsystems/subsys-thermal_level.md)中定义的传感器集合名称 | 46 | level | 定义热策略对应的热等级 | int | 对应[热等级文档](../subsystems/subsys-thermal_level.md)中传感器集合下定义的热等级 | 47 48 **表2** 配置项说明 49 50 | 配置项名称 | 配置项描述 | 配置项类型 | 配置项范围 | 51 | -------- | -------- | -------- | -------- | 52 | scene | 使用场景 | string | 对应[热场景文档](../subsystems/subsys-thermal_scene.md)中定义的使用场景 | 53 | charge | 是否在充电 | int | 0(不在充电),1(正在充电) | 54 | screen | 是否亮屏 | int | 0(灭屏),1(亮屏) | 55 56 **表3** 节点配置说明 57 58 | 节点名称 | 节点值类型 | 节点值范围 | 节点描述 | 59 | -------- | -------- | -------- | -------- | 60 | lcd | double | 0.00~1.00 | 屏幕亮度的百分比(用浮点数表示) | 61 | cpu_big | int | 根据产品定义 | CPU大核频率 | 62 | cpu_med | int | 根据产品定义 | CPU中核频率 | 63 | cpu_lit | int | 根据产品定义 | CPU小核频率 | 64 | process_ctrl | enum | 1:KILL_FG_PROCESS_APP<br>2:KILL_BG_PROCESS_APP<br>3:KILL_ALL_PROCESS_APP | 进程控制 | 65 | gpu | int | 根据产品定义 | GPU频率 | 66 | thermallevel | int | 对应config节点中的level | 热等级 | 67 | current_sc | int | 根据产品定义 | 快充电流 | 68 | current_buck | int | 根据产品定义 | 慢充电流 | 69 | voltage_sc | int | 根据产品定义 | 快充电压 | 70 | voltage_buck | int | 根据产品定义 | 慢充电压 | 71 | volume | double | 0.00~1.00 | 音量百分比(用浮点数表示) | 72 73 ```shell 74 <policy> 75 <config name="base_safe" level="1"> 76 <lcd>1.00</lcd> 77 <lcd scene="cam">0.99</lcd> 78 <lcd scene="call">0.98</lcd> 79 <lcd scene="game">0.95</lcd> 80 <cpu_big>1992000</cpu_big> 81 <cpu_med>1991500</cpu_med> 82 <cpu_lit>1991200</cpu_lit> 83 <process_ctrl>3</process_ctrl> 84 <cpu_big scene="cam" charge="1">1991800</cpu_big> 85 <cpu_big scene="cam" charge="0">1991600</cpu_big> 86 <gpu screen="0">524288</gpu> 87 <gpu screen="1">512000</gpu> 88 <thermallevel>1</thermallevel> 89 <current_sc>1800</current_sc> 90 <current_sc scene="cam">1200</current_sc> 91 <current_buck>1200</current_buck> 92 <voltage_sc>4000</voltage_sc> 93 <voltage_buck>3000</voltage_buck> 94 <volume>1.0</volume> 95 </config> 96 <policy> 97 <config name="base_safe" level="2"> 98 <lcd>0.90</lcd> 99 <lcd scene="cam">0.89</lcd> 100 <lcd scene="call">0.88</lcd> 101 <lcd scene="game">0.87</lcd> 102 <cpu_big>1991000</cpu_big> 103 <cpu_med>1990500</cpu_med> 104 <cpu_lit>1990200</cpu_lit> 105 <process_ctrl>2</process_ctrl> 106 <cpu_big scene="cam" charge="1">1990800</cpu_big> 107 <cpu_big scene="cam" charge="0">1990600</cpu_big> 108 <gpu screen="0">499712</gpu> 109 <gpu screen="1">487424</gpu> 110 <thermallevel>2</thermallevel> 111 <current_sc>1500</current_sc> 112 <current_sc scene="cam">1000</current_sc> 113 <current_buck>1000</current_buck> 114 <voltage_sc>3000</voltage_sc> 115 <voltage_buck>2000</voltage_buck> 116 <volume>0.8</volume> 117 </config> 118 </policy> 119 ``` 120 1214. 参考[默认热策略配置文件夹中的BUILD.gn](https://gitee.com/openharmony/powermgr_thermal_manager/blob/master/services/native/profile/BUILD.gn)编写BUILD.gn文件,将thermal_service_config.xml打包到`/vendor/etc/thermal_config`目录下 122 123 ```shell 124 import("//build/ohos.gni") # 引用build/ohos.gni 125 126 ohos_prebuilt_etc("thermal_service_config") { 127 source = "thermal_service_config.xml" 128 relative_install_dir = "thermal_config" 129 install_images = [ chipset_base_dir ] # 安装到vendor目录下的必要配置 130 part_name = "product_rk3568" # part_name暂定为product_rk3568,以实现后续编译,产品定制根据需要自行修改 131 } 132 ``` 133 1345. 将编译目标添加到[ohos.build](https://gitee.com/openharmony/vendor_hihope/blob/master/rk3568/ohos.build)的"module_list"中,例如: 135 136 ```json 137 { 138 "parts": { 139 "product_rk3568": { 140 "module_list": [ 141 "//vendor/hihope/rk3568/default_app_config:default_app_config", 142 "//vendor/hihope/rk3568/image_conf:custom_image_conf", 143 "//vendor/hihope/rk3568/preinstall-config:preinstall-config", 144 "//vendor/hihope/rk3568/resourceschedule:resourceschedule", 145 "//vendor/hihope/rk3568/etc:product_etc_conf", 146 "//vendor/hihope/rk3568/thermal/profile:thermal_service_config", // 添加thermal_service_config的编译 147 ] 148 } 149 }, 150 "subsystem": "product_hihope" 151 } 152 ``` 153 “//vendor/hihope/rk3568/thermal/”为文件夹路径,“profile”为创建的文件夹名字,“thermal_service_config”为编译目标。 154 1556. 参考《[快速入门](../quick-start/quickstart-overview.md)》编译定制版本,编译命令如下: 156 157 ```shell 158 ./build.sh --product-name rk3568 --ccache 159 ``` 160 1617. 将定制版本烧录到DAYU200开发板中。 162 163### 调测验证 164 1651. 开机后,进入shell命令行: 166 ```shell 167 hdc shell 168 ``` 169 1702. 获取当前热策略信息。 171 ```shell 172 hidumper -s 3303 -a -p 173 ``` 174 175 查看定制后的热策略结果如下: 176 ```shell 177 -------------------------------[ability]------------------------------- 178 179 180 ----------------------------------ThermalService--------------------------------- 181 name: base_safe level: 1 182 actionName: lcd actionValue: 1.00 isProp: 0 183 actionName: lcd actionValue: 0.99 scene: cam isProp: 1 184 actionName: lcd actionValue: 0.98 scene: call isProp: 1 185 actionName: lcd actionValue: 0.95 scene: game isProp: 1 186 actionName: cpu_big actionValue: 1992000 isProp: 0 187 actionName: cpu_med actionValue: 1991500 isProp: 0 188 actionName: cpu_lit actionValue: 1991200 isProp: 0 189 actionName: process_ctrl actionValue: 3 isProp: 0 190 actionName: cpu_big actionValue: 1991800 charge: 1 scene: cam isProp: 1 191 actionName: cpu_big actionValue: 1991600 charge: 0 scene: cam isProp: 1 192 actionName: gpu actionValue: 524288 screen: 0 isProp: 1 193 actionName: gpu actionValue: 512000 screen: 1 isProp: 1 194 actionName: thermallevel actionValue: 1 isProp: 0 195 actionName: current_sc actionValue: 1800 isProp: 0 196 actionName: current_sc actionValue: 1200 scene: cam isProp: 1 197 actionName: current_buck actionValue: 1200 isProp: 0 198 actionName: voltage_sc actionValue: 4000 isProp: 0 199 actionName: voltage_buck actionValue: 3000 isProp: 0 200 actionName: volume actionValue: 1.0 isProp: 0 201 actionName: boost actionValue: 1 isProp: 0 202 203 level: 2 204 actionName: lcd actionValue: 0.90 isProp: 0 205 actionName: lcd actionValue: 0.89 scene: cam isProp: 1 206 actionName: lcd actionValue: 0.88 scene: call isProp: 1 207 actionName: lcd actionValue: 0.87 scene: game isProp: 1 208 actionName: cpu_big actionValue: 1991000 isProp: 0 209 actionName: cpu_med actionValue: 1990500 isProp: 0 210 actionName: cpu_lit actionValue: 1990200 isProp: 0 211 actionName: process_ctrl actionValue: 2 isProp: 0 212 actionName: cpu_big actionValue: 1990800 charge: 1 scene: cam isProp: 1 213 actionName: cpu_big actionValue: 1990600 charge: 0 scene: cam isProp: 1 214 actionName: gpu actionValue: 499712 screen: 0 isProp: 1 215 actionName: gpu actionValue: 487424 screen: 1 isProp: 1 216 actionName: thermallevel actionValue: 2 isProp: 0 217 actionName: current_sc actionValue: 1500 isProp: 0 218 actionName: current_sc actionValue: 1000 scene: cam isProp: 1 219 actionName: current_buck actionValue: 1000 isProp: 0 220 actionName: voltage_sc actionValue: 3000 isProp: 0 221 actionName: voltage_buck actionValue: 2000 isProp: 0 222 actionName: volume actionValue: 0.8 isProp: 0 223 actionName: boost actionValue: 1 isProp: 0 224 ``` 225 226## 参考 227开发过程中可参考的配置文件路径:[默认热策略源码路径](https://gitee.com/openharmony/powermgr_thermal_manager/blob/master/services/native/profile/thermal_service_config.xml) 228 229打包路径:`/vendor/etc/thermal_config/hdf` 230 231