Skip to content

Instantly share code, notes, and snippets.

@nonchip
Last active January 19, 2018 20:11
Show Gist options
  • Save nonchip/ef901aba1234c073b035920e5ab73c23 to your computer and use it in GitHub Desktop.
Save nonchip/ef901aba1234c073b035920e5ab73c23 to your computer and use it in GitHub Desktop.
set the nvidia fan speed to a custom value (optionally derived from the current temperature)
#!/bin/zsh
if [ "_$1" = "_-auto" ]
then nvidia-settings -a '[gpu:0]/GPUFanControlState=0'
elif [ "_$1" = "_-temp" ]
then nvidia-settings -a '[gpu:0]/GPUFanControlState=1'
temp=$(nvidia-settings -tq '[gpu:0]/GPUCoreTemp')
target=$((($temp*$2)/100))
if [ ! "_$3" = "_" ]
then zmodload zsh/mathfunc
target=$(( int( ( $2 * ($temp * $temp) ) + ( $3 * $temp ) + $4 ) ))
fi
[ $target -gt 100 ] && target=100
[ $target -lt 0 ] && target=0
nvidia-settings -a '[fan:0]/GPUTargetFanSpeed='$target
elif [ "_$1" = "_-fix" ]
then nvidia-settings -a '[gpu:0]/GPUFanControlState=1'
nvidia-settings -a '[fan:0]/GPUTargetFanSpeed='$2
else
cat <<END
USAGE: $0 <mode> [...]
Modes:
-temp {<percent>|<a> <b> <c>}
using <percent>:
sets the target fan speed to the current temperature (in C) multiplied by the <percent>age.
sane values: around 150
using <a> <b> <c>:
sets the target fan speed to <a>*temp^2 + <b>*temp + c, with temp being the current temperature in C
-fix <percent>
sets the target fan speed to the <percentage>
sane values: 0..100
-auto
reenables the driver's autothrottling
END
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment