mirror of
https://github.com/AuxXxilium/arc-addons.git
synced 2024-11-23 21:50:52 +07:00
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:
parent
37e76a5ec4
commit
e0fe3b002d
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/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.
|
# This is free software, licensed under the MIT License.
|
||||||
# See /LICENSE for more information.
|
# See /LICENSE for more information.
|
||||||
@ -9,41 +9,22 @@
|
|||||||
# Make things safer
|
# Make things safer
|
||||||
set -euo pipefail
|
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
|
# Load the correct cpufreq module
|
||||||
if [ "${1}" = "ondemand" ] || [ "${1}" = "conservative" ]; then
|
cerror=0
|
||||||
if [ -f "/usr/lib/modules/cpufreq_${1}.ko" ]; then
|
if [ "${1}" == "ondemand" ] || [ "${1}" == "conservative" ]; then
|
||||||
insmod /usr/lib/modules/cpufreq_${1}.ko || true
|
insmod /usr/lib/modules/cpufreq_${1}.ko || cerror=1
|
||||||
echo "CPUFreqScaling: cpufreq_${1} loaded"
|
fi
|
||||||
else
|
# Set correct cpufreq governor to allow frequency scaling
|
||||||
echo "CPUFreqScaling: cpufreq_${1} not found"
|
if [ "${governor}" != "${1}" ]; then
|
||||||
error=1
|
echo "${1}" | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
|
||||||
break
|
|
||||||
fi
|
|
||||||
fi
|
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
|
sleep 10
|
||||||
# Check if the governor is set correctly
|
# Check if the governor is set correctly
|
||||||
for i in $(seq 0 ${cpucorecount}); do
|
verifygovernor=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor)
|
||||||
governor=$(cat /sys/devices/system/cpu/cpu${i}/cpufreq/scaling_governor)
|
if [ "${verifygovernor}" == "${1}" ]; then
|
||||||
if [ "${governor}" = "${1}" ]; then
|
echo "CPUFreqScaling: Governor set to ${1}"
|
||||||
echo "CPUFreqScaling: Governor set to ${1}"
|
else
|
||||||
else
|
echo "CPUFreqScaling: Failed to set governor to ${1}"
|
||||||
echo "CPUFreqScaling: Failed to set governor to ${1}"
|
cerror=1
|
||||||
error=1
|
fi
|
||||||
break
|
[ ${cerror} -eq 1 ] && exit 1 || exit 0
|
||||||
fi
|
|
||||||
done
|
|
||||||
[ ${error} -eq 1 ] && exit 1
|
|
||||||
exit 0
|
|
@ -36,6 +36,19 @@ WantedBy=multi-user.target
|
|||||||
EOF
|
EOF
|
||||||
mkdir -vp /tmpRoot/usr/lib/systemd/system/multi-user.target.wants
|
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
|
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
|
elif [ "${1}" = "uninstall" ]; then
|
||||||
echo "Installing cpufreqscalingscaling - ${1}"
|
echo "Installing cpufreqscalingscaling - ${1}"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user