Working governor override on Snap package
This commit is contained in:
parent
69ef913c1b
commit
fe21ddf245
|
@ -59,7 +59,10 @@ auto_cpufreq_stats_path = None
|
||||||
auto_cpufreq_stats_file = None
|
auto_cpufreq_stats_file = None
|
||||||
|
|
||||||
# track governor override
|
# track governor override
|
||||||
STORE = "/opt/auto-cpufreq/override.pickle"
|
if os.getenv("PKG_MARKER") == "SNAP":
|
||||||
|
governor_override_state = Path("/var/snap/auto-cpufreq/current/override.pickle")
|
||||||
|
else:
|
||||||
|
governor_override_state = Path("/opt/auto-cpufreq/current/override.pickle")
|
||||||
|
|
||||||
if os.getenv("PKG_MARKER") == "SNAP":
|
if os.getenv("PKG_MARKER") == "SNAP":
|
||||||
auto_cpufreq_stats_path = Path("/var/snap/auto-cpufreq/current/auto-cpufreq.stats")
|
auto_cpufreq_stats_path = Path("/var/snap/auto-cpufreq/current/auto-cpufreq.stats")
|
||||||
|
@ -86,20 +89,20 @@ def get_config(config_file=""):
|
||||||
return get_config.config
|
return get_config.config
|
||||||
|
|
||||||
def get_override():
|
def get_override():
|
||||||
if os.path.isfile(STORE):
|
if os.path.isfile(governor_override_state):
|
||||||
with open(STORE, "rb") as store:
|
with open(governor_override_state, "rb") as store:
|
||||||
return pickle.load(store)
|
return pickle.load(store)
|
||||||
else:
|
else:
|
||||||
return "default"
|
return "default"
|
||||||
|
|
||||||
def set_override(override):
|
def set_override(override):
|
||||||
if override in ["powersave", "performance"]:
|
if override in ["powersave", "performance"]:
|
||||||
with open(STORE, "wb") as store:
|
with open(governor_override_state, "wb") as store:
|
||||||
pickle.dump(override, store)
|
pickle.dump(override, store)
|
||||||
print(f"Set governor override to {override}")
|
print(f"Set governor override to {override}")
|
||||||
elif override == "reset":
|
elif override == "reset":
|
||||||
if os.path.isfile(STORE):
|
if os.path.isfile(governor_override_state):
|
||||||
os.remove(STORE)
|
os.remove(governor_override_state)
|
||||||
print("Governor override removed")
|
print("Governor override removed")
|
||||||
elif override is not None:
|
elif override is not None:
|
||||||
print("Invalid option.\nUse force=performance, force=powersave, or force=reset")
|
print("Invalid option.\nUse force=performance, force=powersave, or force=reset")
|
||||||
|
@ -367,6 +370,7 @@ def deploy_daemon():
|
||||||
bluetooth_disable()
|
bluetooth_disable()
|
||||||
|
|
||||||
auto_cpufreq_stats_path.touch(exist_ok=True)
|
auto_cpufreq_stats_path.touch(exist_ok=True)
|
||||||
|
governor_override_state.touch(exist_ok=True)
|
||||||
|
|
||||||
print("\n* Deploy auto-cpufreq install script")
|
print("\n* Deploy auto-cpufreq install script")
|
||||||
shutil.copy(SCRIPTS_DIR / "auto-cpufreq-install.sh", "/usr/local/bin/auto-cpufreq-install")
|
shutil.copy(SCRIPTS_DIR / "auto-cpufreq-install.sh", "/usr/local/bin/auto-cpufreq-install")
|
||||||
|
@ -442,8 +446,8 @@ def remove_daemon():
|
||||||
os.remove("/usr/local/bin/auto-cpufreq-remove")
|
os.remove("/usr/local/bin/auto-cpufreq-remove")
|
||||||
|
|
||||||
# delete override pickle if it exists
|
# delete override pickle if it exists
|
||||||
if os.path.exists(STORE):
|
if os.path.exists(governor_override_state):
|
||||||
os.remove(STORE)
|
os.remove(governor_override_state)
|
||||||
|
|
||||||
# delete stats file
|
# delete stats file
|
||||||
if auto_cpufreq_stats_path.exists():
|
if auto_cpufreq_stats_path.exists():
|
||||||
|
|
|
@ -164,6 +164,7 @@ def main(config, daemon, debug, install, remove, install_performance, live, log,
|
||||||
python_info()
|
python_info()
|
||||||
print("")
|
print("")
|
||||||
device_info()
|
device_info()
|
||||||
|
print(f"VALUE {governor_override_state_path}")
|
||||||
if charging():
|
if charging():
|
||||||
print("Battery is: charging")
|
print("Battery is: charging")
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -43,10 +43,10 @@ plugs:
|
||||||
interface: system-files
|
interface: system-files
|
||||||
write:
|
write:
|
||||||
- /etc/auto-cpufreq.conf
|
- /etc/auto-cpufreq.conf
|
||||||
opt-auto-cpufreq:
|
# opt-auto-cpufreq:
|
||||||
interface: system-files
|
# interface: system-files
|
||||||
write:
|
# write:
|
||||||
- /opt/auto-cpufreq/override.pickle
|
# - /opt/auto-cpufreq/override.pickle
|
||||||
|
|
||||||
apps:
|
apps:
|
||||||
auto-cpufreq:
|
auto-cpufreq:
|
||||||
|
@ -60,15 +60,16 @@ apps:
|
||||||
- cpu-control
|
- cpu-control
|
||||||
- system-observe
|
- system-observe
|
||||||
- hardware-observe
|
- hardware-observe
|
||||||
- opt-auto-cpufreq
|
- etc-auto-cpufreq-conf
|
||||||
|
# - opt-auto-cpufreq
|
||||||
service:
|
service:
|
||||||
command: usr/bin/snapdaemon
|
command: usr/bin/snapdaemon
|
||||||
plugs:
|
plugs:
|
||||||
- cpu-control
|
- cpu-control
|
||||||
- system-observe
|
- system-observe
|
||||||
- hardware-observe
|
- hardware-observe
|
||||||
- etc-auto-cpufreq
|
- etc-auto-cpufreq-conf
|
||||||
- opt-auto-cpufreq
|
# - opt-auto-cpufreq
|
||||||
environment:
|
environment:
|
||||||
LC_ALL: C.UTF-8
|
LC_ALL: C.UTF-8
|
||||||
LANG: C.UTF-8
|
LANG: C.UTF-8
|
||||||
|
|
Loading…
Reference in New Issue