当前位置:网站首页>一点点读懂thermal(一)
一点点读懂thermal(一)
2022-08-04 22:50:00 【szembed】
目录
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 thermal zone
-
* @devdata: private pointer for device private data
-
* @trips: number of trip points the thermal zone supports
-
* @trips_disabled; bitmap for disabled trips
-
* @passive_delay_jiffies: number of jiffies to wait between polls when
-
* performing passive cooling.
-
* @polling_delay_jiffies: number of jiffies to wait between polls when
-
* checking whether trip points have been crossed (0 for
-
* interrupt driven systems)
-
* @temperature: current temperature. This is only for core code,
-
* drivers should use thermal_zone_get_temp() to get the
-
* current temperature
-
* @last_temperature: previous temperature read
-
* @emul_temperature: emulated temperature when using CONFIG_THERMAL_EMULATION
-
* @passive: 1 if you've crossed a passive trip point, 0 otherwise.
-
* @prev_low_trip: the low current temperature if you've crossed a passive
-
trip point.
-
* @prev_high_trip: the above current temperature if you've crossed a
-
passive trip point.
-
* @need_update: if equals 1, thermal_zone_device_update needs to be invoked.
-
* @ops: operations this &thermal_zone_device supports
-
* @tzp: thermal zone parameters
-
* @governor: pointer to the governor for this thermal zone
-
* @governor_data: private pointer for governor data
-
* @thermal_instances: list of &struct thermal_instance of this thermal zone
-
* @ida: &struct ida to generate unique id for this zone's cooling
-
* devices
-
* @lock: lock to protect thermal_instances list
-
* @node: node in thermal_tz_list (in thermal_core.c)
-
* @poll_queue: delayed work for polling
-
* @notify_event: Last notification event
-
*/
-
struct thermal_zone_device {
-
int id;
-
char type[THERMAL_NAME_LENGTH];
-
struct device device;
-
struct attribute_group trips_attribute_group;
-
struct thermal_attr *trip_temp_attrs;
-
struct thermal_attr *trip_type_attrs;
-
struct thermal_attr *trip_hyst_attrs;
-
enum
thermal_device_mode mode;
-
void *devdata;
-
int trips;
-
unsigned
long trips_disabled;
/* bitmap for disabled trips */
-
unsigned
long passive_delay_jiffies;
-
unsigned
long polling_delay_jiffies;
-
int temperature;
-
int last_temperature;
-
int emul_temperature;
-
int passive;
-
int prev_low_trip;
-
int prev_high_trip;
-
atomic_t need_update;
-
struct thermal_zone_device_ops *ops;
-
struct thermal_zone_params *tzp;
-
struct thermal_governor *governor;
-
void *governor_data;
-
struct list_head thermal_instances;
-
struct ida ida;
-
struct mutex lock;
-
struct list_head node;
-
struct delayed_work poll_queue;
-
enum
thermal_notify_event notify_event;
-
};
2.1.2 接口
1、thermal_zone_device_register:zone_device注册接口,需要注册时需要调用该接口来注册。该接口中主要实现以下功能:
1)给zone_device赋值critical接口,再温度过高时,critical接口负责重启系统
2)关联上匹配的governor
3)把该zone_device添加到thermal_tz_list中
4)给该zone_device绑定上相关的cooling_device
5)创建zone_device的温度监控任务
2、thermal_zone_device_unregister:zone_device去注册接口,需要去注册时需要调用该接口来注册。该接口实现的主要功能如下:
1)device从thermal_tz_list中删除
2)对应任务删除
3)对应的governor置空
2.2 Cooling_device注册相关接口
2.2.1关键结构体
-
struct thermal_cooling_device_ops {
-
int (*get_max_state) (
struct thermal_cooling_device *,
unsigned
long *);
-
int (*get_cur_state) (
struct thermal_cooling_device *,
unsigned
long *);
-
int (*set_cur_state) (
struct thermal_cooling_device *,
unsigned
long);
-
int (*get_requested_power)(
struct thermal_cooling_device *, u32 *);
-
int (*state2power)(
struct thermal_cooling_device *,
unsigned
long, u32 *);
-
int (*power2state)(
struct thermal_cooling_device *, u32,
unsigned
long *);
-
};
-
-
struct thermal_cooling_device {
-
int
id;
-
char *type;
-
struct device device;
-
struct device_node *np;
-
void *devdata;
-
void *stats;
-
const
struct thermal_cooling_device_ops *ops;
-
bool updated;
/* true if the cooling device does not need update */
-
struct mutex lock;
/* protect thermal_instances list */
-
struct list_head thermal_instances;
-
struct list_head node;
-
};
2.2.2 接口
1、thermal_cooling_device_register:cooling_device注册接口,cooling_device_ops有3个非常重要的接口,分别是get_max_state、get_cur_state、set_cur_state,分别用于获取最大状态、获取当前状态、设置当前状态,关于state,前边第一节我们介绍了,就不再赘述。该接口实现的主要功能有:
1)添加该device到thermal_cdev_list中
2)Cooling_device与zone_device绑定
3)调用thermal_zone_device_update来更新温度及做对应处理
2、thermal_cooling_device_unregister:与thermal_cooling_device_register互为逆操作。
实现的主要功能有:
1)从hermal_cdev_list中删除该device
2)与zone device解绑定
2.3 Governors注册相关接口
Thermal的governor都是通过THERMAL_GOVERNOR_DECLARE定义到了__thermal_table_entry_这段空间内,然后在thermal core初始化时通过调用thermal_register_governors来注册到thermal_governor_list链表中。
thermal_init->thermal_register_governors-> thermal_set_governor(和zone device关联上)
2.4 关于critial事件和非critial事件的处理流程

边栏推荐
猜你喜欢

Latex fast insert author ORCID

逆序对的数量

【游戏建模模型制作全流程】ZBrush蜥蜴模型雕刻教程

地面高度检测/平面提取与检测(Fast Plane Extraction in Organized Point Clouds Using Agglomerative Hierarchical Clu)
![[Mock Interview - 10 Years of Work] Are more projects an advantage?](/img/fa/2652629d1ff4653aca0d626ac89bf8.jpg)
[Mock Interview - 10 Years of Work] Are more projects an advantage?

社区分享|腾讯海外游戏基于JumpServer构建游戏安全运营能力

双非读者,一举拿下阿里、字节、美团、京东、虾皮offer
![单片机原理[一] 学好单片机必会的五张图](/img/65/cac34bee5470ae85288d4366d8d957.jpg)
单片机原理[一] 学好单片机必会的五张图

good luck

【TCP/IP 五 ICMP】
随机推荐
力扣24-两两交换链表中的节点——链表
双非读者,一举拿下阿里、字节、美团、京东、虾皮offer
【游戏建模模型制作全流程】ZBrush蜥蜴模型雕刻教程
The Controller layer code is written like this, concise and elegant!
Community Sharing|Tencent Overseas Games builds game security operation capabilities based on JumpServer
go语言的日志实现(打印日志、日志写入文件、日志切割)
最温馨的家园
The Record of Reminding myself
备战9月,美团50道软件测试经典面试题及答案汇总
postman接口测试
SQL Server 调用 WebService
If you can't get your heart, use "distributed lock" to lock your people
good luck
论文解读(PPNP)《Predict then Propagate: Graph Neural Networks meet Personalized PageRank》
The Record of Reminding myself
剑指Offer | 数值的整数次方
Rt-thread [三] link.lds链接脚本详解
MySQL的JSON 数据类型2
逆序对的数量
Qt中的常用控件
