cpufreqscaling: simplify code and add user controlled task (if automated way isn't working)

Signed-off-by: AuxXxilium <info@auxxxilium.tech>
This commit is contained in:
AuxXxilium 2024-10-26 20:34:46 +02:00
parent 37e76a5ec4
commit e0fe3b002d
2 changed files with 29 additions and 35 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash
#
# Copyright (C) 2023 AuxXxilium <https://github.com/AuxXxilium>
# Copyright (C) 2024 AuxXxilium <https://github.com/AuxXxilium>
#
# This is free software, licensed under the MIT License.
# See /LICENSE for more information.
@ -9,41 +9,22 @@
# Make things safer
set -euo pipefail
# Get cpu cores count minus 1, to allow maping from 0
cpucorecount=$(cat /proc/cpuinfo | grep processor | wc -l)
cpucorecount=$((cpucorecount - 1))
error=0
# Load the correct cpufreq module
if [ "${1}" = "ondemand" ] || [ "${1}" = "conservative" ]; then
if [ -f "/usr/lib/modules/cpufreq_${1}.ko" ]; then
insmod /usr/lib/modules/cpufreq_${1}.ko || true
echo "CPUFreqScaling: cpufreq_${1} loaded"
else
echo "CPUFreqScaling: cpufreq_${1} not found"
error=1
break
fi
cerror=0
if [ "${1}" == "ondemand" ] || [ "${1}" == "conservative" ]; then
insmod /usr/lib/modules/cpufreq_${1}.ko || cerror=1
fi
# Set correct cpufreq governor to allow frequency scaling
if [ "${governor}" != "${1}" ]; then
echo "${1}" | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
fi
# Deamonize the main function...
for i in $(seq 0 ${cpucorecount}); do
governor=$(cat /sys/devices/system/cpu/cpu${i}/cpufreq/scaling_governor)
# Set correct cpufreq governor to allow frequency scaling
if [ "${governor}" != "${1}" ]; then
echo "${1}" >/sys/devices/system/cpu/cpu${i}/cpufreq/scaling_governor
fi
done
sleep 10
# Check if the governor is set correctly
for i in $(seq 0 ${cpucorecount}); do
governor=$(cat /sys/devices/system/cpu/cpu${i}/cpufreq/scaling_governor)
if [ "${governor}" = "${1}" ]; then
echo "CPUFreqScaling: Governor set to ${1}"
else
echo "CPUFreqScaling: Failed to set governor to ${1}"
error=1
break
fi
done
[ ${error} -eq 1 ] && exit 1
exit 0
verifygovernor=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor)
if [ "${verifygovernor}" == "${1}" ]; then
echo "CPUFreqScaling: Governor set to ${1}"
else
echo "CPUFreqScaling: Failed to set governor to ${1}"
cerror=1
fi
[ ${cerror} -eq 1 ] && exit 1 || exit 0

View File

@ -36,6 +36,19 @@ WantedBy=multi-user.target
EOF
mkdir -vp /tmpRoot/usr/lib/systemd/system/multi-user.target.wants
ln -vsf /usr/lib/systemd/system/cpufreqscaling.service /tmpRoot/usr/lib/systemd/system/multi-user.target.wants/cpufreqscaling.service
if [ ! -f /tmpRoot/usr/syno/etc/esynoscheduler/esynoscheduler.db ]; then
echo "copy esynoscheduler.db"
mkdir -p /tmpRoot/usr/syno/etc/esynoscheduler
cp -vf /addons/esynoscheduler.db /tmpRoot/usr/syno/etc/esynoscheduler/esynoscheduler.db
fi
echo "insert scaling... task to esynoscheduler.db"
export LD_LIBRARY_PATH=/tmpRoot/bin:/tmpRoot/lib
/tmpRoot/bin/sqlite3 /tmpRoot/usr/syno/etc/esynoscheduler/esynoscheduler.db <<EOF
DELETE FROM task WHERE task_name LIKE 'CPUFreqscaling';
INSERT INTO task VALUES('CPUFreqscaling', '', 'bootup', '', 0, 0, 0, 0, '', 0, '/usr/sbin/scaling.sh ${2}', 'script', '{}', '', '', '{}', '{}');
EOF
elif [ "${1}" = "uninstall" ]; then
echo "Installing cpufreqscalingscaling - ${1}"