Skip to content

Commit

Permalink
Refactored epb part, added doc for energy_perf_bias settings
Browse files Browse the repository at this point in the history
  • Loading branch information
snyypi committed Sep 8, 2024
1 parent eccff01 commit 9b86211
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 27 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,14 @@ governor = performance
# EPP: see available preferences by running: cat /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_available_preferences
energy_performance_preference = performance

# EPB (Energy Performance Bias) for the intel_pstate driver
# see conversion info: https://www.kernel.org/doc/html/latest/admin-guide/pm/intel_epb.html
# available EPB options include a numeric value between 0-15
# (where 0 = maximum performance and 15 = maximum power saving),
# or one of the following strings:
# performance (0), balance_performance (4), default (6), balance_power (8), or power (15)
# energy_perf_bias = balance_performance

# Platform Profiles
# https://www.kernel.org/doc/html/latest/userspace-api/sysfs-platform_profile.html
# See available options by running:
Expand Down Expand Up @@ -356,6 +364,14 @@ governor = powersave
# EPP: see available preferences by running: cat /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_available_preferences
energy_performance_preference = power

# EPB (Energy Performance Bias) for the intel_pstate driver
# see conversion info: https://www.kernel.org/doc/html/latest/admin-guide/pm/intel_epb.html
# available EPB options include a numeric value between 0-15
# (where 0 = maximum performance and 15 = maximum power saving),
# or one of the following strings:
# performance (0), balance_performance (4), default (6), balance_power (8), or power (15)
# energy_perf_bias = balance_power

# Platform Profiles
# https://www.kernel.org/doc/html/latest/userspace-api/sysfs-platform_profile.html
# See available options by running:
Expand Down
16 changes: 16 additions & 0 deletions auto-cpufreq.conf-example
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ governor = performance
# EPP: see available preferences by running: cat /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_available_preferences
energy_performance_preference = performance

# EPB (Energy Performance Bias) for the intel_pstate driver
# see conversion info: https://www.kernel.org/doc/html/latest/admin-guide/pm/intel_epb.html
# available EPB options include a numeric value between 0-15
# (where 0 = maximum performance and 15 = maximum power saving),
# or one of the following strings:
# performance (0), balance_performance (4), default (6), balance_power (8), or power (15)
# energy_perf_bias = balance_performance

# Platform Profiles
# https://www.kernel.org/doc/html/latest/userspace-api/sysfs-platform_profile.html
# See available options by running:
Expand Down Expand Up @@ -48,6 +56,14 @@ governor = powersave
# EPP: see available preferences by running: cat /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_available_preferences
energy_performance_preference = power

# EPB (Energy Performance Bias) for the intel_pstate driver
# see conversion info: https://www.kernel.org/doc/html/latest/admin-guide/pm/intel_epb.html
# available EPB options include a numeric value between 0-15
# (where 0 = maximum performance and 15 = maximum power saving),
# or one of the following strings:
# performance (0), balance_performance (4), default (6), balance_power (8), or power (15)
# energy_perf_bias = balance_power

# Platform Profiles
# https://www.kernel.org/doc/html/latest/userspace-api/sysfs-platform_profile.html
# See available options by running:
Expand Down
39 changes: 15 additions & 24 deletions auto_cpufreq/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,18 @@ def set_platform_profile(conf, profile):
print(f'Setting to use: "{pp}" Platform Profile')
run(f"cpufreqctl.auto-cpufreq --pp --set={pp}", shell=True)

def set_energy_perf_bias(conf, profile):
if Path("/sys/devices/system/cpu/intel_pstate").exists() is False:
print('Not setting EPB (not supported by system)')
return
epb = "balance_performance" if profile == "charger" else "balance_power"
if conf.has_option(profile, "energy_perf_bias"):
epb = conf[profile]["energy_perf_bias"]

run(f"cpufreqctl.auto-cpufreq --epb --set={epb}", shell=True)
print(f'Setting to use: "{epb}" EPB')


def set_powersave():
conf = config.get_config()
gov = conf["battery"]["governor"] if conf.has_option("battery", "governor") else AVAILABLE_GOVERNORS_SORTED[-1]
Expand All @@ -530,19 +542,8 @@ 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_energy_perf_bias(conf, "battery")
set_platform_profile(conf, "battery")
set_frequencies()

Expand Down Expand Up @@ -629,17 +630,6 @@ 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"

Expand All @@ -660,7 +650,8 @@ def set_performance():
else:
run("cpufreqctl.auto-cpufreq --epp --set=balance_performance", shell=True)
print('Setting to use: "balance_performance" EPP')


set_energy_perf_bias(conf, "charger")
set_platform_profile(conf, "charger")
set_frequencies()

Expand Down
6 changes: 3 additions & 3 deletions scripts/cpufreqctl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ function set_energy_performance_bias () {
else
case $VALUE in
performance) EPB_VALUE=0;;
balance-performance) EPB_VALUE=4;;
normal| default) EPB_VALUE=6;;
balance-power) EPB_VALUE=8;;
balance_performance) EPB_VALUE=4;;
default) EPB_VALUE=6;;
balance_power) EPB_VALUE=8;;
power) EPB_VALUE=15;;
*)
verbose "Invalid value provided for EPB"
Expand Down

0 comments on commit 9b86211

Please sign in to comment.