Temperature and CPU Frequency Control with Linux

Modern CPU's can be power-hungry beasts, and they can also run quite hot. Take, for example, the highest speed offerings from both Intel and AMD. Intel's 3.0 Gigahertz Yorkfield Quad-core is rated to consume about 130 Watts of power, while AMD's 3.0 Gigahertz 6000+ Dual-core is rated to consume about 125 Watts. Fortunately, modern processors from both companies now include a power-saving technology known as CPU Frequency Scaling. So, when super-high speeds aren't needed, the frequency will get scaled back, so that the CPU consumes less power and runs cooler. (AMD's implementation of this is called Cool n' Quiet, and Intel's implementation is called SpeedStep.) This is all supposed to happen automatically, but there may be times when you'll want to control it manually. Here's one example of why.

I've always had an interest in science, and several years ago I became a fan of distributed computing projects that contribute to scientific research. The one that I most avidly support is Einstein-at-Home. (This project helps search for gravitational waves, in an effort to find pulsars, and to help prove Einstein's Theories of Relativity.)

When you purchase or build a computer, Cool n' Quiet or SpeedStep will be enabled by default. So, a computer with a 3.0 Gigahertz processor, running with a light load, might only have its processor running at 1.0 or 2.0 Gigahertz. When I built my last few computers and loaded them with Linux, I found that my Einstein-at-Home work wasn't being recognized as a heavy load, and my workunits were getting processed at a snail's pace. So, I would just enter the BIOS setup for those machines, and disable Cool n' Quiet or SpeedStep. That works fine, except with the latest one that I built.

I built my newest machine with an AMD 5200+ processor. It's a new Brisbane-core, 65-nanometer job with a rated power consumption of only 65 Watts. It's also rated to run at 2.7 Gigahertz. Unfortunately, it came with the dinkiest little heatsink and cooling fan that I've ever seen on a modern processor. At full load with Einstein, and at full 2.7 Gigahertz speed, it overheats and shuts down in a matter of three to five minutes. Since I don't have another cooling solution at the ready, I needed to find a way to run this without having it overheat.

lm-sensors/lm_sensors

Since at least as far back as the Pentium III days, motherboard manufacturers have installed temperature, fan speed, and voltage sensors on their products. By default, most Linux distros don't come with pre-installed utilities to take advantage of them. That's easy enough to correct; just install "lm sensors".

On a Debian or an Ubuntu system, enter:

sudo apt-get install lm-sensors

On Red Hat, CentOS, or any other Red Hat derivative, enter:

sudo yum install lm_sensors

(Note that the Debian/Ubuntu command had a dash in the package name, while the Red Hat command has an underscore.)

After you've installed the package, run the program by entering:

sensors

or, if you want temperature readings to be in Fahrenheit, enter:

sensors -f

This may work right off-the-bat on some systems, but on other systems you may get a message about how you need to configure the sensors, first. You'd do that by entering:

sudo sensors-detect

This utility will guide you through the process, and configure things for you when it's done.

Additionally, on some systems, you may have to load the proper kernel modules:

Now, you should be able to get an output when you run the "sensors" command. What you see will differ from one machine to the next, since every motherboard manufacture uses different types of sensors. On some machines, you'll see a whole raft-load of information concerning voltages, fan speeds, and temperatures. On other systems, you may not see anything except for CPU temperatures.

When I found that my 5200+ machine wouldn't run for any length of time with Cool n' Quiet disabled, I installed the lm-sensors package, and confirmed what I'd suspected. When running at the full 2.7 Gigahertz speed, the temperature would climb rapidly, until it reached the shutdown temperature of 212 degrees Fahrenheit.

cpufreq-selector

This utility comes as part of the "gnome-applets" package, and should already be installed on your system if you're running a Gnome desktop. (Even if you're running a KDE-type distro, such as Kubuntu, you can still install "gnome-applets" from the repository.) You can use this to dynamically control your CPU's speed from the command-line.

To use it, you first need to have a system with a fairly recent CPU. (Meaning, an Athlon64 or newer from AMD, or at least a Core 2 or newer from Intel. I'm not sure about Intel's Pentium 4's.) You also need to ensure that either Cool n' Quiet or SpeedStep is enabled in your machine's BIOS. By default, your CPU will now run at a slower-than-rated speed.

I first tried using the "performance" setting with the following command:

sudo cpufreq-selector -g performance

However, that just made the CPU run at full speed, again causing it to shutdown after only a few minutes. Next, I tried setting the CPU to a specific speed. For example, to run it at 2.4 Gigahertz, I would enter:

sudo cpufreq-selector -f 2400000

At night, when I have a cool breeze blowing through the back door, I can sometimes get by with increasing the speed to 2.6 Gigahertz.

sudo cpufreq-selector -f 2600000

To verify your CPU speed, use the "cat" utility:

cat /proc/cpuinfo

Conclusion

No, this isn't the ideal solution. I'd much rather be running my new CPU at full speed. But, at least, with cpufreq-selector, I can run it while waiting for a chance to purchase a new cooling unit.