Skip to content

Commit

Permalink
Add the feature that makes EPP changeable (#45)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
validatedev and AdnanHodzic committed Mar 21, 2020
1 parent 6e83d2b commit abe463c
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
54 changes: 54 additions & 0 deletions scripts/cpufreqctl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ]
Expand Down
22 changes: 21 additions & 1 deletion source/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit abe463c

Please sign in to comment.