皇上,还记得我吗?我就是1999年那个Linux伊甸园啊-----24小时滚动更新开源资讯,全年无休!

PowerTOP:在 Linux 上监视电量使用和改善笔记本电池寿命

我们都知道,现在几乎都从 PC 机换到了笔记本电脑了。但是使用笔记本有个问题,我们希望电池耐用,我们可以使用到每一点电量。所以,我们需要知道电量都去哪里了,是不是浪费了。

你可以使用 PowerTOP 工具来查看没有接入电源线时电量都用在了何处。你需要在终端中使用超级用户权限来运行 PowerTOP 工具。它可以访问该电池硬件并测量电量使用情况。

什么是 PowerTOP

PowerTOP 是一个 Linux 工具,用于诊断电量消耗和电源管理的问题。

它是由 Intel 开发的,可以在内核、用户空间和硬件中启用各种节电模式。

除了作为一个一个诊断工具之外,PowweTop 还有一个交互模式,可以让你实验 Linux 发行版没有启用的各种电源管理设置。

它也能监控进程,并展示其中哪个正在使用 CPU,以及从休眠状态页将其唤醒,也可以找出电量消耗特别高的应用程序。

如何安装 PowerTOP

PowerTOP 软件包在大多数发行版的软件库中可用,使用发行版的 包管理器 安装即可。

对于 Fedora 系统,使用 DNF 命令 来安装 PowerTOP。

  1. $ sudo dnf install powertop

对于 Debian/Ubuntu 系统,使用 APT-GET 命令 或 APT 命令 来安装 PowerTOP。

  1. $ sudo apt install powertop

对于基于 Arch Linux 的系统,使用 Pacman 命令 来安装 PowerTOP。

  1. $ sudo pacman -S powertop

对于 RHEL/CentOS 系统,使用 YUM 命令 来安装 PowerTOP。

  1. $ sudo yum install powertop

对于 openSUSE Leap 系统,使用 Zypper 命令 来安装 PowerTOP。

  1. $ sudo zypper install powertop

如何使用 PowerTOP

PowerTOP 需要超级用户权限,所以在 Linux 系统中以 root 身份运行 PowerTOP 工具。

默认情况下其显示 “概览” 页,在这里我们可以看到所有设备的电量消耗情况,也可以看到系统的唤醒秒数。

  1. $ sudo powertop
  2. PowerTOP v2.9 Overview Idle stats Frequency stats Device stats Tunables
  3. The battery reports a discharge rate of 12.6 W
  4. The power consumed was 259 J
  5. The estimated remaining time is 1 hours, 52 minutes
  6. Summary: 1692.9 wakeups/second, 0.0 GPU ops/seconds, 0.0 VFS ops/sec and 54.9% CPU use
  7. Usage Events/s Category Description
  8. 9.3 ms/s 529.4 Timer tick_sched_timer
  9. 378.5 ms/s 139.8 Process [PID 2991] /usr/lib/firefox/firefox -contentproc -childID 7 -isForBrowser -prefsLen 8314 -prefMapSize 173895 -schedulerPrefs 00
  10. 7.5 ms/s 141.7 Timer hrtimer_wakeup
  11. 3.3 ms/s 102.7 Process [PID 1527] /usr/lib/firefox/firefox --new-window
  12. 11.6 ms/s 69.1 Process [PID 1568] /usr/lib/firefox/firefox -contentproc -childID 1 -isForBrowser -prefsLen 1 -prefMapSize 173895 -schedulerPrefs 0001,
  13. 6.2 ms/s 59.0 Process [PID 1496] /usr/lib/firefox/firefox --new-window
  14. 2.1 ms/s 59.6 Process [PID 2466] /usr/lib/firefox/firefox -contentproc -childID 3 -isForBrowser -prefsLen 5814 -prefMapSize 173895 -schedulerPrefs 00
  15. 1.8 ms/s 52.3 Process [PID 2052] /usr/lib/firefox/firefox -contentproc -childID 4 -isForBrowser -prefsLen 5814 -prefMapSize 173895 -schedulerPrefs 00
  16. 1.8 ms/s 50.8 Process [PID 3034] /usr/lib/firefox/firefox -contentproc -childID 7 -isForBrowser -prefsLen 8314 -prefMapSize 173895 -schedulerPrefs 00
  17. 3.6 ms/s 48.4 Process [PID 3009] /usr/lib/firefox/firefox -contentproc -childID 7 -isForBrowser -prefsLen 8314 -prefMapSize 173895 -schedulerPrefs 00
  18. 7.5 ms/s 46.2 Process [PID 2996] /usr/lib/firefox/firefox -contentproc -childID 7 -isForBrowser -prefsLen 8314 -prefMapSize 173895 -schedulerPrefs 00
  19. 25.2 ms/s 33.6 Process [PID 1528] /usr/lib/firefox/firefox --new-window
  20. 5.7 ms/s 32.2 Interrupt [7] sched(softirq)
  21. 2.1 ms/s 32.2 Process [PID 1811] /usr/lib/firefox/firefox -contentproc -childID 4 -isForBrowser -prefsLen 5814 -prefMapSize 173895 -schedulerPrefs 00
  22. 19.7 ms/s 25.0 Process [PID 1794] /usr/lib/firefox/firefox -contentproc -childID 4 -isForBrowser -prefsLen 5814 -prefMapSize 173895 -schedulerPrefs 00
  23. 1.9 ms/s 31.5 Process [PID 1596] /usr/lib/firefox/firefox -contentproc -childID 1 -isForBrowser -prefsLen 1 -prefMapSize 173895 -schedulerPrefs 0001,
  24. 3.1 ms/s 29.9 Process [PID 1535] /usr/lib/firefox/firefox --new-window
  25. 7.1 ms/s 28.2 Process [PID 1488] /usr/lib/firefox/firefox --new-window
  26. 1.8 ms/s 29.5 Process [PID 1762] /usr/lib/firefox/firefox -contentproc -childID 3 -isForBrowser -prefsLen 5814 -prefMapSize 173895 -schedulerPrefs 00
  27. 8.8 ms/s 23.3 Process [PID 1121] /usr/bin/gnome-shell
  28. 1.2 ms/s 21.8 Process [PID 1657] /usr/lib/firefox/firefox -contentproc -childID 2 -isForBrowser -prefsLen 920 -prefMapSize 173895 -schedulerPrefs 000
  29. 13.3 ms/s 13.9 Process [PID 1746] /usr/lib/firefox/firefox -contentproc -childID 3 -isForBrowser -prefsLen 5814 -prefMapSize 173895 -schedulerPrefs 00
  30. 2.7 ms/s 11.1 Process [PID 3410] /usr/lib/gnome-terminal-server
  31. 3.8 ms/s 10.8 Process [PID 1057] /usr/lib/Xorg vt2 -displayfd 3 -auth /run/user/1000/gdm/Xauthority -nolisten tcp -background none -noreset -keeptty
  32. 3.1 ms/s 9.8 Process [PID 1629] /usr/lib/firefox/firefox -contentproc -childID 2 -isForBrowser -prefsLen 920 -prefMapSize 173895 -schedulerPrefs 000
  33. 0.9 ms/s 6.7 Interrupt [136] xhci_hcd
  34. 278.0 us/s 6.4 Process [PID 414] [irq/141-iwlwifi]
  35. 128.7 us/s 5.7 Process [PID 1] /sbin/init
  36. 118.5 us/s 5.2 Process [PID 10] [rcu_preempt]
  37. 49.0 us/s 4.7 Interrupt [0] HI_SOFTIRQ
  38. 459.3 us/s 3.1 Interrupt [142] i915
  39. 2.1 ms/s 2.3 Process [PID 3451] powertop
  40. 8.4 us/s 2.7 kWork intel_atomic_helper_free_state_
  41. 1.2 ms/s 1.8 kWork intel_atomic_commit_work
  42. 374.2 us/s 2.1 Interrupt [9] acpi
  43. 42.1 us/s 1.8 kWork intel_atomic_cleanup_work
  44. 3.5 ms/s 0.25 kWork delayed_fput
  45. 238.0 us/s 1.5 Process [PID 907] /usr/lib/upowerd
  46. 17.7 us/s 1.5 Timer intel_uncore_fw_release_timer
  47. 26.4 us/s 1.4 Process [PID 576] [i915/signal:0]
  48. 19.8 us/s 1.3 Timer watchdog_timer_fn
  49. 1.1 ms/s 0.00 Process [PID 206] [kworker/7:2]
  50. 2.4 ms/s 0.00 Interrupt [1] timer(softirq)
  51. 13.4 us/s 0.9 Process [PID 9] [ksoftirqd/0]
  52. Exit | / Navigate |

PowerTOP 的输出类似如上截屏,在你的机器上由于硬件不同会稍有不同。它的显示有很多页,你可以使用 Tab 和 Shift+Tab 在它们之间切换。

空闲状态页

它会显示处理器的各种信息。

  1. PowerTOP v2.9 Overview Idle stats Frequency stats Device stats Tunables
  2. Package | Core | CPU 0 CPU 4
  3. | | C0 active 6.7% 7.2%
  4. | | POLL 0.0% 0.1 ms 0.0% 0.1 ms
  5. | | C1E 1.2% 0.2 ms 1.6% 0.3 ms
  6. C2 (pc2) 7.5% | |
  7. C3 (pc3) 25.2% | C3 (cc3) 0.7% | C3 0.5% 0.2 ms 0.6% 0.1 ms
  8. C6 (pc6) 0.0% | C6 (cc6) 7.1% | C6 6.6% 0.5 ms 6.3% 0.5 ms
  9. C7 (pc7) 0.0% | C7 (cc7) 59.8% | C7s 0.0% 0.0 ms 0.0% 0.0 ms
  10. C8 (pc8) 0.0% | | C8 33.9% 1.6 ms 32.3% 1.5 ms
  11. C9 (pc9) 0.0% | | C9 2.1% 3.4 ms 0.7% 2.8 ms
  12. C10 (pc10) 0.0% | | C10 39.5% 4.7 ms 41.4% 4.7 ms
  13. | Core | CPU 1 CPU 5
  14. | | C0 active 8.3% 7.2%
  15. | | POLL 0.0% 0.0 ms 0.0% 0.1 ms
  16. | | C1E 1.3% 0.2 ms 1.4% 0.3 ms
  17. | |
  18. | C3 (cc3) 0.5% | C3 0.5% 0.2 ms 0.4% 0.2 ms
  19. | C6 (cc6) 6.0% | C6 5.3% 0.5 ms 4.7% 0.5 ms
  20. | C7 (cc7) 59.3% | C7s 0.0% 0.8 ms 0.0% 1.0 ms
  21. | | C8 27.2% 1.5 ms 23.8% 1.4 ms
  22. | | C9 1.6% 3.0 ms 0.5% 3.0 ms
  23. | | C10 44.5% 4.7 ms 52.2% 4.6 ms
  24. | Core | CPU 2 CPU 6
  25. | | C0 active 11.2% 8.4%
  26. | | POLL 0.0% 0.0 ms 0.0% 0.0 ms
  27. | | C1E 1.4% 0.4 ms 1.3% 0.3 ms
  28. | |
  29. | C3 (cc3) 0.3% | C3 0.2% 0.1 ms 0.4% 0.2 ms
  30. | C6 (cc6) 4.0% | C6 3.7% 0.5 ms 4.3% 0.5 ms
  31. | C7 (cc7) 54.2% | C7s 0.0% 0.0 ms 0.0% 1.0 ms
  32. | | C8 20.0% 1.5 ms 20.7% 1.4 ms
  33. | | C9 1.0% 3.4 ms 0.4% 3.8 ms
  34. | | C10 48.8% 4.6 ms 52.3% 5.0 ms
  35. | Core | CPU 3 CPU 7
  36. | | C0 active 8.8% 8.1%
  37. | | POLL 0.0% 0.1 ms 0.0% 0.0 ms
  38. | | C1E 1.2% 0.2 ms 1.2% 0.2 ms
  39. | |
  40. | C3 (cc3) 0.6% | C3 0.6% 0.2 ms 0.4% 0.2 ms
  41. | C6 (cc6) 7.0% | C6 7.5% 0.5 ms 4.4% 0.5 ms
  42. | C7 (cc7) 56.8% | C7s 0.0% 0.0 ms 0.0% 0.9 ms
  43. | | C8 29.4% 1.4 ms 23.8% 1.4 ms
  44. | | C9 1.1% 2.7 ms 0.7% 3.9 ms
  45. | | C10 41.0% 4.0 ms 50.0% 4.8 ms
  46. Exit | / Navigate |

频率状态页

它会显示 CPU 的主频。

  1. PowerTOP v2.9 Overview Idle stats Frequency stats Device stats Tunables
  2. Package | Core | CPU 0 CPU 4
  3. | | Average 930 MHz 1101 MHz
  4. Idle | Idle | Idle
  5. | Core | CPU 1 CPU 5
  6. | | Average 1063 MHz 979 MHz
  7. | Idle | Idle
  8. | Core | CPU 2 CPU 6
  9. | | Average 976 MHz 942 MHz
  10. | Idle | Idle
  11. | Core | CPU 3 CPU 7
  12. | | Average 924 MHz 957 MHz
  13. | Idle | Idle

设备状态页

它仅针对设备显示其电量使用信息。

  1. PowerTOP v2.9 Overview Idle stats Frequency stats Device stats Tunables
  2. The battery reports a discharge rate of 13.8 W
  3. The power consumed was 280 J
  4. Usage Device name
  5. 46.7% CPU misc
  6. 46.7% DRAM
  7. 46.7% CPU core
  8. 19.0% Display backlight
  9. 0.0% Audio codec hwC0D0: Realtek
  10. 0.0% USB device: Lenovo EasyCamera (160709000341)
  11. 100.0% PCI Device: Intel Corporation HD Graphics 530
  12. 100.0% Radio device: iwlwifi
  13. 100.0% PCI Device: O2 Micro, Inc. SD/MMC Card Reader Controller
  14. 100.0% PCI Device: Intel Corporation Xeon E3-1200 v5/E3-1500 v5/6th Gen Core Processor Host Bridge/DRAM Registers
  15. 100.0% USB device: Lenovo Wireless Optical Mouse N100
  16. 100.0% PCI Device: Intel Corporation Wireless 8260
  17. 100.0% PCI Device: Intel Corporation HM170/QM170 Chipset SATA Controller [AHCI Mode]
  18. 100.0% Radio device: btusb
  19. 100.0% PCI Device: Intel Corporation 100 Series/C230 Series Chipset Family PCI Express Root Port #4
  20. 100.0% USB device: xHCI Host Controller
  21. 100.0% PCI Device: Intel Corporation 100 Series/C230 Series Chipset Family USB 3.0 xHCI Controller
  22. 100.0% PCI Device: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller
  23. 100.0% PCI Device: Intel Corporation 100 Series/C230 Series Chipset Family PCI Express Root Port #3
  24. 100.0% PCI Device: Samsung Electronics Co Ltd NVMe SSD Controller SM951/PM951
  25. 100.0% PCI Device: Intel Corporation 100 Series/C230 Series Chipset Family PCI Express Root Port #2
  26. 100.0% PCI Device: Intel Corporation 100 Series/C230 Series Chipset Family PCI Express Root Port #9
  27. 100.0% PCI Device: Intel Corporation 100 Series/C230 Series Chipset Family SMBus
  28. 26.1 pkts/s Network interface: wlp8s0 (iwlwifi)
  29. 0.0% USB device: usb-device-8087-0a2b
  30. 0.0% runtime-reg-dummy
  31. 0.0% Audio codec hwC0D2: Intel
  32. 0.0 pkts/s Network interface: enp9s0 (r8168)
  33. 0.0% PCI Device: Intel Corporation 100 Series/C230 Series Chipset Family Power Management Controller
  34. 0.0% PCI Device: Intel Corporation HM170 Chipset LPC/eSPI Controller
  35. 0.0% PCI Device: Intel Corporation Xeon E3-1200 v5/E3-1500 v5/6th Gen Core Processor PCIe Controller (x16)
  36. 0.0% PCI Device: Intel Corporation 100 Series/C230 Series Chipset Family MEI Controller #1
  37. 0.0% PCI Device: NVIDIA Corporation GM107M [GeForce GTX 960M]
  38. 0.0% I2C Adapter (i2c-8): nvkm-0000:01:00.0-bus-0005
  39. 0.0% runtime-PNP0C14:00
  40. 0.0% PCI Device: Intel Corporation 100 Series/C230 Series Chipset Family HD Audio Controller
  41. 0.0% runtime-PNP0C0C:00
  42. 0.0% USB device: xHCI Host Controller
  43. 0.0% runtime-ACPI000C:00
  44. 0.0% runtime-regulatory.0
  45. 0.0% runtime-PNP0C14:01
  46. 0.0% runtime-vesa-framebuffer.0
  47. 0.0% runtime-coretemp.0
  48. 0.0% runtime-alarmtimer
  49. Exit | / Navigate |

可调整状态页

这个页面是个重要区域,可以为你的笔记本电池优化提供建议。

  1. PowerTOP v2.9 Overview Idle stats Frequency stats Device stats Tunables
  2. >> Bad Enable SATA link power management for host2
  3. Bad Enable SATA link power management for host3
  4. Bad Enable SATA link power management for host0
  5. Bad Enable SATA link power management for host1
  6. Bad VM writeback timeout
  7. Bad Autosuspend for USB device Lenovo Wireless Optical Mouse N100 [1-2]
  8. Good Bluetooth device interface status
  9. Good Enable Audio codec power management
  10. Good NMI watchdog should be turned off
  11. Good Runtime PM for I2C Adapter i2c-7 (nvkm-0000:01:00.0-bus-0002)
  12. Good Autosuspend for unknown USB device 1-11 (8087:0a2b)
  13. Good Runtime PM for I2C Adapter i2c-3 (i915 gmbus dpd)
  14. Good Autosuspend for USB device Lenovo EasyCamera [160709000341]
  15. Good Runtime PM for I2C Adapter i2c-1 (i915 gmbus dpc)
  16. Good Runtime PM for I2C Adapter i2c-12 (nvkm-0000:01:00.0-bus-0009)
  17. Good Autosuspend for USB device xHCI Host Controller [usb1]
  18. Good Runtime PM for I2C Adapter i2c-13 (nvkm-0000:01:00.0-aux-000a)
  19. Good Runtime PM for I2C Adapter i2c-2 (i915 gmbus dpb)
  20. Good Runtime PM for I2C Adapter i2c-8 (nvkm-0000:01:00.0-bus-0005)
  21. Good Runtime PM for I2C Adapter i2c-15 (nvkm-0000:01:00.0-aux-000c)
  22. Good Runtime PM for I2C Adapter i2c-16 (nvkm-0000:01:00.0-aux-000d)
  23. Good Runtime PM for I2C Adapter i2c-5 (nvkm-0000:01:00.0-bus-0000)
  24. Good Runtime PM for I2C Adapter i2c-0 (SMBus I801 adapter at 6040)
  25. Good Runtime PM for I2C Adapter i2c-11 (nvkm-0000:01:00.0-bus-0008)
  26. Good Runtime PM for I2C Adapter i2c-14 (nvkm-0000:01:00.0-aux-000b)
  27. Good Autosuspend for USB device xHCI Host Controller [usb2]
  28. Good Runtime PM for I2C Adapter i2c-9 (nvkm-0000:01:00.0-bus-0006)
  29. Good Runtime PM for I2C Adapter i2c-10 (nvkm-0000:01:00.0-bus-0007)
  30. Good Runtime PM for I2C Adapter i2c-6 (nvkm-0000:01:00.0-bus-0001)
  31. Good Runtime PM for PCI Device Intel Corporation 100 Series/C230 Series Chipset Family HD Audio Controller
  32. Good Runtime PM for PCI Device Intel Corporation 100 Series/C230 Series Chipset Family USB 3.0 xHCI Controller
  33. Good Runtime PM for PCI Device Intel Corporation Xeon E3-1200 v5/E3-1500 v5/6th Gen Core Processor Host Bridge/DRAM Registers
  34. Good Runtime PM for PCI Device Intel Corporation 100 Series/C230 Series Chipset Family PCI Express Root Port #9
  35. Good Runtime PM for PCI Device Intel Corporation HD Graphics 530
  36. Good Runtime PM for PCI Device Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller
  37. Good Runtime PM for PCI Device Intel Corporation 100 Series/C230 Series Chipset Family PCI Express Root Port #3
  38. Good Runtime PM for PCI Device O2 Micro, Inc. SD/MMC Card Reader Controller
  39. Good Runtime PM for PCI Device Intel Corporation HM170 Chipset LPC/eSPI Controller
  40. Good Runtime PM for PCI Device Intel Corporation 100 Series/C230 Series Chipset Family MEI Controller #1
  41. Good Runtime PM for PCI Device Samsung Electronics Co Ltd NVMe SSD Controller SM951/PM951
  42. Good Runtime PM for PCI Device Intel Corporation HM170/QM170 Chipset SATA Controller [AHCI Mode]
  43. Good Runtime PM for PCI Device Intel Corporation 100 Series/C230 Series Chipset Family Power Management Controller
  44. Good Runtime PM for PCI Device Intel Corporation 100 Series/C230 Series Chipset Family PCI Express Root Port #2
  45. Good Runtime PM for PCI Device Intel Corporation Wireless 8260
  46. Good Runtime PM for PCI Device Intel Corporation Xeon E3-1200 v5/E3-1500 v5/6th Gen Core Processor PCIe Controller (x16)
  47. Good Runtime PM for PCI Device Intel Corporation 100 Series/C230 Series Chipset Family PCI Express Root Port #4
  48. Good Runtime PM for PCI Device Intel Corporation 100 Series/C230 Series Chipset Family SMBus
  49. Good Runtime PM for PCI Device NVIDIA Corporation GM107M [GeForce GTX 960M]
  50. Exit | Toggle tunable | Window refresh

如何生成 PowerTop 的 HTML 报告

运行如下命令生成 PowerTop 的 HTML 报告。

  1. $ sudo powertop --html=powertop.html
  2. modprobe cpufreq_stats failedLoaded 100 prior measurements
  3. Cannot load from file /var/cache/powertop/saved_parameters.powertop
  4. File will be loaded after taking minimum number of measurement(s) with battery only
  5. RAPL device for cpu 0
  6. RAPL Using PowerCap Sysfs : Domain Mask f
  7. RAPL device for cpu 0
  8. RAPL Using PowerCap Sysfs : Domain Mask f
  9. Devfreq not enabled
  10. glob returned GLOB_ABORTED
  11. Cannot load from file /var/cache/powertop/saved_parameters.powertop
  12. File will be loaded after taking minimum number of measurement(s) with battery only
  13. Preparing to take measurements
  14. To show power estimates do 182 measurement(s) connected to battery only
  15. Taking 1 measurement(s) for a duration of 20 second(s) each.
  16. PowerTOP outputing using base filename powertop.html

打开 file:///home/daygeek/powertop.html 文件以访问生成的 PowerTOP 的 HTML 报告。

PowerTOP:在 Linux 上监视电量使用和改善笔记本电池寿命

自动调整模式

这个功能可以将所有可调整选项从 BAD 设置为 GOOD,这可以提升 Linux 中的笔记本电池寿命。

  1. $ sudo powertop --auto-tune
  2. modprobe cpufreq_stats failedLoaded 210 prior measurements
  3. Cannot load from file /var/cache/powertop/saved_parameters.powertop
  4. File will be loaded after taking minimum number of measurement(s) with battery only
  5. RAPL device for cpu 0
  6. RAPL Using PowerCap Sysfs : Domain Mask f
  7. RAPL device for cpu 0
  8. RAPL Using PowerCap Sysfs : Domain Mask f
  9. Devfreq not enabled
  10. glob returned GLOB_ABORTED
  11. Cannot load from file /var/cache/powertop/saved_parameters.powertop
  12. File will be loaded after taking minimum number of measurement(s) with battery only
  13. To show power estimates do 72 measurement(s) connected to battery only
  14. Leaving PowerTOP

via: https://www.2daygeek.com/powertop-monitors-laptop-battery-usage-linux/

作者:Vinoth Kumar 选题:lujun9972 译者:wxy 校对:wxy

本文由 LCTT 原创编译,Linux中国 荣誉推出

转自 https://linux.cn/article-10560-1.html