一点点读懂thermal(一)

目录

1、thermal简介

2、thermal_core分析

2.1 zone_device注册相关接口

2.1.1 关键结构体

2.1.2 接口

2.2 Cooling_device注册相关接口

2.2.1关键结构体

2.2.2 接口

2.3 Governors注册相关接口

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 关键结构体


   
   
  1. /**
  2. * struct thermal_zone_device - structure for a thermal zone
  3. * @id: unique id number for each thermal zone
  4. * @type: the thermal zone device type
  5. * @device: &struct device for this thermal zone
  6. * @trip_temp_attrs: attributes for trip points for sysfs: trip temperature
  7. * @trip_type_attrs: attributes for trip points for sysfs: trip type
  8. * @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis
  9. * @mode: current mode of this thermal zone
  10. * @devdata: private pointer for device private data
  11. * @trips: number of trip points the thermal zone supports
  12. * @trips_disabled; bitmap for disabled trips
  13. * @passive_delay_jiffies: number of jiffies to wait between polls when
  14. * performing passive cooling.
  15. * @polling_delay_jiffies: number of jiffies to wait between polls when
  16. * checking whether trip points have been crossed (0 for
  17. * interrupt driven systems)
  18. * @temperature: current temperature. This is only for core code,
  19. * drivers should use thermal_zone_get_temp() to get the
  20. * current temperature
  21. * @last_temperature: previous temperature read
  22. * @emul_temperature: emulated temperature when using CONFIG_THERMAL_EMULATION
  23. * @passive: 1 if you've crossed a passive trip point, 0 otherwise.
  24. * @prev_low_trip: the low current temperature if you've crossed a passive
  25. trip point.
  26. * @prev_high_trip: the above current temperature if you've crossed a
  27. passive trip point.
  28. * @need_update: if equals 1, thermal_zone_device_update needs to be invoked.
  29. * @ops: operations this &thermal_zone_device supports
  30. * @tzp: thermal zone parameters
  31. * @governor: pointer to the governor for this thermal zone
  32. * @governor_data: private pointer for governor data
  33. * @thermal_instances: list of &struct thermal_instance of this thermal zone
  34. * @ida: &struct ida to generate unique id for this zone's cooling
  35. * devices
  36. * @lock: lock to protect thermal_instances list
  37. * @node: node in thermal_tz_list (in thermal_core.c)
  38. * @poll_queue: delayed work for polling
  39. * @notify_event: Last notification event
  40. */
  41. struct thermal_zone_device {
  42. int id;
  43. char type[THERMAL_NAME_LENGTH];
  44. struct device device;
  45. struct attribute_group trips_attribute_group;
  46. struct thermal_attr *trip_temp_attrs;
  47. struct thermal_attr *trip_type_attrs;
  48. struct thermal_attr *trip_hyst_attrs;
  49. enum thermal_device_mode mode;
  50. void *devdata;
  51. int trips;
  52. unsigned long trips_disabled; /* bitmap for disabled trips */
  53. unsigned long passive_delay_jiffies;
  54. unsigned long polling_delay_jiffies;
  55. int temperature;
  56. int last_temperature;
  57. int emul_temperature;
  58. int passive;
  59. int prev_low_trip;
  60. int prev_high_trip;
  61. atomic_t need_update;
  62. struct thermal_zone_device_ops *ops;
  63. struct thermal_zone_params *tzp;
  64. struct thermal_governor *governor;
  65. void *governor_data;
  66. struct list_head thermal_instances;
  67. struct ida ida;
  68. struct mutex lock;
  69. struct list_head node;
  70. struct delayed_work poll_queue;
  71. enum thermal_notify_event notify_event;
  72. };

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关键结构体


   
   
  1. struct thermal_cooling_device_ops {
  2. int (*get_max_state) ( struct thermal_cooling_device *, unsigned long *);
  3. int (*get_cur_state) ( struct thermal_cooling_device *, unsigned long *);
  4. int (*set_cur_state) ( struct thermal_cooling_device *, unsigned long);
  5. int (*get_requested_power)( struct thermal_cooling_device *, u32 *);
  6. int (*state2power)( struct thermal_cooling_device *, unsigned long, u32 *);
  7. int (*power2state)( struct thermal_cooling_device *, u32, unsigned long *);
  8. };
  9. struct thermal_cooling_device {
  10. int id;
  11. char *type;
  12. struct device device;
  13. struct device_node *np;
  14. void *devdata;
  15. void *stats;
  16. const struct thermal_cooling_device_ops *ops;
  17. bool updated; /* true if the cooling device does not need update */
  18. struct mutex lock; /* protect thermal_instances list */
  19. struct list_head thermal_instances;
  20. struct list_head node;
  21. };

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事件的处理流程

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Linux thermal是一个用于管理系统温度的子系统。它可以监测系统的温度,并根据需要调整风扇转速或者降低CPU频率等措施来控制温度。这个子系统可以通过/sys/class/thermal目录下的文件进行配置和控制。在Linux系统中,thermal子系统是非常重要的,它可以保证系统的稳定性和可靠性。 ### 回答2: Linux thermal(温度)是Linux内核中的一个子系统,用于监测和管理硬件设备的温度。在计算机系统中,温度是一个非常重要的参数,因为过高的温度可能会导致硬件故障、性能下降甚至损坏。 Linux thermal子系统通过不同的方式来获取硬件的温度信息。例如,它可以通过传感器来读取处理器、显卡、硬盘等设备的温度数据。这些传感器通常嵌入在硬件设备中,并通过总线接口(如I2C)与计算机系统连接。 一旦获取到硬件设备的温度数据,Linux thermal子系统会根据预先设置的策略来采取相应的措施。例如,它可以通过调整风扇转速来降低设备的温度。它还可以通过降低处理器频率来减少能量消耗和温度。 此外,Linux thermal子系统还提供了用户空间接口,允许用户查询和控制温度相关的信息。用户可以使用命令行工具或编写脚本来监控和调整硬件设备的温度状态。 总之,Linux thermalLinux内核中的一个重要子系统,用于监控和管理硬件设备的温度。它通过传感器获取温度数据,并根据预先设置的策略来调整硬件设备的工作状态,以保持温度在可接受的范围内。这对于确保计算机系统的性能和可靠性非常重要。 ### 回答3: Linux thermalLinux 热管理系统)是Linux操作系统中的一个功能,旨在监测和管理计算机硬件的温度,在温度升高时采取适当的措施来保护硬件免受损坏。 Linux thermal通过硬件传感器监测计算机中各个部件(如处理器、图形卡、内存等)的温度。传感器可以是来自硬件设备的内置传感器,也可以是外部插件设备的传感器。通过读取这些传感器的数据,Linux thermal能够实时监测温度的变化。 当温度超过设定的安全阈值时,Linux thermal会采取相应的措施来降低硬件的温度。这些措施可以包括调整风扇的转速,降低电压供应,甚至通过暂停或降低某些任务的运行来减少硬件的功耗。 在服务器和桌面计算机等大型计算设备上,Linux thermal的作用非常重要。过高的温度会导致硬件故障、损坏甚至灾难性的停机。通过及时监测温度并进行热管理,Linux系统可以保护硬件的完整性和可靠性。 除了保护硬件免受损坏外,Linux thermal还可以提高计算机的性能和能效。通过优化温度控制,可以避免出现过度降温的情况,提高硬件的工作效率并减少能源消耗。 总之,Linux thermalLinux操作系统中用于监测和管理计算机硬件温度的功能,它通过读取传感器数据并采取适当的措施来保护硬件,提高性能和能效。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值