Skip to content

Commit d335b37

Browse files
viraniacigorpecovnik
authored andcommitted
Add cpufreq options
Signed-off-by: Gunjan Gupta <[email protected]>
1 parent 040586b commit d335b37

File tree

3 files changed

+172
-2
lines changed

3 files changed

+172
-2
lines changed

lib/armbian-configng/config.ng.functions.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,16 @@ function set_runtime_variables() {
212212
DIALOG_CANCEL=1
213213
DIALOG_ESC=255
214214

215+
# Generate empty CPU freq file in case it does not exists
216+
if [[ ! -f /etc/default/armbian-cpufrequtils ]]; then
217+
cat <<- EOF > "/etc/default/armbian-cpufrequtils"
218+
ENABLE=false
219+
MIN_SPEED=
220+
MAX_SPEED=
221+
GOVERNOR=
222+
EOF
223+
fi
224+
215225
# we have our own lsb_release which does not use Python. Others shell install it here
216226
if [[ ! -f /usr/bin/lsb_release ]]; then
217227
if is_package_manager_running; then
@@ -730,9 +740,44 @@ show_menu() {
730740
else
731741
exit 0
732742
fi
743+
}
744+
733745

746+
module_options+=(
747+
["generic_select,author"]="Gunjan Gupta"
748+
["generic_select,ref_link"]=""
749+
["generic_select,feature"]="generic_select"
750+
["generic_select,desc"]="Display a menu a given list of options with a provided prompt"
751+
["generic_select,example"]="generic_select \"true false\" \"Select an option\""
752+
["generic_select,doc_link"]=""
753+
["generic_select,status"]="Active"
754+
)
755+
#
756+
# Display a menu a given list of options with a provided prompt
757+
#
758+
function generic_select()
759+
{
760+
IFS=$' '
761+
PARAMETER=($1)
762+
local LIST=()
763+
for i in "${PARAMETER[@]}"
764+
do
765+
if [[ -n $3 ]]; then
766+
[[ ${i[0]} -ge $3 ]] && \
767+
LIST+=( "${i[0]//[[:blank:]]/}" "" )
768+
else
769+
LIST+=( "${i[0]//[[:blank:]]/}" "" )
770+
fi
771+
done
772+
LIST_LENGTH=$((${#LIST[@]}/2));
773+
if [ "$LIST_LENGTH" -eq 1 ]; then
774+
PARAMETER=${LIST[0]}
775+
else
776+
PARAMETER=$($DIALOG --title "$2" --menu "" 0 0 9 "${LIST[@]}" 3>&1 1>&2 2>&3)
777+
fi
734778
}
735779

780+
736781
module_options+=(
737782
["get_user_continue,author"]="Joey Turner"
738783
["get_user_continue,ref_link"]=""

lib/armbian-configng/config.ng.jobs.json

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,92 @@
383383
"author": "Igor Pecovnik",
384384
"condition": "[ -f /etc/armbian-distribution-status ] && release_upgrade rolling verify"
385385
}
386-
]
386+
]
387+
},
388+
{
389+
"id": "S28",
390+
"description": "Set CPU speed and governor",
391+
"sub": [
392+
{
393+
"id": "S1001",
394+
"description": "Disable CPU frequency utilities",
395+
"command": [
396+
"sed -i \"s/ENABLE=.*/ENABLE=false/\" /etc/default/armbian-cpufrequtils",
397+
"#systemctl restart armbian-cpufrequtils"
398+
],
399+
"status": "Active",
400+
"doc_link": "",
401+
"src_reference": "",
402+
"author": "",
403+
"condition": "grep -q '^ENABLE=true' /etc/default/armbian-cpufrequtils 2>/dev/null"
404+
},
405+
{
406+
"id": "S1002",
407+
"description": "Enable CPU frequency utilities",
408+
"command": [
409+
"sed -i \"s/ENABLE=.*/ENABLE=true/\" /etc/default/armbian-cpufrequtils 2>/dev/null",
410+
"#systemctl restart armbian-cpufrequtils"
411+
],
412+
"status": "Active",
413+
"doc_link": "",
414+
"src_reference": "",
415+
"author": "",
416+
"condition": "grep -q '^ENABLE=false' /etc/default/armbian-cpufrequtils 2>/dev/null"
417+
},
418+
{
419+
"id": "S1003",
420+
"description": "Set minimum CPU speed",
421+
"command": [
422+
"set_cpufreq_option MIN_SPEED"
423+
],
424+
"status": "Active",
425+
"doc_link": "",
426+
"src_reference": "",
427+
"author": "",
428+
"condition": "grep -q '^ENABLE=true' /etc/default/armbian-cpufrequtils 2>/dev/null"
429+
},
430+
{
431+
"id": "S1004",
432+
"description": "Set maximum CPU speed",
433+
"command": [
434+
"set_cpufreq_option MAX_SPEED"
435+
],
436+
"status": "Active",
437+
"doc_link": "",
438+
"src_reference": "",
439+
"author": "",
440+
"condition": "grep -q '^ENABLE=true' /etc/default/armbian-cpufrequtils 2>/dev/null"
441+
},
442+
{
443+
"id": "S1005",
444+
"description": "Set CPU scaling governor",
445+
"command": [
446+
"set_cpufreq_option GOVERNOR"
447+
],
448+
"status": "Active",
449+
"doc_link": "",
450+
"src_reference": "",
451+
"author": "",
452+
"condition": "grep -q '^ENABLE=true' /etc/default/armbian-cpufrequtils 2>/dev/null"
453+
},
454+
{
455+
"id": "S1006",
456+
"description": "Show configuration",
457+
"command": [
458+
"show_message <<< \"$(cat /etc/default/armbian-cpufrequtils)\""
459+
],
460+
"status": "Preview",
461+
"doc_link": "",
462+
"src_reference": "",
463+
"author": "Igor Pecovnik",
464+
"condition": "grep -q '^ENABLE=true' /etc/default/armbian-cpufrequtils 2>/dev/null && [[ -f /etc/default/armbian-cpufrequtils ]]"
465+
}
466+
],
467+
"status": "Active",
468+
"doc_link": "",
469+
"src_reference": "",
470+
"author": "Gunjan Gupta",
471+
"condition": "[ -f /etc/default/armbian-cpufrequtils ]"
387472
}
388473
]
389474
},

lib/armbian-configng/config.ng.system.sh

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ module_options+=(
232232
# @description set/unset Armbian root filesystem to read only
233233
#
234234
function manage_overlayfs() {
235-
236235
if [[ "$1" == "enable" ]]; then
237236
debconf-apt-progress -- apt-get -o Dpkg::Options::="--force-confold" -y install overlayroot cryptsetup cryptsetup-bin
238237
[[ ! -f /etc/overlayroot.conf ]] && cp /etc/overlayroot.conf.dpkg-new /etc/overlayroot.conf
@@ -334,3 +333,44 @@ function adjust_motd() {
334333
# adjust motd config
335334
sed -i "s/^MOTD_DISABLE=.*/MOTD_DISABLE=\"$INSERT\"/g" /etc/default/armbian-motd
336335
}
336+
337+
module_options+=(
338+
["set_cpufreq_option,author"]="Gunjan Gupta"
339+
["set_cpufreq_option,ref_link"]=""
340+
["set_cpufreq_option,feature"]="cpufreq"
341+
["set_cpufreq_option,desc"]="Set cpufreq options like minimum/maximum speed and governor"
342+
["set_cpufreq_option,example"]="set_cpufreq_option MIN_SPEED|MAX_SPEED|GOVERNOR"
343+
["set_cpufreq_option,status"]="Active"
344+
)
345+
#
346+
# @description set cpufreq options like minimum/maximum speed and governor
347+
#
348+
function set_cpufreq_option () {
349+
# Assuming last policy is for the big core
350+
local policy=$(ls /sys/devices/system/cpu/cpufreq/ | tail -n 1)
351+
local selected_value=""
352+
353+
case "$1" in
354+
MIN_SPEED)
355+
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"
356+
selected_value=$PARAMETER
357+
;;
358+
MAX_SPEED)
359+
local min_speed=$(cat /sys/devices/system/cpu/cpufreq/$policy/cpuinfo_min_freq)
360+
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
361+
selected_value=$PARAMETER
362+
;;
363+
GOVERNOR)
364+
generic_select "$(cat /sys/devices/system/cpu/cpufreq/$policy/scaling_available_governors)" "Select CPU governor"
365+
selected_value=$PARAMETER
366+
;;
367+
368+
*)
369+
;;
370+
esac
371+
if [[ -n $selected_value ]]; then
372+
sed -i "s/$1=.*/$1=$selected_value/" /etc/default/armbian-cpufrequtils
373+
#systemctl restart armbiancpufrequtils
374+
fi
375+
}
376+

0 commit comments

Comments
 (0)