Skip to content

Temperature and Fan Control

Jesper Dangaard Brouer edited this page Jan 11, 2018 · 6 revisions
Table of Contents
  1. Hardware Monitoring
    1. Using sysfs
    2. Using lm_sensors
  2. Further Resources

Hardware Monitoring

Temperature monitoring and fan control is implemented using a standard kernel interface called hwmon.

Using sysfs

sysfs files may be accessed directly to monitor temperature and control fans.

Drivers which want to use the kernel sysfs interface, create a hwmon instance under the /sys/class/hwmon/ directory. To check if a hwmon instance is of the mlxsw driver, run:

$ cat /sys/class/hwmon/hwmon1/name 
mlxsw

To query the ASIC for current and highest temperature, run:

$ cat /sys/class/hwmon/hwmon1/temp1_input 
38000
$ cat /sys/class/hwmon/hwmon1/temp1_highest 
39000

Values are in milli-degrees Celsius.

To query the RPM of a fan, run:

$ cat /sys/class/hwmon/hwmon1/fan1_input
12335

Or to query all the fans in the system, run:

$ grep -H . /sys/class/hwmon/hwmon1/fan*_input
/sys/class/hwmon/hwmon1/fan1_input:13043
/sys/class/hwmon/hwmon1/fan2_input:10775
/sys/class/hwmon/hwmon1/fan3_input:12798
/sys/class/hwmon/hwmon1/fan4_input:10691
/sys/class/hwmon/hwmon1/fan5_input:12562
/sys/class/hwmon/hwmon1/fan6_input:10861
/sys/class/hwmon/hwmon1/fan7_input:12335
/sys/class/hwmon/hwmon1/fan8_input:10948

Regulating the speed of a fan is done by altering the PWM value. For example:

$ cat /sys/class/hwmon/hwmon1/pwm1 
153
$ echo "255" > /sys/class/hwmon/hwmon1/pwm1 
$ cat /sys/class/hwmon/hwmon1/fan1_input
21459
$ echo "100" > /sys/class/hwmon/hwmon1/pwm1
$ cat /sys/class/hwmon/hwmon1/fan1_input
8187

Range is 0-255.

Using lm_sensors

Instead of using sysfs it is possible to monitor the temperature and fans using the lm_sensors package:

$ sensors
...
mlxsw-pci-0300
Adapter: PCI adapter
fan1:        12679 RPM
fan2:        10691 RPM
fan3:        12798 RPM
fan4:        10691 RPM
fan5:        12562 RPM
fan6:        10861 RPM
fan7:        12448 RPM
fan8:        10775 RPM
temp1:        +38.0°C  (highest = +39.0°C)

For automatic fan regulation, fancontrol (part of lm_sensors) may be used. However, the user must first create /etc/fancontrol. In order to generate it, it is recommended to use pwmconfig. Run:

$ pwmconfig
... Will generate /etc/fancontrol ...

On systemd based systems, launch fancontrol by running:

$ systemctl start fancontrol

And enable it on boot by running:

$ systemctl enable fancontrol

Further Resources

  1. man sensors
  2. man pwmconfig
  3. man fancontrol
  4. Fan speed control on Arch Linux Wiki
Clone this wiki locally