Changeset 4442

Show
Ignore:
Timestamp:
06/12/07 13:37:19 (7 years ago)
Author:
khali
Message:

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

Location:
lm-sensors/branches/lm-sensors-3.0.0
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/branches/lm-sensors-3.0.0/CHANGES

    r4441 r4442  
    2323                      No longer need awk and grep 
    2424                      Limit calls to external programs (Linux 2.6 only) 
     25                      Check for configuration file validity 
     26                      Support optional min and max PWM values 
    2527  Program pwmconfig: Use smaller steps for low PWM values 
     28                     Support optional min and max PWM values 
    2629  Program rrd: Support only hwmon class devices 
    2730               Look for rrd in /usr/bin by default 
  • lm-sensors/branches/lm-sensors-3.0.0/doc/fancontrol.txt

    r4064 r4442  
    2727Configuration 
    2828 
    29 Since most of you are going to use the prog/pwm/pwmconfig script, the config 
     29Since most of you are going to use the pwmconfig script, the config 
    3030file syntax will be discussed last. First I'm going to describe the various 
    3131variables available for changing fancontrol's behaviour: 
     
    3636 
    3737FCTEMPS 
    38         Maps pwm outputs to temperature sensors so fancontrol know which 
     38        Maps pwm outputs to temperature sensors so fancontrol knows which 
    3939        temperature sensors should be used for calculation of new values for 
    4040        the corresponding pwm outputs. 
     
    4646 
    4747MINTEMP 
    48         The temperature at which the fan gets switched off completely. 
     48        The temperature below which the fan gets switched to minimum speed. 
    4949 
    5050MAXTEMP 
    51         The temperature at which the fan gets switched to full speed. 
     51        The temperature over which the fan gets switched to maximum speed. 
    5252 
    5353MINSTART 
     
    5656 
    5757MINSTOP 
    58         The minimum speed at which the fan still spins. Use a save value here, 
     58        The minimum speed at which the fan still spins. Use a safe value here, 
    5959        too. 
    6060 
    61 If you set up your configuration by hand, be sure to include ALL variables and 
    62 use valid values, there's no error handling yet! The file format is a bit 
    63 strange: 
     61MINPWM 
     62        The PWM value to use when the temperature is below MINTEMP. 
     63        Typically, this will be either 0 if it is OK for the fan to plain 
     64        stop, or the same value as MINSTOP if you don't want the fan to 
     65        ever stop. 
     66        If this value isn't defined, it defaults to 0 (stopped fan). 
    6467 
    65 VARIABLE=chip/pwmdev=value chip/pwmdev2=value2 [...] VARIABLE2=[...] 
     68MAXPWM 
     69        The PWM value to use when the temperature is over MAXTEMP. 
     70        If this value isn't defined, it defaults to 255 (full speed). 
     71 
     72A graph might help you understand how the different values relate 
     73to each other: 
     74 
     75    PWM ^ 
     76    255 + 
     77        | 
     78        | 
     79        |                             ,-------------- MAXPWM 
     80        |                           ,'. 
     81        |                         ,'  . 
     82        |                       ,'    . 
     83        |                     ,'      . 
     84        |                   ,'        . 
     85        |                 ,'          . 
     86        |       MINSTOP .'            . 
     87        |               |             . 
     88        |               |             . 
     89        |               |             . 
     90 MINPWM |---------------'             . 
     91        |               .             . 
     92        |               .             . 
     93        |               .             . 
     94      0 +---------------+-------------+----------------> 
     95                     MINTEMP       MAXTEMP            t (degree C) 
     96 
     97The configuration file format is a bit strange: 
     98 
     99VARIABLE=chip/pwmdev=value chip/pwmdev2=value2 [...] 
     100VARIABLE2=[...] 
    66101 
    67102Each variable has its own line. The variable name is followed by an equal sign 
    68103and the device=value pairs. These consist of the relative path to the pwm 
    69 output (from /proc/sys/dev/sensors/) for which the value is valid, equal sign 
    70 followed by the value and are seperated by a blank. 
     104output (from /proc/sys/dev/sensors, /sys/bus/i2c/devices or /sys/class/hwmon 
     105depending on the kernel version) for which the value is valid, equal sign 
     106followed by the value and are separated by a blank. 
    71107 
    72108Example: 
     
    83119fancontrol first reads its configuration, writes it to arrays and loops its 
    84120main function.  This function gets the temperatures and fanspeeds from 
    85 lm_sensors proc files and calculates new speeds depending on temperature 
     121kernel driver files and calculates new speeds depending on temperature 
    86122changes, but only if the temp is between MINTEMP and MAXTEMP. After that, the 
    87123new values are written to the pwm outputs.  Currently the speed increases 
  • lm-sensors/branches/lm-sensors-3.0.0/prog/pwm/fancontrol

    r4441 r4442  
    33# Simple script implementing a temperature dependent fan speed control 
    44# 
    5 # Version 0.65 
     5# Version 0.66 
    66# 
    77# Usage: fancontrol [CONFIGFILE] 
     
    2323# 
    2424#    Copyright 2003 Marius Reiner <marius.reiner@hdev.de> 
     25#    Copyright (C) 2007 Jean Delvare <khali@linux-fr.org> 
    2526# 
    2627#    This program is free software; you can redistribute it and/or modify 
     
    5657        # optional settings: 
    5758        FCFANS=`egrep '^FCFANS=.*$' $1 | sed -e 's/FCFANS=//g'` 
     59        MINPWM=`egrep '^MINPWM=.*$' $1 | sed -e 's/MINPWM=//g'` 
     60        MAXPWM=`egrep '^MAXPWM=.*$' $1 | sed -e 's/MAXPWM=//g'` 
    5861         
    5962        # Check whether all mandatory settings are set 
     
    6366                exit 1 
    6467        fi 
    65         # here the other settings should be verified 
    66          
     68        if [ "$INTERVAL" -le 0 ] 
     69        then 
     70                echo "Error in configuration file:" 
     71                echo "INTERVAL must be at least 1" 
     72                exit 1 
     73        fi 
    6774 
    6875        # write settings to arrays for easier use and print them 
     
    8188                AFCMINSTART[$fcvcount]=`echo $MINSTART |sed -e 's/ /\n/g' |egrep "${AFCPWM[$fcvcount]}" |cut -d'=' -f2` 
    8289                AFCMINSTOP[$fcvcount]=`echo $MINSTOP |sed -e 's/ /\n/g' |egrep "${AFCPWM[$fcvcount]}" |cut -d'=' -f2` 
     90                AFCMINPWM[$fcvcount]=`echo $MINPWM |sed -e 's/ /\n/g' |egrep "${AFCPWM[$fcvcount]}" |cut -d'=' -f2` 
     91                [ -z "${AFCMINPWM[$fcvcount]}" ] && AFCMINPWM[$fcvcount]=0 
     92                AFCMAXPWM[$fcvcount]=`echo $MAXPWM |sed -e 's/ /\n/g' |egrep "${AFCPWM[$fcvcount]}" |cut -d'=' -f2` 
     93                [ -z "${AFCMAXPWM[$fcvcount]}" ] && AFCMAXPWM[$fcvcount]=255 
     94 
     95                # verify the validity of the settings 
     96                if [ "${AFCMINTEMP[$fcvcount]}" -ge "${AFCMAXTEMP[$fcvcount]}" ] 
     97                then 
     98                        echo "Error in configuration file (${AFCPWM[$fcvcount]}):" 
     99                        echo "MINTEMP must be less than MAXTEMP" 
     100                        exit 1 
     101                fi 
     102                if [ "${AFCMAXPWM[$fcvcount]}" -gt 255 ] 
     103                then 
     104                        echo "Error in configuration file (${AFCPWM[$fcvcount]}):" 
     105                        echo "MAXPWM must be at most 255" 
     106                        exit 1 
     107                fi 
     108                if [ "${AFCMINSTOP[$fcvcount]}" -ge "${AFCMAXPWM[$fcvcount]}" ] 
     109                then 
     110                        echo "Error in configuration file (${AFCPWM[$fcvcount]}):" 
     111                        echo "MINSTOP must be less than MAXPWM" 
     112                        exit 1 
     113                fi 
     114                if [ "${AFCMINSTOP[$fcvcount]}" -lt "${AFCMINPWM[$fcvcount]}" ] 
     115                then 
     116                        echo "Error in configuration file (${AFCPWM[$fcvcount]}):" 
     117                        echo "MINSTOP must be greater than or equal to MINPWM" 
     118                        exit 1 
     119                fi 
     120                if [ "${AFCMINPWM[$fcvcount]}" -lt 0 ] 
     121                then 
     122                        echo "Error in configuration file (${AFCPWM[$fcvcount]}):" 
     123                        echo "MINPWM must be at least 0" 
     124                        exit 1 
     125                fi 
     126 
    83127                echo 
    84128                echo "Settings for ${AFCPWM[$fcvcount]}:" 
     
    89133                echo "  MINSTART=${AFCMINSTART[$fcvcount]}" 
    90134                echo "  MINSTOP=${AFCMINSTOP[$fcvcount]}" 
     135                echo "  MINPWM=${AFCMINPWM[$fcvcount]}" 
     136                echo "  MAXPWM=${AFCMAXPWM[$fcvcount]}" 
    91137                let fcvcount=fcvcount+1 
    92138        done 
     
    210256                minsa=${AFCMINSTART[$fcvcount]} 
    211257                minso=${AFCMINSTOP[$fcvcount]} 
     258                minpwm=${AFCMINPWM[$fcvcount]} 
     259                maxpwm=${AFCMAXPWM[$fcvcount]} 
    212260                 
    213261                read tval < ${tsens} 
     
    262310                        echo "minsa=$minsa" 
    263311                        echo "minso=$minso" 
     312                        echo "minpwm=$minpwm" 
     313                        echo "maxpwm=$maxpwm" 
    264314                        echo "tval=$tval" 
    265315                        echo "pwmpval=$pwmpval" 
     
    268318                 
    269319                if (( $tval <= $mint )) 
    270                   then pwmval=0 # at specified mintemp shut fan off 
     320                  then pwmval=$minpwm # below min temp, use defined min pwm 
    271321                elif (( $tval >= $maxt )) 
    272                   then pwmval=255 # at specified maxtemp switch to 100% 
     322                  then pwmval=$maxpwm # over max temp, use defined max pwm 
    273323                else  
    274324                  # calculate the new value from temperature and settings 
    275                   let pwmval="((${tval}-${mint})**2)*(255-${minso})/((${maxt}-${mint})**2)+${minso}" 
     325                  let pwmval="((${tval}-${mint})**2)*(${maxpwm}-${minso})/((${maxt}-${mint})**2)+${minso}" 
    276326                  if [ $pwmpval -eq 0 -o $fanval -eq 0 ] 
    277327                  then # if fan was stopped start it using a safe value 
  • lm-sensors/branches/lm-sensors-3.0.0/prog/pwm/fancontrol.8

    r2873 r4442  
    1 .TH FANCONTROL 8 "January 27, 2005" 
     1.TH FANCONTROL 8 "June 2007" 
    22.SH NAME 
    33fancontrol \- automated software based fan speed regulation 
     
    5050.TP 
    5151.B MINTEMP 
    52 The temperature below which the fan gets switched off completely. 
     52The temperature below which the fan gets switched to minimum speed. 
    5353.TP 
    5454.B MAXTEMP 
    55 The temperature over which the fan gets switched to full speed. 
     55The temperature over which the fan gets switched to maximum speed. 
    5656.TP 
    5757.B MINSTART 
     
    6262The minimum speed at which the fan still spins. Use a safe value here, 
    6363too. 
     64.TP 
     65.B MINPWM 
     66The PWM value to use when the temperature is below MINTEMP. 
     67Typically, this will be either 0 if it is OK for the fan to plain 
     68stop, or the same value as MINSTOP if you don't want the fan to 
     69ever stop. 
     70If this value isn't defined, it defaults to 0 (stopped fan). 
     71.TP 
     72.B MAXPWM 
     73The PWM value to use when the temperature is over MAXTEMP. 
     74If this value isn't defined, it defaults to 255 (full speed). 
    6475.PP 
    65 If you set up your configuration by hand, be sure to include ALL variables and 
    66 use valid values, there's no error handling yet! The file format is a bit 
    67 strange: 
     76The configuration file format is a bit strange: 
    6877.IP 
    6978.nf 
     
    7483Each variable has its own line. The variable name is followed by an equal sign 
    7584and the device=value pairs. These consist of the relative path to the pwm 
    76 output (from /proc/sys/dev/sensors/) for which the value is valid, equal sign 
    77 followed by the value and are seperated by a blank. Example: 
     85output (from /proc/sys/dev/sensors, /sys/bus/i2c/devices or /sys/class/hwmon 
     86depending on the kernel version) for which the value is valid, equal sign 
     87followed by the value and are separated by a blank. Example: 
    7888.IP 
    7989MINTEMP=w83627hf-isa-0290/pwm2=40 w83627hf-isa-0290/pwm1=54 
     
    8797\fBfancontrol\fP first reads its configuration, writes it to arrays and loops its 
    8898main function.  This function gets the temperatures and fanspeeds from 
    89 lm_sensors proc files and calculates new speeds depending on temperature 
     99kernel driver files and calculates new speeds depending on temperature 
    90100changes, but only if the temp is between MINTEMP and MAXTEMP. After that, the 
    91101new values are written to the PWM outputs. Currently the speed increases 
  • lm-sensors/branches/lm-sensors-3.0.0/prog/pwm/pwmconfig

    r4381 r4442  
    11#!/bin/bash 
    22# 
    3 # pwmconfig v0.7 
     3# pwmconfig v0.8 
    44# Tests the pwm outputs of sensors and configures fancontrol 
    55# 
     
    1111# 
    1212#    Copyright 2003-2005 The lm_sensors project 
     13#    Copyright (C) 2007 Jean Delvare <khali@linux-fr.org> 
    1314# 
    1415#    This program is free software; you can redistribute it and/or modify 
     
    486487        MINSTART=`egrep '^MINSTART=.*$' $1 | sed -e 's/MINSTART= *//g'` 
    487488        MINSTOP=`egrep '^MINSTOP=.*$' $1 | sed -e 's/MINSTOP= *//g'` 
     489        MINPWM=`egrep '^MINPWM=.*$' $1 | sed -e 's/MINPWM= *//g'` 
     490        MAXPWM=`egrep '^MAXPWM=.*$' $1 | sed -e 's/MAXPWM= *//g'` 
    488491 
    489492        # Check for configuration change 
     
    500503                        MINSTART="" 
    501504                        MINSTOP="" 
     505                        MINPWM="" 
     506                        MAXPWM="" 
    502507                fi 
    503508        done 
     
    557562        tmpfile=`mktemp -t pwmcfg.XXXXXXXXXX` || { echo "$0: Cannot create temporary file" >&2; exit 1;  } 
    558563        trap " [ -f \"$tmpfile\" ] && /bin/rm -f -- \"$tmpfile\"" 0 1 2 3 13 15 
    559         egrep -v '(INTERVAL|FCTEMPS|FCFANS|MAXTEMP|MINTEMP|MINSTART|MINSTOP)' $FCCONFIG >$tmpfile 
     564        egrep -v '(INTERVAL|FCTEMPS|FCFANS|MAXTEMP|MINTEMP|MINSTART|MINSTOP|MINPWM|MAXPWM)' $FCCONFIG >$tmpfile 
    560565        echo -e "INTERVAL=$INTERVAL\nFCTEMPS=$FCTEMPS\nFCFANS=$FCFANS\nMINTEMP=$MINTEMP\nMAXTEMP=$MAXTEMP\nMINSTART=$MINSTART\nMINSTOP=$MINSTOP" >>$tmpfile 
     566        [ -n "$MINPWM" ] && echo "MINPWM=$MINPWM" >>$tmpfile 
     567        [ -n "$MAXPWM" ] && echo "MAXPWM=$MAXPWM" >>$tmpfile 
    561568        mv $tmpfile $FCCONFIG 
    562569        #check if file was written correctly 
     
    600607                        echo "  MINSTART=`echo $MINSTART |sed -e \"s/ /\n/g\" |egrep \"${pwmo}\" |sed -e \"s/.*=//g\"`" 
    601608                        echo "  MINSTOP=`echo $MINSTOP |sed -e \"s/ /\n/g\" |egrep \"${pwmo}\" |sed -e \"s/.*=//g\"`" 
     609                        echo "  MINPWM=`echo $MINPWM |sed -e \"s/ /\n/g\" |egrep \"${pwmo}\" |sed -e \"s/.*=//g\"`" 
     610                        echo "  MAXPWM=`echo $MAXPWM |sed -e \"s/ /\n/g\" |egrep \"${pwmo}\" |sed -e \"s/.*=//g\"`" 
    602611                done 
    603612                echo ;; 
     
    641650                        fi 
    642651                        echo 
    643                         echo 'Enter the low temperature (C)' 
    644                         echo -n "at which the fan should be switched off ($DEFMINTEMP): " 
     652                        echo 'Enter the low temperature (degree C)' 
     653                        echo -n "below which the fan should spin at minimum speed ($DEFMINTEMP): " 
    645654                        read XMT 
    646655                        if [ "$XMT" = "" ] 
     
    655664                        fi 
    656665                        echo 
    657                         echo 'Enter the high temperature (C)' 
    658                         echo -n "at which the fan should be switched to full speed ($DEFMAXTEMP): " 
     666                        echo 'Enter the high temperature (degree C)' 
     667                        echo -n "over which the fan should spin at maximum speed ($DEFMAXTEMP): " 
    659668                        read XMT 
    660669                        if [ "$XMT" = "" ] 
     
    705714                        else 
    706715                                MINSTOP="`echo $MINSTOP | sed -e \"s/${pwmsed}[^ ]* *//g\"` ${pwms}=${XMV}" 
     716                        fi 
     717                        echo 
     718                        echo "Enter the PWM value (0-$XMV) to use when the temperature" 
     719                        echo -n "is below the low temperature limit (0): " 
     720                        read XMINP 
     721                        if [ -n "$XMINP" ] 
     722                        then 
     723                                if [ "$MINPWM" = "" ] 
     724                                then 
     725                                        MINPWM="${pwms}=${XMINP}" 
     726                                else 
     727                                        MINPWM="`echo $MINPWM | sed -e \"s/${pwmsed}[^ ]* *//g\"` ${pwms}=${XMINP}" 
     728                                fi 
     729                        fi 
     730                        echo 
     731                        echo "Enter the PWM value ($XMV-$MAX) to use when the temperature" 
     732                        echo -n "is over the high temperature limit ($MAX): " 
     733                        read XMAXP 
     734                        if [ -n "$XMAXP" ] 
     735                        then 
     736                                if [ "$MAXPWM" = "" ] 
     737                                then 
     738                                        MAXPWM="${pwms}=${XMAXP}" 
     739                                else 
     740                                        MAXPWM="`echo $MAXPWM | sed -e \"s/${pwmsed}[^ ]* *//g\"` ${pwms}=${XMAXP}" 
     741                                fi 
    707742                        fi 
    708743                        echo