Bitcoin Forum

Bitcoin => Mining software (miners) => Topic started by: brunoshady on July 08, 2011, 09:32:22 PM



Title: Any linux script for maintain GPU temp? (changing fan speed)
Post by: brunoshady on July 08, 2011, 09:32:22 PM
anyone got something on this?


for example, I wan't to set my GPU temp in 70 ºC, so, when the temp is above, the fan speeds gets higher and when the temp is lower, the fan speed go slow...


Title: Re: Any linux script for maintain GPU temp? (changing fan speed)
Post by: brunoshady on July 08, 2011, 09:55:40 PM
something simple like



vartemp = 70


while true:
     if temp > vartemp
          fan_speed_increase
    else if temp < vartemp
          fan_speed_decrease


Title: Re: Any linux script for maintain GPU temp? (changing fan speed)
Post by: swivel on July 08, 2011, 11:32:30 PM
Here's a simple shell script. Save as fanmon.sh.

Code:
#!/bin/bash

DEVICE=$1
if [ "${DEVICE}" == "" ];
then
        echo "Usage: fanmon.sh <deviceid>"
        exit 1
fi

# temp levels in C
# fan speeds in %
MAXTEMP=80
MAXFAN=99

MIDTEMP=60
MIDFAN=70

MINTEMP=40
MINFAN=50

IDLEFAN=20
LASTTEMP=0

export DISPLAY=:0.${DEVICE}

while true;
do
        TEMP=`aticonfig --adapter=${DEVICE} --odgt | grep Temp | sed  's/.* \([0-9]*[0-9][0-9]\)\..*/\1/'`
        if [ "${TEMP}" -ne "${LASTTEMP}" ];
        then
                echo -n "Temp: ${TEMP}C "
                if [ "${TEMP}" -gt "${MAXTEMP}" ];
                then
                        echo "setting fan speed ${MAXFAN}%"
                        aticonfig --pplib-cmd "set fanspeed 0 ${MAXFAN}"
                elif [ "${TEMP} -gt ${MIDTEMP}" ];
                then
                        echo "setting fan speed ${MIDFAN}%"
                        aticonfig --pplib-cmd "set fanspeed 0 ${MIDFAN}"
                elif [ "${TEMP} -gt ${MINTEMP}" ];
                then
                        echo "setting fan speed ${MINFAN}%"
                        aticonfig --pplib-cmd "set fanspeed 0 ${MINFAN}"
                else
                        echo "setting fan speed ${IDLEFAN}%"
                        aticonfig --pplib-cmd "set fanspeed 0 ${IDLEFAN}"
                fi
        fi
        LASTTEMP=${TEMP}
        sleep 10
done


Run it like so:
Code:
# ./fanmon.sh 0 &

Adjust the temperature thresholds so the fan speed doesn't jump up and down.


Title: Re: Any linux script for maintain GPU temp? (changing fan speed)
Post by: Keninishna on July 09, 2011, 02:43:00 AM
amdoverdrivectrl can also set up fan profiles.


Title: Re: Any linux script for maintain GPU temp? (changing fan speed)
Post by: brunoshady on July 09, 2011, 02:48:07 AM
amdoverdrivectrl can also set up fan profiles.


yes but you only control the fan speed, not the temp..


and btw, I didn't managed to use it with 2 GPUs


Title: Re: Any linux script for maintain GPU temp? (changing fan speed)
Post by: swivel on July 09, 2011, 04:57:01 AM
OK I think this is more what you want.

Code:
#!/bin/bash

MAXSPD=80
MINSPD=20

if [ $# -lt 2 ];
then
        echo "Usage: setfantemp.sh <deviceid> <temp>"
        exit 1
fi

DEVICE=$1
SETTEMP=$2

export DISPLAY=:0.${DEVICE}
aticonfig --pplib-cmd "set fanspeed 0 ${MAXSPD}"

while true;
do
        CURTEMP=`aticonfig --adapter=${DEVICE} --odgt | grep Temp | sed  's/.* \([0-9]*[0-9][0-9]\)\..*/\1/'`
        CURSPD=`aticonfig --pplib-cmd "get fanspeed 0" | grep Result | sed  's/.* \([0-9]*[0-9][0-9]\)\%.*/\1/'`

        echo -n "Set temp: ${SETTEMP}C Current temp: ${CURTEMP}C Current speed: ${CURSPD}% - "

        if [ "${CURTEMP}" -ne "${SETTEMP}" ]; then
                if [ "${CURTEMP}" -lt "${SETTEMP}" ]; then
                        NEWSPD=$((${CURSPD} - 1))
                        if [ "${NEWSPD}" -lt "${MINSPD}" ]; then
                                echo "MIN speed limit"
                        else
                                echo "Decreasing speed to ${NEWSPD}"
                        fi
                else
                        NEWSPD=$((${CURSPD} + 1))
                        if [ "${NEWSPD}" -gt "${MAXSPD}" ]; then
                                echo "MAX speed limit"
                        else
                                echo "Increasing speed to ${NEWSPD}"
                                aticonfig --pplib-cmd "set fanspeed 0 ${NEWSPD}"
                        fi
                fi
        else
                echo "Stable"
        fi
        sleep 10
done


Save to setfantemp.sh. To run:

Code:
# ./setfantemp.sh 0 55 &

That will set your target temperature for card 0 to 55C. The script will adjust the fan speed to hit that target.

Max fan speed and min fan speed are hard coded in the script to be 80% and 20% respectively. You can raise the max speed if your card isn't getting cooled to your target temp.



Title: Re: Any linux script for maintain GPU temp? (changing fan speed)
Post by: brunoshady on July 12, 2011, 05:12:29 PM
OK I think this is more what you want.

Code:
#!/bin/bash

MAXSPD=80
MINSPD=20

if [ $# -lt 2 ];
then
        echo "Usage: setfantemp.sh <deviceid> <temp>"
        exit 1
fi

DEVICE=$1
SETTEMP=$2

export DISPLAY=:0.${DEVICE}

while true;
do
        CURTEMP=`aticonfig --adapter=${DEVICE} --odgt | grep Temp | sed  's/.* \([0-9]*[0-9][0-9]\)\..*/\1/'`
        CURSPD=`aticonfig --pplib-cmd "get fanspeed 0" | grep Result | sed  's/.* \([0-9]*[0-9][0-9]\)\%.*/\1/'`

        echo -n "Set temp: ${SETTEMP}C Current temp: ${CURTEMP}C Current speed: ${CURSPD}% - "

        if [ "${CURTEMP}" -ne "${SETTEMP}" ]; then
                if [ "${CURTEMP}" -lt "${SETTEMP}" ]; then
                        NEWSPD=$((${CURSPD} - 1))
                        if [ "${NEWSPD}" -lt "${MINSPD}" ]; then
                                echo "MIN speed limit"
                        else
                                echo "Decreasing speed to ${NEWSPD}"
                                aticonfig --pplib-cmd "set fanspeed 0 ${NEWSPD}"
                        fi
                else
                        NEWSPD=$((${CURSPD} + 1))
                        if [ "${NEWSPD}" -gt "${MAXSPD}" ]; then
                                echo "MAX speed limit"
                        else
                                echo "Increasing speed to ${NEWSPD}"
                                aticonfig --pplib-cmd "set fanspeed 0 ${NEWSPD}"
                        fi
                fi
        else
                echo "Stable"
        fi
        sleep 10
done


Save to setfantemp.sh. To run:

Code:
# ./setfantemp.sh 0 55 &

That will set your target temperature for card 0 to 55C. The script will adjust the fan speed to hit that target.

Max fan speed and min fan speed are hard coded in the script to be 80% and 20% respectively. You can raise the max speed if your card isn't getting cooled to your target temp.



I didn't test yet, but seems good for my porpose... I will test later today, but I have one question.


this line is correct?


Code:
        CURSPD=`aticonfig --pplib-cmd "get fanspeed 0" | grep Result | sed  's/.* \([0-9]*[0-9][0-9]\)\%.*/\1/'`

the get fanspeed 0 part... is 0 for device?
if yes, I will just change it to 1 over device 2, correct?


Title: Re: Any linux script for maintain GPU temp? (changing fan speed)
Post by: Vince on July 12, 2011, 05:23:22 PM
Here's my card fan regulator tool, written in php.
It adjusts the card temp to a specific temperature. It also catches temperature changes faster and adjusts the fan better than the simple version above.

It also has some safety extras:
Set fan to 100% if card is above 96° (can be adjusted)
Clock card down to 500Mhz at 100°C (100% fan here already)

and you can change clock frequencies by typing 1 <enter> to 5 <enter> (Silent to full speed), adjust frequencies if needed. 6 is for full speed + cooler card

Have fun  :)


Code:
<?

// Start with this fan speed
$fan = 40;

// Target temperature
$targetb = 86;

// At this temp switch to 100% fan
$highlim = 96;

$memspeed = 900;

$hyst = 2; $temp = 0; $target = $targetb;

while ( true) {
        $last = $temp;
        $temp = gt();
        if($last) {
                $diff = $temp - $last;
                if($diff > 2) $fan+=5+2*$diff;
                if($diff < -2) $fan-=5-2*$diff;
        }

        if($temp > $target + $hyst + 2) $fan+=4;
        if($temp > $target + $hyst + 4) $fan+=20;
        if($temp < $target - $hyst - 4) $fan-=4;
        if($temp > $target + $hyst) $fan++;
        if($temp < $target - $hyst) $fan--;
        if($fan > 100) $fan = 100;
        if($fan < 0) $fan = 0;
        if($temp > $highlim) $fan = 100;
        // At 100 Deg throttle card
        if($temp > 100) throttle();
        sf($fan);

        $a = array(STDIN);
        $l = array();

        if(stream_select($a, $l, $l, 10) > 0) {
                $d = fread(STDIN,1);
                echo "--".$d."--";
                switch($d) {
                        case '1':
                                sett(500); $target = $targetb + 1; break;
                        case '2':
                                sett(600); $target = $targetb + 1; break;
                        case '3':
                                sett(700); $target = $targetb; break;
                        case '4':
                                sett(800);  $target = $targetb - 1; break;
                        case '5':
                                sett(840); $target = $targetb - 2; break;
                        case '6':
                                sett(840); $target = $targetb - 4;
                }
        }

}

echo "\n";


function sett($speed) {
        echo "Setting clock to ".$speed."\n";
        exec("aticonfig --odsc ".$speed.",".$GLOBALS["memspeed"]);
}


function throttle() {
        echo "Too hot. Clocking card down to 500Mhz ...\n";
        exec("aticonfig --odsc 500,".$globals["memspeed"]);
}

function sf($speed) {
        echo "Setting fan to ".$speed."\n";
        exec('aticonfig --pplib-cmd "set fanspeed 0 '.$speed.'"');
}

function gt() {
        $ausgabe = array();
        $e = exec("aticonfig --odgt", $ausgabe);
        foreach($ausgabe as $line) {
                $t = explode("Sensor 0: Temperature -", $line);
                if(count($t) > 1) {
                        $t2 = explode(".", $t[1]); echo "Card at ".$t2[0]."\n"; return (int)$t2[0];
                }
        }
}


?>


Title: Re: Any linux script for maintain GPU temp? (changing fan speed)
Post by: swivel on July 12, 2011, 10:46:34 PM

I didn't test yet, but seems good for my porpose... I will test later today, but I have one question.

this line is correct?


Code:
        CURSPD=`aticonfig --pplib-cmd "get fanspeed 0" | grep Result | sed  's/.* \([0-9]*[0-9][0-9]\)\%.*/\1/'`

the get fanspeed 0 part... is 0 for device?
if yes, I will just change it to 1 over device 2, correct?

Yes that's correct. aticonfig get the parameters for the card according to the DISPLAY variable. The DISPLAY variable has the device number assigned to it:

Code:
export DISPLAY=:0.${DEVICE}


Title: Re: Any linux script for maintain GPU temp? (changing fan speed)
Post by: marcus_of_augustus on July 12, 2011, 11:04:43 PM

Yes there is this thread that has python script for doing exactly that on AMD cards ... (you got python if you're mining most likely)

http://forum.bitcoin.org/index.php?topic=10062.0

Wanted to also see the PID controller bit implemented for geek kicks but nobody with python skills ran with it ...

http://forum.bitcoin.org/index.php?topic=10062.20

... this way you would INPUT a desired TEMP. and controller would keep fan speed controlled to acheive temperature set-point ... as best it could.


Title: Re: Any linux script for maintain GPU temp? (changing fan speed)
Post by: brunoshady on July 12, 2011, 11:32:29 PM
is there anything to see the voltage consume of the gpu?


Title: Re: Any linux script for maintain GPU temp? (changing fan speed)
Post by: brunoshady on July 13, 2011, 03:58:03 PM
swivel, could you add something in it with starting fan speed? something like 50%...


when I turn on the script, it's starts from the idle and until get to the desired speed, the GPU gets very hot, even with sleep 5


could be done?


and works like a charm, thank you very much


Title: Re: Any linux script for maintain GPU temp? (changing fan speed)
Post by: swivel on July 13, 2011, 08:21:21 PM
swivel, could you add something in it with starting fan speed? something like 50%...


when I turn on the script, it's starts from the idle and until get to the desired speed, the GPU gets very hot, even with sleep 5


could be done?


and works like a charm, thank you very much

Yup just add the following after the export line:

Code:
export DISPLAY=:0.${DEVICE}
aticonfig --pplib-cmd "set fanspeed 0 50"