Thermal Core 对象、注册与更新路径

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
2
thermal_cooling_device_register()
devm_thermal_of_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)

  1. 检查 enabled;
  2. get_temp;
  3. 更新 last_temperature;
  4. netlink/trace notification;
  5. 遍历 trips;
  6. critical/hot处理;
  7. governor throttle;
  8. 安排下一次 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返回错误不能伪造低温。

文章互动

阅读 --

留言

0 条留言

正在加载留言…