SantaRosaFanControl

Revision 2 as of 2007-10-08 08:05:09

Clear message

Finding that my MacBookPro 3.1 (SantaRosa) was getting incredibly hot, even with applesmc installed, I have written a stupid little script that controls the minimum fan speed so that it stays at a reasonable temperature.

I am looking at how to make it so that this is taken care of by ACPI. If you can help me, contact Nbarcet.

The following scripts create a daemon that will regulate temperature for us. The following are the ones I am pretty happy with, keeping my laptop cpus at an average 51°. MIN and MAX are temperature in degrees x 10.

# A temperature daemon to help for a cooler MacBookPro 3.1
# Author nick barcet nickNOSPAM AT barcet DOT com

do_init()
{
        # I'm pretty happy with the following  values but feel free to
        # play with them.
        # We set different value for on and off line, as we don't care
        # about saving power when on-line.
        if (cat /proc/acpi/ac_adapter/ADP1/state | grep on-line > /dev/null); then
                # We are online, be pretty cool
                MIN=465 # temp in degree celsius x 10
                MAX=520
                let "RATIO = 6000 / ($MAX - $MIN)"
        else
                [ $debug -eq 1 ] && echo "state:                   off-line"
                MIN=510 # temp in degree celsius x 10
                MAX=590
                let "RATIO = 4500 / ($MAX - $MIN)"
        fi
        let "TARGET = ( ($MAX - $MIN)/3 ) + $MIN"
        let "HIGH = ( ($MAX - $MIN)/4 ) + $TARGET"
}

debug=0
do_init
count=1


while [ true ]; do 
        TEMP1=`cat /sys/devices/platform/applesmc.768/temp5_input`
        TEMP2=`cat /sys/devices/platform/applesmc.768/temp8_input`
        TEMP3=`cat /sys/devices/platform/applesmc.768/temp3_input`
        TEMP4=`cat /sys/devices/platform/applesmc.768/temp3_input`
        let "TEMP = ($TEMP1 + $TEMP2 + $TEMP3 + $TEMP4)/ 400"
        let "TEMP = ($TEMP1 + $TEMP2)/200"

        [ $debug -eq 1 ] && echo "average temp: $TEMP (target: $TARGET, high: $HIGH)" 
        
        let "SPEED = ($TEMP - $MIN) * $RATIO"    

        # Just to make sur we do not set fan >6000 or <0
        if [ $SPEED -gt 6000 ]; then
                SPEED=6000
        elif [ $SPEED -lt 1 ]; then
                SPEED=1
        elif [ $TEMP -lt $TARGET ]; then
                #let autoregulation work (if it does)
                SPEED=1  
        fi

        [ $debug -eq 1 ] && echo "set fan speed to: $SPEED (ratio: $RATIO)"
        echo $SPEED > /sys/devices/platform/applesmc.768/fan2_min
        echo $SPEED > /sys/devices/platform/applesmc.768/fan1_min
        
        if [ $SPEED -lt 2 ]; then
                # Sleep longer when autoregulatings
                sleep 20
                let "count = $count+4"
        else
                sleep 5
                let "count = $count+1"
        fi

        if [ $count -gt 10 ]; then
                count=0
                do_init
                # if above HIGH temp level, force the fan speed a bit
                if [ $TEMP -gt $HIGH ]; then
                        [ $debug -eq 1 ] && echo "temp: $TEMP > target: $TARGET"
                        [ $debug -eq 1 ] && echo "Force fan speed to: 6000 for 20 sec"
                        echo 6000 > /sys/devices/platform/applesmc.768/fan2_min
                        echo 6000 > /sys/devices/platform/applesmc.768/fan1_min
                        sleep 20
                fi
        fi
done