linux thermal framework(1)_概述
作者:huowj 发布于:2025-4-14 9:56 分类:电源管理子系统
1. 介绍
热能是电子器件在通电工作后散发能量的主要方式之一,电子器件(cpu、电源适配器等)中的电阻、晶体管、集成电路等元件在工作中,电流通过导体,电子与原子碰撞,导致能量以热能形式散发。
在手持移动设备(手机、手表等)中,由于接触人体皮肤,保证设备的温度在人体可接受范围内是重要的一个研发方向,硬件上可以通过选择更低功耗的电子器件或者在设备内部添加散热材料,比方说导热凝胶、石墨片、金属散热片等,来降低温度,软件上一般可以通过温度监控和动态频率调节减少热量产生的方式来降温。
linux thermal framework是在kernel层面,通过监控器件温度,动态调节频率等方法管理设备温度
本文简单介绍了linux thermal framework的主要功能和接口设计
2. 功能描述
thermal framework按照一定的频率循环查询设备温度,设备通常有电池、cpu、主板,同时根据一定的算法,通过将某些设备降低使用率或者增加散热来使设备降温,如果设备发热超过一定阈值,必要时会通过整机重启来防止设备过热损坏。
为了实现上述功能需求,thermal framework抽象出thermal sensor、thermal zone、cooling device、thermal governor等多个软件实体,通过和其他模块的交互使用可达到软件控温的功能,具体可看下述软件结构说明。
3. 软件结构
thermal framework的软件结构如下图所示:
thermal core是linux温控的统一框架,为了能在内核层面进行温控,thermal core的具体思路是实时监控一个平台上各个关键区域的温度,这些关键区域通常是几大热源:cpu/gpu/battery等,当这些关键区域的温度达到一定程度,会采取必要措施,一般这些措施有降频/限制器件工作速率等,具体应该限制多少程度,thermal core提供了一些算法(governors)来供选择。
thermal zone是被抽象出来描述平台上一块区域温度的数据结构,它并不是一个实际存在的设备,一般是通过平台上的温度传感器设备向thermal core注册的,它的主要功能是,通过传感器设备提供的温度获取函数,可以向thermal core提供不同器件的温度信息。
cooling device是被抽象出来描述平台上一个可以降温的数据结构,同样的,他也不是一个实际存在的设备,一般是其他模块向thermal core注册的,这些模块可以是cpufreq/devfreq/cpuidle,这些模块有共同的特点,即他们可以通过限制器件的工作状态来降温。
thermal governor可以根据thermal zone的温度信息,根据一定的算法,将cooling device设置为某一个状态来控温。
thermal core通过sysfs/debugfs向用户空间提供接口,sysfs的接口通常包括thermal zone/cooling device/governor的信息,上层应用可以通过sysfs接口来获取温度信息,使用的温控策略信息等等,另外用户可以通过sysfs接口来设置温控策略,切换不同的温控策略用来选择不同场景最合适的温控算法。
4. 软件模块的功能和API描述
我们在这个章节简单介绍thermal core对外提供的几个关键数据结构以及API。
-
struct thermal_zone_device
struct thermal_zone_device是被用来描述平台上一片区域温度的数据结构,定义如下:
struct thermal_zone_device { int id; char type[THERMAL_NAME_LENGTH]; struct device device; struct completion removal; struct completion resume; struct attribute_group trips_attribute_group; struct list_head trips_high; struct list_head trips_reached; struct list_head trips_invalid; enum thermal_device_mode mode; void *devdata; int num_trips; unsigned long passive_delay_jiffies; unsigned long polling_delay_jiffies; unsigned long recheck_delay_jiffies; int temperature; int last_temperature; int emul_temperature; int passive; int prev_low_trip; int prev_high_trip; struct thermal_zone_device_ops ops; struct thermal_zone_params *tzp; struct thermal_governor *governor; void *governor_data; struct ida ida; struct mutex lock; struct list_head node; struct delayed_work poll_queue; enum thermal_notify_event notify_event; u8 state; #ifdef CONFIG_THERMAL_DEBUGFS struct thermal_debugfs *debugfs; #endif struct list_head user_thresholds; struct thermal_trip_desc trips[] __counted_by(num_trips); };
1)id,每个thermal zone都有一个id作为区分,每个id是在thermal zone向thermal core注册的时候通过ida被分配
2)type,用来说明描述的哪一片区域的温度,每个thermal zone有唯一一个type,类型通常会有soc/gpu/battery/charger/board等等
3)device,thermal zone也是一个抽象出来的设备,因此有一个device数据结构
4)trips,thermal zone使用trips作为温度的档位,具体来说,当一个thermal zone的温度达到了某一个trip表示的档位,就会触发相应的调整措施,通常会按照温度高低有不同的档位,thermal zone使用数组和链表来管理trips
5)temperature,这个thermal zone的温度
6)ops,这个thermal zone的回调函数,一般都会有get_temp回调函数来获取温度
7)governor,这个thermal zone使用的governor,governor是控温的算法,根据这个thermal zone的当前温度以及过往温度来判断用什么措施来控温
8)poll_queue,每个thermal zone都有一个work,被用来轮巡检测温度,必要时采取措施控制
有关struct thermal_zone_device的API主要包括注册和注销,以及获取温度信息等接口
struct thermal_zone_device *devm_thermal_of_zone_register(struct device *dev, int id, void *data, const struct thermal_zone_device_ops *ops); void devm_thermal_of_zone_unregister(struct device *dev, struct thermal_zone_device *tz); struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name); int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp);
-
struct thermal_cooling_device
struct thermal_cooling_device是被用来描述平台上可降温设备的数据结构,定义如下:
struct thermal_cooling_device { int id; const char *type; unsigned long max_state; 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; #ifdef CONFIG_THERMAL_DEBUGFS struct thermal_debugfs *debugfs; #endif };
1)id,同样的,每个cooling device都有一个id作为区分,这个id也是在注册的时候通过ida分配
2)type,用来说明描述的哪一种类型的cooling device,一般这个type会有cpufreq/devfreq等
3)device,cooling device也是一个抽象出来的设备,因此有一个device数据结构
4)max_state,cooling device会有若干个state,governor通过不断的调整这些state来控制温度
5)ops,这个cooling device的回调函数
有关struct thermal_cooling_device的API主要包括注册和注销:
struct thermal_cooling_device * thermal_of_cooling_device_register(struct device_node *np, const char *, void *,const struct thermal_cooling_device_ops *); void thermal_cooling_device_unregister(struct thermal_cooling_device *);
-
struct thermal_governor
struct thermal_governor是被用来确定cooling device的state来控温的,定义如下:
struct thermal_governor { const char *name; int (*bind_to_tz)(struct thermal_zone_device *tz); void (*unbind_from_tz)(struct thermal_zone_device *tz); void (*trip_crossed)(struct thermal_zone_device *tz, const struct thermal_trip *trip, bool crossed_up); void (*manage)(struct thermal_zone_device *tz); void (*update_tz)(struct thermal_zone_device *tz, enum thermal_notify_event reason); struct list_head governor_list; };
1)name, 每个governor会有一个名字,在温控的governors中,常见的有power_allocator/userspace/step_wise
2)bind_to_tz, governor绑定thermal_zone的回调函数
3)unbind_from_tz,governor和thermal_zone解绑的回调函数
4)trip_crossed,一些governor会注册这个回调函数,在某一个trip被thermal zone温度超过时调用
5)manage, 每个governor必备的函数,每次thermal zone轮巡查询温度后会调用thermal zone对应的governor的manage函数
6)update_tz,在每个thermal zone和cooling device绑定或解绑的时候调用
7)governor_list,thermal core通过一个链表来管理所有的governors,这个是该governor在链表中的节点
有关struct thermal_governor的API主要包括向thermal core的注册和注销:
int thermal_register_governor(struct thermal_governor *); void thermal_unregister_governor(struct thermal_governor *);

功能
最新评论
- 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)
发表评论: