Author

Topic: Two useful perl scripts - part 1 (fan speed) (Read 1071 times)

full member
Activity: 224
Merit: 100
Been wanting to share these for a while.  My miners wouldn't be able to run at peak efficiency without them.  Hopefully they'll be of use to others as well.

1.  Fan speed script

I was trying to find a link to this script (not mine) but can't anymore.  Since the header has all the author's info, and GPL2, I'll just post that here.  He did a nice job with it imho.  But as always, USE AT YOUR OWN RISK.  Farming out fan speed and GPU clock settings to another app can be very, very risky.

----- snip -----

#!/usr/bin/perl -w
# 2008 by Bernhard M. Wiedemann
# Licensed under GNU GPL v2 or later

use strict;

# those below default settings mean:
# spin fan at 100% at 80+ C
# spin fan at 8% at 48- C

my %options=qw(hightemp 80 lowtemp 48 highfan 100 lowfan 8 updateinterval 10 debug 0);


sub diag($)
{ print(@_,"\n") if $options{debug} }


sub setfan($)
{
    my($percent)=@_;
    system("aticonfig", "--pplib-cmd", "set fanspeed 0 $percent");
}

sub mydie($)
{
    setfan($options{highfan});
    print (caller(),@_);
    exit 1;
}


sub gettemp()
{
    $_=`aticonfig --adapter=0 --od-gettemperature`;
    if(m/Sensor 0: Temperature - (\d+\.\d+) C/) {

    } else {mydie "bad temp read: $_"}
    return $1
}

$SIG{INT}=$SIG{TERM}=sub{setfan($options{highfan}) ; exit 2;};

open(STDIN, "if(!$options{debug}) {
    open(STDOUT, ">/dev/null");
    open(STDERR, ">/dev/null");
    if(fork()>0) {exit 0} # background
    if(fork()>0) {exit 0} # background
}

my $trange=$options{hightemp}-$options{lowtemp};
my $frange=$options{highfan}-$options{lowfan};
while(1) {
    my $t=gettemp();
    my $x=($t-$options{lowtemp})/$trange; # number between 0 and 1
    if($x<0) {$x=0}
    if($x>1) {$x=1}
    my $fan=int($x*$frange+$options{lowfan});
    diag "temp at $t";
    diag "setting fan to $fan";
    setfan($fan);
    sleep $options{updateinterval};
}
Jump to: