fancontrol:

* Check for configuration file validity
fancontrol and pwmconfig:
* Support optional min and max PWM values
Documentation updated accordingly.


git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@4438 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Jean Delvare committed 2007-06-11 09:27:15 +00:00
1 parent 8f3f85b86e
commit 8d7e7c1068
5 files changed
+167 -33

No files matched your search

+3
View File
@@ -17,7 +17,10 @@ SVN HEAD
Program fancontrol: Use let for arithmetic evaluation
No longer need awk and grep
Limit calls to external programs (Linux 2.6 only)
Check for configuration file validity
Support optional min and max PWM values
Program pwmconfig: Use smaller steps for low PWM values
Support optional min and max PWM values
Program rrd: Support non-i2c devices (hwmon class)
Add missing shell declarations
Update URI
+48 -12
View File
@@ -26,7 +26,7 @@ some fan fails, because you probably won't hear it anymore ;)
Configuration
Since most of you are going to use the prog/pwm/pwmconfig script, the config
Since most of you are going to use the pwmconfig script, the config
file syntax will be discussed last. First I'm going to describe the various
variables available for changing fancontrol's behaviour:
@@ -35,7 +35,7 @@ INTERVAL
fancontrol will be executed
FCTEMPS
Maps pwm outputs to temperature sensors so fancontrol know which
Maps pwm outputs to temperature sensors so fancontrol knows which
temperature sensors should be used for calculation of new values for
the corresponding pwm outputs.
@@ -45,29 +45,65 @@ FCFANS
stops unexpectedly.
MINTEMP
The temperature at which the fan gets switched off completely.
The temperature below which the fan gets switched to minimum speed.
MAXTEMP
The temperature at which the fan gets switched to full speed.
The temperature over which the fan gets switched to maximum 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,
The minimum speed at which the fan still spins. Use a safe value here,
too.
If you set up your configuration by hand, be sure to include ALL variables and
use valid values, there's no error handling yet! The file format is a bit
strange:
MINPWM
The PWM value to use when the temperature is below MINTEMP.
Typically, this will be either 0 if it is OK for the fan to plain
stop, or the same value as MINSTOP if you don't want the fan to
ever stop.
If this value isn't defined, it defaults to 0 (stopped fan).
VARIABLE=chip/pwmdev=value chip/pwmdev2=value2 [...] VARIABLE2=[...]
MAXPWM
The PWM value to use when the temperature is over MAXTEMP.
If this value isn't defined, it defaults to 255 (full speed).
A graph might help you understand how the different values relate
to each other:
PWM ^
255 +
|
|
| ,-------------- MAXPWM
| ,'.
| ,' .
| ,' .
| ,' .
| ,' .
| ,' .
| MINSTOP .' .
| | .
| | .
| | .
MINPWM |---------------' .
| . .
| . .
| . .
0 +---------------+-------------+---------------->
MINTEMP MAXTEMP t (degree C)
The configuration file format is a bit strange:
VARIABLE=chip/pwmdev=value chip/pwmdev2=value2 [...]
VARIABLE2=[...]
Each variable has its own line. The variable name is followed by an equal sign
and the device=value pairs. These consist of the relative path to the pwm
output (from /proc/sys/dev/sensors/) for which the value is valid, equal sign
followed by the value and are seperated by a blank.
output (from /proc/sys/dev/sensors, /sys/bus/i2c/devices or /sys/class/hwmon
depending on the kernel version) for which the value is valid, equal sign
followed by the value and are separated by a blank.
Example:
@@ -82,7 +118,7 @@ The algorithm
fancontrol first reads its configuration, writes it to arrays and loops its
main function. This function gets the temperatures and fanspeeds from
lm_sensors proc files and calculates new speeds depending on temperature
kernel driver files and calculates new speeds depending on temperature
changes, but only if the temp is between MINTEMP and MAXTEMP. After that, the
new values are written to the pwm outputs. Currently the speed increases
quadratically with rising temperature. This way you won't hear your fans most
+56 -6
View File
@@ -2,7 +2,7 @@
#
# Simple script implementing a temperature dependent fan speed control
#
# Version 0.65
# Version 0.66
#
# Usage: fancontrol [CONFIGFILE]
#
@@ -22,6 +22,7 @@
#
#
# Copyright 2003 Marius Reiner <marius.reiner@hdev.de>
# Copyright (C) 2007 Jean Delvare <khali@linux-fr.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -55,6 +56,8 @@ function LoadConfig {
MINSTOP=`egrep '^MINSTOP=.*$' $1 | sed -e 's/MINSTOP=//g'`
# optional settings:
FCFANS=`egrep '^FCFANS=.*$' $1 | sed -e 's/FCFANS=//g'`
MINPWM=`egrep '^MINPWM=.*$' $1 | sed -e 's/MINPWM=//g'`
MAXPWM=`egrep '^MAXPWM=.*$' $1 | sed -e 's/MAXPWM=//g'`
# Check whether all mandatory settings are set
if [[ -z ${INTERVAL} || -z ${FCTEMPS} || -z ${MINTEMP} || -z ${MAXTEMP} || -z ${MINSTART} || -z ${MINSTOP} ]]
@@ -62,8 +65,12 @@ function LoadConfig {
echo "Some mandatory settings missing, please check your config file!"
exit 1
fi
# here the other settings should be verified
if [ "$INTERVAL" -le 0 ]
then
echo "Error in configuration file:"
echo "INTERVAL must be at least 1"
exit 1
fi
# write settings to arrays for easier use and print them
echo
@@ -80,6 +87,43 @@ function LoadConfig {
AFCMAXTEMP[$fcvcount]=`echo $MAXTEMP |sed -e 's/ /\n/g' |egrep "${AFCPWM[$fcvcount]}" |cut -d'=' -f2`
AFCMINSTART[$fcvcount]=`echo $MINSTART |sed -e 's/ /\n/g' |egrep "${AFCPWM[$fcvcount]}" |cut -d'=' -f2`
AFCMINSTOP[$fcvcount]=`echo $MINSTOP |sed -e 's/ /\n/g' |egrep "${AFCPWM[$fcvcount]}" |cut -d'=' -f2`
AFCMINPWM[$fcvcount]=`echo $MINPWM |sed -e 's/ /\n/g' |egrep "${AFCPWM[$fcvcount]}" |cut -d'=' -f2`
[ -z "${AFCMINPWM[$fcvcount]}" ] && AFCMINPWM[$fcvcount]=0
AFCMAXPWM[$fcvcount]=`echo $MAXPWM |sed -e 's/ /\n/g' |egrep "${AFCPWM[$fcvcount]}" |cut -d'=' -f2`
[ -z "${AFCMAXPWM[$fcvcount]}" ] && AFCMAXPWM[$fcvcount]=255
# verify the validity of the settings
if [ "${AFCMINTEMP[$fcvcount]}" -ge "${AFCMAXTEMP[$fcvcount]}" ]
then
echo "Error in configuration file (${AFCPWM[$fcvcount]}):"
echo "MINTEMP must be less than MAXTEMP"
exit 1
fi
if [ "${AFCMAXPWM[$fcvcount]}" -gt 255 ]
then
echo "Error in configuration file (${AFCPWM[$fcvcount]}):"
echo "MAXPWM must be at most 255"
exit 1
fi
if [ "${AFCMINSTOP[$fcvcount]}" -ge "${AFCMAXPWM[$fcvcount]}" ]
then
echo "Error in configuration file (${AFCPWM[$fcvcount]}):"
echo "MINSTOP must be less than MAXPWM"
exit 1
fi
if [ "${AFCMINSTOP[$fcvcount]}" -lt "${AFCMINPWM[$fcvcount]}" ]
then
echo "Error in configuration file (${AFCPWM[$fcvcount]}):"
echo "MINSTOP must be greater than or equal to MINPWM"
exit 1
fi
if [ "${AFCMINPWM[$fcvcount]}" -lt 0 ]
then
echo "Error in configuration file (${AFCPWM[$fcvcount]}):"
echo "MINPWM must be at least 0"
exit 1
fi
echo
echo "Settings for ${AFCPWM[$fcvcount]}:"
echo " Depends on ${AFCTEMP[$fcvcount]}"
@@ -88,6 +132,8 @@ function LoadConfig {
echo " MAXTEMP=${AFCMAXTEMP[$fcvcount]}"
echo " MINSTART=${AFCMINSTART[$fcvcount]}"
echo " MINSTOP=${AFCMINSTOP[$fcvcount]}"
echo " MINPWM=${AFCMINPWM[$fcvcount]}"
echo " MAXPWM=${AFCMAXPWM[$fcvcount]}"
let fcvcount=fcvcount+1
done
echo
@@ -209,6 +255,8 @@ function UpdateFanSpeeds {
maxt=${AFCMAXTEMP[$fcvcount]}
minsa=${AFCMINSTART[$fcvcount]}
minso=${AFCMINSTOP[$fcvcount]}
minpwm=${AFCMINPWM[$fcvcount]}
maxpwm=${AFCMAXPWM[$fcvcount]}
read tval < ${tsens}
if [ $? -ne 0 ]
@@ -261,18 +309,20 @@ function UpdateFanSpeeds {
echo "maxt=$maxt"
echo "minsa=$minsa"
echo "minso=$minso"
echo "minpwm=$minpwm"
echo "maxpwm=$maxpwm"
echo "tval=$tval"
echo "pwmpval=$pwmpval"
echo "fanval=$fanval"
fi
if (( $tval <= $mint ))
then pwmval=0 # at specified mintemp shut fan off
then pwmval=$minpwm # below min temp, use defined min pwm
elif (( $tval >= $maxt ))
then pwmval=255 # at specified maxtemp switch to 100%
then pwmval=$maxpwm # over max temp, use defined max pwm
else
# calculate the new value from temperature and settings
let pwmval="((${tval}-${mint})**2)*(255-${minso})/((${maxt}-${mint})**2)+${minso}"
let pwmval="((${tval}-${mint})**2)*(${maxpwm}-${minso})/((${maxt}-${mint})**2)+${minso}"
if [ $pwmpval -eq 0 -o $fanval -eq 0 ]
then # if fan was stopped start it using a safe value
echo $minsa > $pwmo
+19 -9
View File
@@ -1,4 +1,4 @@
.TH FANCONTROL 8 "January 27, 2005"
.TH FANCONTROL 8 "June 2007"
.SH NAME
fancontrol \- automated software based fan speed regulation
@@ -49,10 +49,10 @@ Then \fBfancontrol\fP can check the fan speed and restart it if it
stops unexpectedly.
.TP
.B MINTEMP
The temperature below which the fan gets switched off completely.
The temperature below which the fan gets switched to minimum speed.
.TP
.B MAXTEMP
The temperature over which the fan gets switched to full speed.
The temperature over which the fan gets switched to maximum speed.
.TP
.B MINSTART
Sets the minimum speed at which the fan begins spinning. You should
@@ -61,10 +61,19 @@ use a safe value to be sure it works, even when the fan gets old.
.B MINSTOP
The minimum speed at which the fan still spins. Use a safe value here,
too.
.TP
.B MINPWM
The PWM value to use when the temperature is below MINTEMP.
Typically, this will be either 0 if it is OK for the fan to plain
stop, or the same value as MINSTOP if you don't want the fan to
ever stop.
If this value isn't defined, it defaults to 0 (stopped fan).
.TP
.B MAXPWM
The PWM value to use when the temperature is over MAXTEMP.
If this value isn't defined, it defaults to 255 (full speed).
.PP
If you set up your configuration by hand, be sure to include ALL variables and
use valid values, there's no error handling yet! The file format is a bit
strange:
The configuration file format is a bit strange:
.IP
.nf
VARIABLE=chip/pwmdev=value chip/pwmdev2=value2
@@ -73,8 +82,9 @@ VARIABLE2=...
.PP
Each variable has its own line. The variable name is followed by an equal sign
and the device=value pairs. These consist of the relative path to the pwm
output (from /proc/sys/dev/sensors/) for which the value is valid, equal sign
followed by the value and are seperated by a blank. Example:
output (from /proc/sys/dev/sensors, /sys/bus/i2c/devices or /sys/class/hwmon
depending on the kernel version) for which the value is valid, equal sign
followed by the value and are separated by a blank. Example:
.IP
MINTEMP=w83627hf-isa-0290/pwm2=40 w83627hf-isa-0290/pwm1=54
.PP
@@ -86,7 +96,7 @@ editing the config file directly following the rules above.
\fBfancontrol\fP first reads its configuration, writes it to arrays and loops its
main function. This function gets the temperatures and fanspeeds from
lm_sensors proc files and calculates new speeds depending on temperature
kernel driver files and calculates new speeds depending on temperature
changes, but only if the temp is between MINTEMP and MAXTEMP. After that, the
new values are written to the PWM outputs. Currently the speed increases
quadratically with rising temperature. This way you won't hear your fans most
+41 -6
View File
@@ -1,6 +1,6 @@
#!/bin/bash
#
# pwmconfig v0.7
# pwmconfig v0.8
# Tests the pwm outputs of sensors and configures fancontrol
#
# Warning!!! This program will stop your fans, one at a time,
@@ -10,6 +10,7 @@
# program has exited!!!
#
# Copyright 2003-2005 The lm_sensors project
# Copyright (C) 2007 Jean Delvare <khali@linux-fr.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -485,6 +486,8 @@ function LoadConfig {
MAXTEMP=`egrep '^MAXTEMP=.*$' $1 | sed -e 's/MAXTEMP= *//g'`
MINSTART=`egrep '^MINSTART=.*$' $1 | sed -e 's/MINSTART= *//g'`
MINSTOP=`egrep '^MINSTOP=.*$' $1 | sed -e 's/MINSTOP= *//g'`
MINPWM=`egrep '^MINPWM=.*$' $1 | sed -e 's/MINPWM= *//g'`
MAXPWM=`egrep '^MAXPWM=.*$' $1 | sed -e 's/MAXPWM= *//g'`
# Check for configuration change
local item
@@ -499,6 +502,8 @@ function LoadConfig {
MAXTEMP=""
MINSTART=""
MINSTOP=""
MINPWM=""
MAXPWM=""
fi
done
}
@@ -556,8 +561,10 @@ function SaveConfig {
echo "Saving configuration to $FCCONFIG..."
tmpfile=`mktemp -t pwmcfg.XXXXXXXXXX` || { echo "$0: Cannot create temporary file" >&2; exit 1; }
trap " [ -f \"$tmpfile\" ] && /bin/rm -f -- \"$tmpfile\"" 0 1 2 3 13 15
egrep -v '(INTERVAL|FCTEMPS|FCFANS|MAXTEMP|MINTEMP|MINSTART|MINSTOP)' $FCCONFIG >$tmpfile
egrep -v '(INTERVAL|FCTEMPS|FCFANS|MAXTEMP|MINTEMP|MINSTART|MINSTOP|MINPWM|MAXPWM)' $FCCONFIG >$tmpfile
echo -e "INTERVAL=$INTERVAL\nFCTEMPS=$FCTEMPS\nFCFANS=$FCFANS\nMINTEMP=$MINTEMP\nMAXTEMP=$MAXTEMP\nMINSTART=$MINSTART\nMINSTOP=$MINSTOP" >>$tmpfile
[ -n "$MINPWM" ] && echo "MINPWM=$MINPWM" >>$tmpfile
[ -n "$MAXPWM" ] && echo "MAXPWM=$MAXPWM" >>$tmpfile
mv $tmpfile $FCCONFIG
#check if file was written correctly
echo 'Configuration saved'
@@ -599,6 +606,8 @@ select pwms in $pwmactive "Change INTERVAL" "Just quit" "Save and quit" "Show co
echo " MAXTEMP=`echo $MAXTEMP |sed -e \"s/ /\n/g\" |egrep \"${pwmo}\" |sed -e \"s/.*=//g\"`"
echo " MINSTART=`echo $MINSTART |sed -e \"s/ /\n/g\" |egrep \"${pwmo}\" |sed -e \"s/.*=//g\"`"
echo " MINSTOP=`echo $MINSTOP |sed -e \"s/ /\n/g\" |egrep \"${pwmo}\" |sed -e \"s/.*=//g\"`"
echo " MINPWM=`echo $MINPWM |sed -e \"s/ /\n/g\" |egrep \"${pwmo}\" |sed -e \"s/.*=//g\"`"
echo " MAXPWM=`echo $MAXPWM |sed -e \"s/ /\n/g\" |egrep \"${pwmo}\" |sed -e \"s/.*=//g\"`"
done
echo ;;
@@ -640,8 +649,8 @@ select pwms in $pwmactive "Change INTERVAL" "Just quit" "Save and quit" "Show co
fi
fi
echo
echo 'Enter the low temperature (C)'
echo -n "at which the fan should be switched off ($DEFMINTEMP): "
echo 'Enter the low temperature (degree C)'
echo -n "below which the fan should spin at minimum speed ($DEFMINTEMP): "
read XMT
if [ "$XMT" = "" ]
then
@@ -654,8 +663,8 @@ select pwms in $pwmactive "Change INTERVAL" "Just quit" "Save and quit" "Show co
MINTEMP="`echo $MINTEMP | sed -e \"s/${pwmsed}[^ ]* *//g\"` ${pwms}=${XMT}"
fi
echo
echo 'Enter the high temperature (C)'
echo -n "at which the fan should be switched to full speed ($DEFMAXTEMP): "
echo 'Enter the high temperature (degree C)'
echo -n "over which the fan should spin at maximum speed ($DEFMAXTEMP): "
read XMT
if [ "$XMT" = "" ]
then
@@ -706,6 +715,32 @@ select pwms in $pwmactive "Change INTERVAL" "Just quit" "Save and quit" "Show co
MINSTOP="`echo $MINSTOP | sed -e \"s/${pwmsed}[^ ]* *//g\"` ${pwms}=${XMV}"
fi
echo
echo "Enter the PWM value (0-$XMV) to use when the temperature"
echo -n "is below the low temperature limit (0): "
read XMINP
if [ -n "$XMINP" ]
then
if [ "$MINPWM" = "" ]
then
MINPWM="${pwms}=${XMINP}"
else
MINPWM="`echo $MINPWM | sed -e \"s/${pwmsed}[^ ]* *//g\"` ${pwms}=${XMINP}"
fi
fi
echo
echo "Enter the PWM value ($XMV-$MAX) to use when the temperature"
echo -n "is over the high temperature limit ($MAX): "
read XMAXP
if [ -n "$XMAXP" ]
then
if [ "$MAXPWM" = "" ]
then
MAXPWM="${pwms}=${XMAXP}"
else
MAXPWM="`echo $MAXPWM | sed -e \"s/${pwmsed}[^ ]* *//g\"` ${pwms}=${XMAXP}"
fi
fi
echo
break;
done ;;