linux thermal framework(5)_thermal core
作者:huowj 发布于:2025-4-14 10:47 分类:电源管理子系统
1. 介绍
本文从thermal framework core对内部实现做一个简单的分析
2. 提供给用户空间的接口
thermal framework通过sysfs和debugfs向上提供接口,接口分为两类,一类是thermal zone,一类是cooling device,sysfs的接口如下:
-
"thermal"目录
由于发热的设备以及降温的设备都是抽象出来的,并不是一个具体的物理设备,也没有compatible的driver和设备probe,因此linux使用class来描述这一类thermal设备,thermal class中包含了所有向thermal_core注册的thermal_zone和cooling_device的子目录,并按照id区分
/sys/class/thermal/
cooling_device0 cooling_device3 thermal_zone1 thermal_zone12 thermal_zone15 thermal_zone2 thermal_zone5 thermal_zone8 cooling_device1 cooling_device4 thermal_zone10 thermal_zone13 thermal_zone16 thermal_zone3 thermal_zone6 thermal_zone9 cooling_device2 thermal_zone0 thermal_zone11 thermal_zone14 thermal_zone17 thermal_zone4 thermal_zone7
-
"thermal_zone"目录
每个thermal zone目录都包含以下节点
/sys/class/thermal/available_policies
|-- available_policies
|-- temp
|-- type
|-- power
|-- autosuspend_delay_ms
|-- control
|-- runtime_active_time
|-- runtime_status
`-- runtime_suspended_time
|-- policy
|-- subsystem -> ../../../../class/thermal
|-- sustainable_power
|-- k_po
|-- k_pu
|-- k_i
|-- k_d
|-- integral_cutoff
|-- slope
|-- offset
1)available_policies,支持的所有governors的名字
2)temp,现在的温度
3)type,thermal zone的类型
4)policy,当前使用的governor名字
5)sustainable_power,这个thermal zone可以消散的可持续热量
6)k_d, k_po, k_i, k_pu, 是PID算法的相关参数
7)slope, 线性温度调节曲线的斜率
8)offset, 线性温度调节曲线的偏移
-
"cooling device"目录
每个cooling device目录都包含以下节点
/sys/class/thermal/cooling_device0
|-- cur_state
|-- max_state
|-- power
|-- autosuspend_delay_ms
|-- control
|-- runtime_active_time
|-- runtime_status
`-- runtime_suspended_time
|-- stats
|-- reset
|-- time_in_state_ms
|-- total_trans
`-- trans_table
|-- subsystem -> ../../../../class/thermal
|-- type
|-- uevent1)cur_state,这个cooling device当前state
2)max_state,这个cooling device支持的最大state
4)stats-time_in_state_ms,在每个state持续的时间
5)total_trans,状态切换的总次数
6)trans_table,二位表格,表示从某一个状态转换到另一个状态的次数
7)type,这个cooling device的类型
3. thermal core的初始化
thermal core是以postcore在系统初始化的时候注册进整个系统的,初始化的时候会运行thermal_init函数,我们来看看这个函数具体做了什么:
static int __init thermal_init(void) { int result; thermal_debug_init(); result = thermal_netlink_init(); if (result) goto error; result = thermal_register_governors(); if (result) goto unregister_netlink; thermal_class = kzalloc(sizeof(*thermal_class), GFP_KERNEL); if (!thermal_class) { result = -ENOMEM; goto unregister_governors; } thermal_class->name = "thermal"; thermal_class->dev_release = thermal_release; result = class_register(thermal_class); if (result) { kfree(thermal_class); thermal_class = NULL; goto unregister_governors; } result = register_pm_notifier(&thermal_pm_nb); if (result) pr_warn("Thermal: Can not register suspend notifier, return %d\n", result); return 0; unregister_governors: thermal_unregister_governors(); unregister_netlink: thermal_netlink_exit(); error: mutex_destroy(&thermal_list_lock); mutex_destroy(&thermal_governor_lock); return result; } postcore_initcall(thermal_init);1)thermal_debug_init来初始化debugfs
2)thermal_netlink_init,初始化thermal netlink,有thermal事件可以通知用户态进程
3)thermal_register_governors 会遍历所有governor_thermal_table的所有entry,即遍历所有静态定义的governors,调用thermal_register_governor函数将这个governor注册进thermal core中,具体流程是,将governor添加进governor list中,然后遍历所有的thermal zone,如果该governor和这个thermal zone的governor名字一致的话就将thermal zone的governor设置为这个governor
4)thermal_class linux通过class来作为一类设备的集合,thermal_class就是所有thermal zone和cooling device这类设备的集合,thermal_init会初始化thermal_class并将其注册进系统中
5)register_pm_notifier 将thermal的通知链加进pm_chain中
标签: thermal

功能
最新评论
- wangjing
写得太好了 - wangjing
写得太好了! - DRAM
圖面都沒辦法顯示出來好像掛點了。 - Simbr
bus至少是不是还有个subsystem? - troy
@testtest:只要ldrex-modify-strex... - gh
Linux 内核在 sparse 内存模型基础上实现了vme...
文章分类
随机文章
文章存档
- 2025年4月(5)
- 2024年2月(1)
- 2023年5月(1)
- 2022年10月(1)
- 2022年8月(1)
- 2022年6月(1)
- 2022年5月(1)
- 2022年4月(2)
- 2022年2月(2)
- 2021年12月(1)
- 2021年11月(5)
- 2021年7月(1)
- 2021年6月(1)
- 2021年5月(3)
- 2020年3月(3)
- 2020年2月(2)
- 2020年1月(3)
- 2019年12月(3)
- 2019年5月(4)
- 2019年3月(1)
- 2019年1月(3)
- 2018年12月(2)
- 2018年11月(1)
- 2018年10月(2)
- 2018年8月(1)
- 2018年6月(1)
- 2018年5月(1)
- 2018年4月(7)
- 2018年2月(4)
- 2018年1月(5)
- 2017年12月(2)
- 2017年11月(2)
- 2017年10月(1)
- 2017年9月(5)
- 2017年8月(4)
- 2017年7月(4)
- 2017年6月(3)
- 2017年5月(3)
- 2017年4月(1)
- 2017年3月(8)
- 2017年2月(6)
- 2017年1月(5)
- 2016年12月(6)
- 2016年11月(11)
- 2016年10月(9)
- 2016年9月(6)
- 2016年8月(9)
- 2016年7月(5)
- 2016年6月(8)
- 2016年5月(8)
- 2016年4月(7)
- 2016年3月(5)
- 2016年2月(5)
- 2016年1月(6)
- 2015年12月(6)
- 2015年11月(9)
- 2015年10月(9)
- 2015年9月(4)
- 2015年8月(3)
- 2015年7月(7)
- 2015年6月(3)
- 2015年5月(6)
- 2015年4月(9)
- 2015年3月(9)
- 2015年2月(6)
- 2015年1月(6)
- 2014年12月(17)
- 2014年11月(8)
- 2014年10月(9)
- 2014年9月(7)
- 2014年8月(12)
- 2014年7月(6)
- 2014年6月(6)
- 2014年5月(9)
- 2014年4月(9)
- 2014年3月(7)
- 2014年2月(3)
- 2014年1月(4)
发表评论: