xref: /freebsd/share/man/man4/cpufreq.4 (revision eb2336ddb5f04ee3a44e4818b45b37aa8e984daa)
1c3df47e0SNate Lawson.\" Copyright (c) 2005 Nate Lawson
2c3df47e0SNate Lawson.\" All rights reserved.
3c3df47e0SNate Lawson.\"
4c3df47e0SNate Lawson.\" Redistribution and use in source and binary forms, with or without
5c3df47e0SNate Lawson.\" modification, are permitted provided that the following conditions
6c3df47e0SNate Lawson.\" are met:
7c3df47e0SNate Lawson.\" 1. Redistributions of source code must retain the above copyright
8c3df47e0SNate Lawson.\"    notice, this list of conditions and the following disclaimer.
9c3df47e0SNate Lawson.\" 2. Redistributions in binary form must reproduce the above copyright
10c3df47e0SNate Lawson.\"    notice, this list of conditions and the following disclaimer in the
11c3df47e0SNate Lawson.\"    documentation and/or other materials provided with the distribution.
12c3df47e0SNate Lawson.\"
13c3df47e0SNate Lawson.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14c3df47e0SNate Lawson.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15c3df47e0SNate Lawson.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16c3df47e0SNate Lawson.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17c3df47e0SNate Lawson.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18c3df47e0SNate Lawson.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19c3df47e0SNate Lawson.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20c3df47e0SNate Lawson.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21c3df47e0SNate Lawson.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22c3df47e0SNate Lawson.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23c3df47e0SNate Lawson.\" SUCH DAMAGE.
24c3df47e0SNate Lawson.\"
25c3df47e0SNate Lawson.\" $FreeBSD$
26c3df47e0SNate Lawson.\"
27f41eb02cSNate Lawson.Dd April 10, 2005
28c3df47e0SNate Lawson.Dt CPUFREQ 4
29c3df47e0SNate Lawson.Os
30c3df47e0SNate Lawson.Sh NAME
31c3df47e0SNate Lawson.Nm cpufreq
32c3df47e0SNate Lawson.Nd CPU frequency control framework
33c3df47e0SNate Lawson.Sh SYNOPSIS
34c3df47e0SNate Lawson.Cd "device cpufreq"
35c3df47e0SNate Lawson.Pp
36c3df47e0SNate Lawson.In sys/cpu.h
37c3df47e0SNate Lawson.Ft int
384aff7744SRuslan Ermilov.Fn cpufreq_levels "device_t dev" "struct cf_level *levels" "int *count"
39c3df47e0SNate Lawson.Ft int
404aff7744SRuslan Ermilov.Fn cpufreq_set "device_t dev" "const struct cf_level *level" "int priority"
41c3df47e0SNate Lawson.Ft int
424aff7744SRuslan Ermilov.Fn cpufreq_get "device_t dev" "struct cf_level *level"
43c3df47e0SNate Lawson.Ft int
44c3df47e0SNate Lawson.Fo cpufreq_drv_settings
45c3df47e0SNate Lawson.Fa "device_t dev"
46c3df47e0SNate Lawson.Fa "struct cf_setting *sets"
47c3df47e0SNate Lawson.Fa "int *count"
48c3df47e0SNate Lawson.Fc
49c3df47e0SNate Lawson.Ft int
507b6b7181SNate Lawson.Fn cpufreq_drv_type "device_t dev" "int *type"
517b6b7181SNate Lawson.Ft int
524aff7744SRuslan Ermilov.Fn cpufreq_drv_set "device_t dev" "const struct cf_setting *set"
53c3df47e0SNate Lawson.Ft int
544aff7744SRuslan Ermilov.Fn cpufreq_drv_get "device_t dev" "struct cf_setting *set"
55c3df47e0SNate Lawson.Sh DESCRIPTION
56c3df47e0SNate LawsonThe
57c3df47e0SNate Lawson.Nm
58c3df47e0SNate Lawsondriver provides a unified kernel and user interface to CPU frequency
59c3df47e0SNate Lawsoncontrol drivers.
60c3df47e0SNate LawsonIt combines multiple drivers offering different settings into a single
61c3df47e0SNate Lawsoninterface of all possible levels.
62c3df47e0SNate LawsonUsers can access this interface directly via
63c3df47e0SNate Lawson.Xr sysctl 8
64c3df47e0SNate Lawsonor by indicating to
654f068961SRuslan Ermilov.Pa /etc/rc.d/power_profile
66c3df47e0SNate Lawsonthat it should switch settings when the AC line state changes via
67c3df47e0SNate Lawson.Xr rc.conf 5 .
6844cb3ab0SHiroki Sato.Sh SYSCTL VARIABLES
69c3df47e0SNate LawsonThese settings may be overridden by kernel drivers requesting alternate
70c3df47e0SNate Lawsonsettings.
71c3df47e0SNate LawsonIf this occurs, the original values will be restored once the condition
724aff7744SRuslan Ermilovhas passed (e.g., the system has cooled sufficiently).
734aff7744SRuslan ErmilovIf a sysctl cannot be set due to an override condition, it will return
744aff7744SRuslan Ermilov.Er EPERM .
75eb2336ddSMarcus Alves Grando.Pp
76eb2336ddSMarcus Alves GrandoThe frequency cannot be changed if TSC is in use as the timecounter.
77eb2336ddSMarcus Alves GrandoThis is because the timecounter system needs to use a source that has a
78eb2336ddSMarcus Alves Grandoconstant rate. The timecounter source can be changed with the
79eb2336ddSMarcus Alves Grando.Pa kern.timecounter.hardware
80eb2336ddSMarcus Alves Grandosysctl. Available modes are in
81eb2336ddSMarcus Alves Grando.Pa kern.timecounter.choice
82eb2336ddSMarcus Alves Grandosysctl entry.
83c3df47e0SNate Lawson.Bl -tag -width indent
84c3df47e0SNate Lawson.It Va dev.cpu.%d.freq
85c3df47e0SNate LawsonCurrent active CPU frequency in MHz.
86c3df47e0SNate Lawson.It Va dev.cpu.%d.freq_levels
8770610c87SNate LawsonCurrently available levels for the CPU (frequency/power usage).
88c3df47e0SNate LawsonValues are in units of MHz and milliwatts.
8970610c87SNate Lawson.It Va dev.DEVICE.%d.freq_settings
9070610c87SNate LawsonCurrently available settings for the driver (frequency/power usage).
9170610c87SNate LawsonValues are in units of MHz and milliwatts.
9270610c87SNate LawsonThis is helpful for understanding which settings are offered by which
9370610c87SNate Lawsondriver for debugging purposes.
9470610c87SNate Lawson.It Va debug.cpufreq.lowest
9570610c87SNate LawsonLowest CPU frequency in MHz to offer to users.
9670610c87SNate LawsonThis setting is also accessible via a tunable with the same name.
97f41eb02cSNate LawsonThis can be used to disable very low levels that may be unusable on
98f41eb02cSNate Lawsonsome systems.
99f41eb02cSNate Lawson.It Va debug.cpufreq.verbose
100f41eb02cSNate LawsonPrint verbose messages.
101f41eb02cSNate LawsonThis setting is also accessible via a tunable with the same name.
102c3df47e0SNate Lawson.El
103c3df47e0SNate Lawson.Sh SUPPORTED DRIVERS
104c3df47e0SNate LawsonThe following device drivers offer absolute frequency control via the
105c3df47e0SNate Lawson.Nm
106c3df47e0SNate Lawsoninterface.
107c3df47e0SNate LawsonUsually, only one of these can be active at a time.
108c3df47e0SNate Lawson.Pp
10970610c87SNate Lawson.Bl -tag -compact -width ".Pa acpi_perf"
11070610c87SNate Lawson.It Pa acpi_perf
111c3df47e0SNate LawsonACPI CPU performance states
11270610c87SNate Lawson.It Pa est
113edd0e4caSNate LawsonIntel Enhanced SpeedStep
11470610c87SNate Lawson.It Pa ichss
115c3df47e0SNate LawsonIntel SpeedStep for ICH
116ac1936dcSNate Lawson.It Pa powernow
1174f068961SRuslan ErmilovAMD PowerNow!\& for K7 and K8
118f8420b58SNate Lawson.It Pa smist
119f8420b58SNate LawsonIntel SMI-based SpeedStep for PIIX4
120c3df47e0SNate Lawson.El
121c3df47e0SNate Lawson.Pp
122c3df47e0SNate LawsonThe following device drivers offer relative frequency control and
123c3df47e0SNate Lawsonhave an additive effect:
124c3df47e0SNate Lawson.Pp
12570610c87SNate Lawson.Bl -tag -compact -width ".Pa acpi_throttle"
12670610c87SNate Lawson.It Pa acpi_throttle
127c3df47e0SNate LawsonACPI CPU throttling
12870610c87SNate Lawson.It Pa p4tcc
12970610c87SNate LawsonPentium 4 Thermal Control Circuitry
130c3df47e0SNate Lawson.El
131c3df47e0SNate Lawson.Sh KERNEL INTERFACE
132c3df47e0SNate LawsonKernel components can query and set CPU frequencies through the
133c3df47e0SNate Lawson.Nm
134c3df47e0SNate Lawsonkernel interface.
135c3df47e0SNate LawsonThis involves obtaining a
136c3df47e0SNate Lawson.Nm
137c3df47e0SNate Lawsondevice, calling
138c3df47e0SNate Lawson.Fn cpufreq_levels
139c3df47e0SNate Lawsonto get the currently available frequency levels,
140c3df47e0SNate Lawsonchecking the current level with
141c3df47e0SNate Lawson.Fn cpufreq_get ,
142c3df47e0SNate Lawsonand setting a new one from the list with
143c3df47e0SNate Lawson.Fn cpufreq_set .
144c3df47e0SNate LawsonEach level may actually reference more than one
145c3df47e0SNate Lawson.Nm
146c3df47e0SNate Lawsondriver but kernel components do not need to be aware of this.
147c3df47e0SNate LawsonThe
1484aff7744SRuslan Ermilov.Va total_set
149c3df47e0SNate Lawsonelement of
1504aff7744SRuslan Ermilov.Vt "struct cf_level"
151c3df47e0SNate Lawsonprovides a summary of the frequency and power for this level.
152c3df47e0SNate LawsonUnknown or irrelevant values are set to
1534aff7744SRuslan Ermilov.Dv CPUFREQ_VAL_UNKNOWN .
154c3df47e0SNate Lawson.Pp
155c3df47e0SNate LawsonThe
156c3df47e0SNate Lawson.Fn cpufreq_levels
157c3df47e0SNate Lawsonmethod takes a
158c3df47e0SNate Lawson.Nm
159c3df47e0SNate Lawsondevice and an empty array of
1604aff7744SRuslan Ermilov.Fa levels .
161c3df47e0SNate LawsonThe
1624aff7744SRuslan Ermilov.Fa count
163c3df47e0SNate Lawsonvalue should be set to the number of levels available and after the
164c3df47e0SNate Lawsonfunction completes, will be set to the actual number of levels returned.
165c3df47e0SNate LawsonIf there are more levels than
1664aff7744SRuslan Ermilov.Fa count
1674aff7744SRuslan Ermilovwill allow, it should return
1684aff7744SRuslan Ermilov.Er E2BIG .
169c3df47e0SNate Lawson.Pp
170c3df47e0SNate LawsonThe
171c3df47e0SNate Lawson.Fn cpufreq_get
172c3df47e0SNate Lawsonmethod takes a pointer to space to store a
1734aff7744SRuslan Ermilov.Fa level .
174c3df47e0SNate LawsonAfter successful completion, the output will be the current active level
175c3df47e0SNate Lawsonand is equal to one of the levels returned by
176c3df47e0SNate Lawson.Fn cpufreq_levels .
177c3df47e0SNate Lawson.Pp
178c3df47e0SNate LawsonThe
179c3df47e0SNate Lawson.Fn cpufreq_set
180c3df47e0SNate Lawsonmethod takes a pointer a
1814aff7744SRuslan Ermilov.Fa level
182c3df47e0SNate Lawsonand attempts to activate it.
183c3df47e0SNate LawsonThe
1844aff7744SRuslan Ermilov.Fa priority
1854aff7744SRuslan Ermilov(i.e.,
1864aff7744SRuslan Ermilov.Dv CPUFREQ_PRIO_KERN )
187c3df47e0SNate Lawsontells
188c3df47e0SNate Lawson.Nm
189c3df47e0SNate Lawsonwhether to override previous settings while activating this level.
190c3df47e0SNate LawsonIf
1914aff7744SRuslan Ermilov.Fa priority
192c3df47e0SNate Lawsonis higher than the current active level, that level will be saved and
193c3df47e0SNate Lawsonoverridden with the new level.
194952a0376SNate LawsonIf a level is already saved, the new level is set without overwriting
195952a0376SNate Lawsonthe older saved level.
196c3df47e0SNate LawsonIf
197c3df47e0SNate Lawson.Fn cpufreq_set
1984aff7744SRuslan Ermilovis called with a
1994aff7744SRuslan Ermilov.Dv NULL
2004aff7744SRuslan Ermilov.Fa level ,
201952a0376SNate Lawsonthe saved level will be restored.
202952a0376SNate LawsonIf there is no saved level,
203952a0376SNate Lawson.Fn cpufreq_set
204952a0376SNate Lawsonwill return
205952a0376SNate Lawson.Er ENXIO .
206c3df47e0SNate LawsonIf
2074aff7744SRuslan Ermilov.Fa priority
208c3df47e0SNate Lawsonis lower than the current active level's priority, this method returns
2094aff7744SRuslan Ermilov.Er EPERM .
210c3df47e0SNate Lawson.Sh DRIVER INTERFACE
211c3df47e0SNate LawsonKernel drivers offering hardware-specific CPU frequency control export
212c3df47e0SNate Lawsontheir individual settings through the
213c3df47e0SNate Lawson.Nm
214c3df47e0SNate Lawsondriver interface.
2157b6b7181SNate LawsonThis involves implementing these methods:
216c3df47e0SNate Lawson.Fn cpufreq_drv_settings ,
2177b6b7181SNate Lawson.Fn cpufreq_drv_type ,
218c3df47e0SNate Lawson.Fn cpufreq_drv_set ,
219c3df47e0SNate Lawsonand
220c3df47e0SNate Lawson.Fn cpufreq_drv_get .
221c3df47e0SNate LawsonAdditionally, the driver must attach a device as a child of a CPU
222c3df47e0SNate Lawsondevice so that these methods can be called by the
223c3df47e0SNate Lawson.Nm
224c3df47e0SNate Lawsonframework.
225c3df47e0SNate Lawson.Pp
226c3df47e0SNate LawsonThe
227c3df47e0SNate Lawson.Fn cpufreq_drv_settings
228c3df47e0SNate Lawsonmethod returns an array of currently available settings, each of type
2294aff7744SRuslan Ermilov.Vt "struct cf_setting" .
230c3df47e0SNate LawsonThe driver should set unknown or irrelevant values to
2314aff7744SRuslan Ermilov.Dv CPUFREQ_VAL_UNKNOWN .
232c3df47e0SNate LawsonAll the following elements for each setting should be returned:
233c3df47e0SNate Lawson.Bd -literal
234c3df47e0SNate Lawsonstruct cf_setting {
235c3df47e0SNate Lawson	int	freq;	/* CPU clock in Mhz or 100ths of a percent. */
236c3df47e0SNate Lawson	int	volts;	/* Voltage in mV. */
237c3df47e0SNate Lawson	int	power;	/* Power consumed in mW. */
238c3df47e0SNate Lawson	int	lat;	/* Transition latency in us. */
239c3df47e0SNate Lawson	device_t dev;	/* Driver providing this setting. */
240c3df47e0SNate Lawson};
241c3df47e0SNate Lawson.Ed
242c3df47e0SNate Lawson.Pp
243c3df47e0SNate LawsonOn entry to this method,
2444aff7744SRuslan Ermilov.Fa count
245c3df47e0SNate Lawsoncontains the number of settings that can be returned.
246c3df47e0SNate LawsonOn successful completion, the driver sets it to the actual number of
247c3df47e0SNate Lawsonsettings returned.
248c3df47e0SNate LawsonIf the driver offers more settings than
2494aff7744SRuslan Ermilov.Fa count
2504aff7744SRuslan Ermilovwill allow, it should return
2514aff7744SRuslan Ermilov.Er E2BIG .
2527b6b7181SNate Lawson.Pp
2537b6b7181SNate LawsonThe
2547b6b7181SNate Lawson.Fn cpufreq_drv_type
2557b6b7181SNate Lawsonmethod indicates the type of settings it offers, either
2564aff7744SRuslan Ermilov.Dv CPUFREQ_TYPE_ABSOLUTE
257c3df47e0SNate Lawsonor
2584aff7744SRuslan Ermilov.Dv CPUFREQ_TYPE_RELATIVE .
2597b6b7181SNate LawsonAdditionally, the driver may set the
2607b6b7181SNate Lawson.Dv CPUFREQ_FLAG_INFO_ONLY
2617b6b7181SNate Lawsonflag if the settings it provides are information for other drivers only
2627b6b7181SNate Lawsonand cannot be passed to
2637b6b7181SNate Lawson.Fn cpufreq_drv_set
2647b6b7181SNate Lawsonto activate them.
265c3df47e0SNate Lawson.Pp
266c3df47e0SNate LawsonThe
267c3df47e0SNate Lawson.Fn cpufreq_drv_set
268c3df47e0SNate Lawsonmethod takes a driver setting and makes it active.
269c3df47e0SNate LawsonIf the setting is invalid or not currently available, it should return
2704aff7744SRuslan Ermilov.Er EINVAL .
271c3df47e0SNate Lawson.Pp
272c3df47e0SNate LawsonThe
273c3df47e0SNate Lawson.Fn cpufreq_drv_get
274c3df47e0SNate Lawsonmethod returns the currently-active driver setting.
275c3df47e0SNate LawsonThe
2764aff7744SRuslan Ermilov.Vt "struct cf_setting"
277c3df47e0SNate Lawsonreturned must be valid for passing to
278c3df47e0SNate Lawson.Fn cpufreq_drv_set ,
279c3df47e0SNate Lawsonincluding all elements being filled out correctly.
280c3df47e0SNate LawsonIf the driver cannot infer the current setting
281c3df47e0SNate Lawson(even by estimating it with
282c3df47e0SNate Lawson.Fn cpu_est_clockrate )
283c3df47e0SNate Lawsonthen it should set all elements to
2844aff7744SRuslan Ermilov.Dv CPUFREQ_VAL_UNKNOWN .
2854aff7744SRuslan Ermilov.Sh SEE ALSO
2864aff7744SRuslan Ermilov.Xr acpi 4 ,
2874aff7744SRuslan Ermilov.Xr sysctl 8
2884aff7744SRuslan Ermilov.Sh AUTHORS
2894aff7744SRuslan Ermilov.An Nate Lawson
290f41eb02cSNate Lawson.An Bruno Ducrot
291f41eb02cSNate Lawsoncontributed the
292f41eb02cSNate Lawson.Pa powernow
293f41eb02cSNate Lawsondriver.
294c3df47e0SNate Lawson.Sh BUGS
295c3df47e0SNate LawsonThe following drivers have not yet been converted to the
296c3df47e0SNate Lawson.Nm
297c3df47e0SNate Lawsoninterface:
29870610c87SNate Lawson.Xr longrun 4 .
299c3df47e0SNate Lawson.Pp
300952a0376SNate LawsonNotification of CPU and bus frequency changes is not implemented yet.
301c3df47e0SNate Lawson.Pp
302c3df47e0SNate LawsonWhen multiple CPUs offer frequency control, they cannot be set to different
303c3df47e0SNate Lawsonlevels and must all offer the same frequency settings.
304