1.. SPDX-License-Identifier: GPL-2.0 2 3.. include:: ../disclaimer-zh_CN.rst 4 5:Original: Documentation/cpu-freq/cpu-drivers.rst 6 7:������: 8 9 ��������� Yanteng Si <siyanteng@loongson.cn> 10 11:������: 12 13 ��������� Tang Yizhou <tangyeechou@gmail.com> 14 15======================================= 16������������������������CPUFreq������������������������ 17======================================= 18 19������: 20 21 22 - Dominik Brodowski <linux@brodo.de> 23 - Rafael J. Wysocki <rafael.j.wysocki@intel.com> 24 - Viresh Kumar <viresh.kumar@linaro.org> 25 26.. Contents 27 28 1. ������������ 29 1.1 ��������� 30 1.2 Per-CPU ��������� 31 1.3 ������ 32 1.4 target/target_index ��� setpolicy? 33 1.5 target/target_index 34 1.6 setpolicy 35 1.7 get_intermediate ��� target_intermediate 36 2. ��������������� 37 38 39 401. ������������ 41=========== 42 43������������������������������������������CPU/������������������������������������������������CPU/���������������cpufreq 44��������������������������������������������������������� 45 46 471.1 ��������� 48---------- 49 50������������ __initcall level 7 (module_init())������������������������������������������������ 51������������������CPU������������������������������������������������cpufreq_register_driver()��� 52CPUfreq���������������������cpufreq_driver������������ 53 54���������cpufreq_driver������������������������? 55 56 .name - ������������������ 57 58 .init - ������������per-policy��������������������������� 59 60 .verify - ������������"verification"������������������ 61 62 .setpolicy ��� .fast_switch ��� .target ��� .target_index - ��������� 63 ��������� 64 65������������������ 66 67 .flags - ���cpufreq������������������ 68 69 .driver_data - cpufreq������������������������������ 70 71 .get_intermediate ��� target_intermediate - ���������������CPU������������������������ 72 ������������ 73 74 .get - ������CPU������������������ 75 76 .bios_limit - ������HW/BIOS���CPU��������������������������� 77 78 .exit - ������������per-policy������������������������������������CPU������������������CPU_POST_DEAD 79 ������������������ 80 81 .suspend - ������������per-policy������������������������������������������������������������������������������ 82 ��������������� 83 84 .resume - ������������per-policy��������������������������������������������������������������������������������� 85 ��������� 86 87 .ready - ������������per-policy��������������������������������������������������������������������������� 88 89 .attr - ������������NULL���������"struct freq_attr"��������������������������������������������� 90 sysfs��� 91 92 .boost_enabled - ������������������������������(boost)��������� 93 94 .set_boost - ������������per-policy���������������������������������������/������������(boost)��������������� 95 96 971.2 Per-CPU ��������� 98------------------ 99 100������������������CPU���������������������������������������cpufreq������������������������������������CPU���cpufreq��� 101���������������������������per-policy������������������cpufreq_driver.init���������������.init()���.exit()������ 102���������������������������������������������������������������������CPU������������������������������ ``struct cpufreq_policy 103*policy`` ��������������������������������������� 104 105������������������������������CPU���������CPUfreq��������������� 106 107������������������������������������������: 108 109+-----------------------------------+--------------------------------------+ 110|policy->cpuinfo.min_freq��� | ���CPU���������������������������������kHz��� | 111|policy->cpuinfo.max_freq | | 112| | | 113+-----------------------------------+--------------------------------------+ 114|policy->cpuinfo.transition_latency | CPU������������������������������������������������ | 115| | ������������������������������������������ | 116| | CPUFREQ_ETERNAL��� | 117| | | 118+-----------------------------------+--------------------------------------+ 119|policy->cur | ���CPU���������������������(���������) | 120| | | 121+-----------------------------------+--------------------------------------+ 122|policy->min, | ���������������CPU���"������������"��������� | 123|policy->max, | ��������������������� | 124|policy->policy and, if necessary, | cpufreq_driver.verify��������������� | 125|policy->governor | ���������cpufreq_driver.setpolicy��� | 126| | cpufreq_driver.target/target_index | 127| | | 128+-----------------------------------+--------------------------------------+ 129|policy->cpus | ���policy������DVFS���������������������CPU | 130| | (���������CPU������"������/������"���)������ | 131| | ������(���������������������������CPU)������������ | 132| | ��������������� | 133| | | 134+-----------------------------------+--------------------------------------+ 135 136������������������������������(cpuinfo.min[max]_freq, policy->min[max])��������������������������������������� 137������������������������������������������������2������ 138 139 1401.3 ������ 141-------- 142 143���������������������������������������(���"policy,governor,min,max������")������������������������������������������ 144������������������������������������������������������cpufreq_verify_within_limits(``struct cpufreq_policy 145*policy``, ``unsigned int min_freq``, ``unsigned int max_freq``)��������������������������� 146������������������������������������������������������2������ 147 148������������������������������������������������������������������ policy->min ��� policy->max ������������������������ 149���������������policy->max������������������������������������������������������policy->min��� 150 151 1521.4 target ��� target_index ��� setpolicy ��� fast_switch? 153------------------------------------------------------- 154 155���������cpufreq���������������������CPU������������������������������CPU��������������������������������������������������������� 156������������->target()���->target_index()���->fast_switch()��������� 157 158���������������������������������������������������������������������������������CPU������������������������->setpolicy()��������� 159 160 1611.5. target/target_index 162------------------------ 163 164target_index������������������������ ``struct cpufreq_policy * policy`` ��� ``unsigned int`` 165������(������������������������)��� 166 167���������������������CPUfreq������������������������������������������������������freq_table[index].frequency��������� 168 169���������������������������������������������������������������(���policy->restore_freq)��������������������������������� 170��������������� 171 172��������� 173---------- 174target������������������������``struct cpufreq_policy * policy``, unsigned int target_frequency, 175unsigned int relation. 176 177CPUfreq������������������������������������������������������������������������������������������������������ 178 179- ������������"������������"��� 180- policy->min <= new_freq <= policy->max (���������������������!!!) 181- ������ relation==CPUFREQ_REL_L������������������������������������ target_freq ��� new_freq���("L������ 182 ������������������������") 183- ������ relation==CPUFREQ_REL_H������������������������������������ target_freq ��� new_freq���("H������ 184 ������������������������") 185 186������������������������������������������������ -- ���������2������ 187 1881.6. fast_switch 189---------------- 190 191��������������������������������������������������������������������������������������������������������������������������������������������������� 192��������������������������������������������������������������������� 193 194������������������������������ ``struct cpufreq_policy *policy`` ��� ``unsigned int target_frequency``��� 195 196 1971.7 setpolicy 198------------- 199 200setpolicy��������������������� ``struct cpufreq_policy * policy`` ������������������������������������������������������������ 201���������������������������policy->min������������������policy->max���������������������������policy->policy��� 202CPUFREQ_POLICY_PERFORMANCE������������������������������������CPUFREQ_POLICY_POWERSAVE��������������������������������� 203���������������drivers/cpufreq/longrun.c��������������������� 204 2051.8 get_intermediate ��� target_intermediate 206-------------------------------------------- 207 208��������������������� target_index() ��� CPUFREQ_ASYNC_NOTIFICATION ������������ 209 210get_intermediate������������������������������������������������������������������target_intermediate()���������CPU��������� 211������������������������������'index'������������������cpufreq��������������������������������������������� 212target_intermediate()���target_index()������������������ 213 214���������������������������������������������������������������������������������������������get_intermediate()������'0'��� 215���������������������cpufreq���������������������->target_index()��� 216 217���������->target_index()���������������������������������������������������policy->restore_freq��� 218������cpufreq������������������������������ 219 220 2212. ��������������������� 222================= 223 224���������������������cpufreq������������������������������������������������������������������"���������"��������������������������������������������������� 225���������������������������������"���������"������������struct cpufreq_frequency_table���������������������������"driver_data"��������� 226������������������������������"frequency"������������������������������������������������������������������������������������������������ 227cpufreq_frequency_table������������������������CPUFREQ_TABLE_END��������������������������������������������������������������� 228CPUFREQ_ENTRY_INVALID������������������������������������������������������������������������������cpufreq������������DVFS������������������ 229������������������������������������ 230 231���������policy->freq_table������������������������������������������������������������������cpufreq��������������������� 232 233cpufreq_frequency_table_verify()���������������������������������������policy->min���policy->max������������������������������ 234���������������������������->verify��������������������� 235 236cpufreq_frequency_table_target()������������->target������������������������������������������������������������������������������������������ 237���������CPU��������������������������������������� 238 239���������������������cpufreq_frequency_table��������������� 240 241cpufreq_for_each_entry(pos, table) - ��������������������������������� 242 243cpufreq_for_each_valid_entry(pos, table) - ���������������������������������������CPUFREQ_ENTRY_INVALID��������� 244������������"pos" -- ������ ``cpufreq_frequency_table *`` ���������������������������������"table" -- ������������������ 245��� ``cpufreq_frequency_table *`` ��� 246 247������:: 248 249 struct cpufreq_frequency_table *pos, *driver_freq_table; 250 251 cpufreq_for_each_entry(pos, driver_freq_table) { 252 /* Do something with pos */ 253 pos->frequency = ... 254 } 255 256������������������driver_freq_table���������pos������������������������������������������������������������������������������������������ 257cpufreq_for_each_entry_idx() ��� cpufreq_for_each_valid_entry_idx() ��� 258