From 6e5eebe3c18de474f0c0ebbc3fe51794428ba53b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Eug=C3=AAnio?= Date: Wed, 12 Mar 2025 11:38:39 -0300 Subject: [PATCH] amdgpu: limit fan speed --- hosts/monolith/amdgpu.nix | 2 +- scripts/amd-fan-control | 33 +++++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/hosts/monolith/amdgpu.nix b/hosts/monolith/amdgpu.nix index 765e081..2554500 100644 --- a/hosts/monolith/amdgpu.nix +++ b/hosts/monolith/amdgpu.nix @@ -18,7 +18,7 @@ in systemd.services.amd-fan-control = { script = '' - ${lib.getExe pkgs.amd-fan-control} /sys/class/drm/card1/device 60 85 + ${lib.getExe pkgs.amd-fan-control} /sys/class/drm/card1/device 60 90 0 80 ''; serviceConfig = { Restart = "always"; diff --git a/scripts/amd-fan-control b/scripts/amd-fan-control index 1f4c3e7..5b0d7a9 100755 --- a/scripts/amd-fan-control +++ b/scripts/amd-fan-control @@ -39,10 +39,31 @@ if [ -z "$TEMP_MAX" ];then bail "No maximum temperature provided" fi -PWM_MIN=0 -PWM_MAX=255 +PWM_MIN_PCT="$4" +PWM_MAX_PCT="$5" + +if [ -z "$PWM_MIN_PCT" ];then + bail "No minimum fan speed % not provided" +fi + +if [ -z "$PWM_MAX_PCT" ];then + bail "No maximum fan speed % not provided" +fi + +PWM_MIN="$(( $PWM_MIN_PCT * 255 / 100))" +PWM_MAX="$(( $PWM_MAX_PCT * 255 / 100))" echo "Running..." >&2 + +echo "TEMP_MIN=$TEMP_MIN°C" +echo "TEMP_MAX=$TEMP_MAX°C" +echo "FAN_MIN=$PWM_MIN_PCT%" +echo "FAN_MAX=$PWM_MAX_PCT%" + +echo 1 > "$HWMON/pwm1_enable" + +PREV=0 + while true; do TEMPERATURE_RAW=$(cat "$TEMP_INPUT") TEMPERATURE="$(( $TEMPERATURE_RAW / 1000 ))" @@ -55,7 +76,11 @@ while true; do PWM=$PWM_MIN fi - echo 1 > "$HWMON/pwm1_enable" - echo "$PWM" > "$HWMON/pwm1" + AVG="$(( ($PWM * 20 + $PREV * 80) / 100 ))" + + echo "$AVG" + + echo "$AVG" > "$HWMON/pwm1" + PREV="$AVG" sleep .1s done