Controlling fan speed in Linux using sensors

OS / Drivers / BIOS
Post Reply
purrkur
Linux Guru
Posts: 687
Joined: Fri Dec 12, 2003 5:57 pm
Location: Sweden
Contact:

Controlling fan speed in Linux using sensors

Post by purrkur »

After a bit more reading I found out some interesting programs in the sensors package that are not well known. They are called pwmconfig and fancontrol.

The purpose of these two programs is to allow the user to control the fan speeds through the pwm control provided by chips such as the w83782d. While the w83782d provides 4 different pwm controls, the user will only be able to control the speed of two fans (the CPU fan headers) because the program depends on having a tach output for reading the speed of the fan. I guess it is possible to control the third fan header as well (provided that it is connected to a pwm output) but playing around with this can also result in the fan being turned off which could of course have disasterous effect so it is not advisable.

So how do these programs work? There is almost no documentation so I did some digging and messing about. As my two fan headers are dead I cannot give you an idea of how well this works but hopefully some brave soul from the forums can help me out here :)

Before I begin describing how to get this working I want to mention a few things about versions. Pwmconfig and fancontrol are new programs and were added to lm_sensors in version 2.8.0. However, it wasn't until version 2.8.3 that support for kernel versions 2.6 was added. It was in version 2.8.7 of lm_sensors that support for the new sysfs naming scheme was added. So in short, if you have sensors working and you are running version 2.8.3 of sensors or above then this will most probably work. If you are running version 2.8.7 or above then I am sure it will work just fine.

The fancontrol program won't run right off without some user intervention. If you try to run the program it will complain that a config file (/etc/fancontrol) is missing. This is where the pwmconfig program comes in. This program probes for pwm controllers in your sensors configuration and (probably) builds this file. I haven't been able to verify this as I don't have working fan headers. If I run the pwmconfig program I get this output:
[root@loki root]# pwmconfig
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 PWM controls:
0-002d/fan1_pwm
0-002d/fan2_pwm
0-002d/fan3_pwm
0-002d/fan4_pwm

Found the following fan sensors:
0-002d/fan1_input current speed: 0 ... skipping!
0-002d/fan2_input current speed: 0 ... skipping!
0-002d/fan3_input current speed: 0 ... skipping!

There are no working fan sensors, all readings are 0.
Make sure you have a 3-wire fan connected.
You may also need to increase the fan divisors.
See doc/fan-divisors for more information.
So as you can see, the program does identify everything correctly on my BP6 but it refuses to continue because of the lack of tach feedback (because I don't have any fans connected). So I assume that pwmconfig will build the configuration file that fancontrol will use to control your fans. I am not sure how fancontrol works either because I haven't found any documentation on it, but if someone tests this and sends me the config file then I am pretty sure I can work it out.

A word of warning: I found this text below embedded into a script that works pwmconfig:
# Warning!!! This program will stop your fans, one at a time,
# for approximately 5 seconds each!!!
# This may cause your processor temperature to rise!!!
# Verify that all fans are running at normal speed after this
# program has exited!!!
In other words, take precautions when testing this out. Make sure your processors are idle and that you can check to make sure that your fans are working as they should after running the program.


Wanna be a real hardware hacker? Wanna control fanspeed without fanspeed? It is possible by passing information right into the kernel as root.

Here is how it works: Each pwm controller accepts a value between 0 and 255 where 255 represents full speed (which is also default). This value can be changed in the kernel by user root. Please note that changing values in the kernel at runtime doesn't leave room for errors!

The values for sensors that the kernel works with are found (on my BP6 at least) here (I am running a 2.6.5 kernel):

Code: Select all

/sys/bus/i2c/devices/0-002d
If you take a look into that directory you will recognise some of the parameters you find in your sensors.conf file. The ones that contain the values for the pwm controller are "fanX_pwm" parameters. If you do:

Code: Select all

cat /sys/bus/i2c/devices/0-002d/fan1_pwm
You will get the value "255" in return.

So lowering this value will in effect lower the speed of your fans! You can do that like so:

Code: Select all

echo "200" > /sys/bus/i2c/devices/0-002d/fan1_pwm
Try the "cat" command above again and see that the value has been changed to 200. Your fan should be running slower now.

PLEASE NOTE!
I have not been able to test this on my own. My fan headers are not working so I haven't been able to run this to see if it works as advertised. I have tried changing other parameters at runtime to see if "sensors" would report the change and it did.

Also: Don't set this value too low! The motors that the fans use are brushless DC motors and they need a certain speed to operate properly (how much depends on construction and quality). Risk is, if you try to slow them down too much then they might stop! Try setting a value between 200 and 255 to begin with. If you want to go lower, make sure that you can monitor the fans properly before doing so.

I would of course like to hear from someone with working fan headers who can test this out :)
2x533MHz@544MHz, 2.0V
640MB PC100 memory
Realtek RTL-8139 NIC
Maxtor 6Y080L0 80GB hdd
Debian Linux stable with 2.4.8 kernel
24seven
IRC Lurker
Posts: 495
Joined: Wed Jul 24, 2002 5:23 pm
Location: Derbyshire UK
Contact:

Post by 24seven »

Wow thats sounds ace.
Thanks for all the hard work Purrkur.

I hope to get linux reinstalled tonight (didnt get time last night).
purrkur
Linux Guru
Posts: 687
Joined: Fri Dec 12, 2003 5:57 pm
Location: Sweden
Contact:

Post by purrkur »

No problem ;) I got more in store as well. I have been playing around with HPT366 and I got some interesting things to report under Linux....
2x533MHz@544MHz, 2.0V
640MB PC100 memory
Realtek RTL-8139 NIC
Maxtor 6Y080L0 80GB hdd
Debian Linux stable with 2.4.8 kernel
24seven
IRC Lurker
Posts: 495
Joined: Wed Jul 24, 2002 5:23 pm
Location: Derbyshire UK
Contact:

Post by 24seven »

..oh yeah?
hyperspace
Board Admin
Posts: 1395
Joined: Wed Jul 24, 2002 7:39 am
Location: Lincoln, NE USA
Contact:

Post by hyperspace »

Running pwmconfig on 2.6.3 (lm_sensors 2.8.4) produced the following...

(both fans were reporting their normal speeds into gkrellm)

Code: Select all

[root@multiverse etc]# pwmconfig
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 PWM controls:
   0-002d/pwm1
   0-002d/pwm2
   0-002d/pwm3
   0-002d/pwm4

Found the following fan sensors:
   0-002d/fan_input1     current speed: 4927 RPM
   0-002d/fan_input2     current speed: 0 ... skipping!
   0-002d/fan_input3     current speed: 0 ... skipping!

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 0-002d/pwm1 ...
  0-002d/fan_input1 ... speed was 4927 now 0
    It appears that fan 0-002d/fan_input1
    is controlled by pwm 0-002d/pwm1
Would you like to generate a detailed correlation (y)? y
    PWM 255 FAN 4927
    PWM 240 FAN 675000
    PWM 225 FAN 42187
    PWM 210 FAN 675000
    PWM 195 FAN 675000
    PWM 180 FAN 337500
    PWM 165 FAN 675000
    PWM 150 FAN 675000
    PWM 135 FAN 675000
    PWM 120 FAN 675000
    PWM 105 FAN 675000
    PWM 90 FAN 675000
    PWM 75 FAN 675000
    PWM 60 FAN 675000
    PWM 45 FAN 675000
    PWM 30 FAN 675000
    PWM 15 FAN 675000
    PWM 0 FAN 0
    Fan Stopped at PWM = 0


Testing pwm control 0-002d/pwm2 ...
  0-002d/fan_input1 ... speed was 4927 now 4963
    no correlation

No correlations were detected.
There is either no fan connected to the output of 0-002d/pwm2,
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 pwm control 0-002d/pwm3 ...
  0-002d/fan_input1 ... speed was 4927 now 4963
    no correlation

No correlations were detected.
There is either no fan connected to the output of 0-002d/pwm3,
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)?

Testing pwm control 0-002d/pwm4 ...
  0-002d/fan_input1 ... speed was 4927 now 4927
    no correlation

No correlations were detected.
There is either no fan connected to the output of 0-002d/pwm4,
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)?

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)?
/etc/fancontrol does not exist, shall I create it now (y)?
Loading configuration from /etc/fancontrol ...

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

Saving configuration to /etc/fancontrol...
Configuration saved
[root@multiverse etc]#
I could hear both fans go OFF and then come back ON. gkrellm showed 0 for fans when they were OFF but when they came back on, only fan1 showed a normal speed. fan2 showed 0. I looked at the fans and both were ON. The temperatures for both CPU's were normal.

I did not see fan1_pwm in the directory. I saw fan_input1, 2, and 3. Maybe I should upgrade to lm_sensors 2.8.7 and see what happens.
Quantum WormHole

Image
lost in hypertime...
purrkur
Linux Guru
Posts: 687
Joined: Fri Dec 12, 2003 5:57 pm
Location: Sweden
Contact:

Post by purrkur »

Thanks for your reply Hyperspace. I can see by the output that you posted that pwmconfig only finds one fan that it can change the speed of. That is pretty strange given that you have a tach on both which should be enough.

Question: Are both fans of the same type?

After running pwmconfig and after it had shut off your second fan, it should have been easy to start it again by the following command (as root):

Code: Select all

echo "255" > /sys/bus/i2c/devices/0-002d/fan2_pwm
Given that you don't have a tach reader on fan header 3 and the fact that the BP6 doesn't use pwm control nr 4 I would say that the pwmconfig program does exactly what it should. It is just your second fan header that is the problem.

But hey, maybe we can get it working anyways! Could you please post the /etc/fancontrol file? I would like to see how pwmconfig sets it up.
2x533MHz@544MHz, 2.0V
640MB PC100 memory
Realtek RTL-8139 NIC
Maxtor 6Y080L0 80GB hdd
Debian Linux stable with 2.4.8 kernel
24seven
IRC Lurker
Posts: 495
Joined: Wed Jul 24, 2002 5:23 pm
Location: Derbyshire UK
Contact:

Post by 24seven »

Is it just me or does pwmconfig cause the machine to make bleeping noises?
hyperspace
Board Admin
Posts: 1395
Joined: Wed Jul 24, 2002 7:39 am
Location: Lincoln, NE USA
Contact:

Post by hyperspace »

24seven wrote:Is it just me or does pwmconfig cause the machine to make bleeping noises?
Not mine.

fancontrol file:

Code: Select all

INTERVAL=10
FCTEMPS=
FCFANS=
MINTEMP=
MAXTEMP=
MINSTART=
MINSTOP=
Quantum WormHole

Image
lost in hypertime...
purrkur
Linux Guru
Posts: 687
Joined: Fri Dec 12, 2003 5:57 pm
Location: Sweden
Contact:

Post by purrkur »

24seven wrote:Is it just me or does pwmconfig cause the machine to make bleeping noises?
Hmm... Could it be that your sensors are doing it? open up a console and write "sensors". Check if you have any "ALARM" indicators there. If you do, and if you have turned on beeping in the sensors.conf file then I would assume that it would start beeping at you :)

Hyperspace: That fancontrol file looked interesting. It shows that it hasn't been configured at all really. Here is what the parameters mean if you want to plug in some numbers there for your system:
INTERVAL
This variable defines at which interval in seconds the main loop of
fancontrol will be executed

FCTEMPS
Maps pwm outputs to temperature sensors so fancontrol know which temperature sensors should be used for calculation of new values for the corresponding pwm outputs.

FCFANS
FCFANS records the association between a pwm and a fan. Then fancontrol can check the fan speed and restart it if it stops unexpectedly.

MINTEMP
The temperature at which the fan gets switched off completely.

MAXTEMP
The temperature at which the fan gets switched to full speed.

MINSTART
Sets the minimum speed at which the fan begins spinning. You should use a safe value to be sure it works, even when the fan gets old.

MINSTOP
The minimum speed at which the fan still spins. Use a save value here, too.
2x533MHz@544MHz, 2.0V
640MB PC100 memory
Realtek RTL-8139 NIC
Maxtor 6Y080L0 80GB hdd
Debian Linux stable with 2.4.8 kernel
24seven
IRC Lurker
Posts: 495
Joined: Wed Jul 24, 2002 5:23 pm
Location: Derbyshire UK
Contact:

Post by 24seven »

Hmm... Could it be that your sensors are doing it? open up a console and write "sensors". Check if you have any "ALARM" indicators there. If you do, and if you have turned on beeping in the sensors.conf file then I would assume that it would start beeping at you :)

I was using your sensors.conf... :tap: :peace:
I shall have a proper look tonight. I was tierd last night and wasnt really with it. :smash:
purrkur
Linux Guru
Posts: 687
Joined: Fri Dec 12, 2003 5:57 pm
Location: Sweden
Contact:

Post by purrkur »

I was using your sensors.conf...
Excellent! I think that is the issue then. In my sensors.conf I had the following:

Code: Select all

# Turning on speaker beep (for alarms):
set beep_enable 1
So you got two options here:

1. Change the 1 to 0 to turn off the alarm.

2. use the "sensors" program to figure out what exactly is triggering the alarm. It should clearly state "ALARM" on the parameter that is giving you issues.

I would personally go with nr. 2. Post your "sensors" output if you want and I will gladly take a look at it and comment.
2x533MHz@544MHz, 2.0V
640MB PC100 memory
Realtek RTL-8139 NIC
Maxtor 6Y080L0 80GB hdd
Debian Linux stable with 2.4.8 kernel
Post Reply