Deliver custom parallel version of cpufreqctl. (#150)

This will provide a new parallel version of `cpufreqctl` named
`cpufreqctl.auto-cpufreq` that is to be used by `auto-cpufreq`. This
prevents the system-wide version of this file from being clobbered,
which affects the integrity of what the package manager originally
installed. Applications depending on `cpufreqctl` will still get the
version that they expect.
This commit is contained in:
Marco Vermeulen 2021-01-20 18:19:54 +00:00 committed by GitHub
parent c5e02551e1
commit 6f7eec3b05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 21 deletions

View File

@ -29,7 +29,7 @@ parts:
plugin: dump plugin: dump
source: scripts source: scripts
organize: organize:
cpufreqctl.sh: usr/bin/cpufreqctl cpufreqctl.sh: usr/bin/cpufreqctl.auto-cpufreq
snapdaemon.sh: usr/bin/snapdaemon snapdaemon.sh: usr/bin/snapdaemon
apps: apps:

View File

@ -150,7 +150,7 @@ def get_avail_performance():
def get_current_gov(): def get_current_gov():
return print("Currently using:", getoutput("cpufreqctl --governor").strip().split(" ")[0], "governor") return print("Currently using:", getoutput("cpufreqctl.auto-cpufreq --governor").strip().split(" ")[0], "governor")
def cpufreqctl(): def cpufreqctl():
""" """
@ -161,30 +161,23 @@ def cpufreqctl():
if os.getenv('PKG_MARKER') == "SNAP": if os.getenv('PKG_MARKER') == "SNAP":
pass pass
else: else:
# deploy cpufreqctl script (if missing) # deploy cpufreqctl.auto-cpufreq script
if os.path.isfile("/usr/bin/cpufreqctl"): if os.path.isfile("/usr/bin/cpufreqctl"):
shutil.copy("/usr/bin/cpufreqctl", "/usr/bin/cpufreqctl.auto-cpufreq.bak") shutil.copy(SCRIPTS_DIR / "cpufreqctl.sh", "/usr/bin/cpufreqctl.auto-cpufreq")
shutil.copy(SCRIPTS_DIR / "cpufreqctl.sh", "/usr/bin/cpufreqctl")
else: else:
shutil.copy(SCRIPTS_DIR / "cpufreqctl.sh", "/usr/bin/cpufreqctl") shutil.copy(SCRIPTS_DIR / "cpufreqctl.sh", "/usr/bin/cpufreqctl.auto-cpufreq")
def cpufreqctl_restore(): def cpufreqctl_restore():
""" """
restore original cpufreqctl script remove cpufreqctl.auto-cpufreq script
""" """
# detect if running on a SNAP # detect if running on a SNAP
if os.getenv('PKG_MARKER') == "SNAP": if os.getenv('PKG_MARKER') == "SNAP":
pass pass
else: else:
# restore original cpufreqctl script if os.path.isfile("/usr/bin/cpufreqctl.auto-cpufreq"):
if os.path.isfile("/usr/bin/cpufreqctl.auto-cpufreq.bak"): os.remove("/usr/bin/cpufreqctl.auto-cpufreq")
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
def footer(l=79): def footer(l=79):
print("\n" + "-" * l + "\n") print("\n" + "-" * l + "\n")
@ -318,9 +311,9 @@ def display_load():
# set powersave and enable turbo # set powersave and enable turbo
def set_powersave(): def set_powersave():
print(f"Setting to use: \"{get_avail_powersave()}\" governor") print(f"Setting to use: \"{get_avail_powersave()}\" governor")
run(f"cpufreqctl --governor --set={get_avail_powersave()}", shell=True) run(f"cpufreqctl.auto-cpufreq --governor --set={get_avail_powersave()}", shell=True)
if Path("/sys/devices/system/cpu/cpu0/cpufreq/energy_performance_preference").exists(): if Path("/sys/devices/system/cpu/cpu0/cpufreq/energy_performance_preference").exists():
run("cpufreqctl --epp --set=balance_power", shell=True) run("cpufreqctl.auto-cpufreq --epp --set=balance_power", shell=True)
print("Setting to use: \"balance_power\" EPP") print("Setting to use: \"balance_power\" EPP")
# get CPU utilization as a percentage # get CPU utilization as a percentage
@ -458,9 +451,9 @@ def mon_powersave():
def set_performance(): def set_performance():
print(f"Setting to use: \"{get_avail_performance()}\" governor") print(f"Setting to use: \"{get_avail_performance()}\" governor")
run(f"cpufreqctl --governor --set={get_avail_performance()}", shell=True) run(f"cpufreqctl.auto-cpufreq --governor --set={get_avail_performance()}", shell=True)
if Path("/sys/devices/system/cpu/cpu0/cpufreq/energy_performance_preference").exists() and Path("/sys/devices/system/cpu/intel_pstate/hwp_dynamic_boost").exists() == False: if Path("/sys/devices/system/cpu/cpu0/cpufreq/energy_performance_preference").exists() and Path("/sys/devices/system/cpu/intel_pstate/hwp_dynamic_boost").exists() == False:
run("cpufreqctl --epp --set=balance_performance", shell=True) run("cpufreqctl.auto-cpufreq --epp --set=balance_performance", shell=True)
print("Setting to use: \"balance_performance\" EPP") print("Setting to use: \"balance_performance\" EPP")
# get CPU utilization as a percentage # get CPU utilization as a percentage
@ -686,7 +679,7 @@ def sysinfo():
print("Architecture:", cpu_arch) print("Architecture:", cpu_arch)
# get driver # get driver
driver = getoutput("cpufreqctl --driver") driver = getoutput("cpufreqctl.auto-cpufreq --driver")
print("Driver: " + driver) print("Driver: " + driver)
# get usage and freq info of cpus # get usage and freq info of cpus
@ -798,4 +791,4 @@ def running_daemon():
exit(1) exit(1)
elif os.getenv("PKG_MARKER") == "SNAP" and dcheck == "enabled": elif os.getenv("PKG_MARKER") == "SNAP" and dcheck == "enabled":
deploy_complete_msg() deploy_complete_msg()
exit(1) exit(1)