Fan speed control

From Gentoo Wiki
Jump to: navigation, search


Most systems have fans to control the temperature of CPUs and other chips. Typically the speed of the fan or fans is controlled by the BIOS, but it may be possible to control the fan speed with userspace utilities. Reasons for wanting to deviate from BIOS controlled fans could be that the BIOS makes them spin too much (resulting in too much noise), or too slow (resulting in too high temperatures).

This article discusses two of those userspace utilities:

  • fancontrol, and
  • thinkfan

Controlling fan speed is not supported on all computers. The computer needs to have:

  • A BIOS that allows users to control the fan speed
  • A motherboard capable of regulating fan speeds
  • Fans that allow their speed to be controlled

Fans have 2, 3, or 4 wires:

  1. ground
  2. fan voltage
  3. tacho
  4. PWM

Fans with 2 or 3 wires may have voltage regulation: higher voltage (typically up to 12 Volt) results in higher rotation per minute (RPM). Fans with 4 wires are controlled through pulse width modulation (PWM), in theory a more efficient way of controlling the fan speed. The third wire provides feedback on the actual RPM of the fan.

It is generally considered more safe to have the BIOS or dedicated hardware control the fans.

There are two risks when manually controlling fan speeds:

  1. What if the program controlling the fans fails? The computer could overheat and parts could be destroyed.
  2. Higher temperatures cause more wear on the electronics, resulting in a shorter lifespan.


Fancontrol is a generic fan control script provided by package sys-apps/lm-sensors which can run as a system daemon. First install lm-sensors as described in lm_sensors. Make sure that any Super I/O chip is enabled in the kernel, and its module loaded.

Temperature measurement

Verify that temperatures are measured and that there are fans shown with the sensors command:

root #sensors
Adapter: ISA adapter
Vcore:                  +1.24 V  (min =  +0.00 V, max =  +1.74 V)
in14:                   +1.67 V  (min =  +0.00 V, max =  +0.00 V)
fan1:                   490 RPM  (min =    0 RPM)
fan2:                     0 RPM  (min =    0 RPM)
fan3:                     0 RPM  (min =    0 RPM)
fan4:                     0 RPM  (min =    0 RPM)
fan5:                     0 RPM  (min =    0 RPM)
fan7:                     0 RPM  (min =    0 RPM)
SYSTIN:                 +28.0°C  (high = +80.0°C, hyst = +75.0°C)  sensor = thermistor
CPUTIN:                 +28.5°C  (high = +80.0°C, hyst = +75.0°C)  sensor = thermistor
AUXTIN0:               +104.0°C    sensor = thermistor
AUXTIN1:               +114.0°C    sensor = thermistor
AUXTIN2:               +114.0°C    sensor = thermistor
AUXTIN3:                -12.0°C    sensor = thermistor
PCH_CHIP_TEMP:           +0.0°C
PCH_CPU_TEMP:            +0.0°C
PCH_MCH_TEMP:            +0.0°C

Adapter: ACPI interface
temp1:        +36.0°C  (crit = +95.0°C)

Adapter: ISA adapter
Package id 0:  +36.0°C  (high = +105.0°C, crit = +105.0°C)
Core 0:        +34.0°C  (high = +105.0°C, crit = +105.0°C)
Core 1:        +35.0°C  (high = +105.0°C, crit = +105.0°C)
Core 2:        +35.0°C  (high = +105.0°C, crit = +105.0°C)
Core 3:        +35.0°C  (high = +105.0°C, crit = +105.0°C)

Note that not all sensors and fans may be connected and/or provide sensible values. In this case:

  • The system has only one fan; fan2 to fan6 are not connected
  • Temperature readings for AUXTIN0 to PCH_MCH_TEMP are not very likely, and are probably not connected
  • Temperatures reported by the the ACPI interface (acpitz-acpi-0) and the ISA adapter (coretemp-isa-0000) are more real.


Execute pwmconfig as root to create the configuration file for fancontrol:

root #pwmconfig
# pwmconfig revision $Revision$ ($Date$)
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 is coretemp
   hwmon2 is nct6796

Found the following PWM controls:
   hwmon2/pwm1           current value: 224
hwmon2/pwm1 is currently setup for automatic speed control.
In general, automatic mode is preferred over manual mode, as
it is more efficient and it reacts faster. Are you sure that
you want to setup this output for manual control? (n)

Answer all questions posed by pwmconfig. Note that pwmconfig also works for voltage controlled fans.

Pwmconfig will shutdown your fans to calibrate settings against fan speed. Make sure your system won't overheat while you configure your system. Preferably the computer is completely idle, and all powersaving measures are enabled. Check Power_management/Guide if needed.

It is possible to manually fine tune the configuration file:

FILE /etc/fancontrol
# Configuration file generated by pwmconfig, changes will be lost
DEVPATH=hwmon0=devices/virtual/thermal/thermal_zone0 hwmon2=devices/platform/nct6775.656
DEVNAME=hwmon0=acpitz hwmon2=nct6796
FCFANS= hwmon2/pwm1=hwmon2/fan1_input

Useful parameters to tune are:

  • INTERVAL: the number of seconds between temperature samples
  • MINTEMP: the temperature at which the fan should start working
  • MAXTEMP: the temperature at which the fan should spin at maximum RPM

Start fancontrol as a service

Start fancontrol as a service, and enable the service for automatic start:

root #rc-service fancontrol
root #rc-config add fancontrol


Thinkfan is a fan controlling deamon provided by app-laptop/thinkfan and is aimed specifically towards IBM/Lenovo Thinkpad laptops. It can read multiple sensors, but control only a single fan.

Kernel configuration

The kernel needs to have the Thinkpad ACPI driver configured:

KERNEL Enable Thinkpad ACPI support in the kernel
Device Drivers  --->
    [*] X86 Platform Specific Device Drivers  ---> 
        <M>   ThinkPad ACPI Laptop Extras

This will create a module called thinkpad_acpi, which needs to be configured to allow for controlling a fan.

Edit or create /etc/modprobe.d/thinkpad.conf as follows:

FILE /etc/modprobe.d/thinkpad.conf
options thinkpad_acpi fan_control=1

Most Thinkpads provide /proc/acpi/ibm/fan as a path to the fan device.

Manual fan control

It is possible to manually control the fan speed:

root #echo level 7 > /proc/acpi/ibm/fan
root #cat /proc/acpi/ibm/fan
status:         enabled
speed:          3957
level:          7
commands:       level <level> (<level> is 0-7, auto, disengaged, full-speed)
commands:       enable, disable
commands:       watchdog <timeout> (<timeout> is 0 (off), 1-120 (seconds))

There are a few special values:

  • level auto: the fan RPM is controlled by the BIOS
  • level full-speed: the maximum speed while being monitored
  • level disengaged: even faster, where the controller does not monitor the fan speed.

Thinkfan software installation

Automatic speed control can be achieved through a package app-laptop/thinkfan.

Review thinkfan's USE flags prior to installing it:

USE flags for app-laptop/thinkfan simple fan control program for thinkpads

atasmart include libatasmart support to get disc temperature
nvidia allow thinkfan to read GPU temperature from the proprietary nVidia driver
yaml use YAML format for config file

Install thinkfan as per normal:

root #emerge --ask app-laptop/thinkfan


The configuration file of thinkfan is in /etc/thinkfan.conf. It requires manual configuration and supports a simple mode and a complex mode. Simple mode evaluates the highest temperature detected, complex mode allows configuration per sensor. The below example of the configuration file is based on simple mode:

FILE /etc/thinkfan.conf
hwmon /sys/class/hwmon/hwmon0/temp1_input
hwmon /sys/class/hwmon/hwmon2/temp2_input
hwmon /sys/class/hwmon/hwmon2/temp4_input
hwmon /sys/class/hwmon/hwmon3/temp1_input
hwmon /sys/class/hwmon/hwmon2/temp1_input
hwmon /sys/class/hwmon/hwmon2/temp3_input
hwmon /sys/class/hwmon/hwmon2/temp5_input

tp_fan /proc/acpi/ibm/fan

(0, 0,  45)
(1, 43, 50)
(2, 48, 55)
(3, 53, 60)
(4, 58, 65)
(5, 63, 70)
(6, 68, 75)
(7, 73, 90)
(127, 88, 32767)

The sensors to be considered can be found as follows:

root #ls /sys/class/hwmon/hwmon*/temp*_input

The list of arrays show the fan speed in a range of 0 to 7, and the lower and higher temperature. This example can be read as:

  • level 0 (off) until the detected temperature exceeds 45 degrees centigrade
  • level 1 until the temperature goes below 43 degrees, or exceeds 50 degrees
  • level 2 until the temperature goes below 48 degrees, or exceeds 55 degrees
  • and so on

Thinkfan also takes commandline parameters, see thinkfan's man page for details. Take special not of the bias value, which will exaggerate or dampen a sudden increase or decrease between two temperature samples.


Test the behaviour of thinkfan as follows:

root #thinkfan -n -c /etc/thinkfan.conf
Temperatures(bias): 33(0), 34(0), 33(0), 26(0), 41(0), 41(0), 32(0) -> level 0
Temperatures(bias): 38(7), 39(3), 39(4), 24(0), 39(2), 38(4), 36(0) -> level 1
Temperatures(bias): 44(9), 47(12), 43(6), 24(0), 47(12), 40(2), 40(6) -> level 3
Temperatures(bias): 47(4), 41(0), 41(0), 24(0), 49(8), 49(13), 44(6) -> level 4
Temperatures(bias): 49(2), 48(10), 45(6), 24(0), 56(10), 44(0), 56(18) -> level 6
Temperatures(bias): 51(0), 54(9), 47(3), 24(0), 55(0), 52(12), 43(0) -> level 5
Temperatures(bias): 53(0), 48(0), 55(12), 24(0), 57(0), 54(8), 54(16) -> level 6
Temperatures(bias): 55(0), 46(0), 48(0), 24(0), 54(0), 54(5), 44(0) -> level 4
Temperatures(bias): 55(0), 50(6), 47(0), 24(0), 53(0), 47(0), 53(13) -> level 5

It may take a few cycles of configuration update and testing to find the optimum between all the different setting that are possible.

Start thinkfan as a service

Update /etc/init.d/thinkpad as per the selected commandline parameters:

FILE /etc/init.d/thinkfan
#command_args="-q -s5 -c /etc/thinkfan.conf"
command_args="-q -s2 -b0 -c /etc/thinkfan.conf"

Start the thinkfan as a service and enable it as follows:

root #rc-service thinkfan start
root #rc-config add thinkfan

External resources