14. 温控策略与测试操作指南

本文档说明在 CV184x 平台上查看 CPU/TPU 时钟与温度、温控策略与 trip 对应关系、迟滞(hysteresis)含义、模拟温度测试步骤,以及在设备树中修改温控阈值与迟滞的方法。

14.1. 操作准备

1. 内核要求

  • 使用 SDK 提供的内核,并确保内核配置中已开启 CONFIG_THERMAL_EMULATION=y (进行模拟温度测试时需开启,否则 emul_temp 写入无效,不会驱动温控逻辑)。

14.2. 操作流程

14.2.1. 查看 CPU/TPU 时钟

cat /sys/kernel/debug/clk/clk_summary | grep -E '\b(clk_cpu|clk_tpu)\b'

会显示 CPU 和 TPU 的当前频率。

14.2.2. 查看当前温度

cat /sys/class/thermal/thermal_zone0/temp

单位为 millicelsius (毫摄氏度),例如 90000 表示 90°C。

14.2.3. 温控策略(与 trip 对应关系)

温控通过 thermal zone 的 tripcooling device 档位 绑定;档位对应的 CPU/TPU 频率cv184x_cooling 节点的 dev-freqs 决定(该节点定义于 build/boards/default/dts/cv184x_arm/cv184x_base_arm.dtsi)。

表 14.1 温度区间与频率、说明

温度区间

CPU 频率 (Hz)

TPU 频率 (Hz)

说明

tmp < 90°C

1000000000

500000000

未触发第一档 passive trip,cooling state 0

90 ≤ tmp < 100°C

500000000

375000000

触发 trip_0,cooling state 1

100 ≤ tmp < 120°C

500000000

300000000

触发 trip_1,cooling state 2

tmp ≥ 120°C

强制关机 (critical trip)

若板级或 SoC 的 dev-freqs 与上表不完全一致,以 build/boards/default/dts/cv184x_arm/cv184x_base_arm.dtsicv184x_cooling { dev-freqs = ... } 及实际 clk_summary 为准。默认 ARM 侧 DTS 常见为三档:(1100M,750M) / (500M,375M) / (500M,300M),与 cooling state 0/1/2 一一对应。

14.2.4. 迟滞(hysteresis)说明

hysteresis 用于 降温升频 时不立刻在阈值处反复横跳,减少频率抖动。

  • 单位与 temperature 相同,为 millicelsius

  • 典型配置:50005°C 迟滞。

  • 升档(降频):温度 trip 的 temperature 时进入该档。

  • 降档(升频):温度需 低于 temperature - hysteresis 才会退出该档。

示例 (第一档 trip 90°C、迟滞 5°C):

  • 从 91°C 降到 89°C:仍保持 降频档(未低于 90-5=85°C,不升频)。

  • 继续降到 84°C:低于 85°C 后退出第一档,频率恢复到高档。

第二档同理:若 trip 为 100°C、迟滞 5°C,则需降到 95°C 以下 才会从第二档回到第一档。

14.3. 操作示例

14.3.1. 模拟温度测试步骤

14.3.2. 基线

cat /sys/class/thermal/thermal_zone0/temp
cat /sys/kernel/debug/clk/clk_summary | grep -E '\b(clk_cpu|clk_tpu)\b'

14.3.3. 模拟到 90°C(应进入第一档降频)

echo 90000 > /sys/class/thermal/thermal_zone0/emul_temp
cat /sys/kernel/debug/clk/clk_summary | grep -E '\b(clk_cpu|clk_tpu)\b'

14.3.4. 模拟到 100°C(应进入第二档降频)

echo 100000 > /sys/class/thermal/thermal_zone0/emul_temp
cat /sys/kernel/debug/clk/clk_summary | grep -E '\b(clk_cpu|clk_tpu)\b'

14.3.5. 模拟降到 95°C(有迟滞,频率应保持第二档不变)

echo 95000 > /sys/class/thermal/thermal_zone0/emul_temp
cat /sys/kernel/debug/clk/clk_summary | grep -E '\b(clk_cpu|clk_tpu)\b'

14.3.6. 模拟降到 94°C(低于迟滞退档边界,应升回第一档或高档,视策略而定)

echo 94000 > /sys/class/thermal/thermal_zone0/emul_temp
cat /sys/kernel/debug/clk/clk_summary | grep -E '\b(clk_cpu|clk_tpu)\b'

若以 100°C/5°C 迟滞为准,需低于 95°C 才退出第二档;具体以当前 DTS 中 soc_thermal_trip_1temperaturehysteresis 为准。

14.3.7. 模拟到 120°C(触发 critical,强制关机)

echo 120000 > /sys/class/thermal/thermal_zone0/emul_temp

设备将按内核 thermal critical 行为执行关机或复位,请勿 在生产环境随意执行。

14.3.8. 在设备树中修改温控阈值、关机温度与迟滞

默认定义在 build/boards/default/dts/cv184x/cv184x_base.dtsithermal-zones soc_thermal_0 trips 中:

表 14.2 trip 节点默认值

节点标签

默认 temperature

默认 hysteresis

type

作用

soc_thermal_trip_0

90000 (90°C)

5000 (5°C)

passive

第一档降频 trip

soc_thermal_trip_1

100000 (100°C)

5000 (5°C)

passive

第二档降频 trip

soc_thermal_crtical_0

120000 (120°C)

0

critical

关机/临界温度

不推荐直接改默认基线 DTS,以免影响其它板型:

  • build/boards/default/dts/cv184x/cv184x_base.dtsi

应在 板级 DTS 里覆盖同名 trip 属性(板名替换为实际板卡名):

  • build/boards/cv184x/板名/dts_arm/板名.dts

  • 使用 &label 进行 覆盖

14.3.9. 板级覆盖示例

在对应板子的板级 DTS(路径一般为 build/boards/cv184x/板名/dts_arm/板名.dts)末尾增加:

/ {

};

/* 覆盖 base 中 thermal trip:temperature/hysteresis 均为 millicelsius */

&soc_thermal_trip_0 {
     temperature = <90000>;   /* 第一档触发温度,例如 90°C */
     hysteresis = <5000>;     /* 5°C 迟滞,降到此 trip 以下 5°C 才升频退档 */
};

&soc_thermal_trip_1 {
     temperature = <100000>;  /* 第二档触发温度,例如 100°C */
     hysteresis = <5000>;
};

&soc_thermal_crtical_0 {
     temperature = <120000>;  /* shutdown 温度,例如 120°C;type 保持 critical */
     hysteresis = <0>;
};

修改后重新编译设备树并更新镜像,cooling-maps 仍指向同一 trip 标签,无需改 map,仅 trip 阈值变化。

14.4. 相关文件索引

表 14.3 相关文件与路径

文件路径

说明

build/boards/default/dts/cv184x/cv184x_base.dtsi

默认 thermal-zones、trip、cooling-maps

build/boards/default/dts/cv184x_arm/cv184x_base_arm.dtsi

cv184x_cooling 与 dev-freqs

linux_5.10/drivers/soc/cvitek/clock_cooling/cv184x/clock_cooling.c

cooling 档位与 clk_set_rate 实现

板级 build/boards/cv184x/板名/dts_arm/板名.dts

&soc_thermal_trip_0&soc_thermal_trip_1&soc_thermal_crtical_0 覆盖阈值