Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add independent CPUFREQ config manipulation options #150

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions lib/armbian-configng/config.ng.functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,16 @@ function set_runtime_variables() {
DIALOG_CANCEL=1
DIALOG_ESC=255

# Generate empty CPU freq file in case it does not exists
if [[ ! -f /etc/default/armbian-cpufrequtils ]]; then
cat <<- EOF > "/etc/default/armbian-cpufrequtils"
ENABLE=false
MIN_SPEED=
MAX_SPEED=
GOVERNOR=
EOF
fi

# we have our own lsb_release which does not use Python. Others shell install it here
if [[ ! -f /usr/bin/lsb_release ]]; then
if is_package_manager_running; then
Expand Down Expand Up @@ -730,9 +740,44 @@ show_menu() {
else
exit 0
fi
}


module_options+=(
["generic_select,author"]="Gunjan Gupta"
["generic_select,ref_link"]=""
["generic_select,feature"]="generic_select"
["generic_select,desc"]="Display a menu a given list of options with a provided prompt"
["generic_select,example"]="generic_select \"true false\" \"Select an option\""
["generic_select,doc_link"]=""
["generic_select,status"]="Active"
)
#
# Display a menu a given list of options with a provided prompt
#
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
PARAMETER=$($DIALOG --title "$2" --menu "" 0 0 9 "${LIST[@]}" 3>&1 1>&2 2>&3)
fi
}


module_options+=(
["get_user_continue,author"]="Joey Turner"
["get_user_continue,ref_link"]=""
Expand Down
87 changes: 86 additions & 1 deletion lib/armbian-configng/config.ng.jobs.json
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,92 @@
"author": "Igor Pecovnik",
"condition": "[ -f /etc/armbian-distribution-status ] && release_upgrade rolling verify"
}
]
]
},
{
"id": "S28",
"description": "Set CPU speed and governor",
"sub": [
{
"id": "S1001",
"description": "Disable CPU frequency utilities",
"command": [
"sed -i \"s/ENABLE=.*/ENABLE=false/\" /etc/default/armbian-cpufrequtils",
"#systemctl restart armbian-cpufrequtils"
],
"status": "Active",
"doc_link": "",
"src_reference": "",
"author": "",
"condition": "grep -q '^ENABLE=true' /etc/default/armbian-cpufrequtils 2>/dev/null"
},
{
"id": "S1002",
"description": "Enable CPU frequency utilities",
"command": [
"sed -i \"s/ENABLE=.*/ENABLE=true/\" /etc/default/armbian-cpufrequtils 2>/dev/null",
"#systemctl restart armbian-cpufrequtils"
],
"status": "Active",
"doc_link": "",
"src_reference": "",
"author": "",
"condition": "grep -q '^ENABLE=false' /etc/default/armbian-cpufrequtils 2>/dev/null"
},
{
"id": "S1003",
"description": "Set minimum CPU speed",
"command": [
"set_cpufreq_option MIN_SPEED"
],
"status": "Active",
"doc_link": "",
"src_reference": "",
"author": "",
"condition": "grep -q '^ENABLE=true' /etc/default/armbian-cpufrequtils 2>/dev/null"
},
{
"id": "S1004",
"description": "Set maximum CPU speed",
"command": [
"set_cpufreq_option MAX_SPEED"
],
"status": "Active",
"doc_link": "",
"src_reference": "",
"author": "",
"condition": "grep -q '^ENABLE=true' /etc/default/armbian-cpufrequtils 2>/dev/null"
},
{
"id": "S1005",
"description": "Set CPU scaling governor",
"command": [
"set_cpufreq_option GOVERNOR"
],
"status": "Active",
"doc_link": "",
"src_reference": "",
"author": "",
"condition": "grep -q '^ENABLE=true' /etc/default/armbian-cpufrequtils 2>/dev/null"
},
{
"id": "S1006",
"description": "Show configuration",
"command": [
"show_message <<< \"$(cat /etc/default/armbian-cpufrequtils)\""
],
"status": "Preview",
"doc_link": "",
"src_reference": "",
"author": "Igor Pecovnik",
"condition": "grep -q '^ENABLE=true' /etc/default/armbian-cpufrequtils 2>/dev/null && [[ -f /etc/default/armbian-cpufrequtils ]]"
}
],
"status": "Disabled",
"doc_link": "",
"src_reference": "",
"author": "Gunjan Gupta",
"condition": ""
}
]
},
Expand Down
42 changes: 41 additions & 1 deletion lib/armbian-configng/config.ng.system.sh
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ module_options+=(
# @description set/unset Armbian root filesystem to read only
#
function manage_overlayfs() {

if [[ "$1" == "enable" ]]; then
debconf-apt-progress -- apt-get -o Dpkg::Options::="--force-confold" -y install overlayroot cryptsetup cryptsetup-bin
[[ ! -f /etc/overlayroot.conf ]] && cp /etc/overlayroot.conf.dpkg-new /etc/overlayroot.conf
Expand Down Expand Up @@ -334,3 +333,44 @@ function adjust_motd() {
# adjust motd config
sed -i "s/^MOTD_DISABLE=.*/MOTD_DISABLE=\"$INSERT\"/g" /etc/default/armbian-motd
}

module_options+=(
["set_cpufreq_option,author"]="Gunjan Gupta"
["set_cpufreq_option,ref_link"]=""
["set_cpufreq_option,feature"]="cpufreq"
["set_cpufreq_option,desc"]="Set cpufreq options like minimum/maximum speed and governor"
["set_cpufreq_option,example"]="set_cpufreq_option MIN_SPEED|MAX_SPEED|GOVERNOR"
["set_cpufreq_option,status"]="Active"
)
#
# @description set cpufreq options like minimum/maximum speed and governor
#
function set_cpufreq_option () {
# Assuming last policy is for the big core
local policy=$(ls /sys/devices/system/cpu/cpufreq/ | tail -n 1)
local selected_value=""

case "$1" in
MIN_SPEED)
generic_select "$(cat /sys/devices/system/cpu/cpufreq/$policy/scaling_available_frequencies 2>/dev/null || cat /sys/devices/system/cpu/cpufreq/$policy/scaling_min_freq 2>/dev/null)" "Select minimum CPU speed"
selected_value=$PARAMETER
;;
MAX_SPEED)
local min_speed=$(cat /sys/devices/system/cpu/cpufreq/$policy/cpuinfo_min_freq)
generic_select "$(cat /sys/devices/system/cpu/cpufreq/$policy/scaling_available_frequencies 2>/dev/null || cat /sys/devices/system/cpu/cpufreq/$policy/scaling_max_freq 2>/dev/null)" "Select maximum CPU speed" $min_speed
selected_value=$PARAMETER
;;
GOVERNOR)
generic_select "$(cat /sys/devices/system/cpu/cpufreq/$policy/scaling_available_governors)" "Select CPU governor"
selected_value=$PARAMETER
;;

*)
;;
esac
if [[ -n $selected_value ]]; then
sed -i "s/$1=.*/$1=$selected_value/" /etc/default/armbian-cpufrequtils
#systemctl restart armbiancpufrequtils
fi
}

Loading