CPU Fan Control on ThinkPad Laptop

I have a Lenovo ThinkPad laptop that occasionally displays error messages about "Hardware events/THERMAL EVENTS" during times of high CPU usage.  This is a scary set of messages in the journal logs that could prophecy a short life span of the CPU if neglected; at times I've suspected that it may have been the culprit of system crashes, though, I won't go into further details on that here.

It's worth noting that the performance improves and error messages subside after one disassembles the laptop and cleans out the heat sink; maybe even properly applies a fresh coat of thermal compound on it.  This improvement, however, never lasts too long as the dust accumulates within the heatsink area again.

I can recall reading anecdotal evidence of this problem from other ThinkPad owners on the Lenovo forums and other places when I first came across these scary messages on my system.  Those owners running Linux on their laptops offered explanations about the poor air flow around the CPU socket, cheap parts, bad chassis design, and/or other guesstimates trying to rationalize this phenomenon.  However, I always wondered why I had no noticeable performance issues when I was running Windows.  Even though there was no Windows equivalent to dmesg or journal messages that would notify with instantaneous alerts, the CPU fan activity seemed to be more aggressive and responsive than on Linux; one can argue that this is due to the resource-intensive nature of a Winblows Operating System, still, something didn't quite add up.  As we all know the reluctance of most major OEMs to work with the Open Source community is, as always, a major hurdle for Kernel- and otherwise FOSS developers that deal with hardware devices.  Developing generalized blanket solutions for an ever-growing pool of hardware devices and their proprietary low-level software leaves the Linux community to their own devices--no pun intended--to rectify the situation.

There are a number of different ways to use software in Linux to, perhaps, improve the CPU fan performance and, subsequently, extend your system's lifespan through better CPU/chassis cooling of the ThinkPad laptops.  As always with ThinkPad-related Linux issues, the thinkwiki is a great source of information; the "Fan Control Scripts" and "Thinkpad-acpi" wiki pages are of particular use related to this issue.

Besides third-party projects that may or may not be in your distribution's repositories, e.g. tpfanco and thinkfan, the lm_sensors package, which is included in most distros' repos, comes with a fancontrol program (bash script) that can be easily configured with the pwmconfig command.  The prerequisite for, probably, all of the methods related to manually overriding CPU fan control is to pass some options to the thinkpad_acpi module.  This can be accomplished by executing the following command to save the options persistently to a file:

# echo options experimental=1 fan_control=1 > /etc/modprobe.d/thinkpad_acpi.conf

You may have to reboot the system for these changes to take affect.  Once this prerequisite is fulfilled, you can continue with the pwmconfig command.  The process looks something like this:

# pwmconfig
# pwmconfig revision 6166 (2013-05-01)
This program will search your sensors for pulse width modulation (pwm)
controls, and test each one to see if it controls a fan on
your motherboard. Note that many motherboards do not have pwm
circuitry installed, even if your sensor chip supports pwm.

We will attempt to briefly stop each fan using the pwm controls.
The program will attempt to restore each fan to full speed
after testing. However, it is ** very important ** that you
physically verify that the fans have been to full speed
after the program has completed.

Found the following devices:
   hwmon0 is acpitz
   hwmon1/device is thinkpad
   hwmon2/device is coretemp

Found the following PWM controls:
   hwmon1/device/pwm1           current value: 255

Giving the fans some time to reach full speed...
Found the following fan sensors:
   hwmon1/device/fan1_input     current speed: 4365 RPM

Warning!!! This program will stop your fans, one at a time,
for approximately 5 seconds each!!!
This may cause your processor temperature to rise!!!
If you do not want to do this hit control-C now!!!
Hit return to continue: 

Testing pwm control hwmon1/device/pwm1 ...
  hwmon1/device/fan1_input ... speed was 4365 now 4150
    no correlation

No correlations were detected.
There is either no fan connected to the output of hwmon1/device/pwm1,
or the connected fan has no rpm-signal connected to one of
the tested fan sensors. (Note: not all motherboards have
the pwm outputs connected to the fan connectors,
check out the hardware database on http://www.almico.com/forumindex.php)

Did you see/hear a fan stopping during the above test (n)? y

Testing is complete.
Please verify that all fans have returned to their normal speed.

The fancontrol script can automatically respond to temperature changes
of your system by changing fanspeeds.
Do you want to set up its configuration file now (y)? 
What should be the path to your fancontrol config file (/etc/fancontrol)? 

Select fan output to configure, or other action:
1) hwmon1/device/pwm1  3) Just quit           5) Show configuration
2) Change INTERVAL     4) Save and quit
select (1-n): 1

hwmon0 is acpitz
hwmon1/device is thinkpad
hwmon2/device is coretemp

Current temperature readings are as follows:
hwmon0/temp1_input      48
hwmon2/device/temp1_input       55
hwmon2/device/temp2_input       56
hwmon2/device/temp3_input       49
hwmon2/device/temp4_input       50
hwmon2/device/temp5_input       47

Select a temperature sensor as source for hwmon1/device/pwm1:
1) hwmon0/temp1_input
2) hwmon2/device/temp1_input
3) hwmon2/device/temp2_input
4) hwmon2/device/temp3_input
5) hwmon2/device/temp4_input
6) hwmon2/device/temp5_input
7) None (Do not affect this PWM output)
select (1-n): 2

Enter the low temperature (degree C)
below which the fan should spin at minimum speed (20): 

Enter the high temperature (degree C)
over which the fan should spin at maximum speed (60): 

Enter the minimum PWM value (0-255)
at which the fan STOPS spinning (press t to test) (100): 

Enter the minimum PWM value (100-255)
at which the fan STARTS spinning (press t to test) (150): 

Enter the PWM value (0-100) to use when the temperature
is below the low temperature limit (0): 

Enter the PWM value (100-255) to use when the temperature
is over the high temperature limit (255): 

Select fan output to configure, or other action:
1) hwmon1/device/pwm1  3) Just quit           5) Show configuration
2) Change INTERVAL     4) Save and quit
select (1-n): 5

Common Settings:

Settings of hwmon1/device/pwm1:
  Depends on hwmon2/device/temp1_input

Select fan output to configure, or other action:
1) hwmon1/device/pwm1  3) Just quit           5) Show configuration
2) Change INTERVAL     4) Save and quit
select (1-n): 4

Saving configuration to /etc/fancontrol...
Configuration saved

The configuration file that's created looks like this:

# cat /etc/fancontrol 
# Configuration file generated by pwmconfig, changes will be lost
DEVPATH=hwmon1=devices/platform/thinkpad_hwmon hwmon2=devices/platform/coretemp.0
DEVNAME=hwmon1=thinkpad hwmon2=coretemp
FCFANS= hwmon1/device/pwm1=

The user can also create this file or make changes to it even without running the pwmconfig utility, though, the initial setup is probably best done with pwmconfig.

There may be utilities and methods, or even configuration options to fancontrol, that offer a more responsive way to step through the different "levels" of CPU fan speed; however, since this option is already in the RHEL7 repos it's one of the easier options to implement a more aggressive cooling policy before it's too late for the CPU.

NOTE: This method is, potentially, dangerous.  Read all pertinent warnings and instructions carefully before you embark on this journey.  Also, I'm assuming that the user has lm_sensors properly configured, though, I'm not sure if this is a prerequisite for the pwmconfig/fancontrol utility.


Popular posts from this blog

RHEL 7 and CentOS 7 syslog Rate Limit

Set Focus to Follow Mouse Cursor in GNOME 3

Centos 7 pulseaudio