cpufreqscaling: add sanity check

Signed-off-by: AuxXxilium <info@auxxxilium.tech>
This commit is contained in:
AuxXxilium 2024-06-20 18:53:55 +02:00
parent 340f2b8763
commit 351477b087
2 changed files with 27 additions and 18 deletions

View File

@ -13,9 +13,14 @@ cpucorecount=$(cat /proc/cpuinfo | grep processor | wc -l)
cpucorecount=$((cpucorecount - 1))
governor=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor)
# Set correct cpufreq governor to allow user defined frequency scaling
if [ "$governor" != "${1}" ]; then
if [ -f "/usr/lib/modules/cpufreq_${1}" ] || [ "${1}" = "userspace" ]; then
# Set correct cpufreq governor to allow user defined frequency scaling
if [ "$governor" != "${1}" ]; then
for i in $(seq 0 "${cpucorecount}"); do
echo "${1}" >/sys/devices/system/cpu/cpu"${i}"/cpufreq/scaling_governor
done
fi
else
echo "No cpufreq_${1} module found"
exit 1
fi

View File

@ -98,26 +98,30 @@ function userspace() {
# Deamonize the main function...
while true; do
if [ -f /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor ]; then
if [ -f "/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor" ]; then
rm -f /usr/sbin/stopscale
# Get cpu cores count minus 1, to allow maping from 0
cpucorecount=$(cat /proc/cpuinfo | grep processor | wc -l)
cpucorecount=$((cpucorecount - 1))
governor=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor)
if [ -f "/usr/lib/modules/cpufreq_${1}" ] || [ "${1}" = "userspace" ]; then
# Set correct cpufreq governor to allow user defined frequency scaling
if [ "$governor" != "${1}" ]; then
for i in $(seq 0 "${cpucorecount}"); do
echo "${1}" >/sys/devices/system/cpu/cpu"${i}"/cpufreq/scaling_governor
done
fi
governor=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor)
if [ "$governor" = "userspace" ]; then
userspace
fi
sleep 0.5
else
exit 0
echo "No cpufreq_${1} module found"
exit 1
fi
else
exit 1
fi
done