[Bug 201539] AMDGPU R9 390 automatic fan speed control in Linux 4.19/4.20/5.0

bugzilla-daemon at bugzilla.kernel.org bugzilla-daemon at bugzilla.kernel.org
Fri Dec 6 03:22:25 UTC 2019


https://bugzilla.kernel.org/show_bug.cgi?id=201539

--- Comment #38 from muncrief (rmuncrief at humanavance.com) ---
(In reply to MasterCATZ from comment #37)
> well its neither of those modules 
> I should have looked at the files after I scanned for files containing 104000
> 
> 
> I can not even force run the cards in performance mode anymore with 100% fan
> speed stuck on 
> 
> if i could just find the setting to tell amdgpu / hwmon / powerplay what
> temp I call hot this would be solved

Here is a slightly modified version of a fan control script, along with the
service to run it, from the Arch Wiki. I don't know what distribution you use
but hopefully this will at least get you started. Unfortunately it doesn't seem
like the kernel devs are interested in fixing this, so after a long time I just
had to use this kludgey solution.

1. Create a file with the following contents named "amdgpu-fancontrol" in
"/usr/local/bin" and make it executable.

--------------- Start amdgpu-fancontrol ---------------

#!/bin/bash

HYSTERESIS=6000   # in mK
SLEEP_INTERVAL=1  # in s
DEBUG=true

# set temps (in degrees C * 1000) and corresponding pwm values in ascending
order and with the same amount of values
TEMPS=( 40000  50000  65000 75000 80000 90000 )
PWMS=(      0  100     140   190   200   255 )

# hwmon paths, hardcoded for one amdgpu card, adjust as needed
HWMON=$(ls /sys/class/drm/card0/device/hwmon)
FILE_PWM=$(echo /sys/class/drm/card0/device/hwmon/$HWMON/pwm1)
FILE_FANMODE=$(echo /sys/class/drm/card0/device/hwmon/$HWMON/pwm1_enable)
FILE_TEMP=$(echo /sys/class/drm/card0/device/hwmon/$HWMON/temp1_input)
# might want to use this later
#FILE_TEMP_CRIT=$(echo /sys/class/hwmon/hwmon?/temp1_crit_hyst)
[[ -f "$FILE_PWM" && -f "$FILE_FANMODE" && -f "$FILE_TEMP" ]] || { echo
"invalid hwmon files" ; exit 1; }

# load configuration file if present
[ -f /etc/amdgpu-fancontrol.cfg ] && . /etc/amdgpu-fancontrol.cfg

# check if amount of temps and pwm values match
if [ "${#TEMPS[@]}" -ne "${#PWMS[@]}" ]
then
  echo "Amount of temperature and pwm values does not match"
  exit 1
fi

# checking for privileges
if [ $UID -ne 0 ]
then
  echo "Writing to sysfs requires privileges, relaunch as root"
  exit 1
fi

function debug {
  if $DEBUG; then
    echo $1
  fi
}

# set fan mode to max(0), manual(1) or auto(2)
function set_fanmode {
  echo "setting fan mode to $1"
  echo "$1" > "$FILE_FANMODE"
}

function set_pwm {
  NEW_PWM=$1
  OLD_PWM=$(cat $FILE_PWM)

  echo "current pwm: $OLD_PWM, requested to set pwm to $NEW_PWM"
  debug "current pwm: $OLD_PWM, requested to set pwm to $NEW_PWM"
  if [ $(cat ${FILE_FANMODE}) -ne 1 ]
  then
    echo "Fanmode not set to manual."
    set_fanmode 1
  fi

  if [ "$NEW_PWM" -gt "$OLD_PWM" ] || [ -z "$TEMP_AT_LAST_PWM_CHANGE" ] || [
$(($(cat $FILE_TEMP) + HYSTERESIS)) -le "$TEMP_AT_LAST_PWM_CHANGE" ]; then
    $DEBUG || echo "current temp: $TEMP"
    echo "temp at last change was $TEMP_AT_LAST_PWM_CHANGE"
    echo "changing pwm to $NEW_PWM"
    echo "$NEW_PWM" > "$FILE_PWM"
    TEMP_AT_LAST_PWM_CHANGE=$(cat $FILE_TEMP)
  else
    debug "not changing pwm, we just did at $TEMP_AT_LAST_PWM_CHANGE, next
change when below $((TEMP_AT_LAST_PWM_CHANGE - HYSTERESIS))"
  fi
}

function interpolate_pwm {
  i=0
  TEMP=$(cat $FILE_TEMP)

  debug "current temp: $TEMP"

  if [[ $TEMP -le ${TEMPS[0]} ]]; then
    # below first point in list, set to min speed
    set_pwm "${PWMS[i]}"
    return
  fi

  for i in "${!TEMPS[@]}"; do
    if [[ $i -eq $((${#TEMPS[@]}-1)) ]]; then
      # hit last point in list, set to max speed
      set_pwm "${PWMS[i]}"
      return
    elif [[ $TEMP -gt ${TEMPS[$i]} ]]; then
      continue
    fi

    # interpolate linearly
    LOWERTEMP=${TEMPS[i-1]}
    HIGHERTEMP=${TEMPS[i]}
    LOWERPWM=${PWMS[i-1]}
    HIGHERPWM=${PWMS[i]}
    PWM=$(echo "( ( $TEMP - $LOWERTEMP ) * ( $HIGHERPWM - $LOWERPWM ) / (
$HIGHERTEMP - $LOWERTEMP ) ) + $LOWERPWM" | bc)
    debug "interpolated pwm value for temperature $TEMP is: $PWM"
    set_pwm "$PWM"
    return
  done
}

function reset_on_fail {
  echo "exiting, resetting fan to auto control..."
  set_fanmode 2
  exit 1
}

# always try to reset fans on exit
trap "reset_on_fail" SIGINT SIGTERM

function run_daemon {
  while :; do
    interpolate_pwm
    debug
    sleep $SLEEP_INTERVAL
  done
}

# set fan control to manual
set_fanmode 1

# finally start the loop
run_daemon

--------------- End amdgpu-fancontrol ---------------


2. Create a file with the following contents named "amdgpu-fancontrol.service"
in /etc/systemd/system.

--------------- Start amdgpu-fancontrol.service ---------------

[Unit]
Description=amdgpu-fancontrol

[Service]
Type=simple
ExecStart=/usr/local/bin/amdgpu-fancontrol

[Install]
WantedBy=multi-user.target

--------------- End amdgpu-fancontrol.service ---------------

3. Here's how to enable, disable, and get the status of the fan control
service:

sudo systemctl enable amdgpu-fancontrol
sudo systemctl start amdgpu-fancontrol
sudo systemctl status amdgpu-fancontrol

-- 
You are receiving this mail because:
You are watching the assignee of the bug.


More information about the dri-devel mailing list