Skip to content

Instantly share code, notes, and snippets.

@KekTuSx
Last active September 5, 2022 09:26
Show Gist options
  • Save KekTuSx/b8394c993ba22618d797349c7da41671 to your computer and use it in GitHub Desktop.
Save KekTuSx/b8394c993ba22618d797349c7da41671 to your computer and use it in GitHub Desktop.
Sets upper limit for CPU frequency via TLP. EXPERIMENTAL
#!/bin/bash
#
# Sets upper limit for CPU clock speed with TLP config.
set -e
# Variables
#####################
reload=false
conf="/etc/tlp.conf"
PS3="Select max CPU frequency: "
FREQS=("2100000" "2300000")
current_value_ac=$(grep -0 "CPU_SCALING_MAX_FREQ_ON_AC=*" $conf)
current_value_bat=$(grep -0 "CPU_SCALING_MAX_FREQ_ON_BAT=*" $conf)
# Script
#####################
echo -e "Current value on AC: $current_value_ac"
echo -e "Current value on BAT: $current_value_bat\n"
# Menu
select opt in "${FREQS[@]}";
do
echo -e "\nApplying selected value ($opt)..."
# AC state
if grep -q "CPU_SCALING_MAX_FREQ_ON_AC=$opt" $conf
then
echo -e "\nThis value is already the current value for AC power state."
else
sed -i "s/CPU_SCALING_MAX_FREQ_ON_AC=.*/CPU_SCALING_MAX_FREQ_ON_AC=$opt/g" $conf
echo -e "\nApplied value for AC power state."
reload=true
fi
# BAT state
if grep -q "CPU_SCALING_MAX_FREQ_ON_BAT=$opt" $conf
then
echo "This value is already the current value for BAT power state."
else
sed -i "s/CPU_SCALING_MAX_FREQ_ON_BAT=.*/CPU_SCALING_MAX_FREQ_ON_BAT=$opt/g" $conf
echo "Applied value for BAT power state."
reload=true
fi
if [ $reload = true ]
then
echo -e "\nReloading TLP config..."
sudo tlp start
fi
echo -e "\nOperation succesful"
break
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment