Linux内核Thermal框架详解十一、Thermal Governor(1)
创始人
2025-05-29 09:22:11
0

本文部分内容参考

万字长文 | Thermal框架源码剖析,

Linux Thermal机制源码分析之框架概述_不捡风筝的玖伍贰柒的博客-CSDN博客,

特此致谢!

一、概述

Thermal Governor即温控算法,笔者更习惯称之为温控策略。其实在讲解Thermal Core的时候已经涉及了一部分内容,这里再专门从Governor的角度对其作出更为详尽的解析,并对各种具体的温控算法进行一一讲解。

首先再次列出governor结构的定义,在include/linux/thermal.h中,代码如下:

/*** struct thermal_governor - structure that holds thermal governor information* @name:	name of the governor* @bind_to_tz: callback called when binding to a thermal zone.  If it*		returns 0, the governor is bound to the thermal zone,*		otherwise it fails.* @unbind_from_tz:	callback called when a governor is unbound from a*			thermal zone.* @throttle:	callback called for every trip point even if temperature is*		below the trip point temperature* @governor_list:	node in thermal_governor_list (in thermal_core.c)*/
struct thermal_governor {char name[THERMAL_NAME_LENGTH];int (*bind_to_tz)(struct thermal_zone_device *tz);void (*unbind_from_tz)(struct thermal_zone_device *tz);int (*throttle)(struct thermal_zone_device *tz, int trip);struct list_head	governor_list;
};

目前Linux内核有5种governor(温度控制策略,温控策略):

(1)power_allocator

引⼊PID(⽐例-积分-微分)控制,根据当前温度,动态给各cooling device分配power,并将power 转换为频率,从而达到根据温度限制频率的效果。

(2)step_wise

根据当前温度,cooling device逐级降频。

(3)fair_share

频率档位⽐较多的cooling device优先降频。

(4)bang_bang

两点温度调节,可用于cooling device有风扇的场景。

(5)user_space

用户空间控制。

目前可配置默认的Thermal Governor策略,即默认的Thermal Governor可以进入menuconfig中进行选择。默认Thermal Governor对应DEFAULT_THERMAL_GOVERNOR宏定义,其在drivers/thermal/thermal_core.h中,代码如下:

/* Default Thermal Governor */
#if defined(CONFIG_THERMAL_DEFAULT_GOV_STEP_WISE)
#define DEFAULT_THERMAL_GOVERNOR       "step_wise"
#elif defined(CONFIG_THERMAL_DEFAULT_GOV_FAIR_SHARE)
#define DEFAULT_THERMAL_GOVERNOR       "fair_share"
#elif defined(CONFIG_THERMAL_DEFAULT_GOV_USER_SPACE)
#define DEFAULT_THERMAL_GOVERNOR       "user_space"
#elif defined(CONFIG_THERMAL_DEFAULT_GOV_POWER_ALLOCATOR)
#define DEFAULT_THERMAL_GOVERNOR       "power_allocator"
#endif

Kconfig中的Thermal Governor相关配置,在drivers/thermal/Kconfig中,代码如下:

choiceprompt "Default Thermal governor"default THERMAL_DEFAULT_GOV_STEP_WISEhelpThis option sets which thermal governor shall be loaded atstartup. If in doubt, select 'step_wise'.config THERMAL_DEFAULT_GOV_STEP_WISEbool "step_wise"select THERMAL_GOV_STEP_WISEhelpUse the step_wise governor as default. This throttles thedevices one step at a time.config THERMAL_DEFAULT_GOV_FAIR_SHAREbool "fair_share"select THERMAL_GOV_FAIR_SHAREhelpUse the fair_share governor as default. This throttles thedevices based on their 'contribution' to a zone. Thecontribution should be provided through platform data.config THERMAL_DEFAULT_GOV_USER_SPACEbool "user_space"select THERMAL_GOV_USER_SPACEhelpThe Userspace governor allows to get trip point crossednotification from the kernel via uevents. It is recommendedto use the netlink interface instead which gives richerinformation about the thermal framework events.config THERMAL_DEFAULT_GOV_POWER_ALLOCATORbool "power_allocator"depends on THERMAL_GOV_POWER_ALLOCATORhelpSelect this if you want to control temperature based onsystem and device power allocation. This governor can onlyoperate on cooling devices that implement the power API.endchoiceconfig THERMAL_GOV_FAIR_SHAREbool "Fair-share thermal governor"helpEnable this to manage platform thermals using fair-share governor.config THERMAL_GOV_STEP_WISEbool "Step_wise thermal governor"helpEnable this to manage platform thermals using a simple lineargovernor.config THERMAL_GOV_BANG_BANGbool "Bang Bang thermal governor"default nhelpEnable this to manage platform thermals using bang bang governor.Say 'Y' here if you want to use two point temperature regulationused for fans without throttling.  Some fan drivers depend on thisgovernor to be enabled (e.g. acerhdf).config THERMAL_GOV_USER_SPACEbool "User_space thermal governor"helpEnable this to let the user space manage the platform thermals.config THERMAL_GOV_POWER_ALLOCATORbool "Power allocator thermal governor"depends on ENERGY_MODELhelpEnable this to manage platform thermals by dynamicallyallocating and limiting power to devices.

可见,默认的温控策略是step_wise。

实际上光指定了DEFAULT_THERMAL_GOVERNOR还不够,还需要相应的代码配合使其实际生效才可以,这段相关代码其实之前已经列出过,是在drivers/thermal/thermal_core.c中的thermal_register_governors函数调用的thermal_register_governor函数,代码如下:

int thermal_register_governor(struct thermal_governor *governor)
{int err;const char *name;struct thermal_zone_device *pos;if (!governor)return -EINVAL;mutex_lock(&thermal_governor_lock);err = -EBUSY;if (!__find_governor(governor->name)) {bool match_default;err = 0;list_add(&governor->governor_list, &thermal_governor_list);match_default = !strncmp(governor->name,DEFAULT_THERMAL_GOVERNOR,THERMAL_NAME_LENGTH);if (!def_governor && match_default)def_governor = governor;}mutex_lock(&thermal_list_lock);list_for_each_entry(pos, &thermal_tz_list, node) {/** only thermal zones with specified tz->tzp->governor_name* may run with tz->govenor unset*/if (pos->governor)continue;name = pos->tzp->governor_name;if (!strncasecmp(name, governor->name, THERMAL_NAME_LENGTH)) {int ret;ret = thermal_set_governor(pos, governor);if (ret)dev_err(&pos->device,"Failed to set governor %s for thermal zone %s: %d\n",governor->name, pos->type, ret);}}mutex_unlock(&thermal_list_lock);mutex_unlock(&thermal_governor_lock);return err;
}

其中match_default的这一段代码:

match_default = !strncmp(governor->name,DEFAULT_THERMAL_GOVERNOR,THERMAL_NAME_LENGTH);if (!def_governor && match_default)def_governor = governor;

就完成了默认管理策略(def_governor)的设置。

从下篇文章开始,将分别对5种策略中的每一种进行详细介绍和解析。

相关内容

热门资讯

同课异构活动方案 同课异构活动方案(通用7篇)  为了确保活动扎实开展,预先制定活动方案是必不可少的,活动方案其实就是...
国庆优惠活动促销方案 国庆优惠活动促销方案(通用11篇)  为确保活动高质量高水平开展,常常需要提前制定一份优秀的活动方案...
五四晚会活动方案 五四晚会活动方案(通用13篇)  为保障活动顺利开展,常常需要预先准备活动方案,活动方案是为某一活动...
学校主题活动方案 学校主题活动方案(通用25篇)  为有力保证活动开展的质量水平,时常需要预先制定一份周密的活动方案,...
你是真的“C”——结构体中鲜有... 你是真的“C”——结构体中的精髓剖析【内存对齐】+ 【位段】 😎前言...
爱心组织活动方案 爱心组织活动方案  为了确保工作或事情能有条不紊地开展,就需要我们事先制定方案,方案是阐明行动的时间...
珠宝店国庆节活动方案 珠宝店国庆节活动方案(6篇)  为了确保工作或事情能高效地开展,常常需要提前制定一份优秀的方案,方案...
教师读书交流会活动方案 教师读书交流会活动方案  读书交流会是很重要的活动,下面unjs小编整理了教师读书交流会活动方案,欢...
国际残疾人日主题活动方案 2021国际残疾人日主题活动方案范文(通用5篇)  为了确保活动得以顺利进行,时常需要预先制定一份周...
字体压缩 前端字体压缩 最近在写官网时候开开心心的将需求开发完成验收完毕,就在上线的时候你发生了奇怪的事情。 ...
基于java下springbo... 基于java下springboot框架实现汽车租赁系统管理 开发语言:Java 框架...
燕山大学-面向对象程序设计实验... CSDN的各位友友们你们好,今天千泽为大家带来的是燕山大学-面向对象程序设计实验-实验5 派生与继承...
爱心社爱心义卖活动总结 爱心社爱心义卖活动总结这是爱心社成员第一次与暑期实践队员一起合作开展的活动,而且只要愿意参加的在校生...
开展法制宣传教育活动方案 开展法制宣传教育活动方案(通用8篇)  方案是从目的、要求、方式、方法、进度等都部署具体、周密,并有...
团体辅导 活动方案 团体辅导 活动方案  为确保事情或工作顺利开展,时常需要预先开展方案准备工作,方案是阐明行动的时间,...
主题沙龙活动方案 主题沙龙活动方案  活动方案的正文写法  方案的正文一般有两种写法:一是常规写法,即按“指导方针”、...
用Wireshark分析TLS... 准备工作Wireshark是一个非常强大的网络分析软件,下载地址:Wir...
NetSuite顾问的自我修养 今天本来想写一篇技术文章,但是由于近期遭受“GPT综合症”,处于莫名焦虑...
算法训练营day57_动态规划... 算法训练营day57_动态规划(3.18提前写) 647.回文子串 求一...
员工培训计划方案 员工培训计划方案  培训计划影响因素  在制定培训计划时,必须顾及以下的因素:  1、员工的参与让员...