Add the feature that makes EPP changeable (#45)
* Add the feature that makes EPP changeable * Remove .vscode folder * Fix little statement thing * implemented mechanism to backup/restore original cpufreqctl file Co-authored-by: Adnan Hodzic <adnan@hodzic.org>
This commit is contained in:
parent
58cb83e156
commit
9a6b9cf387
|
@ -50,6 +50,7 @@ function help () {
|
|||
echo ""
|
||||
echo " --driver Current processor driver"
|
||||
echo " --governor Scaling governor's options"
|
||||
echo " --epp Governor's energy_performance_preference options"
|
||||
echo " --frequency Frequency options"
|
||||
echo " --on Turn on --core=NUMBER"
|
||||
echo " --off Turn off --core=NUMBER"
|
||||
|
@ -235,6 +236,42 @@ function set_frequency_max () {
|
|||
fi
|
||||
}
|
||||
|
||||
function get_energy_performance_preference () {
|
||||
if [ -z $CORE ]
|
||||
then
|
||||
i=0
|
||||
ag=''
|
||||
while [ $i -ne $cpucount ]
|
||||
do
|
||||
if [ $i = 0 ]
|
||||
then
|
||||
ag=`cat /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_preference`
|
||||
else
|
||||
ag=$ag' '`cat /sys/devices/system/cpu/cpu$i/cpufreq/energy_performance_preference`
|
||||
fi
|
||||
i=`expr $i + 1`
|
||||
done
|
||||
echo $ag
|
||||
else
|
||||
cat /sys/devices/system/cpu/cpu$CORE/cpufreq/energy_performance_preference
|
||||
fi
|
||||
}
|
||||
|
||||
function set_energy_performance_preference () {
|
||||
if [ -z $CORE ]
|
||||
then
|
||||
i=0
|
||||
while [ $i -ne $cpucount ]
|
||||
do
|
||||
FLNM="$FLROOT/cpu"$i"/cpufreq/energy_performance_preference"
|
||||
echo $VALUE > $FLNM
|
||||
i=`expr $i + 1`
|
||||
done
|
||||
else
|
||||
echo $VALUE > /sys/devices/system/cpu/cpu$CORE/cpufreq/energy_performance_preference
|
||||
fi
|
||||
}
|
||||
|
||||
if [ -z $OPTION ] # No options
|
||||
then
|
||||
info
|
||||
|
@ -272,6 +309,23 @@ then
|
|||
fi
|
||||
exit
|
||||
fi
|
||||
if [ $OPTION = "--epp" ]
|
||||
then
|
||||
if [ ! -z $AVAILABLE ]
|
||||
then
|
||||
cat /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_available_preferences
|
||||
exit
|
||||
fi
|
||||
if [ -z $VALUE ]
|
||||
then
|
||||
verbose "Getting CPU"$CORE" EPPs"
|
||||
get_energy_performance_preference
|
||||
else
|
||||
verbose "Setting CPU"$CORE" EPPs to "$VALUE
|
||||
set_energy_performance_preference
|
||||
fi
|
||||
exit
|
||||
fi
|
||||
if [ $OPTION = "--frequency" ]
|
||||
then
|
||||
if [ ! -z $AVAILABLE ]
|
||||
|
|
|
@ -54,10 +54,25 @@ def cpufreqctl():
|
|||
else:
|
||||
# deploy cpufreqctl script (if missing)
|
||||
if os.path.isfile("/usr/bin/cpufreqctl"):
|
||||
pass
|
||||
os.system("cp /usr/bin/cpufreqctl /usr/bin/cpufreqctl.auto-cpufreq.bak")
|
||||
os.system("cp " + scripts_dir + "cpufreqctl.sh /usr/bin/cpufreqctl")
|
||||
else:
|
||||
os.system("cp " + scripts_dir + "cpufreqctl.sh /usr/bin/cpufreqctl")
|
||||
|
||||
# restore original cpufreqctl script
|
||||
def cpufreqctl_restore():
|
||||
# detect if running on a SNAP
|
||||
if os.getenv('PKG_MARKER') == "SNAP":
|
||||
pass
|
||||
else:
|
||||
# restore original cpufreqctl script
|
||||
if os.path.isfile("/usr/bin/cpufreqctl.auto-cpufreq.bak"):
|
||||
os.system("cp /usr/bin/cpufreqctl.auto-cpufreq.bak /usr/bin/cpufreqctl")
|
||||
os.remove("/usr/bin/cpufreqctl.auto-cpufreq.bak")
|
||||
# ToDo: implement mechanism to make sure cpufreqctl (auto-cpufreq) file is
|
||||
# restored if overwritten by system. But during tool removal to also remove it
|
||||
# in def cpufreqctl
|
||||
|
||||
# print footer func
|
||||
def footer(l):
|
||||
print("\n" + "-" * l + "\n")
|
||||
|
@ -133,6 +148,9 @@ def remove():
|
|||
# delete log file
|
||||
delete_file(auto_cpufreq_log_file)
|
||||
|
||||
# restore original cpufrectl script
|
||||
cpufreqctl_restore()
|
||||
|
||||
# check for necessary scaling governors
|
||||
def gov_check():
|
||||
avail_gov = avail_gov_loc
|
||||
|
@ -170,6 +188,7 @@ def countdown(s):
|
|||
def set_powersave():
|
||||
print("Setting to use: powersave")
|
||||
s.run("cpufreqctl --governor --set=powersave", shell=True)
|
||||
s.run("cpufreqctl --epp --set=balance_power", shell=True)
|
||||
|
||||
# get system/CPU load
|
||||
load1m, _, _ = os.getloadavg()
|
||||
|
@ -231,6 +250,7 @@ def mon_powersave():
|
|||
def set_performance():
|
||||
print("Setting to use \"performance\" governor")
|
||||
s.run("cpufreqctl --governor --set=performance", shell=True)
|
||||
s.run("cpufreqctl --epp --set=balance_performance", shell=True)
|
||||
|
||||
# get system/CPU load
|
||||
load1m, _, _ = os.getloadavg()
|
||||
|
|
Loading…
Reference in New Issue