Thermal Core 对象、注册与更新路径
1. Zone注册
现代路径:
1 | thermal_zone_device_register_with_trips() |
OF sensor driver通常调用 devm_thermal_of_zone_register(),thermal_of.c 找到引用该 sensor/index的 zone,解析 trips和 cooling maps后创建 zone。
2. Zone ops
核心回调:
- get_temp;
- set_trips;
- get_trend;
- set_emul_temp;
- change_mode;
- bind/unbind(legacy)。
RK TSADC实现 get_temp和 set_trips。
3. Cooling device注册
1 | thermal_cooling_device_register() |
ops:
- get_max_state;
- get_cur_state;
- set_cur_state;
- power2state/state2power/get_requested_power(power actor可选)。
4. 绑定
thermal_zone_bind_cooling_device() 创建 thermal_instance:
- trip index;
- lower/upper;
- weight;
- target;
- initialized;
- zone/cdev双向 list/RB tree关联。
同一 cdev可绑定多个 zone/trip。
5. Update
thermal_zone_device_update(tz, event):
- 检查 enabled;
- get_temp;
- 更新 last_temperature;
- netlink/trace notification;
- 遍历 trips;
- critical/hot处理;
- governor throttle;
- 安排下一次 polling。
6. Cooling state聚合
多个 instance对同一 cdev提出 target,__thermal_cdev_update() 聚合为最终 state并调用 set_cur_state()。一个 zone降温不保证 cdev立即解除限制,另一 zone可能仍要求高 state。
7. Polling
polling_delay:正常;passive_delay:passive trip active期间;- delayed work;
- sensor IRQ可主动 update;
- set_trips可编程硬件 window减少轮询。
8. Mode/policy
zone可 enabled/disabled,policy决定 governor。切换 governor会 unbind旧策略、bind新策略并重新 update。
9. 生命周期
unregister时:
- cancel polling;
-解除 cooling instances;
-移除 sysfs/netlink/hwmon;
-释放 ID;
-等待活动引用/锁; - driver停止 IRQ后释放 sensor。
10. 单位
温度统一 milli-Celsius,power通常 milliwatt,state是无量纲离散等级。driver返回错误不能伪造低温。
正在加载留言…