From 351477b087802495254edca437533d808ef25236 Mon Sep 17 00:00:00 2001 From: AuxXxilium Date: Thu, 20 Jun 2024 18:53:55 +0200 Subject: [PATCH] cpufreqscaling: add sanity check Signed-off-by: AuxXxilium --- cpufreqscaling/all/usr/sbin/rescaler.sh | 15 ++++++++----- cpufreqscaling/all/usr/sbin/scaler.sh | 30 ++++++++++++++----------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/cpufreqscaling/all/usr/sbin/rescaler.sh b/cpufreqscaling/all/usr/sbin/rescaler.sh index d00718e..d5a2e2d 100755 --- a/cpufreqscaling/all/usr/sbin/rescaler.sh +++ b/cpufreqscaling/all/usr/sbin/rescaler.sh @@ -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 - for i in $(seq 0 "${cpucorecount}"); do - echo "${1}" >/sys/devices/system/cpu/cpu"${i}"/cpufreq/scaling_governor - done +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 diff --git a/cpufreqscaling/all/usr/sbin/scaler.sh b/cpufreqscaling/all/usr/sbin/scaler.sh index ebfdcfa..614d17c 100755 --- a/cpufreqscaling/all/usr/sbin/scaler.sh +++ b/cpufreqscaling/all/usr/sbin/scaler.sh @@ -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) - # 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 + 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 + echo "No cpufreq_${1} module found" + exit 1 fi - - governor=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor) - if [ "$governor" = "userspace" ]; then - userspace - fi - sleep 0.5 else - exit 0 + exit 1 fi done