• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Thermal Control Customization
2
3## Overview
4
5### Introduction
6
7By default, OpenHarmony provides the thermal control feature. If a device becomes overheated during usage, thermal control measures need to be taken for the device. For example, if the battery temperature is too high during charging, then thermal control needs to be applied to the charging device. However, thermal control varies according to product specifications. To address this issue, OpenHarmony provides the thermal control customization function.
8
9### Constraints
10
11The configuration path for battery level customization is subject to the [configuration policy](https://gitee.com/openharmony/customization_config_policy). In this development guide, `/vendor` is used as an example of the configuration path. During actual development, you need to modify the customization path based on the product configuration policy.
12
13## How to Develop
14
15### Setting Up the Environment
16
17**Hardware requirements:**
18
19Development board running the standard system, for example, the DAYU200 or Hi3516D V300 open source suite.
20
21**Environment requirements:**
22
23For details about the requirements on the Linux environment, see [Quick Start](../quick-start/quickstart-overview.md).
24
25### Getting Started with Development
26
27The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/blob/master/rk3568) as an example to illustrate thermal control customization.
28
291. Create the `thermal` folder in the product directory [/vendor/hihope/rk3568](https://gitee.com/openharmony/vendor_hihope/blob/master/rk3568).
30
312. Create a target folder by referring to the [default thermal control configuration folder](https://gitee.com/openharmony/powermgr_thermal_manager/blob/master/services/native/profile), and install it in `//vendor/hihope/rk3568/thermal`. The content is as follows:
32
33    ```text
34    profile
35    ├── BUILD.gn
36    ├── thermal_service_config.xml
37    ```
38
393. Write the custom `thermal_service_config.xml` file by referring to the [thermal_service_config.xml](https://gitee.com/openharmony/powermgr_thermal_manager/blob/master/services/native/profile/thermal_service_config.xml) file in the default thermal control configuration folder. The following table describes the related configuration items.
40
41    **Table 1** Configuration items for thermal control
42
43    | Configuration Item| Description| Parameter| Parameter Description| Data Type|Value Range|
44    | -------- | -------- | -------- | -------- | -------- | -------- |
45    | name="airplane" | Airplane mode control| N/A| N/A| N/A| N/A|
46    | name="cpu_big" | Big-core CPU control (big-core CPU frequency)| N/A| N/A| N/A| N/A|
47    | name="cpu_med" | Medium-core CPU control (medium-core CPU frequency)| N/A| N/A| N/A| N/A|
48    | name="cpu_lit" | Small-core CPU control (small-core CPU frequency)| N/A| N/A| N/A| N/A|
49    | name="gpu" | GPU control (GPU frequency)| N/A| N/A| N/A| N/A|
50    | name="boost" | SOCPERF thermal level control| event | - **1**: event sending enabled<br>-**0**: event sending disabled| int | 0 or 1|
51    | name="isolate" | CPU frequency increase control| event | - **1**: event sending enabled<br>-**0**: event sending disabled| int | 0 or 1|
52    | name="lcd" | LCD control (screen brightness)| N/A| N/A| N/A| N/A|
53    | name="volume" | Sound control (volume)| uid | User ID| int | Product-specific|
54    | name="current_xxx" | Charging current control (charging current during fast charging and slow charging)| protocol<br>param | Set **protocol** to **current** and **param** to a supported charging protocol, that is, fast charging (**sc**) or slow charging (**buck**).| string |protocol="current" param="sc" |
55    | name="current_xxx" | Charging current control | event | - **1**: event sending enabled<br>-**0**: event sending disabled| int | 0 or 1|
56    | name="voltage_xxx" | Charging voltage control (charging voltage during fast charging and slow charging)| protocol<br>param | Set **protocol** to **voltage** and **param** to a charging protocol, that is, fast charging (**sc**) or slow charging (**buck**).| string | protocol="voltage" param="buck" |
57    | name="voltage_xxx" | Charging voltage control | event | - **1**: event sending enabled<br>-**0**: event sending disabled| int | 0 or 1|
58    | name="process_ctrl" | Process control (survival status of foreground and background processes)| param | Set **param** to any string.| string | N/A|
59    | name="process_ctrl" | Process control (survival status of foreground and background processes)| event | - **1**: event sending enabled<br>-**0**: event sending disabled<br>If this parameter is not set, the value is defaulted to **0**.| int | 0 or 1|
60    | name="shut_down" | Shutdown control (device shutdown)| event | - **1**: event sending enabled<br>-**0**: event sending disabled| int | 0 or 1|
61    | name="thermallevel" | Thermal level control (thermal level reporting)| event | - **1**: event sending enabled<br>-**0**: event sending disabled| int | 0 or 1|
62    | name="popup" | Pop-up window control (pop-up window display)| N/A| N/A| N/A| N/A|
63    | name="xxx" | Node thermal control action| protocol<br>param | Set **protocol** to **node**.<br>Set **param** to the node path and rollback value, which are separated by a|backslash (\).| string | N/A|
64
65    ```shell
66    <action>
67        <item name="airplane"/>
68        <item name="cpu_big"/>
69        <item name="cpu_med"/>
70        <item name="cpu_lit"/>
71        <item name="gpu"/>
72        <item name="boost" event="1"/>
73        <item name="isolate" event="1"/>
74        <item name="lcd"/>
75        <item name="volume" uid="2001,2002"/>
76        <item name="current_sc" protocol="current" param="sc" event="1"/>
77        <item name="voltage_buck" protocol="voltage" param="buck" event="1"/>
78        <item name="process_ctrl" param="32,64,128,256" event=""/>
79        <item name="shut_down" event="0"/>
80        <item name="thermallevel" event="1"/>
81        <item name="popup"/>
82        <item name="(action_name)" protocol="node" param="/sys/class/thermal/xxx"/>
83        <item name="test"/>
84    </action>
85    ```
86
874. Write the `BUILD.gn` file by referring to the [BUILD.gn](https://gitee.com/openharmony/powermgr_thermal_manager/blob/master/services/native/profile/BUILD.gn) file in the default thermal control configuration folder to pack the `thermal_service_config.xml` file to the `/vendor/etc/thermal_config` directory. The configuration is as follows:
88
89    ```shell
90    import("//build/ohos.gni")                      # Reference build/ohos.gni.
91
92    ohos_prebuilt_etc("thermal_service_config") {
93        source = "thermal_service_config.xml"
94        relative_install_dir = "thermal_config"
95        install_images = [ chipset_base_dir ]       # Required configuration for installing the thermal_service_config.xml file in the vendor directory.
96        part_name = "product_rk3568"                # Set part_name to product_rk3568 for subsequent build. You can change it as required.
97    }
98    ```
99
1005. Add the build target to `module_list` in [ohos.build](https://gitee.com/openharmony/vendor_hihope/blob/master/rk3568/ohos.build). For example:
101
102    ```json
103    {
104        "parts": {
105            "product_rk3568": {
106                "module_list": [
107                    "//vendor/hihope/rk3568/default_app_config:default_app_config",
108                    "//vendor/hihope/rk3568/image_conf:custom_image_conf",
109                    "//vendor/hihope/rk3568/preinstall-config:preinstall-config",
110                    "//vendor/hihope/rk3568/resourceschedule:resourceschedule",
111                    "//vendor/hihope/rk3568/etc:product_etc_conf",
112                    "//vendor/hihope/rk3568/thermal/profile:thermal_service_config", // Add the configuration for building of thermal_service_config.
113                ]
114            }
115        },
116        "subsystem": "product_hihope"
117    }
118    ```
119    In the preceding code, `//vendor/hihope/rk3568/thermal/` is the folder path, `profile` is the folder name, and `thermal_service_config` is the build target.
120
1216. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md).
122
123    ```shell
124    ./build.sh --product-name rk3568 --ccache
125    ```
126
1277. Burn the customized version to the DAYU200 development board.
128
129### Debugging and Verification
130
131Temperature simulation debugging is supported since OpenHarmony 5.0.0 Release. The following procedure implements temperature level transition through simulating temperature changes to verify the custom thermal control policy. Write the custom `thermal_service_config.xml` file by referring to the [thermal_service_config.xml](https://gitee.com/openharmony/powermgr_thermal_manager/blob/master/services/native/profile/thermal_service_config.xml) file in the default thermal control configuration folder.
132
1331. After startup, run the following command to launch the shell command line:
134    ```shell
135    hdc shell
136    ```
137
1382. Obtain the current thermal control information.
139    ```shell
140    hidumper -s 3303 -a -a
141    ```
142
143    The following is the reference thermal control result after customization:
144    ```shell
145    -------------------------------[ability]-------------------------------
146
147
148    ----------------------------------ThermalService---------------------------------
149    name: airplane	strict: 0	enableEvent: 0
150    name: cpu_big	strict: 0	enableEvent: 0
151    name: cpu_med	strict: 0	enableEvent: 0
152    name: cpu_lit	strict: 0	enableEvent: 0
153    name: gpu	strict: 0	enableEvent: 0
154    name: boost	strict: 0	enableEvent: 1
155    name: isolate	strict: 0	enableEvent: 1
156    name: lcd	strict: 0	enableEvent: 0
157    name: volume	uid: 2001,2002	strict: 0	enableEvent: 0
158    name: current_sc    params: sc	protocol: current	strict: 0	enableEvent: 1
159    name: current_buck    params: buck	protocol: current	strict: 0	enableEvent: 1
160    name: voltage_sc   params: sc	protocol: voltage	strict: 0	enableEvent: 1
161    name: voltage_buck   params: buck	protocol: voltage	strict: 0	enableEvent: 1
162    name: process_ctrl  params: 32,64,128,256	strict: 0	enableEvent: 0
163    name: shut_down	strict: 0	enableEvent: 0
164    name: thermallevel	strict: 0	enableEvent: 1
165    name: popup	strict: 0	enableEvent: 0
166    name: test	strict: 0	enableEvent: 0
167    ```
168
1693. Stop automatic temperature reporting.
170
171    Run `hidumper -s 3303 -a '-st [f] [...]'` to specify whether to enable automatic temperature reporting. Where, **...** indicates any character. If **f** is **0**, automatic temperature reporting is disabled. Otherwise, automatic temperature reporting is enabled.
172
173    ```shell
174    $ hidumper -s 3303 -a '-st 0'
175
176    -------------------------------[ability]-------------------------------
177
178
179    ----------------------------------ThermalService----------------------------------
180    Temperature reporting has been stopped.
181    ```
182
1834. Simulate temperature changes.
184
185    To trigger the thermal control policy, simulate a low temperature and then a high temperature. Run `hidumper -s 3303 -a '-te [name] [num]'` to report the simulated temperatures. In the command, **name** indicates the name of the temperature sensor, and **num** indicates its temperature. If there are multiple groups of **name** and **num**, multiple simulated temperatures are uploaded at the same time.
186
187    ```shell
188    $ hidumper -s 3303 -a '-te battery 32000 charger 32000'
189
190    -------------------------------[ability]-------------------------------
191
192
193    ----------------------------------ThermalService----------------------------------
194    Report temperature [ battery ]: 32000
195    Report temperature [ charger ]: 32000
196    $ hidumper -s 3303 -a '-te battery 39000 charger 39000'
197
198    -------------------------------[ability]-------------------------------
199
200
201    ----------------------------------ThermalService----------------------------------
202    Report temperature [ battery ]: 39000
203    Report temperature [ charger ]: 39000
204    ```
205
2065. Obtain the current temperature level.
207    ```shell
208    hidumper -s 3303 -a -l
209    ```
210
211    The following shows the temperature level after the simulated temperatures are uploaded:
212    ```shell
213    -------------------------------[ability]-------------------------------
214
215
216    ----------------------------------ThermalService----------------------------------
217    name: base_safe level: 1
218    name: cold_safe level: 0
219    name: high_safe level: 0
220    name: screenoff_charge  level: 0
221    name: warm_5G   level: 0
222    name: warm_safe level: 0
223    ```
224
2256. View the thermal control node information.
226    ```shell
227    cat /data/service/el0/thermal/config/process_ctrl
228    ```
229
230    If the thermal control node information is as follows, the **process_ctrl** thermal control policy is effective:
231    ```shell
232    3
233    ```
234
235## Reference
236During development, you can refer to the [default thermal control configuration](https://gitee.com/openharmony/powermgr_thermal_manager/blob/master/services/native/profile/thermal_service_config.xml).
237
238Packing path: `/vendor/etc/thermal_config/hdf`
239
240<!--no_check-->