OpenHarmony子系统开发 - 热管理(一)

OpenHarmony子系统开发 - 热管理(一)


一、充电空闲状态定制开发指导

概述

简介

OpenHarmony默认提供了充电空闲状态的特性。根据设备的热等级、电量、充电状态和充电电流,来决策当前设备是否处于空闲状态,处于此种状态的设备可以执行一些重度的后台任务。但是各设备达到充电空闲状态的条件在不同的产品上规格是不同的,产品希望根据产品的设计规格来定制此特性。OpenHarmony提供了充电空闲状态的定制方式,产品定制开发者可根据产品的设计规格来定制这些特性。

约束与限制

产品定制的配置路径,需要根据配置策略决定。本开发指导中的定制路径以/vendor进行举例,请开发者根据具体的产品配置策略,修改定制路径。

开发指导

搭建环境

设备要求:

标准系统开发板,如DAYU200/Hi3516DV300开源套件。

环境要求:

Linux调测环境,相关要求和配置可参考《快速入门》。

开发步骤

本文以DAYU200为例介绍充电空闲状态的定制方法。

  1. 在产品目录(/vendor/hihope/rk3568)下创建thermal文件夹。

  2. 参考默认充电空闲状态的配置文件夹创建目标文件夹,并安装到//vendor/hihope/rk3568/thermal,文件格式如下:

    复制代码
    profile
    ├── BUILD.gn
    ├── thermal_service_config.xml
  3. 参考默认充电空闲状态的配置文件夹中的thermal_service_config.xml编写定制的thermal_service_config.xml。包含充电空闲状态配置说明及定制后的充电空闲状态配置如下:

    表1 充电空闲状态配置说明

    配置项 描述 数据类型 取值范围
    thermallevel 热等级阈值 int 根据产品的热等级进行定义,当设备热等级小于等于该阈值时,其状态为充电空闲状态。
    soc 电池电量阈值 int 0~100,当设备电量大于等于该阈值时,其状态为充电空闲状态。
    charging 电池是否在充电 int 1为正在充电,0为不在充电。
    current 电池充电电流阈值 int 单位为mA,当电池充电电流大于等于该阈值时,其状态为充电空闲状态。
    复制代码
    <idle name="charging">
        <thermallevel>1</thermallevel>
        <soc>90</soc>
        <charging>1</charging>
        <current>1000</current>
    </idle>
  4. 参考默认充电空闲状态配置文件夹中的BUILD.gn编写BUILD.gn文件,将thermal_service_config.xml打包到/vendor/etc/thermal_config目录下

    复制代码
    import("//build/ohos.gni")                      # 引用build/ohos.gni
    
    ohos_prebuilt_etc("thermal_service_config") {
        source = "thermal_service_config.xml"
        relative_install_dir = "thermal_config"
        install_images = [ chipset_base_dir ]       # 安装到vendor目录下的必要配置
        part_name = "product_rk3568"                # part_name暂定为product_rk3568,以实现后续编译,产品定制根据需要自行修改
    }
  5. 将编译目标添加到ohos.build的"module_list"中,例如:

    复制代码
    {
        "parts": {
            "product_rk3568": {
                "module_list": [
                    "//vendor/hihope/rk3568/default_app_config:default_app_config",
                    "//vendor/hihope/rk3568/image_conf:custom_image_conf",
                    "//vendor/hihope/rk3568/preinstall-config:preinstall-config",
                    "//vendor/hihope/rk3568/resourceschedule:resourceschedule",
                    "//vendor/hihope/rk3568/etc:product_etc_conf",
                    "//vendor/hihope/rk3568/thermal/profile:thermal_service_config", // 添加thermal_service_config的编译
                ]
            }
        },
        "subsystem": "product_hihope"
    }

    "//vendor/hihope/rk3568/thermal/"为文件夹路径,"profile"为创建的文件夹名字,"thermal_service_config"为编译目标。

  6. 参考《快速入门》编译定制版本,编译命令如下:

    复制代码
    ./build.sh --product-name rk3568 --ccache
  7. 将定制版本烧录到DAYU200开发板中。

调测验证

  1. 开机后,进入shell命令行:

    复制代码
    hdc shell
  2. 获取当前充电空闲状态。

    复制代码
    hidumper -s 3303 -a -i

    查看定制后的充电空闲状态结果如下:

    复制代码
    -------------------------------[ability]-------------------------------
    
    
    ----------------------------------ThermalService---------------------------------
    thermallevel: 1
    soc: 100
    charging: 1
    current: 1000

参考

开发过程中可参考的配置文件路径:默认充电空闲状态源码路径

打包路径:/vendor/etc/thermal_config/hdf


二、热管控定制开发指导

概述

简介

OpenHarmony默认提供了热管控的特性。设备在使用的过程中如果发热过多,则需要对发热的器件进行管控,如充电时电池温度过高,则需要对充电进行限制。但是管控动作在不同的产品上规格是不同的,产品希望根据产品的设计规格来定制此特性。为此OpenHarmony提供了热管控的定制方式,产品定制开发者可根据产品的设计规格来定制这些特性。

约束与限制

产品定制的配置路径,需要根据配置策略决定。本开发指导中的定制路径以/vendor进行举例,请开发者根据具体的产品配置策略,修改定制路径。

开发指导

搭建环境

设备要求:

标准系统开发板,如DAYU200/Hi3516DV300开源套件。

环境要求:

Linux调测环境,相关要求和配置可参考《快速入门》。

开发步骤

本文以DAYU200为例介绍热管控的定制方法。

  1. 在产品目录(/vendor/hihope/rk3568)下创建thermal文件夹。

  2. 参考默认热管控的配置文件夹创建目标profile文件夹,并安装到//vendor/hihope/rk3568/thermal,文件格式如下:

    复制代码
    profile
    ├── BUILD.gn
    ├── thermal_service_config.xml
  3. 参考默认热管控的配置文件夹中的thermal_service_config.xml编写定制的thermal_service_config.xml。包含热管控配置说明及定制后的热管控配置如下:

    表1 热管控配置说明

    管控动作配置项名称 管控动作配置项描述 管控动作配置项参数 管控动作配置项参数描述 数据类型 取值范围
    name="airplane" 飞行模式管控动作
    name="cpu_big" 大核CPU管控动作(控制大核CPU频率)
    name="cpu_med" 中核CPU管控动作(控制中核CPU频率)
    name="cpu_lit" 小核CPU管控动作(控制小核CPU频率)
    name="gpu" GPU管控动作(控制GPU频率)
    name="boost" SOCPERF热等级管控动作 event 为1时发送事件,为0时不发送事件 int 0,1
    name="isolate" CPU提高频率管控动作 event 为1时发送事件,为0时不发送事件 int 0,1
    name="lcd" LCD管控动作(控制屏幕亮度)
    name="volume" 声音管控动作(控制音量大小) uid 用户id int 根据产品定义
    name="current_xxx" 充电电流管控动作(控制快充和慢充时的充电电流大小) protocol param protocol填写current,param填写支持的充电协议,快充(sc)和慢充(buck) string protocol="current" param="sc"
    name="current_xxx" 充电电流管控动作 event 为1时发送事件,为0时不发送事件 int 0,1
    name="voltage_xxx" 充电电压管控动作(控制快充和慢充时的充电电压大小) protocol param protocol填写voltage,param填写支持的充电协议,快充(sc)和慢充(buck) string protocol="voltage" param="buck"
    name="voltage_xxx" 充电电压管控动作 event 为1时发送事件,为0时不发送事件 int 0,1
    name="process_ctrl" 进程管控动作(控制前台和后台进程存活状态) param param填写任意字符串 string
    name="process_ctrl" 进程管控动作(控制前台和后台进程存活状态) event 为1时发送事件,为0时不发送事件,为空时默认值为0 int 0,1
    name="shut_down" 关机管控动作(控制是否关机) event 为1时发送事件,为0时不发送事件 int 0,1
    name="thermallevel" 热等级管控动作(控制热等级上报) event 为1时发送事件,为0时不发送事件 int 0,1
    name="popup" 弹窗管控动作(控制是否弹窗)
    name="xxx" 节点定制温控动作 protocol param protocol填入node param填入节点路径及回退值,用"|"隔开 string
    复制代码
    <action>
        <item name="airplane"/>
        <item name="cpu_big"/>
        <item name="cpu_med"/>
        <item name="cpu_lit"/>
        <item name="gpu"/>
        <item name="boost" event="1"/>
        <item name="isolate" event="1"/>
        <item name="lcd"/>
        <item name="volume" uid="2001,2002"/>
        <item name="current_sc" protocol="current" param="sc" event="1"/>
        <item name="voltage_buck" protocol="voltage" param="buck" event="1"/>
        <item name="process_ctrl" param="32,64,128,256" event=""/>
        <item name="shut_down" event="0"/>
        <item name="thermallevel" event="1"/>
        <item name="popup"/>
        <item name="(action_name)" protocol="node" param="/sys/class/thermal/xxx"/>
        <item name="test"/>
    </action>
  4. 参考默认热管控配置文件夹中的BUILD.gn编写BUILD.gn文件,将thermal_service_config.xml打包到/vendor/etc/thermal_config目录下

    复制代码
    import("//build/ohos.gni")                      # 引用build/ohos.gni
    
    ohos_prebuilt_etc("thermal_service_config") {
        source = "thermal_service_config.xml"
        relative_install_dir = "thermal_config"
        install_images = [ chipset_base_dir ]       # 安装到vendor目录下的必要配置
        part_name = "product_rk3568"                # part_name暂定为product_rk3568,以实现后续编译,产品定制根据需要自行修改
    }
  5. 将编译目标添加到ohos.build的"module_list"中,例如:

    复制代码
    {
        "parts": {
            "product_rk3568": {
                "module_list": [
                    "//vendor/hihope/rk3568/default_app_config:default_app_config",
                    "//vendor/hihope/rk3568/image_conf:custom_image_conf",
                    "//vendor/hihope/rk3568/preinstall-config:preinstall-config",
                    "//vendor/hihope/rk3568/resourceschedule:resourceschedule",
                    "//vendor/hihope/rk3568/etc:product_etc_conf",
                    "//vendor/hihope/rk3568/thermal/profile:thermal_service_config", // 添加thermal_service_config的编译
                ]
            }
        },
        "subsystem": "product_hihope"
    }

    "//vendor/hihope/rk3568/thermal/"为文件夹路径,"profile"为创建的文件夹名字,"thermal_service_config"为编译目标。

  6. 参考《快速入门》编译定制版本,编译命令如下:

    复制代码
    ./build.sh --product-name rk3568 --ccache
  7. 将定制版本烧录到DAYU200开发板中。

调测验证

OpenHarmony从5.0.0 Release版本起,支持温度模拟调测功能。下述操作通过模拟温度变化实现温度等级的跃迁,以此来验证热管控策略的定制能力。下述调测验证步骤,默认定制的thermal_service_config.xml按照默认热管控的配置文件夹中的thermal_service_config.xml配置。

  1. 开机后,进入shell命令行:

    复制代码
    hdc shell
  2. 获取当前热管控信息。

    复制代码
    hidumper -s 3303 -a -a

    查看定制后的热管控结果如下:

    复制代码
    -------------------------------[ability]-------------------------------
    
    
    ----------------------------------ThermalService---------------------------------
    name: airplane	strict: 0	enableEvent: 0
    name: cpu_big	strict: 0	enableEvent: 0
    name: cpu_med	strict: 0	enableEvent: 0
    name: cpu_lit	strict: 0	enableEvent: 0
    name: gpu	strict: 0	enableEvent: 0
    name: boost	strict: 0	enableEvent: 1
    name: isolate	strict: 0	enableEvent: 1
    name: lcd	strict: 0	enableEvent: 0
    name: volume	uid: 2001,2002	strict: 0	enableEvent: 0
    name: current_sc    params: sc	protocol: current	strict: 0	enableEvent: 1
    name: current_buck    params: buck	protocol: current	strict: 0	enableEvent: 1
    name: voltage_sc   params: sc	protocol: voltage	strict: 0	enableEvent: 1
    name: voltage_buck   params: buck	protocol: voltage	strict: 0	enableEvent: 1
    name: process_ctrl  params: 32,64,128,256	strict: 0	enableEvent: 0
    name: shut_down	strict: 0	enableEvent: 0
    name: thermallevel	strict: 0	enableEvent: 1
    name: popup	strict: 0	enableEvent: 0
    name: test	strict: 0	enableEvent: 0
  3. 停止自动上报温度。

    使用hidumper -s 3303 -a '-st [f] [...]'指令控制是否自动上报温度。其中...表示任意字符串。如果f为0,则停止自动上报温度;否则,则恢复自动上报温度。

    复制代码
    $ hidumper -s 3303 -a '-st 0'
    
    -------------------------------[ability]-------------------------------
    
    
    ----------------------------------ThermalService----------------------------------
    Temperature reporting has been stopped.
  4. 模拟温度变化。

    为触发热管控策略,先设置低温,再设置高温。使用hidumper -s 3303 -a '-te [name] [num]'指令上报模拟温度。其中name表示温度传感器名称,num表示该传感器对应的模拟温度。多组name和num,表示同时上传多组模拟温度。

    复制代码
    $ hidumper -s 3303 -a '-te battery 32000 charger 32000'
    
    -------------------------------[ability]-------------------------------
    
    
    ----------------------------------ThermalService----------------------------------
    Report temperature [ battery ]: 32000
    Report temperature [ charger ]: 32000
    $ hidumper -s 3303 -a '-te battery 39000 charger 39000'
    
    -------------------------------[ability]-------------------------------
    
    
    ----------------------------------ThermalService----------------------------------
    Report temperature [ battery ]: 39000
    Report temperature [ charger ]: 39000
  5. 获取当前温度等级信息。

    复制代码
    hidumper -s 3303 -a -l

    查看上传模拟温度后的温度等级信息如下:

    复制代码
    -------------------------------[ability]-------------------------------
    
    
    ----------------------------------ThermalService----------------------------------
    name: base_safe level: 1
    name: cold_safe level: 0
    name: high_safe level: 0
    name: screenoff_charge  level: 0
    name: warm_5G   level: 0
    name: warm_safe level: 0
  6. 查看温控结点信息。

    复制代码
    cat /data/service/el0/thermal/config/process_ctrl

    查看温控结点信息如下,表明process_ctrl热管控策略正确执行:

    复制代码
    3

参考

开发过程中可参考的配置文件路径:默认热管控源码路径

打包路径:/vendor/etc/thermal_config/hdf

相关推荐
江畔柳前堤18 小时前
roLabelImg 详细安装教程
开发语言·人工智能·后端·云原生
阿里云大数据AI技术18 小时前
分链路差异化设计的DSP准实时数仓|钛动科技基于阿里云实时计算 Flink 版 + DLF Paimon + EMR Serverless StarRocks 的实践
人工智能·flink
陕西企来客18 小时前
2026年7月AI智能搜索曝光趋势研判
大数据·人工智能·机器学习·ai智能搜索曝光
咱入行浅18 小时前
汽车之家联合HarmonyOS SDK,深度构建鸿蒙生态体系
华为·汽车·harmonyos
阿里云大数据AI技术19 小时前
从算力到智能体,面向 Agentic AI 的基础设施演进
人工智能·agent
hangyuekejiGEO19 小时前
GEO技术服务选型指南
大数据·人工智能·python
阿里云大数据AI技术20 小时前
EMR Serverless Spark AI Function 的双维降本实践
人工智能·sql·spark
维基框架20 小时前
GitHub源码处理提速 一趟扫描反而更慢
人工智能·github
冬奇Lab20 小时前
代码库知识库系列(05):向量检索 vs 知识图谱——加了调用图并没有变更好
人工智能
AKAMAI20 小时前
你的源服务器可能是你做出的最昂贵决定
运维·人工智能·云计算