1
- CPU frequency and voltage scaling code in the Linux(TM) kernel
1
+ .. SPDX-License-Identifier: GPL-2.0
2
2
3
+ ===============================================
4
+ How to Implement a new CPUFreq Processor Driver
5
+ ===============================================
3
6
4
- L i n u x C P U F r e q
7
+ Authors:
5
8
6
- C P U D r i v e r s
7
9
8
- - information for developers -
10
+ - Dominik Brodowski <
[email protected] >
11
+ - Rafael J. Wysocki <
[email protected] >
12
+ - Viresh Kumar <
[email protected] >
9
13
14
+ .. Contents
10
15
11
- Dominik Brodowski <
[email protected] >
12
- Rafael J. Wysocki <
[email protected] >
13
-
14
-
15
-
16
-
17
- Clock scaling allows you to change the clock speed of the CPUs on the
18
- fly. This is a nice method to save battery power, because the lower
19
- the clock speed, the less power the CPU consumes.
20
-
21
-
22
- Contents:
23
- ---------
24
- 1. What To Do?
25
- 1.1 Initialization
26
- 1.2 Per-CPU Initialization
27
- 1.3 verify
28
- 1.4 target/target_index or setpolicy?
29
- 1.5 target/target_index
30
- 1.6 setpolicy
31
- 1.7 get_intermediate and target_intermediate
32
- 2. Frequency Table Helpers
16
+ 1. What To Do?
17
+ 1.1 Initialization
18
+ 1.2 Per-CPU Initialization
19
+ 1.3 verify
20
+ 1.4 target/target_index or setpolicy?
21
+ 1.5 target/target_index
22
+ 1.6 setpolicy
23
+ 1.7 get_intermediate and target_intermediate
24
+ 2. Frequency Table Helpers
33
25
34
26
35
27
@@ -49,7 +41,7 @@ function check whether this kernel runs on the right CPU and the right
49
41
chipset. If so, register a struct cpufreq_driver with the CPUfreq core
50
42
using cpufreq_register_driver()
51
43
52
- What shall this struct cpufreq_driver contain?
44
+ What shall this struct cpufreq_driver contain?
53
45
54
46
.name - The name of this driver.
55
47
@@ -108,37 +100,42 @@ Whenever a new CPU is registered with the device model, or after the
108
100
cpufreq driver registers itself, the per-policy initialization function
109
101
cpufreq_driver.init is called if no cpufreq policy existed for the CPU.
110
102
Note that the .init() and .exit() routines are called only once for the
111
- policy and not for each CPU managed by the policy. It takes a struct
112
- cpufreq_policy *policy as argument. What to do now?
103
+ policy and not for each CPU managed by the policy. It takes a `` struct
104
+ cpufreq_policy *policy `` as argument. What to do now?
113
105
114
106
If necessary, activate the CPUfreq support on your CPU.
115
107
116
108
Then, the driver must fill in the following values:
117
109
118
- policy->cpuinfo.min_freq _and_
119
- policy->cpuinfo.max_freq - the minimum and maximum frequency
120
- (in kHz) which is supported by
121
- this CPU
122
- policy->cpuinfo.transition_latency the time it takes on this CPU to
123
- switch between two frequencies in
124
- nanoseconds (if appropriate, else
125
- specify CPUFREQ_ETERNAL)
126
-
127
- policy->cur The current operating frequency of
128
- this CPU (if appropriate)
129
- policy->min,
130
- policy->max,
131
- policy->policy and, if necessary,
132
- policy->governor must contain the "default policy" for
133
- this CPU. A few moments later,
134
- cpufreq_driver.verify and either
135
- cpufreq_driver.setpolicy or
136
- cpufreq_driver.target/target_index is called
137
- with these values.
138
- policy->cpus Update this with the masks of the
139
- (online + offline) CPUs that do DVFS
140
- along with this CPU (i.e. that share
141
- clock/voltage rails with it).
110
+ +-----------------------------------+--------------------------------------+
111
+ | policy->cpuinfo.min_freq _and_ | |
112
+ | policy->cpuinfo.max_freq | the minimum and maximum frequency |
113
+ | | (in kHz) which is supported by |
114
+ | | this CPU |
115
+ +-----------------------------------+--------------------------------------+
116
+ | policy->cpuinfo.transition_latency | the time it takes on this CPU to |
117
+ | | switch between two frequencies in |
118
+ | | nanoseconds (if appropriate, else |
119
+ | | specify CPUFREQ_ETERNAL) |
120
+ +-----------------------------------+--------------------------------------+
121
+ | policy->cur | The current operating frequency of |
122
+ | | this CPU (if appropriate) |
123
+ +-----------------------------------+--------------------------------------+
124
+ | policy->min, | |
125
+ | policy->max, | |
126
+ | policy->policy and, if necessary, | |
127
+ | policy->governor | must contain the "default policy" for|
128
+ | | this CPU. A few moments later, |
129
+ | | cpufreq_driver.verify and either |
130
+ | | cpufreq_driver.setpolicy or |
131
+ | | cpufreq_driver.target/target_index is|
132
+ | | called with these values. |
133
+ +-----------------------------------+--------------------------------------+
134
+ | policy->cpus | Update this with the masks of the |
135
+ | | (online + offline) CPUs that do DVFS |
136
+ | | along with this CPU (i.e. that share|
137
+ | | clock/voltage rails with it). |
138
+ +-----------------------------------+--------------------------------------+
142
139
143
140
For setting some of these values (cpuinfo.min[max]_freq, policy->min[max]), the
144
141
frequency table helpers might be helpful. See the section 2 for more information
@@ -151,8 +148,8 @@ on them.
151
148
When the user decides a new policy (consisting of
152
149
"policy,governor,min,max") shall be set, this policy must be validated
153
150
so that incompatible values can be corrected. For verifying these
154
- values cpufreq_verify_within_limits(struct cpufreq_policy *policy,
155
- unsigned int min_freq, unsigned int max_freq) function might be helpful.
151
+ values cpufreq_verify_within_limits(`` struct cpufreq_policy *policy `` ,
152
+ `` unsigned int min_freq ``, `` unsigned int max_freq `` ) function might be helpful.
156
153
See section 2 for details on frequency table helpers.
157
154
158
155
You need to make sure that at least one valid frequency (or operating
@@ -163,7 +160,7 @@ policy->max first, and only if this is no solution, decrease policy->min.
163
160
1.4 target or target_index or setpolicy or fast_switch?
164
161
-------------------------------------------------------
165
162
166
- Most cpufreq drivers or even most cpu frequency scaling algorithms
163
+ Most cpufreq drivers or even most cpu frequency scaling algorithms
167
164
only allow the CPU frequency to be set to predefined fixed values. For
168
165
these, you use the ->target(), ->target_index() or ->fast_switch()
169
166
callbacks.
@@ -175,18 +172,18 @@ limits on their own. These shall use the ->setpolicy() callback.
175
172
1.5. target/target_index
176
173
------------------------
177
174
178
- The target_index call has two arguments: struct cpufreq_policy *policy,
179
- and unsigned int index (into the exposed frequency table).
175
+ The target_index call has two arguments: `` struct cpufreq_policy *policy `` ,
176
+ and `` unsigned int `` index (into the exposed frequency table).
180
177
181
178
The CPUfreq driver must set the new frequency when called here. The
182
179
actual frequency must be determined by freq_table[index].frequency.
183
180
184
181
It should always restore to earlier frequency (i.e. policy->restore_freq) in
185
182
case of errors, even if we switched to intermediate frequency earlier.
186
183
187
- Deprecated:
184
+ Deprecated
188
185
----------
189
- The target call has three arguments: struct cpufreq_policy *policy,
186
+ The target call has three arguments: `` struct cpufreq_policy *policy `` ,
190
187
unsigned int target_frequency, unsigned int relation.
191
188
192
189
The CPUfreq driver must set the new frequency when called here. The
@@ -210,14 +207,14 @@ Not all drivers are expected to implement it, as sleeping from within
210
207
this callback isn't allowed. This callback must be highly optimized to
211
208
do switching as fast as possible.
212
209
213
- This function has two arguments: struct cpufreq_policy *policy and
214
- unsigned int target_frequency.
210
+ This function has two arguments: `` struct cpufreq_policy *policy `` and
211
+ `` unsigned int target_frequency `` .
215
212
216
213
217
214
1.7 setpolicy
218
215
-------------
219
216
220
- The setpolicy call only takes a struct cpufreq_policy *policy as
217
+ The setpolicy call only takes a `` struct cpufreq_policy *policy `` as
221
218
argument. You need to set the lower limit of the in-processor or
222
219
in-chipset dynamic frequency switching to policy->min, the upper limit
223
220
to policy->max, and -if supported- select a performance-oriented
@@ -278,10 +275,10 @@ table.
278
275
279
276
cpufreq_for_each_valid_entry(pos, table) - iterates over all entries,
280
277
excluding CPUFREQ_ENTRY_INVALID frequencies.
281
- Use arguments "pos" - a cpufreq_frequency_table * as a loop cursor and
282
- "table" - the cpufreq_frequency_table * you want to iterate over.
278
+ Use arguments "pos" - a `` cpufreq_frequency_table * `` as a loop cursor and
279
+ "table" - the `` cpufreq_frequency_table * `` you want to iterate over.
283
280
284
- For example:
281
+ For example::
285
282
286
283
struct cpufreq_frequency_table *pos, *driver_freq_table;
287
284
0 commit comments