Since nobody replied, I decided to figure out how things work. The following bash script has been tested in Fedora 12, and most likely won't work in other versions. First, the script:
Code:
#!/bin/sh
# Script to throttle cpu speed.
# Works for any number of cpus, but only tested on Fedora 12.
# I have no idea how long this will be around,
# see http://patchwork.kernel.org/patch/43071 for more info.
if [ -n "$1" ]
then
let "state = $1 + 0"
if [ "$state" -ne "$1" ] || [ "$state" -lt "0" ]
then
echo "Usage: `basename $0` [ non-negative integer ]"
exit 1
fi
for device in `ls -d /sys/devices/virtual/thermal/cooling_device*`
do
if [ "`cat $device/type`" = "Processor" ]
then
let "max_state = `cat $device/max_state`"
if [ "$state" -gt "$max_state" ]
then
echo $max_state > "$device/cur_state"
else
echo $state > "$device/cur_state"
fi
fi
done
fi
echo "Current CPU thermal cooling states:"
for device in `ls -d /sys/devices/virtual/thermal/cooling_device*`
do
if [ "`cat $device/type`" = "Processor" ]
then
echo "$device = `cat $device/cur_state` "
fi
done
exit 0
For testing, I ran two threads of Prime95 to push both CPUs to 100%. Setting cur_state to 1 capped the CPU frequency at roughly 75%, 1.33GHz on a 1.73GHz duo core processor. It's a laptop, so both CPUs bumped against 99C even at 1.33GHz. Setting cur_state to 2 dropped the frequency to 800MHz, and dropped the temperatures to 86C. With just one thread running, which simulates one runaway process, the maximum temperature was 94C for a cur_state of 1. I'm not sure if it's my BIOS, or Fedora, but the thread switches between CPUs to balance the temperatures. See the attached screenshot.
This mimics the behaviour of the Windows power manager. The default maximum battery life scheme for Toshiba laptops limits the CPU frequency to 50%.
dd_wizard
P.S. You can run the script as an unprivileged user to display the current states, but you need to run it with su -c "cputhrottle 2" to write to the files.