Rev.1, 2008-Apr-27, Cosmetic changes; correction of typos; comment on 3.01
Rev.2, 2008-May-17, Addition of min/max frequency fine tuning
Rev.3, 2010-Nov-15 (after a long absence): I downloaded and set up Lucid (luci-235) on my brand-new hp pavilion dv7-4050eb (with dual-core intel i5 processor). I noticed that Lucid includes a cpu frequency-scaling gui, that automates/replaces the manual work described below, and that works fine. After some research I find the gui has been developed and documented by trio: http://murga-linux.com/puppy/viewtopic.php?t=45143 - thanks trio, great job!
1. Introduction
This HOW-TO explains how to keep your cpu cool and your fan quiet, practically without affecting performance, by cpu frequency-scaling. This method employs the dynamic in-kernel ondemand governor, that changes cpu clock frequency (and supply voltage) at run time according to cpu load. Don't worry, it's much simpler than it sounds.
Note that bits and pieces on cpu frequency-scaling can be found in various forum threads. This HOW-TO intends to bring the pieces together into a well-documented, consistent and correct text.
2. What to expect
Summary of the findings on my laptop (hp/compaq nx9030) running pcPuppyOS rc6 (a 3.01 derivative) at ambient room temperature (around 20°C):
before frequency-scaling
- cpu temperature (monitored with conky) was constantly around 60...62° C,
- the fan was blowing roughly half-time, switching on/off every minute or so,
- the battery was drained from full to empty in some 55 to 60 minutes.
with frequency-scaling
- cpu stays below 50°C,
- the fan is completely silent (it never blows),
- the battery lasts for some 70 minutes,
- user responsiveness is not noticeably affected.
Note that the method described here only saves power on the cpu; there may be room for further power saving on other parts of the system. In comparison, WinXP/SP2 appears to be slightly more power-conservative overall (the battery lasts for some 75 minutes) even though the fan occasionally blows.
Comment 2008-Apr-27
I have applied this method on four Puppy versions (vanilla 2.16.1, vanilla 3.01, and 3.01 derivatives pcPuppyOS rc6 and final). For an as yet unknown reason (under investigation), the method described here appears to be much less effective for vanilla 3.01. In this case, it helps to reduce the maximum frequency.
Percentage of time spent at the highest cpu frequency (see section 4.3) for fairly light usage of the laptop:
- for Puppy 2.16.1: 0...4%
- for pcPuppyOS: 0...4%
- for Puppy 3.01: 60...65%
3. Outline of steps
(1) For background, read detailed explanation (section 4)
(2) Copy/paste below code section into /etc/rc.d/rc.local
(3) Uncomment/comment appropriate lines
(4) Reboot
The code has just three active lines. That's all!
Code: Select all
# cpu frequency-scaling (to save energy and to keep the system cool)
# step 1: load cpu driver, setup cpufreq system
#modprobe speedstep-lib # library, not needed
#modprobe acpi-cpufreq # generic
#modprobe p4-clockmod # Intel
modprobe speedstep-centrino # Intel Centrino
#modprobe speedstep-ich # Intel
#modprobe speedstep-smi # Intel
#modprobe powernow-k6 # AMD
#modprobe powernow-k7 # AMD
#modprobe powernow-k8 # AMD
#modprobe longrun # Transmeta
#modprobe longhaul # VIA Technologies
#modprobe e_powersaver # VIA Technologies
#modprobe cpufreq-nforce2 # nVidia
#modprobe gx-suspmod # Cyrix Media
# step 2: load driver(s) for frequency-scaling mode(s)
modprobe cpufreq_ondemand # ondemand mode
#modprobe cpufreq_powersave # powersave mode (not used)
#modprobe cpufreq_conservative # conservative mode (not used)
#modprobe cpufreq_userspace # userspace mode (not used)
# step 3: min/max fine-tuning; launch ondemand frequency-scaling mode
# replace [min] resp. [max] with numeric values from available frequencies
#echo [min] > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
#echo [max] > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
4.1. Background reading
Many cpus have mechanisms to save power by changing the core supply voltage and clock frequency at run time. These are described in detail in the 16-page document Ref.1 "The ondemand governor". You should read this document as background. A quick reading should suffice, it's not necessary to bother about the fine details.
4.2. Manual set-up method
Before modifying rc.local, it is useful to boot from fresh (e.g. from live-CD with pfix=ram boot option) and to find out manually (using rxvt) which modules are required.
4.2.1. Step 1: load appropriate cpu frequency-scaling driver
These modules are in directory
/lib/modules/2.6.21.7/kernel/arch/i386/kernel/cpu/cpufreq/
The modules (shown using ls of this directory) are speedstep-lib, acpi-cpufreq, p4-clockmod, speedstep-centrino, speedstep-ich, speedstep-smi, powernow-k6, powernow-k7, powernow-k8, longrun, longhaul, e_powersaver, cpufreq-nforce2, gx-suspmod.
Module speedstep-lib is a library for common functions for Intel SpeedStep v.1 and v.2 support. On my laptop it can be modprobed without errors, but it's apparently not needed and so I don't load it. Some other modules may depend on it and load it automatically.
The other modules are the actual drivers. Insofar I found on the web, p4-clockmod and speedstep-x are Intel, powernow-x are AMD, longrun is Transmeta, longhaul and e_powersave are VIA Technologies, cpufreq_nforce2 is nVidia, gx-suspmod is Cyrix Media.
Evidently only one driver is needed. The drivers will not load on the "wrong" hardware, so it is safe to try each driver in turn when in doubt as to which is the correct one.
On my laptop (with Intel Centrino):
- modprobing acpi-cpufreq or p4-clockmod gives the error message
Code: Select all
FATAL: Error inserting <module> (...): Device or resource busy
Code: Select all
FATAL: Error inserting <module> (...): No such device
Successful modprobing of the correct cpu frequency-scaling driver also sets up the filesystem for frequency scaling, under /sys/devices/system/cpu/cpu0/cpufreq/
4.2.2.Step 2: load driver(s) for frequency-scaling governor(s)
The driver modules (cpufreq_xxx with xxx = powersave, ondemand, conservative and userspace) are in directory /lib/modules/2.6.21.7/kernel/drivers/cpufreq/
There are five frequency-scaling governors:
- performance is a static mode, that runs the cpu constantly at its highest frequency (this mode has/needs no driver module and is default in Puppy),
- powersave is a static mode, that runs the cpu constantly at its lowest frequency (this mode uses least power; on my laptop user responsiveness is clearly degraded as seen e.g. when dragging a window)
- ondemand is a dynamic mode, that rapidly switches cpu frequency according to cpu load, in order to minimize power use with virtually no performance loss,
- conservative is a variant of ondemand, see Ref.1.
- userspace requires additional tools, see Ref.1.
You should modprobe the cpufreq-xxx driver(s) for all governors that you intend to use. In my case, I only use ondemand. Also performance and powersave governors may be useful, resp. for maximum speed and for minimum power consumption. In Puppy, I see little or no use for the conservative and userspace governors.
4.2.3. Step 3: activate frequency-scaling governor
This is done by writing the selected governor into the scaling_governor file, e.g.
Code: Select all
echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
These files are in directory /sys/devices/system/cpu/cpu0/cpufreq/
(this directory is set up by the cpu frequency-scaling driver)
In this directory, you can inspect at any time (from rxvt):
- available governors, by catting scaling_available_governors
- the active governor, by catting scaling_governor
- available cpu frequencies, by catting scaling_available_frequencies
- the current cpu frequency, by catting cpuinfo_cur_freq,
- frequency statistics, by catting stats/time_in_state
The active scaling governor takes into account the maximum and minimum frequencies as specified in the files scaling_max_freq and scaling_min_freq. Maybe, in ondemand mode, you find that the fan is still blowing too much to your taste. Maybe, in powersave mode, you find that your laptop is too slow to your taste. Then you may select another maximum resp. minimum cpu frequency, from the list of available frequencies in scaling_available_frequencies, and write it to file scaling_max_freq resp. scaling_min_freq.
4.4. Boot-time configuration
Copy/paste the rc.local code section as shown higher, and comment/uncomment the appropriate lines according to the required modules, as identified manually. The selected governor is then active after every reboot.
5. Further comments
(1) Above discussion applies to systems with one cpu (cpu0).
(2) I have tested above method on Puppy 2.16.1, Puppy 3.01, pcPuppyOS rc6 and pcPuppyOS final, and I expect it to work for all Puppy versions 2.13 and higher. For lower versions, cfr. Ref.4
(3) The ondemand mode can be further tuned if so desired. The parameter files are in directory /sys/devices/system/cpu/cpu0/cpufreq/ondemand
I personally did not experiment with these, since I'm perfectly satisfied with the default settings.
(4) Kazm has written a GUI script that autodetects the cpu type, cfr his post further down this thread and cfr Ref.4 (I have not tested it).
6. References
Ref.1 "The Ondemand Governor"
http://kernel.org/pub/linux/kernel/peop ... -paper.pdf
Ref.2 "Power management" (wikipedia)
http://en.wikipedia.org/wiki/List_of_CP ... chnologies
Ref.3 "Linux Kernel Documentation / cpu-freq"
http://www.mjmwired.net/kernel/Documentation/cpu-freq
Ref.4 "Howto get CPU frequency scaling to work in 2.xx"
http://www.murga-linux.com/puppy/viewtopic.php?t=12019
Ref.5 "Prozessorauslastung minimieren / optimieren?"
http://www.murga-linux.com/puppy/viewtopic.php?t=25669