Created
June 20, 2011 21:38
-
-
Save asm/1036648 to your computer and use it in GitHub Desktop.
ATI fan controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Quick and dirty ATI fan control script. This script will attempt to keep your | |
# cards around the OPTIMAL temperature within WINDOW degrees. You'll probably | |
# need to run this as root. | |
OPTIMAL = 75 # Celcius | |
WINDOW = 1 # Celcius | |
MIN_FAN = 40 # Minimum fan speed | |
def system_capture(cmd, raise_on_error = true) | |
handle = IO.popen(cmd + " 2>&1") | |
exit_code = Process.waitpid2(handle.pid)[1] >> 8 | |
output = handle.read | |
if exit_code.to_i > 0 and raise_on_error | |
raise "Command: #{cmd} exited with code: #{exit_code}, output follows:\n#{output}" | |
end | |
return [exit_code, output] | |
end | |
while true do | |
# Get current temps | |
code, temps = system_capture('aticonfig --odgt --adapter=all') | |
temps.gsub("\n", '').scan(/Adapter (\d+).*? (\d+\.\d+) C/).each do |card, temp| | |
# Get current fan for this card | |
code, fan = system_capture("DISPLAY=:0.#{card} aticonfig --pplib-cmd 'get fanspeed 0'") | |
fan = fan.match(/Speed: (\d+)/)[1] | |
puts "Card #{card} current: temp #{temp}C, fan #{fan}%" | |
temp = temp.to_i | |
fan = fan.to_i | |
next if (OPTIMAL - temp).abs <= WINDOW | |
if OPTIMAL > temp | |
next if fan <= MIN_FAN | |
puts "\tDecreasing fan" | |
code, output = system_capture("DISPLAY=:0.#{card} aticonfig --pplib-cmd 'set fanspeed 0 #{fan - 1}'") | |
raise "unable to decrease fan to #{new_fan} on card #{card}" if code != 0 | |
else | |
puts "\tIncreasing fan" | |
code, output = system_capture("DISPLAY=:0.#{card} aticonfig --pplib-cmd 'set fanspeed 0 #{fan + 1}'") | |
raise "unable to increase fan to #{new_fan} on card #{card}" if code != 0 | |
end | |
end | |
sleep 5 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment