目录
目录
目录
目录
AHCI 链路电源管理
基本概念
.AHCI Link Power Management is a technique in which the AHCI SATA controller places the SATA link into an SSD or HDD at very low power mode.
You can use the following settings:
Setting | Describe |
Active | HIPM or DIPM is not allowed. Do not use Link Power Management |
HIPM | Only HIPM (Host Initiated Link Power Management) allowed |
HIPM + DIPM | Enable HIPM and DIPM |
DIPM | Only DIPM (Device Initiated Link Power Management) allowed |
Lowest | Allow HIPM, DIPM and DEVSLP (if the storage device supports DEVSLP) |
在linux下的管理接口
several modes for power management of a SATA drive are available. 这里特别关注是针对SATA 盘的。现代笔记本里面很多NVME接口的盘走PCIE,不适应此种电源管理策略。
同时针对SSD盘,HDD机械盘在节能模式下,会被spindown掉,除了导致性能下降严重外,会导致各种问题。
/sys/class/scsi_host/host0$ cat link_power_management_policy
med_power_with_dipm
- max_performance: A disk is typically kept awake and running to get the best performance out of it. This is most indicative when thinking about spinning disks, as a spindown leads to inevitable significant latencies for the next access of the drive
- min_power: This mode prefers power saving over maximum performance. For spinning disks this for example implies spindowns to save power
- medium_power: A compromise between the aforementioned two.
- med_power_with_dipm: This mode configures the drive like
medium_power
does, but with additional Device Initiated Power Management
med_power_with_dipm this has been merged for kernel 4.15, as part of this change this new policy will be the default on all Intel mobile chipsets. This saves aprox. 1.0 - 1.5 Watts of power on an idle laptop
策略选择
The newest mode med_power_with_dipm
proves to be both among the lowest consuming ones for all modes for the tested SSD models and also very consistent in this, whereas other modes are either equal, systematically higher or highly dependent of the scenario at play (for example the min_power
mode on the MX500).
最新的模式 med_power_with_dipm 是最能节省功耗的模式。
The performance impact, both in latency and in throughput, was, however, somewhere between measurable and completely negligible, the highest impact could be seen in the throughput of the M550 where the data still implies med_power_with_dipm
to be the preferred choice.
采用 med_power_with_dipm 模式 ,对于IO延迟和吞吐量的影响也很小。
Beware that the results in this post are only applicable to SSDs. HDDs might have significantly different performance and power characteristics due to spin-down and spin-up times and other factors. Furthermore, the aforementioned results will likely apply for SSDs in general, but were obviously only tested on certain models. Different models, especially from differend vendors, could have different characteristics.
HDD的由于存在磁盘spindown的情况,spinup会耗时较长,并不适应此种策略。
测试方法
- Install Fedora 27 (with its 4.13.x release kernel), or boot Fedora 28 with a F27 4.13.x kernel, install powertop, run laptop on battery power, login and run "sudo powertop" in a terminal, let it idle for 5 minutes and note idle power-consumption rate
- Install Fedora 28, install powertop, run laptop on battery power, login and run "sudo powertop" in a terminal, let it idle for 5 minutes and note idle powerconsumption rate
- Note the screen brightness should be the same for both tests, if your laptop has a brightness sensor, disable automatic brightness adjustments
- Fedora 28 idle power-consumption should be lower then Fedora 27's power-consumption, esp. on Haswell and later systems using a SATA disk
上面描述的测试方法和我们用的是一致的,即用powertop测试,测试5分钟。
测试数据
通过下面的数据可以看到,采用 med_power_with_dipm可以节省1-1.5w的能耗
Laptop model | Disk | Normal Idle use | med_power_with_dipm use | notes |
---|---|---|---|---|
Dell Latitude E6400 | TOSHIBA THNSFC12 | 16.0 W | 14.5 W | |
Dell Latitude E6430 | C400-MTFDDAC256M | 12.1 W | 11.0 W | |
T-Bao T-Book Air | Starsway-N200 | 3.7W | 2.9 W | |
HP EliteBook 8540w | Samsung SSD 850 | 18.8 W | 17.9 W | |
Lenovo W530 | M4-CT128M4SSD2 | 11.9 W | 10.4 W | |
Lenovo Thinkpad T530 | Samsung SSD 850 | 7.7 W | 6.9 W | |
ThinkPad T510 | WDC WD800BEVS-08 | 10.6 W | 9.6 W | |
Dell Latitude E7450 | SAMSUNG SSD PM87 | 6.4 W | 5.2 W | |
Lenovo Thinkpad T400 | SanDisk Ultra II | 13.6 W | 11.8 W | |
Lenovo ThinkPad T450s | Samsung SSD 850 EVO 500GB | 4.5 W | 3.4 W | |
Asus Zenbook UX31A | Crucial_CT275MX3 | 4.9 W | 4.4 W | |
Lenovo ThinkPad X1 Carbon 2nd gen | Crucial_CT525MX3 | 11 W | 8 W | Data corruption when using min_power |
Lenovo ThinkPad T520 | INTEL SSDSC2BW18 | 10.7 W | 10.1 W | |
Lenovo Thinkpad T440s | SAMSUNG MZ7TE256 | 7.9 W | 6.7 W | |
Lenovo ThinkPad X220 | SAMSUNG MZ7TD128 | 8.8 W | 7.6 W |
Runtime PM
NVME
APST
不可操作的电源状态主要用于消费者级的SSD,用于改进续航时间。NVME 充分利用PCIE low power state来完成低功耗的目标。在主要的消费级应用场景中,SSD大多数处于idle状态,因而对于续航,低电力消耗是非常重要的。但是在数据中心,由于从PCIE L1 状态恢复的延时,不能采用这些低功耗态。
ACTP (active power)表示了过去10秒钟的最大平均电力消耗。如果控制器支持APST (Autonomous Power State transition),则host控制器可以自动地切换电源状态。控制器支持的电源状态示例如下:
可以看出最节能的状态,功耗消耗很小。
用户接口
apst_max_latency_ns
This patch teaches the driver to program APST so that each successive non-operational state will be entered after an idle time
equal to 100% of the total latency (entry plus exit) associated with that state.
A sysfs attribute 'apst_max_latency_ns' gives the maximum acceptable latency in ns; non-operational states with total latency greater than this value will not be used. As a special
case, apst_max_latency_ns=0 will disable APST entirely.
On hardware without APST support, apst_max_latency_ns will not be exposed in sysfs.
On my laptop, enabling APST seems to save nearly 1W.
查询磁盘支持ASPT的命令
# nvme get-feature /dev/nvme0 -f 0x0c -H
get-feature:0xc (Autonomous Power State Transition), Current value:0x000001
Autonomous Power State Transition Enable (APSTE): Enabled
Auto PST Entries .................
...
When APST is enabled the output should contain "Autonomous Power State Transition Enable (APSTE): Enabled" and there should be non-zero entries in the table below indicating the idle time before transitioning into each of the available states.
If APST is enabled but no non-zero states appear in the table, the latencies might be too high for any states to be enabled by default. The output of nvme id-ctrl /dev/nvme[0-9]
(as the root user) should show the available non-operational power states of the NVME controller. If the total latency of any state (enlat + xlat) is greater than 25000 (25ms) you must pass a value at least that high as parameter default_ps_max_latency_us
for the nvme_core
kernel module. This should enable APST and make the table in nvme get-feature
(as the root user) show the entries.
如果总的延时大于25ms,必须修改 default_ps_max_latency_us
值大于25ms
NVME 三种测试场景
1) Active idle is representative of a typical desktop, where none of the advanced PCIe link power saving features are enabled and the drive is immediately ready to process new commands.
PCIE 链路电源管理功能被禁用。nvme盘可以立即响应IO请求
2) Our Desktop Idle number represents what can usually be expected from a desktop system that is configured to enable SATA link power management, PCIe ASPM and NVMe APST, but where the lowest PCIe L1.2 link power states are not available.
使能SATA 链路电源管理;PCIE 链路状态电源管理;及NVME自动电源状态切换。但是PCIE L1.2 低功耗状态被禁用。
3)The Laptop Idle number represents the maximum power savings possible with all the NVMe and PCIe power management features in use—usually the default for a battery-powered system but rarely achievable on a desktop even after changing BIOS and OS settings.
开启所有的电源管理状态。
前两个测试场景的数据如下:根据磁盘的类型,可以看到 功耗减少 几百到上千毫瓦。
APM
参考资料:
实验power mangement policy 的影响 https://insanity.industries/post/sata-power-consumption/
合入med_power_with_dipm 的patch说明
https://lore.kernel.org/patchwork/patch/830838/
在fedora上面测试配置不同策略的数据 https://fedoraproject.org/wiki/Changes/ImprovedLaptopBatteryLife
TLP 配置参数的讨论 https://archived.forum.manjaro.org/t/ssd-hdd-optimisations-for-performance-and-longevity/79804/2
NVME power save 技术及各个状态进入 退出时间:https://www.phoronix.com/scan.php?page=news_item&px=NVMe-Power-Savings-APST
win10 NVME的管理策略 https://winaero.com/add-primary-nvme-idle-timeout-to-power-options-in-windows-10/
NVME 电源管理的详细说明: https://nvmexpress.org/resources/nvm-express-technology-features/nvme-technology-power-features/
SK 现代ssd的功耗及状态评测 https://www.anandtech.com/show/16012/the-sk-hynix-gold-p31-ssd-review/7
合入 APST的补丁 https://lore.kernel.org/patchwork/patch/711737/
APST的命令及开启后在某些磁盘上的bug: https://wiki.archlinux.org/title/Solid_state_drive/NVMe
DELL 笔记本 功耗优化 https://wiki.archlinux.org/title/Dell_XPS_15_9560
APST的状态转换图画的不错 https://blog.csdn.net/weixin_39571219/article/details/112525480
https://www.laptopmag.com/articles/ssds-with-best-laptop-battery-life