Friday, September 20, 2013

Automatically Reduce CPU Utilization When Computer Overheats

I love my Lenovo X61, but it sucks pretty badly now from old age. My keyboard has been replaced twice (yes, you can buy them on eBay, here), my tablet pen no longer works, and the cooling fan has died (not to be confused with fan death: link here).

My big issue is computer overheating – due to the dead fan. If I run anything CPU intensive, and leave my power setting to ”Maximum Performance,” the computer turns itself off in less than a minute because the CPU gets too hot (at around 95 degrees, Celsius). My solution up to this point has been to run things in a low power setting – the “Power Saver” mode. Under the power options, if you select the “Power Saver” mode, and then select “Change advanced power settings,” you can lower the maximum processor state of the power modes. For me, I have set the maximum state for the “Power Saver” mode to 50% – meaning that CPU intensive activities run at half speed.

image

image

The better solution I just come up with now automatically throttles between the “Maximum Performance” and “Power Saver” mode, base on the temperature of the CPU. It allows me to run CPU intensive programs a bit faster, and I don’t have to be mindful of the power mode I am in. Sometimes, the computer turns itself off unexpectedly because some programs started to use the CPU intensively. At other times, I run Matlab and forget to change the power mode. The automatic throttle eliminates these two problems.

To get the automation up, I use two batch files, a VB script, and the utility program CoreTemp. Alternatively, SpeedFan (project page here) should also work – but that program crashes (BSOD) my computer.

You can download CoreTemp from the project page (here). On the project page, if you click on the “More downloads…” link, it will give you the option to download the standalone version of the program. The standalone version is packaged as a ZIP file. You can just download the file, unzip the file to a location where you keep you program files, and run the exe program. I recommend the standalone version because the regular version contains an installer that VirusTotal flags as dangerous (over 10 of the virus scanners think the program is dangerous).

After starting the CoreTemp program, go to the Overheat Protection option:

image

Here are the “Overheat Protection” settings I am using, which runs a batch file when the CPU temperature goes over 92 degrees.

image

Under Options –> Settings, you can set CoreTemp to start with Windows. You can also put a program shortcut in the Start Up folder. Note that I set the polling to every 3 seconds instead of every 1 second.

image

The content of the batch file, TempPowerMin_invisible.bat (one line) is the following:

"C:\Windows\System32\wscript.exe" "C:\Programs\BIN\invisible.vbs" "C:\Programs\BIN\TempPowerMin.bat"

The batch file runs a VB script with another batch file as the argument. The VB script hides the command prompt that normally appears when batch files are ran. You will need to change “C:\Programs\BIN\” to reflect the path of your batch file location. Because I basically run a batch file that changes the power modes back and forth, hides the command prompt is very convenient.

Here is the content of the VBS file, invisible.vbs (see reference 1):

CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False

Finally, here is the content of the other batch file, TempPowerMin.bat:

C:\Windows\System32\powercfg.exe -setactive  a1841308-3541-4fab-bc81-f71556f20b4a
sleep 60
C:\Windows\System32\powercfg.exe -setactive 1e748f75-2189-40dd-9fc0-09b37de01e03

The bath file TempPowerMin.bat uses the powercfg.exe program to change the power mode to “Power Saver”, wait a minute for the CPU to cool down, and then change the power mode back to “Maximum Performance”. To find the power modes, you need to run the following command to get the power mode ID: POWERCFG –L. I suspect every computer’s power mode IDs are different, so you will need to run this and replace the power mode ID in your batch file.

image

After the setup, you can now just leave the power mode at “Maximum Performance”. The CoreTemp program will run the batch file to change the power mode if the CPU overheats.

Reference 1: http://superuser.com/questions/62525/run-a-completly-hidden-batch-file
Reference 2: https://www.youtube.com/watch?v=wVMe8IPaXn4