Merge pull request #22 from Miouyouyou/main

modules: Added cpufreq
This commit is contained in:
lanefu
2022-07-09 07:57:30 -04:00
committed by GitHub
5 changed files with 90 additions and 0 deletions

1
modules/cpufreq/DESC Normal file
View File

@@ -0,0 +1 @@
Determine the CPU frequency

View File

@@ -0,0 +1 @@
dash cpufrequtils

View File

@@ -0,0 +1 @@
dash cpufrequtils ncurses

34
modules/cpufreq/module.cli Executable file
View File

@@ -0,0 +1,34 @@
#!/bin/bash
show_usage()
{
echo "Usage ${0} cpu_min_freq cpu_max_freq cpu_governor"
POLICY="policy0"
[[ $(grep -c '^processor' /proc/cpuinfo) -gt 4 ]] && POLICY="policy4"
[[ ! -d /sys/devices/system/cpu/cpufreq/policy4 ]] && POLICY="policy0"
[[ -d /sys/devices/system/cpu/cpufreq/policy0 && -d /sys/devices/system/cpu/cpufreq/policy2 ]] && POLICY="policy2"
echo "AVAILABLE FREQUENCIES :"
cat /sys/devices/system/cpu/cpufreq/$POLICY/scaling_available_frequencies
echo "AVAILABLE GOVERNORS :"
cat /sys/devices/system/cpu/cpufreq/$POLICY/scaling_available_governors
}
if [ "$#" -ge 3 ]; then
MIN_SPEED=$1
MAX_SPEED=$2
GOVERNOR=$3
sed -i "s/MIN_SPEED=.*/MIN_SPEED=$MIN_SPEED/" /etc/default/cpufrequtils
sed -i "s/MAX_SPEED=.*/MAX_SPEED=$MAX_SPEED/" /etc/default/cpufrequtils
sed -i "s/GOVERNOR=.*/GOVERNOR=$GOVERNOR/" /etc/default/cpufrequtils
systemctl restart cpufrequtils
sync
else
show_usage
fi

53
modules/cpufreq/module.tui Executable file
View File

@@ -0,0 +1,53 @@
#!/bin/bash
#
# Generic select box
#
function generic_select()
{
IFS=$' '
PARAMETER=($1)
local LIST=()
for i in "${PARAMETER[@]}"
do
if [[ -n $3 ]]; then
[[ ${i[0]} -ge $3 ]] && \
LIST+=( "${i[0]//[[:blank:]]/}" "" )
else
LIST+=( "${i[0]//[[:blank:]]/}" "" )
fi
done
LIST_LENGTH=$((${#LIST[@]}/2));
if [ "$LIST_LENGTH" -eq 1 ]; then
PARAMETER=${LIST[0]}
else
exec 3>&1
PARAMETER=$(dialog --nocancel --backtitle "$BACKTITLE" --no-collapse \
--title "$2" --clear --menu "" $((6+${LIST_LENGTH})) 0 $((1+${LIST_LENGTH})) "${LIST[@]}" 2>&1 1>&3)
exec 3>&-
fi
}
POLICY="policy0"
[[ $(grep -c '^processor' /proc/cpuinfo) -gt 4 ]] && POLICY="policy4"
[[ ! -d /sys/devices/system/cpu/cpufreq/policy4 ]] && POLICY="policy0"
[[ -d /sys/devices/system/cpu/cpufreq/policy0 && -d /sys/devices/system/cpu/cpufreq/policy2 ]] && POLICY="policy2"
generic_select "$(cat /sys/devices/system/cpu/cpufreq/$POLICY/scaling_available_frequencies)" "Select minimum CPU speed"
MIN_SPEED=$PARAMETER
generic_select "$(cat /sys/devices/system/cpu/cpufreq/$POLICY/scaling_available_frequencies)" "Select maximum CPU speed" "$PARAMETER"
MAX_SPEED=$PARAMETER
generic_select "$(cat /sys/devices/system/cpu/cpufreq/$POLICY/scaling_available_governors)" "Select CPU governor"
GOVERNOR=$PARAMETER
if [[ -n $MIN_SPEED && -n $MAX_SPEED && -n $GOVERNOR ]]; then
dialog --colors --title " Apply and save changes " --backtitle "$BACKTITLE" --yes-label "OK" --no-label "Cancel" --yesno \
"\nCPU frequency will be within \Z1$(($MIN_SPEED / 1000))\Z0 and \Z1$(($MAX_SPEED / 1000)) MHz\Z0. The governor \Z1$GOVERNOR\Z0 will decide which speed to use within this range." 9 58
if [[ $? -eq 0 ]]; then
sed -i "s/MIN_SPEED=.*/MIN_SPEED=$MIN_SPEED/" /etc/default/cpufrequtils
sed -i "s/MAX_SPEED=.*/MAX_SPEED=$MAX_SPEED/" /etc/default/cpufrequtils
sed -i "s/GOVERNOR=.*/GOVERNOR=$GOVERNOR/" /etc/default/cpufrequtils
systemctl restart cpufrequtils
sync
fi
fi