目录
2.4 关于critial事件和非critial事件的处理流程
1、thermal简介
thermal模块主要负责温度控制,温度低时想办法升温,温度高时想办法降温,甚至复位系统。Linux kernel有个通用的思想就是抽象分层,比如把该子系统所有资源和信息综合在一起的一层叫core层,不同的设备的操作叫device层,对设备的操作的屏蔽层叫driver层或者governor。同样thermal子系统也是采用了该思想:核心为 thermal_core,可以获取温度的设备抽象为 thermal_zone_device, 如Temp Sensor、NTC(板上的热敏电阻)等。控制温度的设备抽象为 thermal_cooling_device, 如风扇、CPU、DDR、GPU等。温控策略抽象为 thermal_governor,比如 step_wise、bang_bang 等。
thermal_cooling_device 对应系统实施冷却措施的驱动,是温控的执行者。cooling device 维护一个 cooling 等级,即 state,一般 state 越高即系统的冷却需求越高。cooling device 根据不同等级的冷却需求进行冷却行为。cooling device 只根据 state 进行冷却操作,是实施者,而 state 的计算由 thermal governor 完成。结构 struct cpufreq_cooling_device 和 struct devfreq_cooling_device 作为对 thermal_cooling_device 的扩展,分别主要在 cpufreq_cooling.c 和 devfreq_cooling.c 中使用。
2、thermal_core分析
thermal_core作为thermal的核心部分,负责把governor\cool device\zone_device关联在一起,因此thermal_core就需要提供注册接口和作为记录的全局变量来记录注册的信息:
2.1 zone_device注册相关接口
2.1.1 关键结构体
/**
* struct thermal_zone_device - structure for a thermal zone
* @id: unique id number for each thermal zone
* @type: the thermal zone device type
* @device: &struct device for this thermal zone
* @trip_temp_attrs: attributes for trip points for sysfs: trip temperature
* @trip_type_attrs: attributes for trip points for sysfs: trip type
* @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis
* @mode: current mode of this