Skip to content

Commit

Permalink
Working governor override on Snap package
Browse files Browse the repository at this point in the history
  • Loading branch information
AdnanHodzic committed Feb 3, 2023
1 parent 69ef913 commit fe21ddf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
20 changes: 12 additions & 8 deletions auto_cpufreq/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@
auto_cpufreq_stats_file = None

# 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":
auto_cpufreq_stats_path = Path("/var/snap/auto-cpufreq/current/auto-cpufreq.stats")
Expand All @@ -86,20 +89,20 @@ def get_config(config_file=""):
return get_config.config

def get_override():
if os.path.isfile(STORE):
with open(STORE, "rb") as store:
if os.path.isfile(governor_override_state):
with open(governor_override_state, "rb") as store:
return pickle.load(store)
else:
return "default"

def set_override(override):
if override in ["powersave", "performance"]:
with open(STORE, "wb") as store:
with open(governor_override_state, "wb") as store:
pickle.dump(override, store)
print(f"Set governor override to {override}")
elif override == "reset":
if os.path.isfile(STORE):
os.remove(STORE)
if os.path.isfile(governor_override_state):
os.remove(governor_override_state)
print("Governor override removed")
elif override is not None:
print("Invalid option.\nUse force=performance, force=powersave, or force=reset")
Expand Down Expand Up @@ -367,6 +370,7 @@ def deploy_daemon():
bluetooth_disable()

auto_cpufreq_stats_path.touch(exist_ok=True)
governor_override_state.touch(exist_ok=True)

print("\n* Deploy auto-cpufreq install script")
shutil.copy(SCRIPTS_DIR / "auto-cpufreq-install.sh", "/usr/local/bin/auto-cpufreq-install")
Expand Down Expand Up @@ -442,8 +446,8 @@ def remove_daemon():
os.remove("/usr/local/bin/auto-cpufreq-remove")

# delete override pickle if it exists
if os.path.exists(STORE):
os.remove(STORE)
if os.path.exists(governor_override_state):
os.remove(governor_override_state)

# delete stats file
if auto_cpufreq_stats_path.exists():
Expand Down
1 change: 1 addition & 0 deletions bin/auto-cpufreq
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def main(config, daemon, debug, install, remove, install_performance, live, log,
python_info()
print("")
device_info()
print(f"VALUE {governor_override_state_path}")
if charging():
print("Battery is: charging")
else:
Expand Down
15 changes: 8 additions & 7 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ plugs:
interface: system-files
write:
- /etc/auto-cpufreq.conf
opt-auto-cpufreq:
interface: system-files
write:
- /opt/auto-cpufreq/override.pickle
# opt-auto-cpufreq:
# interface: system-files
# write:
# - /opt/auto-cpufreq/override.pickle

apps:
auto-cpufreq:
Expand All @@ -60,15 +60,16 @@ apps:
- cpu-control
- system-observe
- hardware-observe
- opt-auto-cpufreq
- etc-auto-cpufreq-conf
# - opt-auto-cpufreq
service:
command: usr/bin/snapdaemon
plugs:
- cpu-control
- system-observe
- hardware-observe
- etc-auto-cpufreq
- opt-auto-cpufreq
- etc-auto-cpufreq-conf
# - opt-auto-cpufreq
environment:
LC_ALL: C.UTF-8
LANG: C.UTF-8
Expand Down

0 comments on commit fe21ddf

Please sign in to comment.