Commit 1a2d2023 authored by Igor Pecovnik's avatar Igor Pecovnik
Browse files

Add SoC CPU speed and governor manipulation

parent ee532c2c
...@@ -80,7 +80,16 @@ do ...@@ -80,7 +80,16 @@ do
# count number of menu items to adjust window size # count number of menu items to adjust window size
LISTLENGTH="$((11+${#LIST[@]}/2))" LISTLENGTH="$((11+${#LIST[@]}/2))"
BOXLENGTH=${#LIST[@]} BOXLENGTH=${#LIST[@]}
MENUTITLE="Configure $DISTRO $DISTROID" MENUTITLE="Configure \Z1$DISTRO $DISTROID\Z0"
# read cpu speed
num=$(cat /sys/devices/system/cpu/cpufreq/policy0/scaling_min_freq 2> /dev/null)
if [[ -f /etc/default/cpufrequtils && ! -z "${num##*[!0-9]*}" ]]; then
FREQENCIES="\n"$(LC_ALL="C" cpufreq-info | grep policy | sed "s/ current policy: //" | sed 's/.*/\u&/' | tail -1)"\n"
LISTLENGTH=$((LISTLENGTH + 2))
FREQENCIES="\nSoC runs between \Z1$(($(cat /sys/devices/system/cpu/cpufreq/policy0/scaling_min_freq) / 1000))\Z0 and \Z1$(($(cat /sys/devices/system/cpu/cpufreq/policy0/scaling_max_freq) / 1000)) MHz\Z0 using \Z1$(cat /sys/devices/system/cpu/cpufreq/policy0/scaling_governor)\Z0 governor.\n"
fi
[[ -n "${BOARD_NAME/ /}" ]] && MENUTITLE=$MENUTITLE" based \Z1Armbian\Z0 for the \Z1${BOARD_NAME}\Z0 " [[ -n "${BOARD_NAME/ /}" ]] && MENUTITLE=$MENUTITLE" based \Z1Armbian\Z0 for the \Z1${BOARD_NAME}\Z0 "
# main dialog routine # main dialog routine
...@@ -92,7 +101,7 @@ do ...@@ -92,7 +101,7 @@ do
exec 3>&1 exec 3>&1
selection=$(dialog --colors --backtitle "$BACKTITLE" --title " armbian-config " --clear \ selection=$(dialog --colors --backtitle "$BACKTITLE" --title " armbian-config " --clear \
--cancel-label "Exit" --menu "\n$MENUTITLE \n \nSupport: \Z1https://forum.armbian.com\Z0\n " \ --cancel-label "Exit" --menu "\n$MENUTITLE \n$FREQENCIES\nSupport: \Z1https://forum.armbian.com\Z0\n " \
$LISTLENGTH ${TITLELENGTH} $BOXLENGTH "${LIST[@]}" 2>&1 1>&3) $LISTLENGTH ${TITLELENGTH} $BOXLENGTH "${LIST[@]}" 2>&1 1>&3)
exit_status=$? exit_status=$?
exec 3>&- exec 3>&-
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
# beta_disclaimer # beta_disclaimer
# show_box # show_box
# description # description
# generic_select
# reload_bsp # reload_bsp
# other_kernel_version # other_kernel_version
# aval_dtbs # aval_dtbs
...@@ -295,6 +296,35 @@ function description ...@@ -295,6 +296,35 @@ function description
} }
#
# 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=${PARAMETER[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
}
# #
......
...@@ -1028,6 +1028,28 @@ function jobs () ...@@ -1028,6 +1028,28 @@ function jobs ()
[[ $exitstatus = 2 ]] && sed -i 's/^#kernel.printk\(.*\)/kernel.printk\1/' /etc/sysctl.conf && reboot [[ $exitstatus = 2 ]] && sed -i 's/^#kernel.printk\(.*\)/kernel.printk\1/' /etc/sysctl.conf && reboot
;; ;;
# CPU speed and governor
#
"CPU" )
generic_select "$(cat /sys/devices/system/cpu/cpufreq/policy0/scaling_available_frequencies)" "Select minimum CPU speed"
MIN_SPEED=$PARAMETER
generic_select "$(cat /sys/devices/system/cpu/cpufreq/policy0/scaling_available_frequencies)" "Select maximum CPU speed" "$PARAMETER"
MAX_SPEED=$PARAMETER
generic_select "$(cat /sys/devices/system/cpu/cpufreq/policy0/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
;;
# Edit boot environment # Edit boot environment
# #
......
...@@ -59,6 +59,10 @@ while true; do ...@@ -59,6 +59,10 @@ while true; do
[[ -f /boot/armbianEnv.txt ]] && LIST+=( "Bootenv" "Edit boot environment" ) [[ -f /boot/armbianEnv.txt ]] && LIST+=( "Bootenv" "Edit boot environment" )
[[ -f /boot/boot.ini ]] && LIST+=( "Bootscript" "Edit boot script" ) [[ -f /boot/boot.ini ]] && LIST+=( "Bootscript" "Edit boot script" )
if [[ -f /etc/default/cpufrequtils ]]; then
LIST+=( "CPU" "Set CPU speed and governor" )
fi
[[ -d ${OVERLAYDIR} ]] && \ [[ -d ${OVERLAYDIR} ]] && \
LIST+=( "Hardware" "Toggle hardware configuration: UART, I2C, etc." ) LIST+=( "Hardware" "Toggle hardware configuration: UART, I2C, etc." )
[[ "$LINUXFAMILY" = cubox && "$BRANCH" = "next" ]] && LIST+=( "DTB" "Switch board .dtb configuration" ) [[ "$LINUXFAMILY" = cubox && "$BRANCH" = "next" ]] && LIST+=( "DTB" "Switch board .dtb configuration" )
...@@ -135,7 +139,7 @@ while true; do ...@@ -135,7 +139,7 @@ while true; do
exec 3>&1 exec 3>&1
selection=$(DIALOGRC=$temp_rc dialog --colors --backtitle "$BACKTITLE" --title " $sys_title " --clear \ selection=$(DIALOGRC=$temp_rc dialog --colors --backtitle "$BACKTITLE" --title " $sys_title " --clear \
--cancel-label "Back" --menu "$disclaimer" $LISTLENGTH 68 $BOXLENGTH \ --cancel-label "Back" --menu "$disclaimer" $LISTLENGTH 0 $BOXLENGTH \
"${LIST[@]}" 2>&1 1>&3) "${LIST[@]}" 2>&1 1>&3)
exit_status=$? exit_status=$?
exec 3>&- exec 3>&-
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment