Merge pull request #81 from r3claimer/dev

tweak fan profiles, thanks doc brown
This commit is contained in:
r3claimer 2024-04-09 12:59:20 -07:00 committed by GitHub
commit 7ba416e8ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 128 additions and 44 deletions

View file

@ -4,7 +4,16 @@
. /etc/profile . /etc/profile
DEBUG=false ### Enable logging
case $(get_setting system.loglevel) in
verbose)
DEBUG=true
;;
*)
DEBUG=false
;;
esac
COOLING_PROFILE=$(get_setting "cooling.profile") COOLING_PROFILE=$(get_setting "cooling.profile")
FAN_PWM="${DEVICE_PWM_FAN}" FAN_PWM="${DEVICE_PWM_FAN}"
@ -22,7 +31,7 @@ trap "set_control 0 && exit 0" SIGHUP SIGINT SIGQUIT SIGABRT
if [ -e "/storage/.config/fancontrol.conf" ] && [ "${COOLING_PROFILE}" = "custom" ] if [ -e "/storage/.config/fancontrol.conf" ] && [ "${COOLING_PROFILE}" = "custom" ]
then then
log $0 "Loading configuration file" 2>/dev/null $DEBUG && log $0 "Loading configuration file" 2>/dev/null
source /storage/.config/fancontrol.conf source /storage/.config/fancontrol.conf
if [ ! $? = 0 ] if [ ! $? = 0 ]
then then
@ -37,17 +46,17 @@ if [ ! "${COOLING_PROFILE}" = "custom" ]
then then
if [ "${COOLING_PROFILE}" = "aggressive" ] if [ "${COOLING_PROFILE}" = "aggressive" ]
then then
SPEEDS=(255 225 192) SPEEDS=(192 225 255)
TEMPS=(70000 65000 0) TEMPS=(45000 75000 85000)
elif [ "${COOLING_PROFILE}" = "moderate" ] elif [ "${COOLING_PROFILE}" = "moderate" ]
then then
SPEEDS=(255 192 128 96) SPEEDS=(48 64 96 128 192 255)
TEMPS=(75000 70000 65000 0) TEMPS=(50000 55000 60000 70000 80000 90000)
elif [ "${COOLING_PROFILE}" = "quiet" ] elif [ "${COOLING_PROFILE}" = "quiet" ]
then then
# Quiet. # Quiet.
SPEEDS=(255 192 128 96 64 48 32) SPEEDS=(32 48 64 96 128 192 255)
TEMPS=(75000 70000 65000 60000 55000 50000 0) TEMPS=(50000 55000 60000 65000 70000 80000 90000)
else else
# auto # auto
set_control 0 >/dev/null 2>&1 set_control 0 >/dev/null 2>&1
@ -58,22 +67,41 @@ fi
log $0 "Enabling fan control." log $0 "Enabling fan control."
set_control 1 >/dev/null 2>&1 set_control 1 >/dev/null 2>&1
CURRENTSPEED=0
TEMP=${TEMPS[0]}
declare -a HISTORY
while true while true
do do
INDEX=0 INDEX=0
CPU_TEMP=$(printf "%.0f" $(awk '{ total += $1; count++ } END { print total/count }' ${DEVICE_TEMP_SENSOR})) CPU_TEMP=$(printf "%.0f" $(awk '{ total += $1; count++ } END { print total/count }' ${DEVICE_TEMP_SENSOR}))
$DEBUG && log $0 "CPU TEMP: ${CPU_TEMP}" 2>/dev/null
### Keep a rolling history of CPU temps.
HISTORY+=(${CPU_TEMP})
while (( ${#HISTORY[@]} > 10 ))
do
unset HISTORY[-0]
PRIOR_HISTORY=( ${HISTORY[*]} )
HISTORY=( ${PRIOR_HISTORY[*]} )
unset PRIOR_HISTORY
done
AVERAGE=$(echo $(IFS=+; echo "$((${HISTORY[*]}))") / ${#HISTORY[@]} | bc)
$DEBUG && log $0 "Current/Average/Ceiling (Speed): ${CPU_TEMP}/${AVERAGE}/${TEMP} (${CURRENTSPEED})."
for TEMP in "${TEMPS[@]}" for TEMP in "${TEMPS[@]}"
do do
if (( "${CPU_TEMP}" > "${TEMP}" )) && \ if (( "${CPU_TEMP}" >= "90000" )) || \
[ ! "${LASTSPEED}" = "${SPEEDS[${INDEX}]}" ] (( "${AVERAGE}" <= "${TEMP}" ))
then then
$DEBUG && log $0 "Setting PWM FAN to ${SPEEDS[${INDEX}]} (${TEMP})" 2>/dev/null if (( ${CURRENTSPEED} != ${SPEEDS[${INDEX}]} ))
echo ${SPEEDS[${INDEX}]} >${FAN_PWM} then
LASTSPEED=${SPEEDS[${INDEX}]} CURRENTSPEED=${SPEEDS[${INDEX}]}
echo ${SPEEDS[${INDEX}]} >${FAN_PWM}
$DEBUG && log $0 "Set fan to ${CURRENTSPEED}."
fi
break break
else
INDEX=$(( $INDEX + 1 ))
fi fi
INDEX=$(( $INDEX + 1 ))
done done
sleep 2 sleep 2
done done

View file

@ -4,7 +4,16 @@
. /etc/profile . /etc/profile
DEBUG=false ### Enable logging
case $(get_setting system.loglevel) in
verbose)
DEBUG=true
;;
*)
DEBUG=false
;;
esac
COOLING_PROFILE=$(get_setting "cooling.profile") COOLING_PROFILE=$(get_setting "cooling.profile")
FAN_PWM="${DEVICE_PWM_FAN}" FAN_PWM="${DEVICE_PWM_FAN}"
@ -38,17 +47,17 @@ if [ ! "${COOLING_PROFILE}" = "custom" ]
then then
if [ "${COOLING_PROFILE}" = "aggressive" ] if [ "${COOLING_PROFILE}" = "aggressive" ]
then then
SPEEDS=(255 225 195) SPEEDS=(195 225 255)
TEMPS=(55000 45000 0) TEMPS=(45000 60000 80000)
elif [ "${COOLING_PROFILE}" = "moderate" ] elif [ "${COOLING_PROFILE}" = "moderate" ]
then then
SPEEDS=(255 192 128 96) SPEEDS=(48 64 96 128 192 255)
TEMPS=(65000 55000 45000 0) TEMPS=(45000 55000 65000 75000 85000 90000)
elif [ "${COOLING_PROFILE}" = "quiet" ] elif [ "${COOLING_PROFILE}" = "quiet" ]
then then
# Quiet. # Quiet.
SPEEDS=(255 192 128 96 64 48 32) SPEEDS=(32 48 64 96 128 192 255)
TEMPS=(70000 60000 55000 50000 49000 47000 0) TEMPS=(45000 50000 55000 65000 75000 85000 90000)
else else
# auto # auto
set_control 0 >/dev/null 2>&1 set_control 0 >/dev/null 2>&1
@ -59,22 +68,41 @@ fi
log $0 "Enabling fan control." log $0 "Enabling fan control."
set_control 1 >/dev/null 2>&1 set_control 1 >/dev/null 2>&1
CURRENTSPEED=0
TEMP=${TEMPS[0]}
declare -a HISTORY
while true while true
do do
INDEX=0 INDEX=0
CPU_TEMP=$(printf "%.0f" $(awk '{ total += $1; count++ } END { print total/count }' ${DEVICE_TEMP_SENSOR})) CPU_TEMP=$(printf "%.0f" $(awk '{ total += $1; count++ } END { print total/count }' ${DEVICE_TEMP_SENSOR}))
$DEBUG && log $0 "CPU TEMP: ${CPU_TEMP}" 2>/dev/null
### Keep a rolling history of CPU temps.
HISTORY+=(${CPU_TEMP})
while (( ${#HISTORY[@]} > 10 ))
do
unset HISTORY[-0]
PRIOR_HISTORY=( ${HISTORY[*]} )
HISTORY=( ${PRIOR_HISTORY[*]} )
unset PRIOR_HISTORY
done
AVERAGE=$(echo $(IFS=+; echo "$((${HISTORY[*]}))") / ${#HISTORY[@]} | bc)
$DEBUG && log $0 "Current/Average/Ceiling (Speed): ${CPU_TEMP}/${AVERAGE}/${TEMP} (${CURRENTSPEED})."
for TEMP in "${TEMPS[@]}" for TEMP in "${TEMPS[@]}"
do do
if (( "${CPU_TEMP}" > "${TEMP}" )) && \ if (( "${CPU_TEMP}" >= "90000" )) || \
[ ! "${LASTSPEED}" = "${SPEEDS[${INDEX}]}" ] (( "${AVERAGE}" <= "${TEMP}" ))
then then
$DEBUG && log $0 "Setting PWM FAN to ${SPEEDS[${INDEX}]} (${TEMP})" 2>/dev/null if (( ${CURRENTSPEED} != ${SPEEDS[${INDEX}]} ))
echo ${SPEEDS[${INDEX}]} >${FAN_PWM} then
LASTSPEED=${SPEEDS[${INDEX}]} CURRENTSPEED=${SPEEDS[${INDEX}]}
echo ${SPEEDS[${INDEX}]} >${FAN_PWM}
$DEBUG && log $0 "Set fan to ${CURRENTSPEED}."
fi
break break
else
INDEX=$(( $INDEX + 1 ))
fi fi
INDEX=$(( $INDEX + 1 ))
done done
sleep 2 sleep 2
done done

View file

@ -4,7 +4,16 @@
. /etc/profile . /etc/profile
DEBUG=false ### Enable logging
case $(get_setting system.loglevel) in
verbose)
DEBUG=true
;;
*)
DEBUG=false
;;
esac
COOLING_PROFILE=$(get_setting "cooling.profile") COOLING_PROFILE=$(get_setting "cooling.profile")
log $0 "Setting profile to ${COOLING_PROFILE}" log $0 "Setting profile to ${COOLING_PROFILE}"
@ -34,16 +43,16 @@ if [ ! "${COOLING_PROFILE}" = "custom" ]
then then
if [ "${COOLING_PROFILE}" = "aggressive" ] if [ "${COOLING_PROFILE}" = "aggressive" ]
then then
SPEEDS=(128 96 72) SPEEDS=(72 96 128)
TEMPS=(70000 65000 0) TEMPS=(45000 75000 85000)
elif [ "${COOLING_PROFILE}" = "moderate" ] elif [ "${COOLING_PROFILE}" = "moderate" ]
then then
SPEEDS=(128 96 72 64 48) SPEEDS=(32 48 64 72 96 128)
TEMPS=(70000 65000 60000 55000 0) TEMPS=(50000 55000 60000 70000 80000 90000)
elif [ "${COOLING_PROFILE}" = "quiet" ] elif [ "${COOLING_PROFILE}" = "quiet" ]
then then
SPEEDS=(128 96 64 48 32) SPEEDS=(24 32 48 64 72 96 128)
TEMPS=(70000 65000 60000 55000 0) TEMPS=(50000 55000 60000 65000 70000 80000 90000)
else else
# auto # auto
set_control 0x01 >/dev/null 2>&1 set_control 0x01 >/dev/null 2>&1
@ -51,25 +60,44 @@ then
fi fi
fi fi
log $0 "Enabling fan control." $DEBUG && log $0 "Enabling fan control."
set_control 0x00 >/dev/null 2>&1 set_control 0x00 >/dev/null 2>&1
CURRENTSPEED=0
TEMP=${TEMPS[0]}
declare -a HISTORY
while true while true
do do
INDEX=0 INDEX=0
CPU_TEMP=$(printf "%.0f" $(awk '{ total += $1; count++ } END { print total/count }' ${DEVICE_TEMP_SENSOR})) CPU_TEMP=$(printf "%.0f" $(awk '{ total += $1; count++ } END { print total/count }' ${DEVICE_TEMP_SENSOR}))
$DEBUG && log $0 "CPU TEMP: ${CPU_TEMP}" 2>/dev/null
### Keep a rolling history of CPU temps.
HISTORY+=(${CPU_TEMP})
while (( ${#HISTORY[@]} > 10 ))
do
unset HISTORY[-0]
PRIOR_HISTORY=( ${HISTORY[*]} )
HISTORY=( ${PRIOR_HISTORY[*]} )
unset PRIOR_HISTORY
done
AVERAGE=$(echo $(IFS=+; echo "$((${HISTORY[*]}))") / ${#HISTORY[@]} | bc)
$DEBUG && log $0 "Current/Average/Ceiling (Speed): ${CPU_TEMP}/${AVERAGE}/${TEMP} (${CURRENTSPEED})."
for TEMP in "${TEMPS[@]}" for TEMP in "${TEMPS[@]}"
do do
if (( "${CPU_TEMP}" > "${TEMP}" )) && \ if (( "${CPU_TEMP}" >= "90000" )) || \
[ ! "${LASTSPEED}" = "${SPEEDS[${INDEX}]}" ] (( "${AVERAGE}" <= "${TEMP}" ))
then then
$DEBUG && log $0 "Setting PWM FAN to ${SPEEDS[${INDEX}]} (${TEMP})" 2>/dev/null if (( ${CURRENTSPEED} != ${SPEEDS[${INDEX}]} ))
ectool -w 0x11 -z $(printf '%x\n' ${SPEEDS[${INDEX}]}) >/dev/null 2>&1 then
LASTSPEED=${SPEEDS[${INDEX}]} CURRENTSPEED=${SPEEDS[${INDEX}]}
ectool -w 0x11 -z $(printf '%x\n' ${CURRENTSPEED}) >/dev/null 2>&1
$DEBUG && log $0 "Set fan to ${CURRENTSPEED}."
fi
break break
else
INDEX=$(( $INDEX + 1 ))
fi fi
INDEX=$(( $INDEX + 1 ))
done done
sleep 2 sleep 2
done done