Limit CPU usage in terms of temperature
I run distributed computing projects, which typically want to use 100% of the CPU. How do I limit the CPU usage in terms of temperature instead of percent usage? Also, what is the maximum safe temperature to keep an Intel i5 running 24/7? (With no CPU limit FahCore_a4 causes this machine to run at 82 degrees Celsius.)
Solution 1:
On this webpage there is a bash script that will attempt to keep your CPU below a specified temperature. http://seperohacker.blogspot.com/2012/10/linux-keep-your-cpu-cool-with-frequency.html
You just need to provide it with your desired maximum temperature, and it will throttle your CPU(s) in an effort to stay below that temperature.
Shameless plug- I wrote and maintain the above script.
Solution 2:
Here is how I solved it using bash. If anyone comes up with a better daemon (better at staying near the target temperature) please post it.
#!/bin/bash
while true; do
val=$(sensors | awk '/Core 0/ {print $3}')
max="+60.0"
if [[ "$val" < "$max" ]]
then
killall cpulimit
sleep .1
else
cpulimit -e FahCore_a4 -l 99 &
sleep 1
fi
clear
sensors
done
Solution 3:
The CPU itsself has a mechanism where it powers itsself down if it gets too hot. (maybe not if you disable SMI interrupts, I'm not sure about that.)
The main user-space application is the lm-sensors
package. After installing it run sensors-detect
to set it up, if your machines are the same you can run this once, and use the resulting findings everywhere.
CPU frequency is easily controled via the cpufreq driver subsystem. see https://wiki.archlinux.org/index.php/CPU_Frequency_Scaling
You could write a daemon that uses lm-sensors to poll the temp and if its too hot turn down the cpu frequency.