From eccff01039b93c995b66fd4f88d87bc32316387f Mon Sep 17 00:00:00 2001 From: Anton Tamakhin Date: Sat, 7 Sep 2024 15:38:30 +0400 Subject: [PATCH] Added `energy_perf_bias` support for intel_pstate driver --- auto_cpufreq/core.py | 23 ++++++++++++++++ scripts/cpufreqctl.sh | 62 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/auto_cpufreq/core.py b/auto_cpufreq/core.py index b51d55d..4e26fed 100755 --- a/auto_cpufreq/core.py +++ b/auto_cpufreq/core.py @@ -530,6 +530,18 @@ def set_powersave(): else: run("cpufreqctl.auto-cpufreq --epp --set=balance_power", shell=True) print('Setting to use: "balance_power" EPP') + + if Path("/sys/devices/system/cpu/intel_pstate").exists(): + if Path("/sys/devices/system/cpu/cpu0/power/energy_perf_bias").exists() is False: + print('Not setting EPB (not supported by system)') + else: + if conf.has_option("battery", "energy_perf_bias"): + epb = conf["battery"]["energy_perf_bias"] + run(f"cpufreqctl.auto-cpufreq --epb --set={epb}", shell=True) + print(f'Setting to use: "{epb}" EPB') + else: + run("cpufreqctl.auto-cpufreq --epb --set=balance-power", shell=True) + print('Setting to use: "balance-power" EPB') set_platform_profile(conf, "battery") set_frequencies() @@ -617,6 +629,17 @@ def set_performance(): else: run("cpufreqctl.auto-cpufreq --epp --set=balance_performance", shell=True) print('Setting to use: "balance_performance" EPP') + + if Path("/sys/devices/system/cpu/cpu0/power/energy_perf_bias").exists() is False: + print('Not setting EPB (not supported by system)') + else: + if conf.has_option("charger", "energy_perf_bias"): + epb = conf["charger"]["energy_perf_bias"] + run(f"cpufreqctl.auto-cpufreq --epb --set={epb}", shell=True) + print(f'Setting to use: "{epb}" EPB') + else: + run("cpufreqctl.auto-cpufreq --epb --set=default", shell=True) + print('Setting to use: "default" EPB') elif Path("/sys/devices/system/cpu/amd_pstate").exists(): amd_pstate_status_path = "/sys/devices/system/cpu/amd_pstate/status" diff --git a/scripts/cpufreqctl.sh b/scripts/cpufreqctl.sh index 5f493ad..05279f6 100755 --- a/scripts/cpufreqctl.sh +++ b/scripts/cpufreqctl.sh @@ -240,6 +240,58 @@ function set_energy_performance_preference () { fi } + +function get_energy_performance_bias () { + if [ -z $CORE ]; then + i=0 + ag='' + while [ $i -ne $cpucount ]; do + if [ $i = 0 ]; then + ag=`cat $FLROOT/cpu0/power/energy_perf_bias` + else + ag=$ag' '`cat $FLROOT/cpu$i/power/energy_perf_bias` + fi + i=`expr $i + 1` + done + echo $ag + else cat $FLROOT/cpu$CORE/power/energy_perf_bias + fi +} + +function set_energy_performance_bias () { + if [ `driver` != 'intel_pstate' ]; then + verbose "EPB is not supported by a driver other than intel_pstate" + return + fi + local EPB_VALUE=6 # default value + if [[ "$VALUE" =~ ^[0-9]+$ && $VALUE -ge 0 && $VALUE -le 15 ]]; then + EPB_VALUE=$VALUE + else + case $VALUE in + performance) EPB_VALUE=0;; + balance-performance) EPB_VALUE=4;; + normal| default) EPB_VALUE=6;; + balance-power) EPB_VALUE=8;; + power) EPB_VALUE=15;; + *) + verbose "Invalid value provided for EPB" + verbose "Acceptable values: performance|balance-power|default|balance-power|power or a number in the range [0-15]" + return + ;; + esac + fi + + if [ -z $CORE ]; then + i=0 + while [ $i -ne $cpucount ]; do + FLNM="$FLROOT/cpu"$i"/power/energy_perf_bias" + if [ -w $FLNM ]; then echo $EPB_VALUE > $FLNM; fi + i=`expr $i + 1` + done + else echo $EPB_VALUE > $FLROOT/cpu$CORE/power/energy_perf_bias + fi +} + case $OPTION in -h|--help) help;; --version) echo $VERSION;; @@ -264,6 +316,16 @@ case $OPTION in set_energy_performance_preference fi ;; + --epb) + if [ ! -z $AVAILABLE ]; then cat $FLROOT/cpu0/power/energy_perf_bias + elif [ -z $VALUE ]; then + verbose "Getting CPU"$CORE" EBPs" + get_energy_performance_bias + else + verbose "Setting CPU"$CORE" EBPs to "$VALUE + set_energy_performance_bias + fi + ;; -p|--pp) if [ ! -z $AVAILABLE ]; then cat $FWROOT/acpi/platform_profile_choices elif [ -z $VALUE ]; then