1 AUTHOR: Ken Moffat <ken@kenmoffat.uklinux.net>
4 SYNOPSIS: cpu frequency scaling using the kernel or powernowd.
5 DESCRIPTION: With processors that support it (e.g. recent athlon64,
6 many laptop processors), you can reduce the processor frequency, to
7 reduce wasted energy or conserve battery power.
9 PREREQUISITES: 2.6.9 or later kernel, the bootscripts target LFS-6.1
17 Frequency scaling is an important part of increasing the battery life
18 of notebooks, but it also has a place in reducing power consumption,
19 and thus waste heat, on desktops and servers. Most CPUs that support
20 it will have at least two valid frequency/voltage settings, e.g. my
21 athlon64 Winchester 3200 (2.0 GHz) can run at approx 1.0 GHz, 1.8 GHz,
22 and 2.0 GHz. Give the ondemand governor a heavy load and the speed
23 quickly ramps up. After the load has fallen back, the speed will
24 first fall to 1.8 GHz and then some seconds later to 1.0 GHz.
26 The kernel began by offering 'powersave' (slow) and 'performance'
27 (fast) drivers, with a 'userspace' alternative to allow a daemon to
28 dynamically change the frequency. As of 2.6.9, an 'ondemand' driver
29 was made available. Other demand-based governors, such as
30 'conservative', have been introduced in later kernels.
32 Meanwhile, the powernowd daemon was developed, see
33 http://www.deater.net/john/powernowd.html - this will dynamically
34 change the frequency as the load goes up and down.
36 It would seem that the 'ondemand' driver makes powernowd redundant,
37 but some CPUs (like the ppc 7447) apparently have a very high
38 transition latency which causes the ondemand governor to decline to
39 manage them - on my 7447A the powersave and performance drivers
40 ('governors') work, but trying to install 'ondemand' fails. Equally,
41 on a laptop powernowd will probably be a little quicker at dropping
42 the speed, and can therefore give a little more battery life.
44 On x86 and x86_64 it appears that your bios has to support frequency
45 scaling (typically labelled Cool'n'Quiet on boards with AMD CPUs) -
46 after upgrading to a new mobo/cpu, I lost the ability to use both the
47 'ondemand' governor and powernowd until I configured the bios properly.
53 On the Processor menu, select CPU Frequency scaling
55 Set the Default CPUFreq governor to userspace (the default is often
58 Select the governors you wish to use, typically 'performance',
59 'powersave', and try 'ondemand'. Feel free to select any other
60 available governors. I assume most people will want to build these
61 governors in, rather than compiling them as modules.
63 Select the correct cpu-freq hardware driver (on a mac there is nothing
64 further to select, on x86, choose from POWERNOW_K7, POWERNOW_K8,
65 SPEEDSTEP_CENTRINO, and similar options).
71 After you've booted the new kernel, you can test which of the kernel
72 governors work. As root, echo the governor name to
73 /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor - presumably,
74 people with SMP boxes need to try this for each CPU. Then test the
75 status of the command, e.g. with 'echo $?' - if the governor loaded,
76 the status will be 0 and you can use that governor, otherwise the
79 You can view the current CPU frequency in /proc/cpuinfo. To test the
80 ondemand or other variable-speed governors, run something "expensive"
81 (e.g. untar the gcc .bz2, or do a big compile) and repeatedly check
82 the spead in the cpuinfo file. You should find that it ramps up
83 shortly after the load starts, and falls back a few seconds after the
84 load drops. [ BUT, if you are in an xterm on a kernel > 2.6.12-rc5,
85 see the ignore_nice line in my bootscript below. ]
88 Bootscript for kernel cpufreq
89 _____________________________
91 If one or more of the demand-based governors works for you, you're
92 almost done, you just need to ensure the appropriate governor is
93 loaded after you boot. For my desktop box (athlon64) I use the
96 cat >>/etc/rc.d/init.d/cpufreq << EOF
104 boot_mesg "Enabling ondemand cpu frequency"
106 >/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
107 boot_mesg "ignoring niceness for ondemand"
109 >/sys/boot/devices/system/cpu0/cpufreq/ondemand/ignore_nice
112 boot_mesg "Enabling powersave cpu frequency"
114 >/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
117 boot_mesg "Enabling performance cpu frequency"
119 >/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
122 echo "Usage: ${0} {start|demand|powersave|performance}"
128 chmod 754 /etc/rc.d/init.d/cpufreq
130 ln -s ../init.d/cpufreq /etc/rc.d/rcsysinit.d/S45cpufreq
132 Note that this allows me to set powersave or performance if I ever wish
133 to, and that I just install this in rcsysinit.d so there is no 'stop'
136 The 'ignore_nice' ensures the old behaviour of ondemand for kernels
137 newer than 2.6.12-rc5 : without this, anything I start in an xterm has a
138 niceness of 10 and the kernel doesn't allow it to influence the cpu
146 This is based on 0.96. Untar it, you'll notice the Makefile is
147 described as -very- simple. Unfortunately, it installs into /usr/sbin
148 - on a laptop, you probably want to bring it up as part of the boot
149 process, so I think it belongs in /sbin. The easy way to do that is
151 make && install -m 755 powernowd /sbin
153 There is an example powernowd.init in the package, which could be
154 adapted for the bootscript, using variations of "dyn" (dynamic), "low",
155 "high" - I go with something a little simple - dynamic frequency
156 control at all times:
158 Bootscript for powernowd
159 ________________________
161 cat >>/etc/rc.d/init.d/powernowd << EOF
169 boot_mesg "Starting powernowd"
170 loadproc /sbin/powernowd
173 boot_mesg "Starting powernowd"
174 statusproc /sbin/powernowd
177 boot_mesg "Starting powernowd"
178 killproc /sbin/powernowd
181 echo "Usage: ${0} {start|status|stop}"
187 chmod 754 /etc/rc.d/init.d/powernowd
189 ln -s ../init.d/powernowd /etc/rc.d/rcsysinit.d/S45powernowd
190 ln -s ../init.d/powernowd /etc/rc.d/rc0.d/K45powernowd
191 ln -s ../init.d/powernowd /etc/rc.d/rc6.d/K45powernowd
196 Barry Shilliday for bringing the scaling_governors to my attention
197 in an article in PC Plus magazine.
199 Eric Piel for explaining how to restore the old behaviour for the
206 2005-07-12 First version.
209 Updated versions of this hint may be found at
210 http://www.kenmoffat.uklinux.net/hints/