add caching, minor improvements
parent
06533ceba4
commit
16ea60a4fb
|
@ -16,10 +16,14 @@ use List::Util qw[min max];
|
|||
`ipmitool sensor thresh FAN4 lower 0 100 200`;
|
||||
`ipmitool sensor thresh FAN5 lower 0 100 200`;
|
||||
|
||||
# cache SDR data for faster access
|
||||
`rm /opt/ipmi-cache.sdr`;
|
||||
`while ipmitool sdr dump /opt/ipmi-cache.sdr; [ $? != 0 ]; do sleep 2; done`;
|
||||
|
||||
my $min_temp_change = 2; # °C minimum change to actually cause a fan speed update
|
||||
my $seconds_to_sleep = 2; # Number of seconds to sleep between update loops
|
||||
|
||||
# 0x64 = 100, 0x00 = 0.
|
||||
# 0x64 = 100, 0x00 = 0.
|
||||
# CPU Temp -> Fan Speed Mappings
|
||||
my %cpu_temp_to_fan_speed;
|
||||
$cpu_temp_to_fan_speed{80} = 0x64;
|
||||
|
@ -53,9 +57,9 @@ my $g_current_cpu_temp = 0;
|
|||
my $g_last_set_cpu_temp = 0;
|
||||
my $g_last_set_sys_temp = 0;
|
||||
|
||||
sub UpdateFanSpeed {
|
||||
# Gather statistics for fan speed and CPU Temp and stuch
|
||||
my $ipmi_output = `ipmitool sdr list full`;
|
||||
sub UpdateFanSpeed {
|
||||
# Gather statistics for fan speed and CPU Temp
|
||||
my $ipmi_output = `ipmitool sdr list full -S /opt/ipmi-cache.sdr`;
|
||||
my @vals = split( "\n", $ipmi_output );
|
||||
|
||||
my $current_cpu_temp = 0;
|
||||
|
@ -74,7 +78,7 @@ sub UpdateFanSpeed {
|
|||
my $sys_temp = $2;
|
||||
$current_sys_temp = max( $sys_temp, $current_sys_temp );
|
||||
}
|
||||
|
||||
|
||||
} # foreach my $value (@vals)
|
||||
|
||||
$g_current_cpu_temp = $current_cpu_temp;
|
||||
|
@ -82,7 +86,7 @@ sub UpdateFanSpeed {
|
|||
|
||||
my $desired_cpu_fan_speed = 0x0;
|
||||
my $desired_sys_fan_speed = 0x0;
|
||||
|
||||
|
||||
my @cpu_temps = keys %cpu_temp_to_fan_speed;
|
||||
for my $cpu_temp (@cpu_temps) {
|
||||
if( $current_cpu_temp >= $cpu_temp ) {
|
||||
|
@ -102,16 +106,16 @@ sub UpdateFanSpeed {
|
|||
# print "The fan speed setting for GPU Temp $sys_temp *C is $sys_temp_to_fan_speed{$sys_temp} % duty cycle\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( $desired_cpu_fan_speed == 0x0 ) {
|
||||
print "\n***** ERROR: Failed to determine a desired fan speed. Forcing CPU fans to 100% duty cycle as a safety fallback measure. *****\n";
|
||||
$desired_cpu_fan_speed = 0x64;
|
||||
}
|
||||
}
|
||||
|
||||
if( $desired_sys_fan_speed == 0x0 ) {
|
||||
print "\n***** ERROR: Failed to determine a desired fan speed. Forcing SYS fans to 100% duty cycle as a safety fallback measure. *****\n";
|
||||
$desired_sys_fan_speed = 0x64;
|
||||
}
|
||||
}
|
||||
|
||||
$cpu_temp_difference = $g_current_cpu_temp - $g_last_set_cpu_temp;
|
||||
$sys_temp_difference = $g_current_sys_temp - $g_last_set_sys_temp;
|
||||
|
@ -132,7 +136,7 @@ sub UpdateFanSpeed {
|
|||
$g_current_cpu_fan_duty_cycle = $desired_cpu_fan_speed;
|
||||
|
||||
`ipmitool raw 0x30 0x70 0x66 0x01 0x00 $desired_cpu_fan_speed`;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -144,4 +148,4 @@ while( 1 ) {
|
|||
UpdateFanSpeed();
|
||||
#print "Update Complete - going to sleep for $seconds_to_sleep seconds...\n";
|
||||
sleep $seconds_to_sleep;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue