diff --git a/cpufreqscaling/all/usr/sbin/rescaler.sh b/cpufreqscaling/all/usr/sbin/rescaler.sh index c8043e0..8e48070 100755 --- a/cpufreqscaling/all/usr/sbin/rescaler.sh +++ b/cpufreqscaling/all/usr/sbin/rescaler.sh @@ -3,29 +3,37 @@ # Make things safer set -euo pipefail -rm -f /usr/sbin/stopscale - -#systemctl enable cpufreqscaling.service -#systemctl start cpufreqscaling.service +if [ -f /usr/sbin/stopscale ]; then + rm -f /usr/sbin/stopscale +fi # 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}.ko" ] || [ "${1}" = "schedutil" ]; then - # Set correct cpufreq governor to allow user defined frequency scaling +# Set correct cpufreq governor to allow user defined frequency scaling +if [ "${1}" == "ondemand" ] || [ "${1}" == "conservative" ]; then + if [ -f "/usr/lib/modules/cpufreq_${1}.ko" ]; then + modprobe cpufreq_${1} + 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 +else if [ "$governor" != "${1}" ]; then for i in $(seq 0 "${cpucorecount}"); do echo "${1}" >/sys/devices/system/cpu/cpu"${i}"/cpufreq/scaling_governor done fi - if [ "${1}" = "ondemand" ] || [ "${1}" = "conservative" ]; then - modprobe cpufreq_${1} - fi -else - echo "No cpufreq_${1} module found" - exit 1 fi -exit 0 \ No newline at end of file +governor=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor) +if [ "$governor" != "${1}" ]; then + systemctl restart cpufreqscaling.service +fi \ No newline at end of file diff --git a/cpufreqscaling/all/usr/sbin/scaler.sh b/cpufreqscaling/all/usr/sbin/scaler.sh index aefb8b3..daec173 100755 --- a/cpufreqscaling/all/usr/sbin/scaler.sh +++ b/cpufreqscaling/all/usr/sbin/scaler.sh @@ -112,10 +112,8 @@ while true; do done fi governor=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor) - if [ "$governor" = "userspace" ]; then + if [ "$governor" == "userspace" ]; then main fi sleep 0.5 -done - -exit 0 \ No newline at end of file +done \ No newline at end of file diff --git a/cpufreqscaling/all/usr/sbin/unscaler.sh b/cpufreqscaling/all/usr/sbin/unscaler.sh index 8e92d64..5bfd5b3 100755 --- a/cpufreqscaling/all/usr/sbin/unscaler.sh +++ b/cpufreqscaling/all/usr/sbin/unscaler.sh @@ -18,6 +18,4 @@ if [ "$governor" != "performance" ]; then done fi -touch /usr/sbin/stopscale - -exit 0 \ No newline at end of file +touch /usr/sbin/stopscale \ No newline at end of file