From 7ac55199f230c49f43ab23e751ce225ff8217b14 Mon Sep 17 00:00:00 2001 From: Harsh Panchal Date: Sun, 4 Aug 2024 13:45:46 +0530 Subject: [PATCH] Add support for setting "Platform Profile" (#752) * Add support for setting "Platform Profile" * Add reference for Platform Profile --- README.md | 12 ++++++++++++ auto-cpufreq.conf-example | 12 ++++++++++++ auto_cpufreq/core.py | 12 ++++++++++++ scripts/cpufreqctl.sh | 11 +++++++++++ 4 files changed, 47 insertions(+) diff --git a/README.md b/README.md index 9035fbdc..c49254e0 100644 --- a/README.md +++ b/README.md @@ -303,6 +303,12 @@ governor = performance # EPP: see available preferences by running: cat /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_available_preferences energy_performance_preference = performance +# Platform Profiles +# https://www.kernel.org/doc/html/latest/userspace-api/sysfs-platform_profile.html +# See available options by running: +# cat /sys/firmware/acpi/platform_profile_choices +# platform_profile = 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 @@ -327,6 +333,12 @@ governor = powersave # EPP: see available preferences by running: cat /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_available_preferences energy_performance_preference = power +# Platform Profiles +# https://www.kernel.org/doc/html/latest/userspace-api/sysfs-platform_profile.html +# See available options by running: +# cat /sys/firmware/acpi/platform_profile_choices +# platform_profile = low-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 925e79ea..a6a59241 100644 --- a/auto-cpufreq.conf-example +++ b/auto-cpufreq.conf-example @@ -7,6 +7,12 @@ governor = performance # EPP: see available preferences by running: cat /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_available_preferences energy_performance_preference = performance +# Platform Profiles +# https://www.kernel.org/doc/html/latest/userspace-api/sysfs-platform_profile.html +# See available options by running: +# cat /sys/firmware/acpi/platform_profile_choices +# platform_profile = 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 @@ -31,6 +37,12 @@ governor = powersave # EPP: see available preferences by running: cat /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_available_preferences energy_performance_preference = power +# Platform Profiles +# https://www.kernel.org/doc/html/latest/userspace-api/sysfs-platform_profile.html +# See available options by running: +# cat /sys/firmware/acpi/platform_profile_choices +# platform_profile = low-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 e79daaaf..a7350eee 100755 --- a/auto_cpufreq/core.py +++ b/auto_cpufreq/core.py @@ -476,6 +476,15 @@ def set_frequencies(): # set the frequency run(f"cpufreqctl.auto-cpufreq {frequency[freq_type]['cmdargs']} --set={frequency[freq_type]['value']}", shell=True) +def set_platform_profile(conf, profile): + if conf.has_option(profile, "platform_profile"): + if not Path("/sys/firmware/acpi/platform_profile").exists(): + print('Not setting Platform Profile (not supported by system)') + else: + pp = conf[profile]["platform_profile"] + print(f'Setting to use: "{pp}" Platform Profile') + run(f"cpufreqctl.auto-cpufreq --pp --set={pp}", shell=True) + def set_powersave(): conf = config.get_config() gov = conf["battery"]["governor"] if conf.has_option("battery", "governor") else AVAILABLE_GOVERNORS_SORTED[-1] @@ -503,6 +512,7 @@ def set_powersave(): run("cpufreqctl.auto-cpufreq --epp --set=balance_power", shell=True) print('Setting to use: "balance_power" EPP') + set_platform_profile(conf, "battery") set_frequencies() cpuload, load1m= get_load() @@ -608,6 +618,8 @@ def set_performance(): else: run("cpufreqctl.auto-cpufreq --epp --set=balance_performance", shell=True) print('Setting to use: "balance_performance" EPP') + + set_platform_profile(conf, "charger") set_frequencies() cpuload, load1m = get_load() diff --git a/scripts/cpufreqctl.sh b/scripts/cpufreqctl.sh index 363ff2fd..5f493ad2 100755 --- a/scripts/cpufreqctl.sh +++ b/scripts/cpufreqctl.sh @@ -3,6 +3,7 @@ VERSION='20' cpucount=`cat /proc/cpuinfo | grep processor | wc -l` FLROOT=/sys/devices/system/cpu +FWROOT=/sys/firmware DRIVER=auto VERBOSE=0 @@ -263,6 +264,16 @@ case $OPTION in set_energy_performance_preference fi ;; + -p|--pp) + if [ ! -z $AVAILABLE ]; then cat $FWROOT/acpi/platform_profile_choices + elif [ -z $VALUE ]; then + verbose "Getting Platform Profile" + cat $FWROOT/acpi/platform_profile + else + verbose "Getting Platform Profile to "$VALUE + echo $VALUE > $FWROOT/acpi/platform_profile + fi + ;; -f|--frequency) if [ ! -z $AVAILABLE ]; then cat $FLROOT/cpu0/cpufreq/scaling_available_frequencies elif [ -z $VALUE ]; then