ordinarykuma的blog

Linux的電源管理TLP(for tlp 1.9)

我記得我幾個月前寫過關於TLP設定教學的文章,總共兩篇,我就不附上連結了,因為在我撰文的當下,最新的TLP 1.9版有了翻天覆地的改變,首先是增加了可以在桌面環境的選單選擇電源模式(例如效能模式、平衡模式、省電模式),這一舉跟上了power-profiles-deamon或是tuned(tlp>tuned>power-profiles-deamon,懶人就裝tuned,省心)。我在此統一寫一篇設定教學的文章,順便作爲記錄。

安裝(以debian爲例)

#使用backports倉庫安裝最新版tlp  
sudo apt install -t tlp tlp-rdw tlp-pd*
sudo apt install tlp tlp-rdw tlp-pd

設定

同樣地,我們先用tlp-stat -p來查看CPU的電源狀態、sudo tlp-stat -g查看GPU電源狀態、sudo tlp-stat -b查看電池狀態,這個步驟是要大致掌握電腦可用的電源模式。下面出輸出範例。

xjd@debian:~$ tlp-stat -p
--- TLP 1.9.1 --------------------------------------------

+++ Processor
CPU model = Intel(R) Core(TM) 5 120U

/sys/devices/system/cpu/cpu0/cpufreq/scaling_driver        = intel_pstate
/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor      = powersave
/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors = performance powersave
/sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq      = 400000 [kHz]
/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq      = 5000000 [kHz]
/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq      = 400000 [kHz]
/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq      = 5000000 [kHz]
/sys/devices/system/cpu/cpu0/cpufreq/energy_performance_preference = balance_power [EPP]
/sys/devices/system/cpu/cpu0/cpufreq/energy_performance_available_preferences = default performance balance_performance balance_power power

/sys/devices/system/cpu/cpu1...cpu11: omitted for clarity, use -v to show all

/sys/devices/system/cpu/intel_pstate/status          = active
/sys/devices/system/cpu/intel_pstate/min_perf_pct    = 9 [%]
/sys/devices/system/cpu/intel_pstate/max_perf_pct    = 100 [%]
/sys/devices/system/cpu/intel_pstate/no_turbo        = 0
/sys/devices/system/cpu/intel_pstate/hwp_dynamic_boost = 0
/sys/devices/system/cpu/intel_pstate/turbo_pct      = (not available)
/sys/devices/system/cpu/intel_pstate/num_pstates     = (not available)
/sys/module/workqueue/parameters/power_efficient      = N
/proc/sys/kernel/nmi_watchdog                          = 0

+++ Platform Profile
/sys/firmware/acpi/platform_profile                    = (not available)
/sys/firmware/acpi/platform_profile_choices            = (not available)
xjd@debian:~$ sudo tlp-stat -g
[sudo] xjd 的密碼:
--- TLP 1.9.1 --------------------------------------------

+++ Intel Graphics
/sys/class/drm/card0/device/driver              = i915

/sys/class/drm/card0/power/rc6_enable           = 1 (enabled)
/sys/kernel/debug/dri/0/i915_fbc_status          = FBC disabled: pixel format not supported
/sys/module/i915/parameters/enable_psr           = -1 (use per-chip default)

/sys/class/drm/card0/gt_min_freq_mhz             = 100 [MHz]
/sys/class/drm/card0/gt_max_freq_mhz             = 1250 [MHz]
/sys/class/drm/card0/gt_boost_freq_mhz           = 1250 [MHz]
/sys/class/drm/card0/gt_RPn_freq_mhz             = 100 [MHz] (GPU min)
/sys/class/drm/card0/gt_RP0_freq_mhz             = 1250 [MHz] (GPU max)
xjd@debian:~$ sudo tlp-stat -b
[sudo] xjd 的密碼:
--- TLP 1.9.1 --------------------------------------------

+++ Battery Care
Plugin: generic
Supported features: none available


+++ Battery Status: BAT0
/sys/class/power_supply/BAT0/manufacturer              = WB SR 1
/sys/class/power_supply/BAT0/model_name               = WB Lion Battery
/sys/class/power_supply/BAT0/cycle_count              = 0 (or not supported)
/sys/class/power_supply/BAT0/energy_full_design       = 58140 [mWh]
/sys/class/power_supply/BAT0/energy_full              = 58140 [mWh]
/sys/class/power_supply/BAT0/energy_now               = 58140 [mWh]
/sys/class/power_supply/BAT0/power_now                = 0 [mW]
/sys/class/power_supply/BAT0/status                   = Full

/sys/class/power_supply/BAT0/charge_control_start_threshold = (not available)
/sys/class/power_supply/BAT0/charge_control_end_threshold   = (not available)
/sys/class/power_supply/BAT0/charge_behaviour              = (not available)
/sys/class/power_supply/BAT0/charge_types                  = (not available)

Charge                                                    = 100.0 [%]
Capacity                                                  = 100.0 [%]

  使用「sudo nano /etc/tlp.conf」進入nano編輯器界面,我將介紹新版的使用邏輯。原文我會複製貼上在說明下面,用斜體表示且每一行開頭會有「#」。同時,我也會附上我的設定值(裡面加底線就是我有取消注解或是有調整的)。我在此不會全部說明,僅挑我覺得、有玩過、有在用的設定。說實在的,在我花了很多時間看了下裡面的設定,我發現基本不用調整,預設的設定就很棒了。

  我們先簡單講一下TLP三個檔次的運作邏輯。效能模式是指我們手動制定「效能模式」,或是套用文件上有修改的「_AC結尾的參數且接上電源」,舉個例子,我現在有接上電源,現在會自動使用效能模式,假如我有修改tlp.conf這個文件,則會套用_AC結尾的參數;同理,平衡模式是指我們手動制定「平衡模式」,或是套用文件上有修改的「_BAT結尾的參數且使用電池」,舉個例子,我筆電離電就會套用平衡模式,假如我有修改tlp.conf這個文件,則會套用_BAT結尾的參數;省電模式是只可以手動啓用,才會使用省電模式,假如我們有修改tlp.conf這個文件,則會套用_SAV結尾的參數。

  舉例來說,我們要設定DISK_IDLE_SECS這個參數,則「DISK_IDLE_SECS_AC=」是指針對電源的參數,以此類推。

# Power Profiles: a part of TLP's parameters is divided into two or three  
# groups:  
# - performance: parameters ending in \_AC are used when AC power is  
#   connected or when the command 'tlp performance' is run.  
# - balanced: parameters ending in \_BAT are used when operating  
#   on battery power or when the command 'tlp balanced' is run.  
# - power-saver: parameters ending in \_SAV are used when the command  
#   'tlp power-saver' is run. If there is no \_SAV parameter available  
#   for a feature, the \_BAT parameter will be used instead.  
# - Any remaining parameters not divided apply to all power profiles.
# Please note:  
# - If parameters are specified more than once, the last occurrence takes  
#   precedence. This also means that any parameters defined here will take  
#   precedence over any drop-ins.  
# - You can however, append values to a parameter already defined as intrinsic  
#   default or in a previously read file: use PARAMETER+="add values".  
# - Important: all parameters are disabled here. Remove the leading '#' if you  
#   want to enable a feature without a default or if you want to set a value  
#   other than the default.  
# - Parameters must always be specified for all power profiles, i.e. in the  
#   AC, BAT and SAV category (where applicable). If you omit one of them,  
#   the missing profile will receive its value from another profile, since  
#   a change will only occur if different values are defined.  
# - To completely disable a parameter, use PARAMETER=""
# Legend for defaults:  
# - Default \*: intrinsic default that is effective when the parameter is  
#   missing or the line has a leading #'.  
# - Default : do nothing or use kernel/hardware defaults.
# Battery Care -- Charge thresholds  
# Charging starts when the charger is connected and the charge level  
# is below the start threshold. Charging stops when the charge level  
# is above the stop threshold.  
# Required hardware: Lenovo ThinkPads and other laptop brands are driven  
#   via specific plugins:  
# - Use the tlp-stat -b command to see if a plugin for your hardware is  
#   active and to look up vendor-specific threshold values. Some  
#   laptops support only 1 (on)/0 (off) instead of a percentage level.  
# - If your hardware supports a start \*and\* a stop threshold, you must  
#   specify both, otherwise TLP will refuse to apply the single threshold.  
# - If your hardware supports only a stop threshold, set the start  
#   value to 0.  
# - The names of the batteries shown by tlp-stat -b don't have to match  
#   the \_BAT0 or \_BAT1 parameter qualifiers. Please refer to [2]  
#   to see which qualifier applies to which battery.  
# For further explanation and all vendor specific details refer to  
# [1] https://linrunner.de/tlp/settings/battery.html  
# [2] https://linrunner.de/tlp/settings/bc-vendors.html
# tlp - Parameters for power saving  

# Set to 0 to disable, 1 to enable TLP.  
# Default: 1  

#TLP\_ENABLE=1
# Set to 1 to deactivate all intrinsic defaults of TLP. This means that  
# TLP only applies settings that have been explicitly activated i.e.  
# parameters without a leading '#'.  
# Notes:  
# - Helpful if one wants to use only selected features of TLP  
# - After activation, use tlp-stat -c to display your effective configuration  

#TLP\_DISABLE\_DEFAULTS=1
# Control how warnings about invalid settings are issued:  
#   0=disabled  
#   1=background tasks (boot, resume, change of power source) report to syslog  
#   2=shell commands report to the terminal (stderr)  
#   3=combination of 1 and 2  
# Default: 3  

#TLP\_WARN\_LEVEL=3
# Control automatic switching of the power profile when connecting or removing  
# the charger, when booting the system or when executing 'tlp start':  
#   0=disabled - never switch, use TLP\_DEFAULT\_MODE if configured  
#   1=auto  - always switch, select performance on AC and  
#             balanced on battery power.  
#   2=smart - do not switch if the following profiles were active previously:  
#             power-saver or balanced on AC resp.  
#             power-saver or performance on battery power.  
# Note: the same applies if the charger was connected/removed during suspend.  
# Default: 2

*#TLP\_AUTO\_SWITCH=2
#Power profile to use when automatic switching is disabled  
# (TLP\_AUTO\_SWITCH=0), profile is locked (TLP\_PERSISTENT\_DEFAULT=1)  
# or no power supply is detected:  
#   PRF=performance, BAL=balanced, SAV=power-saver.  
# Note: legacy values AC and BAT continue to work. They are mapped to  
# PRF and BAL, respectively.  
# Default:   

TLP\_DEFAULT\_MODE=BAL
# Lock power profile:  
#   0=profile depends on automatic switching,  
#   1=profile is locked to TLP\_DEFAULT\_MODE (TLP\_AUTO\_SWITCH is ignored).  
# Default: 0  

TLP\_PERSISTENT\_DEFAULT=1
# Power supply classes to ignore when determining power profile:  
#  AC, USB, BAT.  
# Separate multiple classes with spaces.  
# Note: try on laptops where operation mode AC/BAT is incorrectly detected.  
# Default:   

TLP\_PS\_IGNORE="BAT"
# Seconds laptop mode has to wait after the disk goes idle before doing a  
# sync. Non-zero value enables, zero disables laptop mode.  
# Default: 0 (AC), 2 (BAT)  

DISK\_IDLE\_SECS\_ON\_AC=0  
DISK\_IDLE\_SECS\_ON\_BAT=2*DISK\_IDLE\_SECS\_ON\_SAV=2
# Dirty page values (timeouts in secs).  
# Default: 15 (AC), 60 (BAT)* *MAX\_LOST\_WORK\_SECS\_ON\_AC=15  
MAX\_LOST\_WORK\_SECS\_ON\_BAT=60  
MAX\_LOST\_WORK\_SECS\_ON\_SAV=120
# Select a CPU scaling driver operation mode.  
# Intel CPU with intel\_pstate driver:  
#   active, passive.  
# AMD Zen 2 or newer CPU with amd-pstate driver as of kernel 6.3/6.4(\*):  
#   active, passive, guided(\*).  
# Default:   
#CPU\_DRIVER\_OPMODE\_ON\_AC=active  
#CPU\_DRIVER\_OPMODE\_ON\_BAT=active  
#CPU\_DRIVER\_OPMODE\_ON\_SAV=active
# Select a CPU frequency scaling governor.  
# Intel CPU with intel\_pstate driver or  
# AMD CPU with amd-pstate driver in active mode ('amd-pstate-epp'):  
#   performance, powersave(\*).  
# Intel CPU with intel\_pstate driver in passive mode ('intel\_cpufreq') or  
# AMD CPU with amd-pstate driver in passive or guided mode ('amd-pstate') or  
# Intel, AMD and other CPU brands with acpi-cpufreq driver:  
#   conservative, ondemand(\*), userspace, powersave, performance, schedutil(\*)  
# Use tlp-stat -p to show the active driver and available governors.  
# Important:  
#   Governors marked (\*) above are power efficient for \*almost all\* workloads  
#   and therefore kernel and most distributions have chosen them as defaults.  
#   You should have done your research about advantages/disadvantages \*before\*  
#   changing the governor.  
# Default:

CPU\_SCALING\_GOVERNOR\_ON\_AC=performance  
CPU\_SCALING\_GOVERNOR\_ON\_BAT=powersave  
CPU\_SCALING\_GOVERNOR\_ON\_SAV=powersave
# Set the min/max frequency available for the scaling governor.  
# Possible values depend on your CPU. For available frequencies see  
# the output of tlp-stat -p.  
# Notes:  
# - Min/max frequencies must always be specified for both AC \*and\* BAT  
# - Not recommended for use with the intel\_pstate driver, use  
#   CPU\_MIN/MAX\_PERF\_ON\_AC/BAT below instead  
# Default:*

#CPU\_SCALING\_MIN\_FREQ\_ON\_AC=0     
#CPU\_SCALING\_MAX\_FREQ\_ON\_AC=0      
#CPU\_SCALING\_MIN\_FREQ\_ON\_BAT=0     
#CPU\_SCALING\_MAX\_FREQ\_ON\_BAT=0     
#CPU\_SCALING\_MIN\_FREQ\_ON\_SAV=0  
#CPU\_SCALING\_MAX\_FREQ\_ON\_SAV=0
# Set CPU energy/performance policies EPP and EPB:  
#   performance, balance\_performance, default, balance\_power, power.  
# Values are given in order of increasing power saving.  
# Requires:  
# \* Intel CPU  
#   EPP: Intel Core i 6th gen. or newer CPU with intel\_pstate driver  
#   EPB: Intel Core i 2nd gen. or newer CPU with intel\_pstate driver  
#   EPP and EPB are mutually exclusive: when EPP is available, Intel CPUs  
#   will not honor EPB. Only the matching feature will be applied by TLP.  
# \* AMD Zen 2 or newer CPU  
#   EPP: amd-pstate driver in active mode ('amd-pstate-epp') as of kernel 6.3  
# Default: balance\_performance (AC), balance\_power (BAT), power (SAV)  

CPU\_ENERGY\_PERF\_POLICY\_ON\_AC=balance\_performance  
CPU\_ENERGY\_PERF\_POLICY\_ON\_BAT=balance\_power  
CPU\_ENERGY\_PERF\_POLICY\_ON\_SAV=power
# Set Intel CPU P-state performance: 0..100 (%).  
# Limit the max/min P-state to control the power dissipation of the CPU.  
# Values are stated as a percentage of the available performance.  
# Requires Intel Core i 2nd gen. or newer CPU with intel\_pstate driver.  
# Default:   

CPU\_MIN\_PERF\_ON\_AC=0  
CPU\_MAX\_PERF\_ON\_AC=100  
CPU\_MIN\_PERF\_ON\_BAT=0  
CPU\_MAX\_PERF\_ON\_BAT=70  
CPU\_MIN\_PERF\_ON\_SAV=0  
CPU\_MAX\_PERF\_ON\_SAV=60
# Set the CPU "turbo boost" (Intel) or "core performance boost" (AMD) feature:  
#   0=disable, 1=allow.  
# Allows to raise the maximum frequency/P-state of some cores if the  
# CPU chip is not fully utilized and below it's intended thermal budget.  
# Note: a value of 1 does \*not\* activate boosting, it just allows it.  
# Default:**CPU\_BOOST\_ON\_AC=1  
CPU\_BOOST\_ON\_BAT=0  
CPU\_BOOST\_ON\_SAV=0
# Select platform profile:  
#   performance, balanced, low-power.  
# Controls system operating characteristics around power/performance levels,  
# thermal and fan speed. Values are given in order of increasing power saving.  
# Note: check the output of tlp-stat -p to determine availability on your  
# hardware and additional profiles such as: balanced-performance, quiet, cool.  
# Default: performance (AC), balanced (BAT), low-power (SAV)  

#PLATFORM\_PROFILE\_ON\_AC=performance  
#PLATFORM\_PROFILE\_ON\_BAT=balanced  
#PLATFORM\_PROFILE\_ON\_SAV=low-power
# System suspend mode:  
#   s2idle: Idle standby - a pure software, light-weight, system sleep state,  
#   deep: Suspend to RAM - the whole system is put into a low-power state,  
#     except for memory, usually resulting in higher savings than s2idle.  
# CAUTION: changing suspend mode may lead to system instability and even  
# data loss. As for the availability of different modes on your system,  
# check the output of tlp-stat -s. If unsure, stick with the system default  
# by not enabling this.  
# Default:   

MEM\_SLEEP\_ON\_AC=s2idle  
MEM\_SLEEP\_ON\_BAT=deep
# Restore radio device state (Bluetooth, WiFi, WWAN) from previous shutdown  
# on system startup: 0=disable, 1=enable.  
# Note: the parameters DEVICES\_TO\_DISABLE/ENABLE\_ON\_STARTUP/SHUTDOWN below  
# are ignored when this is enabled.  
# Default: 0  

RESTORE\_DEVICE\_STATE\_ON\_STARTUP=1
# Radio devices to disable on startup: bluetooth, nfc, wifi, wwan.  
# Separate multiple devices with spaces.  
# Default:   

#DEVICES\_TO\_DISABLE\_ON\_STARTUP="bluetooth nfc wifi wwan"
# Radio devices to enable on startup: bluetooth, nfc, wifi, wwan.  
# Separate multiple devices with spaces.  
# Default:   

#DEVICES\_TO\_ENABLE\_ON\_STARTUP="wifi"
# Radio devices to disable on connect.  

DEVICES\_TO\_DISABLE\_ON\_LAN\_CONNECT=""  
DEVICES\_TO\_DISABLE\_ON\_WIFI\_CONNECT=""  
DEVICES\_TO\_DISABLE\_ON\_WWAN\_CONNECT=""  

# Radio devices to enable on disconnect.  

DEVICES\_TO\_ENABLE\_ON\_LAN\_DISCONNECT=""  
DEVICES\_TO\_ENABLE\_ON\_WIFI\_DISCONNECT=""  
DEVICES\_TO\_ENABLE\_ON\_WWAN\_DISCONNECT=""

參考資料

#Debian #Fedora #Linux