14

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.)

6 Answers 6

12

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.

3
5

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.

#!/usr/bin/env 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
1

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.

2
  • what language would writing such a daemon be easiest in? bash, python, awk? Aug 3, 2012 at 7:43
  • I'd say bash is the simplest. Here's an example (look at lines 55-66).
    – Adobe
    Aug 3, 2012 at 14:54
1

This is how I solved my overheating problems, which were not caused by a specific process, but by failure of my laptop to dissipate the heat caused by running on a high CPU load for longer periods of time. The main difference to the solution offered by jeffythedragonslayer's answer is that I use CPU frequency scaling, instead of using cpulimit on a specific process. Since I have Psensor installed and running anyway, I piggyback on Psensor. A daemon like the other answer suggested should also work, however two thresholds (min and max) are required. In Psensor (Sensor Preferences->Alarm) I set an alarm for the relevant sensor if it becomes higher than the high threshold (I use 85) or lower than the low threshold (I use 80). In Preferences->Sensors->Script executed when an alarm is raised, I call my script heatcontrol.sh like this:

heatcontrol.sh powersave ondemand 82

The first parameter is a valid scaling_governor which reduces CPU frequency, e.g. powersave. The second parameter is the default scaling_governor - ondemand for most systems. The third parameter is a temperature between low and high threshold (the exact value is not important). Psensor adds two more parameters: a sensor ID and the temperature reported.

And this is my heatcontrol.sh script:

#!/usr/bin/env bash
# TempNZ is temperature reported by Psensor; strip of trailing °C
TempNZ=$5 
bnum=$(expr index "$TempNZ" "°")
if (( bnum < 2 )); then
  echo "ERROR"
fi
TempNZ=${TempNZ:0:$(($bnum-1))}
STR=$1
# Is this a low threshold alarm?
if [ "$TempNZ" -le "$3" ]; then
  STR=$2
fi
sudo sh -c "echo '$STR' > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"
# echo new scaling_governor
sudo cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
# play sound - audio feedback - optional
paplay /usr/share/sounds/ubuntu/stereo/message-new-instant.ogg

Works fine for me (UBUNTU 14.04 LTS).

Being a novice to Linux and bash, I used a number of resources, including:

0

"Safe" temperature

The maximum safe temperature for a CPU is usually specified on its technical specs from the manufacturer. A maximum of 100°C is pretty common. You may want to stay several °C below this value to have some margin (safety and maybe longevity of component).

Also, the CPU heating will tranfert some of its heat to the other, physically close, components of your computer. You may want to make some tests and monitor the temperature of these while your CPU is running at 100%, to check if you don't get too close to their limits in the long run. Better to test this during a hot day. :)

Temperature regulation

  • Then you can install thermald which is a program designed to monitor and limit CPU temperature using various techniques.

  • Finally, Intel Core CPUs for example have an internal temperature limiting mechanism that you can configure below the 100°C mentioned above, by choosing a margin in °C.

See this answer for more details.

0

Ubuntu 22.04

need find device /sys/devices/virtual/thermal/cooling_device*/type

with "type" "TCC Offset"

cat /sys/devices/virtual/thermal/cooling_device6/type
TCC Offset

to set max 80C temperature ( 100 - 20 = 80 )

echo 20 > /sys/devices/virtual/thermal/cooling_device6/cur_state

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.