From fe296206462f204c3abb9d73e005fccd8c8a6bb6 Mon Sep 17 00:00:00 2001 From: Murray Gervais Date: Thu, 28 Dec 2023 23:11:27 -0800 Subject: [PATCH] Add support for configuring/overriding "Energy Performance Preference (EPP)" (#619) * Added support for configuring/overriding energy performance preference (EPP) * Corrected path to print available energy performance preferences in docs * Added "EPP" wording to config examples * Added message when EPP is not supported --- README.md | 6 ++++++ auto-cpufreq.conf-example | 6 ++++++ auto_cpufreq/core.py | 22 ++++++++++++++++++---- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 159f8563..80acccc7 100644 --- a/README.md +++ b/README.md @@ -286,6 +286,9 @@ By default, auto-cpufreq does not use the config file! If you wish to use it, th # preferred governor governor = performance +# EPP: see available preferences by running: cat /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_available_preferences +energy_performance_preference = performance + # minimum cpu frequency (in kHz) # example: for 800 MHz = 800000 kHz --> scaling_min_freq = 800000 # see conversion info: https://www.rapidtables.com/convert/frequency/mhz-to-hz.html @@ -307,6 +310,9 @@ turbo = auto # preferred governor governor = powersave +# EPP: see available preferences by running: cat /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_available_preferences +energy_performance_preference = power + # minimum cpu frequency (in kHz) # example: for 800 MHz = 800000 kHz --> scaling_min_freq = 800000 # see conversion info: https://www.rapidtables.com/convert/frequency/mhz-to-hz.html diff --git a/auto-cpufreq.conf-example b/auto-cpufreq.conf-example index 3a141ac2..3ede8ae5 100644 --- a/auto-cpufreq.conf-example +++ b/auto-cpufreq.conf-example @@ -4,6 +4,9 @@ # preferred governor. governor = performance +# EPP: see available preferences by running: cat /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_available_preferences +energy_performance_preference = performance + # minimum cpu frequency (in kHz) # example: for 800 MHz = 800000 kHz --> scaling_min_freq = 800000 # see conversion info: https://www.rapidtables.com/convert/frequency/mhz-to-hz.html @@ -25,6 +28,9 @@ turbo = auto # preferred governor governor = powersave +# EPP: see available preferences by running: cat /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_available_preferences +energy_performance_preference = power + # minimum cpu frequency (in kHz) # example: for 800 MHz = 800000 kHz --> scaling_min_freq = 800000 # see conversion info: https://www.rapidtables.com/convert/frequency/mhz-to-hz.html diff --git a/auto_cpufreq/core.py b/auto_cpufreq/core.py index 0ef4315b..76ece278 100755 --- a/auto_cpufreq/core.py +++ b/auto_cpufreq/core.py @@ -676,8 +676,15 @@ def set_powersave(): Path("/sys/devices/system/cpu/cpu0/cpufreq/energy_performance_preference").exists() and Path("/sys/devices/system/cpu/intel_pstate/hwp_dynamic_boost").exists() is False ): - run("cpufreqctl.auto-cpufreq --epp --set=balance_power", shell=True) - print('Setting to use: "balance_power" EPP') + if conf.has_option("battery", "energy_performance_preference"): + epp = conf["battery"]["energy_performance_preference"] + run(f"cpufreqctl.auto-cpufreq --epp --set={epp}", shell=True) + print(f'Setting to use: "{epp}" EPP') + else: + run("cpufreqctl.auto-cpufreq --epp --set=balance_power", shell=True) + print('Setting to use: "balance_power" EPP') + else: + print('Not setting EPP (not supported by system)') # set frequencies set_frequencies() @@ -887,8 +894,15 @@ def set_performance(): Path("/sys/devices/system/cpu/cpu0/cpufreq/energy_performance_preference").exists() and Path("/sys/devices/system/cpu/intel_pstate/hwp_dynamic_boost").exists() is False ): - run("cpufreqctl.auto-cpufreq --epp --set=balance_performance", shell=True) - print('Setting to use: "balance_performance" EPP') + if conf.has_option("charger", "energy_performance_preference"): + epp = conf["charger"]["energy_performance_preference"] + run(f"cpufreqctl.auto-cpufreq --epp --set={epp}", shell=True) + print(f'Setting to use: "{epp}" EPP') + else: + run("cpufreqctl.auto-cpufreq --epp --set=balance_performance", shell=True) + print('Setting to use: "balance_performance" EPP') + else: + print('Not setting EPP (not supported by system)') # set frequencies set_frequencies()