一点点读懂thermal(一)
目錄
1、thermal簡介
2、thermal_core分析
2.1 zone_device注冊相關(guān)接口
2.1.1 關(guān)鍵結(jié)構(gòu)體
2.1.2 接口
2.2 Cooling_device注冊相關(guān)接口
2.2.1關(guān)鍵結(jié)構(gòu)體
2.2.2 接口
2.3 Governors注冊相關(guān)接口
2.4 關(guān)于critial事件和非critial事件的處理流程
1、thermal簡介
? ? ?thermal模塊主要負責(zé)溫度控制,溫度低時想辦法升溫,溫度高時想辦法降溫,甚至復(fù)位系統(tǒng)。Linux kernel有個通用的思想就是抽象分層,比如把該子系統(tǒng)所有資源和信息綜合在一起的一層叫core層,不同的設(shè)備的操作叫device層,對設(shè)備的操作的屏蔽層叫driver層或者governor。同樣thermal子系統(tǒng)也是采用了該思想:核心為 thermal_core,可以獲取溫度的設(shè)備抽象為 thermal_zone_device, 如Temp Sensor、NTC(板上的熱敏電阻)等。控制溫度的設(shè)備抽象為 thermal_cooling_device, 如風(fēng)扇、CPU、DDR、GPU等。溫控策略抽象為 thermal_governor,比如 step_wise、bang_bang 等。
? ? ? ?thermal_cooling_device 對應(yīng)系統(tǒng)實施冷卻措施的驅(qū)動,是溫控的執(zhí)行者。cooling device 維護一個 cooling 等級,即 state,一般 state 越高即系統(tǒng)的冷卻需求越高。cooling device 根據(jù)不同等級的冷卻需求進行冷卻行為。cooling device 只根據(jù) state 進行冷卻操作,是實施者,而 state 的計算由 thermal governor 完成。結(jié)構(gòu) struct cpufreq_cooling_device 和 struct devfreq_cooling_device 作為對 thermal_cooling_device 的擴展,分別主要在 cpufreq_cooling.c 和 devfreq_cooling.c?中使用。
2、thermal_core分析
? ? ? ?thermal_core作為thermal的核心部分,負責(zé)把governor\cool device\zone_device關(guān)聯(lián)在一起,因此thermal_core就需要提供注冊接口和作為記錄的全局變量來記錄注冊的信息:
2.1 zone_device注冊相關(guān)接口
2.1.1 關(guān)鍵結(jié)構(gòu)體
/*** 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 passivetrip point.* @prev_high_trip: the above current temperature if you've crossed apassive 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注冊接口,需要注冊時需要調(diào)用該接口來注冊。該接口中主要實現(xiàn)以下功能:
1)給zone_device賦值critical接口,再溫度過高時,critical接口負責(zé)重啟系統(tǒng)
2)關(guān)聯(lián)上匹配的governor
3)把該zone_device添加到thermal_tz_list中
4)給該zone_device綁定上相關(guān)的cooling_device
5)創(chuàng)建zone_device的溫度監(jiān)控任務(wù)
2、thermal_zone_device_unregister:zone_device去注冊接口,需要去注冊時需要調(diào)用該接口來注冊。該接口實現(xiàn)的主要功能如下:
1)device從thermal_tz_list中刪除
2)對應(yīng)任務(wù)刪除
3)對應(yīng)的governor置空
2.2 Cooling_device注冊相關(guān)接口
2.2.1關(guān)鍵結(jié)構(gòu)體
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,分別用于獲取最大狀態(tài)、獲取當(dāng)前狀態(tài)、設(shè)置當(dāng)前狀態(tài),關(guān)于state,前邊第一節(jié)我們介紹了,就不再贅述。該接口實現(xiàn)的主要功能有:
1)添加該device到thermal_cdev_list中
2)Cooling_device與zone_device綁定
3)調(diào)用thermal_zone_device_update來更新溫度及做對應(yīng)處理
2、thermal_cooling_device_unregister:與thermal_cooling_device_register互為逆操作。
實現(xiàn)的主要功能有:
1)從hermal_cdev_list中刪除該device
2)與zone device解綁定
2.3 Governors注冊相關(guān)接口
? ? ? ?Thermal的governor都是通過THERMAL_GOVERNOR_DECLARE定義到了__thermal_table_entry_這段空間內(nèi),然后在thermal core初始化時通過調(diào)用thermal_register_governors來注冊到thermal_governor_list鏈表中。
thermal_init->thermal_register_governors->?thermal_set_governor(和zone device關(guān)聯(lián)上)
2.4 關(guān)于critial事件和非critial事件的處理流程
總結(jié)
以上是生活随笔為你收集整理的一点点读懂thermal(一)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何恢复 TrustedInstalle
- 下一篇: 有一分数序列:2/1,3/2,5/3..