Skip to content

Commit

Permalink
feat(proxmox): improve cpu-config script
Browse files Browse the repository at this point in the history
It now only sets values if they differ from the current configuration.
  • Loading branch information
martinohmann committed Mar 17, 2024
1 parent 9ed2ab0 commit f5633cd
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions ansible/proxmox/playbooks/files/cpu-config
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,47 @@ in_array() {
return 1
}

current_no_turbo() {
cat /sys/devices/system/cpu/intel_pstate/no_turbo
}

available_scaling_govenors() {
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
}

current_scaling_govenor() {
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
}

available_energy_performance_preferences() {
cat /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_available_preferences
}

current_energy_performance_preference() {
cat /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_preference
}

show_config() {
info "scaling_govenor=$scaling_govenor"
info "energy_performance_preference=$energy_performance_preference"
info "no_turbo=$no_turbo"
info "scaling_govenor = $(current_scaling_govenor)"
info "energy_performance_preference = $(current_energy_performance_preference)"
info "no_turbo = $(current_no_turbo)"
}

update_config() {
info "setting scaling_govenor=$scaling_govenor"
echo "$scaling_govenor" | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor > /dev/null
if [ "$scaling_govenor" != "$(current_scaling_govenor)" ]; then
info "setting scaling_govenor = $scaling_govenor"
echo "$scaling_govenor" | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor > /dev/null
fi

info "setting no_turbo=$no_turbo"
echo "$no_turbo" | tee /sys/devices/system/cpu/intel_pstate/no_turbo > /dev/null
if [ "$no_turbo" != "$(current_no_turbo)" ]; then
info "setting no_turbo = $no_turbo"
echo "$no_turbo" | tee /sys/devices/system/cpu/intel_pstate/no_turbo > /dev/null
fi

info "setting energy_performance_preference=$energy_performance_preference"
echo "$energy_performance_preference" | tee /sys/devices/system/cpu/cpu*/cpufreq/energy_performance_preference > /dev/null
if [ "$energy_performance_preference" != "$(current_energy_performance_preference)" ]; then
info "setting energy_performance_preference = $energy_performance_preference"
echo "$energy_performance_preference" | tee /sys/devices/system/cpu/cpu*/cpufreq/energy_performance_preference > /dev/null
fi
}

require_opt_arg() {
Expand Down Expand Up @@ -134,8 +152,8 @@ main() {
}

cmd=
energy_performance_preference="$(cat /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_preference)"
no_turbo=$(cat /sys/devices/system/cpu/intel_pstate/no_turbo)
scaling_govenor="$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor)"
energy_performance_preference="$(current_energy_performance_preference)"
no_turbo=$(current_no_turbo)
scaling_govenor="$(current_scaling_govenor)"

main "$@"

0 comments on commit f5633cd

Please sign in to comment.