https://www.thinkwiki.org/w/api.php?action=feedcontributions&user=Sylecn&feedformat=atomThinkWiki - User contributions [en]2024-03-29T09:51:07ZUser contributionsMediaWiki 1.31.12https://www.thinkwiki.org/w/index.php?title=How_to_make_use_of_Dynamic_Frequency_Scaling&diff=50566How to make use of Dynamic Frequency Scaling2011-02-10T18:20:42Z<p>Sylecn: /* Troubleshooting */ add link to Problem with CPU frequency scaling</p>
<hr />
<div>==General==<br />
Linux supports dynamic frequency scaling for systems with the following processors:<br />
*[[Intel Mobile Pentium III]]<br />
*[[Intel Mobile Pentium III-M]]<br />
*[[Intel Mobile Pentium 4]]<br />
*[[Intel Mobile Pentium 4-M]]<br />
*[[Intel Pentium M (Banias)]]<br />
*[[Intel Pentium M (Dothan)]]<br />
*[[Intel Core Solo (Yonah)]]<br />
*[[Intel Core Duo (Yonah)]]<br />
*[[Intel Core 2 Duo]]<br />
*Mobile Athlon<br />
*AMD64<br />
*Opteron<br />
*Via C3<br />
*Via C7<br />
<br />
==Configuring the Kernel==<br />
<br />
<br />
===2.6 Kernels===<br />
You need to enable the CPU frequency scaling for your kernel (usually your distros kernel will have this enabled), under {{kernelconf||||CPU Frequency scaling|Power management options (ACPI, APM)|||}}: {{kernelconf|CONFIG_CPU_FREQ|<*>|||||}}<br />
<br />
If you own a Dothan processor, you need to enable Enhanced SpeedStep functionalities.<br />
:{{kernelconf|CONFIG_X86_SPEEDSTEP_CENTRINO|<*>|||||}}<br />
<br />
Alternatively, there seems to be some advocacy of a switch over to <br />
:{{kernelconf|CONFIG_X86_ACPI_CPUFREQ|<*>|||||}}<br />
for controlling speedstep technology. Apparently this newer kernel option is more aware of acpi powersaving that's done in the BIOS. In any case, both {{kernelconf|CONFIG_X86_SPEEDSTEP_CENTRINO|<*>|||||}} and {{kernelconf|CCONFIG_X86_ACPI_CPUFREQ|<*>|||||}} were found to work on a Menrom (Core 2).<br />
<br />
You also need to enable governors, if not already done in your distros default kernel:<br />
:{{kernelconf|CONFIG_CPU_FREQ_GOV_PERFORMANCE|<*>|||||}}<br />
<br />
The '''performance''' CPU governor lets your CPU frequency always to the highest available.<br />
<br />
:{{kernelconf|CONFIG_CPU_FREQ_GOV_POWERSAVE|<*>|||||}}<br />
<br />
The '''powersave''' governor sets the frequency to the lowest available. That's not the best choice for battery lifetime on modern Intel CPU, though (see above).<br />
<br />
:{{kernelconf|CONFIG_CPU_FREQ_GOV_USERSPACE|<*>|||||}}<br />
<br />
The '''userspace''' governor allows you to set the frequency manually, unlike the others. Some [[#Using Frequency Scaling Daemons|frequency scaling daemons]] require this governor to operate correctly. This is typically the recommended option with older processors like A30p's pIIIm-1200.<br />
<br />
:{{kernelconf|CONFIG_CPU_FREQ_GOV_ONDEMAND|<*>|||||}}<br />
:{{kernelconf|CONFIG_CPU_FREQ_GOV_CONSERVATIVE|<*>|||||}}<br />
<br />
The '''ondemand''' (available since 2.6.10) and '''conservative''' (since 2.6.12) are governors based on in kernel implementations of CPU scaling algorithms: they scale the CPU frequencies according to the needs (like does the userspace frequency scaling daemons, but in kernel). They differs in the way they scale up and down. The ondemand governor switches to the highest frequency immediately when there is load, while the conservative governor increases frequency step by step. Likewise they behave the other way round for stepping down frequency when the CPU is idle. The conservative governor is good for battery powered environments on AMD64 (but may not work on older ThinkPads like the T21). Ondemand may not work on older laptops without Enhanced SpeedStep due to [http://lists.debian.org/debian-powerpc/2005/05/msg00542.html latency reasons]. Anyway, for recent enough Intel CPU, ondemand is the one recommended for power efficiency (over userspace, and even over "powersave") by the Intel's kernel developer Arjan van de Ven (see [http://www.bughost.org/pipermail/power/2007-May/000166.html], [http://www.bughost.org/pipermail/power/2007-May/000073.html], [http://www.bughost.org/pipermail/power/2007-May/000071.html])<br />
<br />
=== 2.6 doing it with modules ===<br />
With the Debian flavour of 2.6.21 and possibly earlier versions as well as other distros, all of the above kernel options are compiled as modules out of the box. You'll have to load them yourself to get speedstep functionality. This can be done simply enough in an /etc/modules file with the lines<br />
<pre><br />
acpi-cpufreq<br />
cpufreq_ondemand<br />
cpufreq_userspace<br />
cpufreq_conservative<br />
cpufreq_powersave<br />
</pre><br />
of course, this is a bit excessive if you're only going to use one governor (see below), you only need to load the modules for the governor(s) you are going to use. It seems that "performance" is not a loadable module in my case. Probably because it's built into the kernel as the default. Finally if you're a fan of useless statistics, you can load cpufreq_stats so that you can see how long your processor spends in each state and how many times it transitions with<br />
<pre><br />
cat /sys/devices/system/cpu/cpu0/cpufreq/stats/total_trans<br />
cat /sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state<br />
</pre><br />
<br />
{{NOTE| "acpi-cpufreq" does not work on a T43. Use the module called "speedstep-centrino" instead!<br><br><br />
The code for "speedstep-centrino" was added to "acpi-cpufreq" and set for depreciation in kernel 2.6.20}}<br />
<br />
With kernel >=2.6.31, possibly some versions below that, different CPUFreq processor drivers are added. <br />
* "powernow-k8" is the frequency scaling module for '''AMD''' processors and <br />
* "acpi-cpufreq" looks like the right choose for '''INTEL''' processors, though there is a more aggressive method for P4 and XEON processors called <br />
* "p4-clockmod". But the last can cause slowdowns and latencies, so you really should read your kernels Handbook Documentation/cpu-freq/ on this.<br />
<br />
==Using the Sys Interface==<br />
The files in {{path|/sys/devices/system/cpu/cpu0/cpufreq/}} provide information and a means of controlling the frequency scaling subsystem.<br />
Seed values are given in Khz. You need to be root to access the /sys filesystem.<br />
<br />
Your max speed is at {{path|/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq}}.<br />
:{{cmdroot|cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq}}<br />
:{{cmdresult|700000}}<br />
Your min speed is at {{path|/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq}}.<br />
:{{cmdroot|cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq}}<br />
:{{cmdresult|500000}}<br />
If you are using the userspace governor, you can write to {{path|/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed}} to change the current speed.<br />
:{{cmdroot|echo 700000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed}}<br />
:{{cmdroot|cat /proc/cpuinfo | grep "cpu MHz"}}<br />
:{{cmdresult|cpu MHz : 697.252}}<br />
:{{cmdroot|echo 900000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed}}<br />
:{{cmdroot|cat /proc/cpuinfo | grep "cpu MHz"}}<br />
:{{cmdresult|cpu MHz : 976.152}}<br />
<br />
==Using Frequency Scaling Governors==<br />
You can get a list of available governors with (as root):<br />
:{{cmdroot|cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors}}<br />
:{{cmdresult|conservative ondemand powersave userspace performance}}<br />
<br />
Note: If the governors are compiled as modules, load them first:<br />
:{{cmdroot|modprobe cpufreq_performance cpufreq_ondemand cpufreq_conservative cpufreq_powersave cpufreq_userspace}}<br />
<br />
Now we set our governor:<br />
What is our current governor?<br />
:{{cmdroot|cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor}}<br />
:{{cmdresult|userspace}}<br />
Set new governor and watch if it has changed<br />
:{{cmdroot|echo conservative > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor}}<br />
:{{cmdroot|cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor}}<br />
:{{cmdresult|conservative}}<br />
<br />
Congrats! Your governor is active.<br />
<br />
You may set the governor in your rc.local, to make it used on every boot.<br />
<br />
==Using Frequency Scaling Daemons==<br />
Frequency Scaling Daemons adapt the frequency policy to different situations. A typical configuration would be to use the ondemand governor running off batteries and performance otherwise, or combining powersave with conservative on laptops with heat problems. More sophisticated setups adapt to battery level, CPU temperature or even running programs. Some daemons are able to control other power management features like hard disks or graphic cards.<br />
<br />
{{NOTE|Daemons are optional. If you don't plan to change policies depending on the situation, you don't need one and you can stick to the <tt>ondemand</tt> or <tt>conservative</tt> frequency scaling governors, available in kernels after 2.6.10 or 2.6.12 respectively. See [[#Using Frequency Scaling Governors|above]]. They require less configuration and have generally been experienced to flawlessly adapt to the situations at hand.}}<br />
<br />
Some daemons use the kernel governors (see above), others implement the functionality on their own. In the latter case you have to enable the userspace governor. If it is built as module, load it as <tt>cpufreq-userspace</tt>.<br />
<br />
There are plenty of userspace frequency scaling daemons available:<br />
<br />
*[[How to configure cpudynd | cpudynd]]<br />
*[[How to configure cpufreqd | cpufreqd]]<br />
*[[How to use cpufrequtils | cpufrequtils]]<br />
*[[How to configure powernowd | powernowd]]<br />
*[[How to configure powersaved | powersaved]]<br />
*[[How to configure speedfreqd | speedfreqd]]<br />
*[[laptop-mode-tools]] can also be configured to switch governors when the laptop is plugged in and unplugged<br />
<br />
==Debian notes==<br />
Instead of compiling your own kernel, you can use the {{Debian}} "stock" kernel. In Debian/Etch the 2.6.18 kernel image with an {{path|/etc/modules}} file that includes:<br />
<br />
battery<br />
ac<br />
thermal<br />
processor<br />
acpi-cpufreq<br />
cpufreq-userspace<br />
<br />
With the powernowd package and you should be setup.<br />
<br />
{{Debian}} Etch now has {{path|rc.local}} (see package initscripts).<br />
<br />
However, a better alternative for Debian, rather than modifying bootscripts, is to install the [http://packages.debian.org/cgi-bin/search_packages.pl?searchon=names&version=all&exact=1&keywords=sysfsutils sysfsutils package]. Then edit {{path|/etc/sysfs.conf}} (as root), where you can setup values to sysfs entries that you want to be modified automatically on boot.<br />
<br />
==Troubleshooting==<br />
*If you have a Coppermine-piix-smi based ThinkPads like from the A2x, X2x and T2x series you need to enable the <tt>speedstep-smi</tt> driver in the kernel and load it if it's built as module. You might want to look at [[How to get SpeedStep working on Coppermine-piix4-smi based ThinkPads | this page]].<br />
<br />
*If you have a p4-class celeron based ThinkPad like the R40e you might want to look at [[How to get SpeedStep working on P4-class-Celeron based ThinkPads | this page]]<br />
<br />
*You may need to set your BIOS to "maximum performance" if you are using Linux to set the CPU speed. This is necessary to prevent odd behaviour (cpufreq 'freezing' at certain frequencies) with the T4x series.<br />
<br />
*You will need to have the cpufreq-selector applet installed at SUID root to use the gnome cpufreq applet. See [http://ubuntu.wordpress.com/2005/11/04/enabling-cpu-frequency-scaling/ this page] for info.<br />
<br />
*If you have a thinkpad with intel core i3/5/7 cpu, and it always runs at lowest speed, see [[Problem with CPU frequency scaling]]<br />
<br />
==Finetuning voltages and available frequencies==<br />
See [[Pentium M undervolting and underclocking]].<br />
<br />
==A note about CPU throttling==<br />
<br />
Throttling the CPU through ACPI "T" states is generally useless for power consumption reduction nowadays. It is an artifact of the past, when there was no clock frequency scaling and ACPI "C" states were mostly not implemented or didn't exist.<br />
<br />
Throttling does not decrease clock frequency at all, and it can even increase power consumption in a modern CPU capable of ACPI "C" states, as it can interfere with the CPU reaching the higher C states (such as C2).<br />
<br />
On a T43, setting a CPU to a ACPI Throttle state different than T0 (no throttling) can cause it to draw more than 100mW extra power, as it will reach C2 less often.<br />
<br />
In case your BIOS offers "cpu power management" and "pci bus power management" disabled by default (that's the case in X40 with the 2.08 BIOS), you should turn them on (or choose "automatic"). Despite what the BIOS online documentation says ("rarely needed"), this is quite useful, since it make the deepests (C3 and C4) ACPI C-states avaibles. On a kernel more with [[dynticks]] (2.6.21 and over), this should save about 2W or more.<br />
<br />
==External links==<br />
* [http://kernel.org/pub/linux/kernel/people/lenb/acpi/doc/OLS2006-ondemand-presentation.pdf ''The Ondemand Governor''], Intel Open Source Technology Center (Venkatesh Pallipadi, Alexey Starikovskiy, Len Brown), presentation at Ottawa Linux Symposium, July 19 2006<br />
<br />
[[Category:600X]] [[Category:A20m]] [[Category:A20p]] [[Category:A21e]] [[Category:A21m]] [[Category:A21p]] [[Category:A22e]] [[Category:A22m]] [[Category:A22p]] [[Category:A30]] [[Category:A30p]] [[Category:A31]] [[Category:A31p]] [[Category:i1200]] [[Category:i1300]] [[Category:i1620]] [[Category:G40]] [[Category:G41]] [[Category:R30]] [[Category:R31]] [[Category:R32]] [[Category:R40]] [[Category:R40e]] [[Category:R50]] [[Category:R50e]] [[Category:R50p]] [[Category:R51]] [[Category:R52]] [[Category:R60]] [[Category:R60e]] [[Category:T20]] [[Category:T21]] [[Category:T22]] [[Category:T23]] [[Category:T30]] [[Category:T40]] [[Category:T40p]] [[Category:T41]] [[Category:T41p]] [[Category:T42]] [[Category:T42p]] [[Category:T43]] [[Category:T43p]] [[Category:T60]] [[Category:T60p]] [[Category:T61]] [[Category:X20]] [[Category:X21]] [[Category:X22]] [[Category:X23]] [[Category:X24]] [[Category:X30]] [[Category:X31]] [[Category:X32]] [[Category:X40]] [[Category:X41]] [[Category:X41 Tablet]] [[Category:X60]] [[Category:X60s]] [[Category:Z60m]] [[Category:Z60t]] [[Category:Z61t]] [[Category:Z61e]] [[Category:TransNote]]</div>Sylecnhttps://www.thinkwiki.org/w/index.php?title=Problem_with_CPU_frequency_scaling&diff=50422Problem with CPU frequency scaling2011-02-04T23:53:53Z<p>Sylecn: added known affected models: x201 and t410</p>
<hr />
<div>{{stub}}<br />
<br />
{{WARN|CPU frequency limitation is a safety feature of your ThinkPad, do not work around it! If you have set the BIOS to performance mode and it is still limiting maximum CPU frequency, there is almost always a damn good reason for that}}<br />
<br />
==Symptom==<br />
If the battery pack is removed and the laptop is powered by a 65W AC adapter only, the CPU downclocks to the lowest multiplier and remains locked in low speed. This happens irrespective of the scaling method in use (kernelspace or userspace) and of the frequency governor selected (ondemand, performance, etc.).<br />
<br />
Output of cpufreq-info (on AC power without battery):<br />
<br />
analyzing CPU 0:<br />
driver: centrino<br />
CPUs which need to switch frequency at the same time: 0 1<br />
hardware limits: 1000 MHz - 1.83 GHz<br />
available frequency steps: 1.83 GHz, 1.33 GHz, 1000 MHz<br />
available cpufreq governors: ondemand, userspace, powersave, performance<br />
'''current policy: frequency should be within 1000 MHz and 1000 MHz.'''<br />
The governor "ondemand" may decide which speed to use<br />
within this range.<br />
current CPU frequency is 1000 MHz (asserted by call to hardware).<br />
<br />
analyzing CPU 1:<br />
driver: centrino<br />
CPUs which need to switch frequency at the same time: 0 1<br />
hardware limits: 1000 MHz - 1.83 GHz<br />
available frequency steps: 1.83 GHz, 1.33 GHz, 1000 MHz<br />
available cpufreq governors: ondemand, userspace, powersave, performance<br />
'''current policy: frequency should be within 1000 MHz and 1000 MHz.'''<br />
The governor "ondemand" may decide which speed to use<br />
within this range.<br />
current CPU frequency is 1000 MHz (asserted by call to hardware).<br />
<br />
Output of cpufreq-info (on AC power with battery plugged in):<br />
<br />
analyzing CPU 0:<br />
driver: centrino<br />
CPUs which need to switch frequency at the same time: 0 1<br />
hardware limits: 1000 MHz - 1.83 GHz<br />
available frequency steps: 1.83 GHz, 1.33 GHz, 1000 MHz<br />
available cpufreq governors: ondemand, userspace, powersave, performance<br />
'''current policy: frequency should be within 1000 MHz and 1.83 GHz.'''<br />
The governor "ondemand" may decide which speed to use<br />
within this range.<br />
current CPU frequency is 1000 MHz (asserted by call to hardware).<br />
<br />
analyzing CPU 1:<br />
driver: centrino<br />
CPUs which need to switch frequency at the same time: 0 1<br />
hardware limits: 1000 MHz - 1.83 GHz<br />
available frequency steps: 1.83 GHz, 1.33 GHz, 1000 MHz<br />
available cpufreq governors: ondemand, userspace, powersave, performance<br />
'''current policy: frequency should be within 1000 MHz and 1.83 GHz.'''<br />
The governor "ondemand" may decide which speed to use<br />
within this range.<br />
current CPU frequency is 1000 MHz (asserted by call to hardware).<br />
<br />
==Explanation==<br />
<br />
The 65W AC adaptor does not supply enough power to handle peak power draws from the CPU/disk/GPU on the later ThinkPads. The battery is required to supply the peak demand and ensure correct system operation.<br />
<br />
Messing with this can cause data loss, data corruption, and hardware damage.<br />
<br />
==Solution==<br />
<br />
Make sure no BIOS setting is limiting the CPU frequency range (like "thermal management" = "BALANCED").<br />
<br />
# Buy a 90W AC adapter<br />
# Don't use the laptop without the battery pack<br />
<br />
Other solution than using the laptop with the battery pack always inserted is to add "processor.ignore_ppc=1" to kernel boot command line. This allows to disable BIOS frequency limit, but can be mischievous to the computer if it's power consumption is higher than 65W.<br />
<br />
== Affected Models ==<br />
<br />
* {{Z61m}}<br />
* {{T61}}<br />
* {{T60p}}<br />
* {{X201}}<br />
* {{T410}}<br />
<br />
Probably ALL Lenovo ThinkPads. One can actually track this through the DSDT, but it is not worth the effort.</div>Sylecn