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.\" 25*963a032bSMateusz Piotrowski.Dd April 4, 2022 26c3df47e0SNate Lawson.Dt CPUFREQ 4 27c3df47e0SNate Lawson.Os 28c3df47e0SNate Lawson.Sh NAME 29c3df47e0SNate Lawson.Nm cpufreq 30c3df47e0SNate Lawson.Nd CPU frequency control framework 31c3df47e0SNate Lawson.Sh SYNOPSIS 32c3df47e0SNate Lawson.Cd "device cpufreq" 33c3df47e0SNate Lawson.Pp 34c3df47e0SNate Lawson.In sys/cpu.h 35c3df47e0SNate Lawson.Ft int 364aff7744SRuslan Ermilov.Fn cpufreq_levels "device_t dev" "struct cf_level *levels" "int *count" 37c3df47e0SNate Lawson.Ft int 384aff7744SRuslan Ermilov.Fn cpufreq_set "device_t dev" "const struct cf_level *level" "int priority" 39c3df47e0SNate Lawson.Ft int 404aff7744SRuslan Ermilov.Fn cpufreq_get "device_t dev" "struct cf_level *level" 41c3df47e0SNate Lawson.Ft int 42c3df47e0SNate Lawson.Fo cpufreq_drv_settings 43c3df47e0SNate Lawson.Fa "device_t dev" 44c3df47e0SNate Lawson.Fa "struct cf_setting *sets" 45c3df47e0SNate Lawson.Fa "int *count" 46c3df47e0SNate Lawson.Fc 47c3df47e0SNate Lawson.Ft int 487b6b7181SNate Lawson.Fn cpufreq_drv_type "device_t dev" "int *type" 497b6b7181SNate Lawson.Ft int 504aff7744SRuslan Ermilov.Fn cpufreq_drv_set "device_t dev" "const struct cf_setting *set" 51c3df47e0SNate Lawson.Ft int 524aff7744SRuslan Ermilov.Fn cpufreq_drv_get "device_t dev" "struct cf_setting *set" 53c3df47e0SNate Lawson.Sh DESCRIPTION 54c3df47e0SNate LawsonThe 55c3df47e0SNate Lawson.Nm 56c3df47e0SNate Lawsondriver provides a unified kernel and user interface to CPU frequency 57c3df47e0SNate Lawsoncontrol drivers. 58c3df47e0SNate LawsonIt combines multiple drivers offering different settings into a single 59c3df47e0SNate Lawsoninterface of all possible levels. 60c3df47e0SNate LawsonUsers can access this interface directly via 61c3df47e0SNate Lawson.Xr sysctl 8 62c3df47e0SNate Lawsonor by indicating to 634f068961SRuslan Ermilov.Pa /etc/rc.d/power_profile 64c3df47e0SNate Lawsonthat it should switch settings when the AC line state changes via 65c3df47e0SNate Lawson.Xr rc.conf 5 . 6644cb3ab0SHiroki Sato.Sh SYSCTL VARIABLES 67c3df47e0SNate LawsonThese settings may be overridden by kernel drivers requesting alternate 68c3df47e0SNate Lawsonsettings. 69c3df47e0SNate LawsonIf this occurs, the original values will be restored once the condition 704aff7744SRuslan Ermilovhas passed (e.g., the system has cooled sufficiently). 714aff7744SRuslan ErmilovIf a sysctl cannot be set due to an override condition, it will return 724aff7744SRuslan Ermilov.Er EPERM . 73eb2336ddSMarcus Alves Grando.Pp 7443524989SConrad MeyerThe frequency cannot be changed if TSC is in use as the timecounter and the 7543524989SConrad Meyerhardware does not support invariant TSC. 76eb2336ddSMarcus Alves GrandoThis is because the timecounter system needs to use a source that has a 772b0b822eSMarcus Alves Grandoconstant rate. 7843524989SConrad Meyer(On invariant TSC hardware, the TSC runs at the P0 rate regardless of the 7943524989SConrad Meyerconfigured P-state.) 8043524989SConrad MeyerModern hardware mostly has invariant TSC. 812b0b822eSMarcus Alves GrandoThe timecounter source can be changed with the 82eb2336ddSMarcus Alves Grando.Pa kern.timecounter.hardware 832b0b822eSMarcus Alves Grandosysctl. 842b0b822eSMarcus Alves GrandoAvailable modes are in 85eb2336ddSMarcus Alves Grando.Pa kern.timecounter.choice 86eb2336ddSMarcus Alves Grandosysctl entry. 87c3df47e0SNate Lawson.Bl -tag -width indent 88c3df47e0SNate Lawson.It Va dev.cpu.%d.freq 89c3df47e0SNate LawsonCurrent active CPU frequency in MHz. 904577cf37SConrad Meyer.It Va dev.cpu.%d.freq_driver 914577cf37SConrad MeyerThe specific 924577cf37SConrad Meyer.Nm 934577cf37SConrad Meyerdriver used by this cpu. 94c3df47e0SNate Lawson.It Va dev.cpu.%d.freq_levels 9570610c87SNate LawsonCurrently available levels for the CPU (frequency/power usage). 96c3df47e0SNate LawsonValues are in units of MHz and milliwatts. 9770610c87SNate Lawson.It Va dev.DEVICE.%d.freq_settings 9870610c87SNate LawsonCurrently available settings for the driver (frequency/power usage). 9970610c87SNate LawsonValues are in units of MHz and milliwatts. 10070610c87SNate LawsonThis is helpful for understanding which settings are offered by which 10170610c87SNate Lawsondriver for debugging purposes. 10270610c87SNate Lawson.It Va debug.cpufreq.lowest 10370610c87SNate LawsonLowest CPU frequency in MHz to offer to users. 10470610c87SNate LawsonThis setting is also accessible via a tunable with the same name. 105f41eb02cSNate LawsonThis can be used to disable very low levels that may be unusable on 106f41eb02cSNate Lawsonsome systems. 107f41eb02cSNate Lawson.It Va debug.cpufreq.verbose 108f41eb02cSNate LawsonPrint verbose messages. 109f41eb02cSNate LawsonThis setting is also accessible via a tunable with the same name. 11043524989SConrad Meyer.It Va debug.hwpstate_pstate_limit 11143524989SConrad MeyerIf enabled, the AMD hwpstate driver limits administrative control of P-states 11243524989SConrad Meyer(including by 11343524989SConrad Meyer.Xr powerd 8 ) 11443524989SConrad Meyerto the value in the 0xc0010061 MSR, known as "PStateCurLim[CurPstateLimit]." 11543524989SConrad MeyerIt is disabled (0) by default. 11643524989SConrad MeyerOn some hardware, the limit register seems to simply follow the configured 11743524989SConrad MeyerP-state, which results in the inability to ever raise the P-state back to P0 11843524989SConrad Meyerfrom a reduced frequency state. 119c3df47e0SNate Lawson.El 120c3df47e0SNate Lawson.Sh SUPPORTED DRIVERS 121c3df47e0SNate LawsonThe following device drivers offer absolute frequency control via the 122c3df47e0SNate Lawson.Nm 123c3df47e0SNate Lawsoninterface. 124c3df47e0SNate LawsonUsually, only one of these can be active at a time. 125c3df47e0SNate Lawson.Pp 126*963a032bSMateusz Piotrowski.Bl -tag -compact -width "hwpstate_intel(4)" 127*963a032bSMateusz Piotrowski.It acpi_perf 128c3df47e0SNate LawsonACPI CPU performance states 129*963a032bSMateusz Piotrowski.It Xr est 4 130edd0e4caSNate LawsonIntel Enhanced SpeedStep 131*963a032bSMateusz Piotrowski.It hwpstate 13243524989SConrad MeyerAMD Cool'n'Quiet2 used in K10 through Family 17h 133*963a032bSMateusz Piotrowski.It Xr hwpstate_intel 4 13443524989SConrad MeyerIntel SpeedShift driver 135*963a032bSMateusz Piotrowski.It ichss 136c3df47e0SNate LawsonIntel SpeedStep for ICH 137*963a032bSMateusz Piotrowski.It powernow 138259c7688SChristian BruefferAMD PowerNow!\& and Cool'n'Quiet for K7 and K8 139*963a032bSMateusz Piotrowski.It smist 140f8420b58SNate LawsonIntel SMI-based SpeedStep for PIIX4 141c3df47e0SNate Lawson.El 142c3df47e0SNate Lawson.Pp 143c3df47e0SNate LawsonThe following device drivers offer relative frequency control and 144c3df47e0SNate Lawsonhave an additive effect: 145c3df47e0SNate Lawson.Pp 146*963a032bSMateusz Piotrowski.Bl -tag -compact -width "acpi_throttle" 147*963a032bSMateusz Piotrowski.It acpi_throttle 148c3df47e0SNate LawsonACPI CPU throttling 149*963a032bSMateusz Piotrowski.It p4tcc 15070610c87SNate LawsonPentium 4 Thermal Control Circuitry 151c3df47e0SNate Lawson.El 152c3df47e0SNate Lawson.Sh KERNEL INTERFACE 153c3df47e0SNate LawsonKernel components can query and set CPU frequencies through the 154c3df47e0SNate Lawson.Nm 155c3df47e0SNate Lawsonkernel interface. 156c3df47e0SNate LawsonThis involves obtaining a 157c3df47e0SNate Lawson.Nm 158c3df47e0SNate Lawsondevice, calling 159c3df47e0SNate Lawson.Fn cpufreq_levels 160c3df47e0SNate Lawsonto get the currently available frequency levels, 161c3df47e0SNate Lawsonchecking the current level with 162c3df47e0SNate Lawson.Fn cpufreq_get , 163c3df47e0SNate Lawsonand setting a new one from the list with 164c3df47e0SNate Lawson.Fn cpufreq_set . 165c3df47e0SNate LawsonEach level may actually reference more than one 166c3df47e0SNate Lawson.Nm 167c3df47e0SNate Lawsondriver but kernel components do not need to be aware of this. 168c3df47e0SNate LawsonThe 1694aff7744SRuslan Ermilov.Va total_set 170c3df47e0SNate Lawsonelement of 1714aff7744SRuslan Ermilov.Vt "struct cf_level" 172c3df47e0SNate Lawsonprovides a summary of the frequency and power for this level. 173c3df47e0SNate LawsonUnknown or irrelevant values are set to 1744aff7744SRuslan Ermilov.Dv CPUFREQ_VAL_UNKNOWN . 175c3df47e0SNate Lawson.Pp 176c3df47e0SNate LawsonThe 177c3df47e0SNate Lawson.Fn cpufreq_levels 178c3df47e0SNate Lawsonmethod takes a 179c3df47e0SNate Lawson.Nm 180c3df47e0SNate Lawsondevice and an empty array of 1814aff7744SRuslan Ermilov.Fa levels . 182c3df47e0SNate LawsonThe 1834aff7744SRuslan Ermilov.Fa count 184c3df47e0SNate Lawsonvalue should be set to the number of levels available and after the 185c3df47e0SNate Lawsonfunction completes, will be set to the actual number of levels returned. 186c3df47e0SNate LawsonIf there are more levels than 1874aff7744SRuslan Ermilov.Fa count 1884aff7744SRuslan Ermilovwill allow, it should return 1894aff7744SRuslan Ermilov.Er E2BIG . 190c3df47e0SNate Lawson.Pp 191c3df47e0SNate LawsonThe 192c3df47e0SNate Lawson.Fn cpufreq_get 193c3df47e0SNate Lawsonmethod takes a pointer to space to store a 1944aff7744SRuslan Ermilov.Fa level . 195c3df47e0SNate LawsonAfter successful completion, the output will be the current active level 196c3df47e0SNate Lawsonand is equal to one of the levels returned by 197c3df47e0SNate Lawson.Fn cpufreq_levels . 198c3df47e0SNate Lawson.Pp 199c3df47e0SNate LawsonThe 200c3df47e0SNate Lawson.Fn cpufreq_set 201c3df47e0SNate Lawsonmethod takes a pointer a 2024aff7744SRuslan Ermilov.Fa level 203c3df47e0SNate Lawsonand attempts to activate it. 204c3df47e0SNate LawsonThe 2054aff7744SRuslan Ermilov.Fa priority 2064aff7744SRuslan Ermilov(i.e., 2074aff7744SRuslan Ermilov.Dv CPUFREQ_PRIO_KERN ) 208c3df47e0SNate Lawsontells 209c3df47e0SNate Lawson.Nm 210c3df47e0SNate Lawsonwhether to override previous settings while activating this level. 211c3df47e0SNate LawsonIf 2124aff7744SRuslan Ermilov.Fa priority 213c3df47e0SNate Lawsonis higher than the current active level, that level will be saved and 214c3df47e0SNate Lawsonoverridden with the new level. 215952a0376SNate LawsonIf a level is already saved, the new level is set without overwriting 216952a0376SNate Lawsonthe older saved level. 217c3df47e0SNate LawsonIf 218c3df47e0SNate Lawson.Fn cpufreq_set 2194aff7744SRuslan Ermilovis called with a 2204aff7744SRuslan Ermilov.Dv NULL 2214aff7744SRuslan Ermilov.Fa level , 222952a0376SNate Lawsonthe saved level will be restored. 223952a0376SNate LawsonIf there is no saved level, 224952a0376SNate Lawson.Fn cpufreq_set 225952a0376SNate Lawsonwill return 226952a0376SNate Lawson.Er ENXIO . 227c3df47e0SNate LawsonIf 2284aff7744SRuslan Ermilov.Fa priority 229c3df47e0SNate Lawsonis lower than the current active level's priority, this method returns 2304aff7744SRuslan Ermilov.Er EPERM . 231c3df47e0SNate Lawson.Sh DRIVER INTERFACE 232c3df47e0SNate LawsonKernel drivers offering hardware-specific CPU frequency control export 233c3df47e0SNate Lawsontheir individual settings through the 234c3df47e0SNate Lawson.Nm 235c3df47e0SNate Lawsondriver interface. 2367b6b7181SNate LawsonThis involves implementing these methods: 237c3df47e0SNate Lawson.Fn cpufreq_drv_settings , 2387b6b7181SNate Lawson.Fn cpufreq_drv_type , 239c3df47e0SNate Lawson.Fn cpufreq_drv_set , 240c3df47e0SNate Lawsonand 241c3df47e0SNate Lawson.Fn cpufreq_drv_get . 242c3df47e0SNate LawsonAdditionally, the driver must attach a device as a child of a CPU 243c3df47e0SNate Lawsondevice so that these methods can be called by the 244c3df47e0SNate Lawson.Nm 245c3df47e0SNate Lawsonframework. 246c3df47e0SNate Lawson.Pp 247c3df47e0SNate LawsonThe 248c3df47e0SNate Lawson.Fn cpufreq_drv_settings 249c3df47e0SNate Lawsonmethod returns an array of currently available settings, each of type 2504aff7744SRuslan Ermilov.Vt "struct cf_setting" . 251c3df47e0SNate LawsonThe driver should set unknown or irrelevant values to 2524aff7744SRuslan Ermilov.Dv CPUFREQ_VAL_UNKNOWN . 253c3df47e0SNate LawsonAll the following elements for each setting should be returned: 254c3df47e0SNate Lawson.Bd -literal 255c3df47e0SNate Lawsonstruct cf_setting { 25679649302SGavin Atkinson int freq; /* CPU clock in MHz or 100ths of a percent. */ 257c3df47e0SNate Lawson int volts; /* Voltage in mV. */ 258c3df47e0SNate Lawson int power; /* Power consumed in mW. */ 259c3df47e0SNate Lawson int lat; /* Transition latency in us. */ 260c3df47e0SNate Lawson device_t dev; /* Driver providing this setting. */ 261c3df47e0SNate Lawson}; 262c3df47e0SNate Lawson.Ed 263c3df47e0SNate Lawson.Pp 264c3df47e0SNate LawsonOn entry to this method, 2654aff7744SRuslan Ermilov.Fa count 266c3df47e0SNate Lawsoncontains the number of settings that can be returned. 267c3df47e0SNate LawsonOn successful completion, the driver sets it to the actual number of 268c3df47e0SNate Lawsonsettings returned. 269c3df47e0SNate LawsonIf the driver offers more settings than 2704aff7744SRuslan Ermilov.Fa count 2714aff7744SRuslan Ermilovwill allow, it should return 2724aff7744SRuslan Ermilov.Er E2BIG . 2737b6b7181SNate Lawson.Pp 2747b6b7181SNate LawsonThe 2757b6b7181SNate Lawson.Fn cpufreq_drv_type 2767b6b7181SNate Lawsonmethod indicates the type of settings it offers, either 2774aff7744SRuslan Ermilov.Dv CPUFREQ_TYPE_ABSOLUTE 278c3df47e0SNate Lawsonor 2794aff7744SRuslan Ermilov.Dv CPUFREQ_TYPE_RELATIVE . 2807b6b7181SNate LawsonAdditionally, the driver may set the 2817b6b7181SNate Lawson.Dv CPUFREQ_FLAG_INFO_ONLY 2827b6b7181SNate Lawsonflag if the settings it provides are information for other drivers only 2837b6b7181SNate Lawsonand cannot be passed to 2847b6b7181SNate Lawson.Fn cpufreq_drv_set 2857b6b7181SNate Lawsonto activate them. 286c3df47e0SNate Lawson.Pp 287c3df47e0SNate LawsonThe 288c3df47e0SNate Lawson.Fn cpufreq_drv_set 289c3df47e0SNate Lawsonmethod takes a driver setting and makes it active. 290c3df47e0SNate LawsonIf the setting is invalid or not currently available, it should return 2914aff7744SRuslan Ermilov.Er EINVAL . 292c3df47e0SNate Lawson.Pp 293c3df47e0SNate LawsonThe 294c3df47e0SNate Lawson.Fn cpufreq_drv_get 295c3df47e0SNate Lawsonmethod returns the currently-active driver setting. 296c3df47e0SNate LawsonThe 2974aff7744SRuslan Ermilov.Vt "struct cf_setting" 298c3df47e0SNate Lawsonreturned must be valid for passing to 299c3df47e0SNate Lawson.Fn cpufreq_drv_set , 300c3df47e0SNate Lawsonincluding all elements being filled out correctly. 301c3df47e0SNate LawsonIf the driver cannot infer the current setting 302c3df47e0SNate Lawson(even by estimating it with 303c3df47e0SNate Lawson.Fn cpu_est_clockrate ) 304c3df47e0SNate Lawsonthen it should set all elements to 3054aff7744SRuslan Ermilov.Dv CPUFREQ_VAL_UNKNOWN . 3064aff7744SRuslan Ermilov.Sh SEE ALSO 3074aff7744SRuslan Ermilov.Xr acpi 4 , 308f89d8b9aSSean Bruno.Xr est 4 , 309e3bf726bSAlexander Motin.Xr timecounters 4 , 3101d9fef71SDaniel Gerzo.Xr powerd 8 , 3114aff7744SRuslan Ermilov.Xr sysctl 8 3124aff7744SRuslan Ermilov.Sh AUTHORS 3134aff7744SRuslan Ermilov.An Nate Lawson 314f41eb02cSNate Lawson.An Bruno Ducrot 315f41eb02cSNate Lawsoncontributed the 316f41eb02cSNate Lawson.Pa powernow 317f41eb02cSNate Lawsondriver. 318c3df47e0SNate Lawson.Sh BUGS 319c3df47e0SNate LawsonThe following drivers have not yet been converted to the 320c3df47e0SNate Lawson.Nm 321c3df47e0SNate Lawsoninterface: 32270610c87SNate Lawson.Xr longrun 4 . 323c3df47e0SNate Lawson.Pp 324952a0376SNate LawsonNotification of CPU and bus frequency changes is not implemented yet. 325c3df47e0SNate Lawson.Pp 326c3df47e0SNate LawsonWhen multiple CPUs offer frequency control, they cannot be set to different 327c3df47e0SNate Lawsonlevels and must all offer the same frequency settings. 328