启动时自动调用 powertop auto-tune

启动时自动调用 powertop auto-tune

我使用的是 Compaq 615,它的风扇声音很大。对此你无能为力,但我正在尝试让 CPU/GPU 尽可能保持凉爽。这是 Powertop 所说的:

PowerTOP 1.97 - 概述 - 空闲统计 - 频率统计 - 设备统计 - 可调参数

如果我将它们全部改为“好”,则重新启动后这些更改将无法保留。

我将这一行添加到“grub”文件中,如下所示建议在这里

如何使 Powertop 建议的“可调参数”永久生效?

答案1

如果你无论如何都要把它们全部改好,你可以简单地使用命令

sudo powertop --auto-tune

启动时自动调用 powertop auto-tune

1.

在使用启动管理器的系统上systemd(例如 Ubuntu)将其安装为服务:

cat << EOF | sudo tee /etc/systemd/system/powertop.service
[Unit]
Description=PowerTOP auto tune

[Service]
Type=oneshot
Environment="TERM=dumb"
RemainAfterExit=true
ExecStart=/usr/sbin/powertop --auto-tune

[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl enable powertop.service

2.

在不使用的系统上systemd,或者如果您想使用旧样式的/etc/rc.local文件,请在末尾添加此行/etc/rc.local

powertop --auto-tune
exit 0

笔记:如果脚本已经包含,exit 0请确保将所有命令放在该行之前,因为这会退出脚本

如果您想要将所有内容设置为良好但保留一行,您可以先自动调整,然后使用额外的一行禁用一项设置,例如,如果您想重新启用触摸屏设备(在 USB 2-7),请在之前添加以下内容exit 0

powertop --auto-tune
echo 'on' > '/sys/bus/usb/devices/2-7/power/control'
exit 0

笔记:在 Linux 上systemd,确保兼容服务在启动时执行 /etc/rc.local

systemctl status rc-local.service

答案2

使更改永久生效的方法如下:

sudo powertop --html

这将生成一个powertop-xxxxxxxxxx-xxxxxx.html文件。

现在在浏览器中打开它并将echo命令从“...需要调整”复制到/etc/rc.local

或者使用如下命令提取命令:

echo "grep 'echo ' powertop-20120805-125538.html | sed 's/.*\(echo.*\);.*/\1/g'"

如果rc.local包含,exit 0则需要确保将命令放在此行之前。

答案3

您需要下载并编译它,因为没有人拥有最新版本

下载 powertophttps://01.org/powertop/downloads/2013/powertop-v2.3

powertop-2.3.tar.gz< < < 点击并下载我

编译之前需要安装依赖项

安装依赖项(只需复制粘贴以下命令)

sudo apt-get install libtool autoconf libnl-dev ncurses-dev pciutils-dev build-essential -y

安装 Powertop

要构建和安装 PowerTOP,请输入以下命令,

cd Downloads/powertop*  # assuming that you have downloaded in Downloads folder in you home directory   
configure 
make        # use -j option if you want to see details below
make install

您还可以使用-j2你想使用多少个核心。/制作。代替-j2编译过程中可以使用任意数量的 CPU 核心。例如,我使用过./make -j8

Powertop 安装后,您可以拔下交流电源并运行

sudo powertop

但是,大多数设置都不会保存,重启后就会丢失。但是,您可以使用 PowerTOP html 报告中提供的命令使它们永久生效。要生成 HTML 报告,请运行以下命令:webupd8.org

sudo powertop --html=powertop.html

实施 Powertop 建议电池供电并返回以最大程度提高交流电源性能

为此,您需要编写一个脚本,在电池上运行 powertop 建议并最大化交流电源的性能

将其放入/etc/pm/power.d/并赋予执行权限

sudo gedit /etc/pm/power.d/power

将以下内容复制粘贴到 power file 中

 #!/bin/sh

 # Shell script to reduce energy consumption when running battery. Place
 # it in /etc/pm/power.d/ and give execution rights.

 if on_ac_power; then

 # Start AC powered settings --------------------------------------------#


 # Disable laptop mode
 echo 0 > /proc/sys/vm/laptop_mode

 #NMI watchdog should be turned on
 for foo in /proc/sys/kernel/nmi_watchdog;
 do echo 1 > $foo;
 done

 # Set SATA channel: max performance
 for foo in /sys/class/scsi_host/host*/link_power_management_policy;
 do echo max_performance > $foo;
 done

 # CPU Governor: Performance
 for foo in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor;
 do echo performance > $foo;
 done 

 # Disable USB autosuspend
 for foo in /sys/bus/usb/devices/*/power/level;
 do echo on > $foo;
 done

 # Disable PCI autosuspend
 for foo in /sys/bus/pci/devices/*/power/control;
 do echo on > $foo;
 done

 # Disabile audio_card power saving
 echo 0 > /sys/module/snd_hda_intel/parameters/power_save_controller
 echo 0 > /sys/module/snd_hda_intel/parameters/power_save

 # End AC powered settings ----------------------------------------------#

 else

 # Start battery powered settings ---------------------------------------#

 # Enable Laptop-Mode disk writing
 echo 5 > /proc/sys/vm/laptop_mode

 #NMI watchdog should be turned on
 for foo in /proc/sys/kernel/nmi_watchdog;
 do echo 0 > $foo;
 done

 # Set SATA channel to power saving
 for foo in /sys/class/scsi_host/host*/link_power_management_policy;
 do echo min_power > $foo;
 done

 # Select Ondemand CPU Governor
 for foo in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor;
 do echo ondemand > $foo;
 done

 # Activate USB autosuspend
 for foo in /sys/bus/usb/devices/*/power/level;
 do echo auto > $foo;
 done

 # Activate PCI autosuspend
 for foo in /sys/bus/pci/devices/*/power/control;
 do echo auto > $foo;
 done

 # Activate audio card power saving
 # (sounds shorter than 5 seconds will not be played)
 echo 5 > /sys/module/snd_hda_intel/parameters/power_save
 echo 1 > /sys/module/snd_hda_intel/parameters/power_save_controller

 # End battery powered settings -----------------------------------------#

 fi

现在您需要分配执行权限力量脚本

 sudo chmod +x /etc/pm/power.d/power

现在当你拔掉插头,Powertop 建议将接管并最大限度地延长电池寿命,并且您已插入交流电您将获得最佳表现。

有用的链接

http://ubuntuforums.org/showthread.php?t=1855126&page=3 http://www.webupd8.org/2012/08/install-powertop-21-in-ubuntu-1204.html

对于 -j 选项http://dnscrypt.org/

答案4

Udev 规则

为了永久节省电量,直接在源头配置设置,而不是创建脚本或依赖可能未安装的软件包。因此,随着硬件的增加udev你的设置已应用

正确的udev规则使得设置不会在硬件不存在时应用,从而使配置更具可移植性。而且,您可以了解有关 Linux 内核内部工作原理的更多信息 :-)。这样进行的配置在不使用电池运行时也适用。

可调参数的示例Enable SATA link power Managmenet for host0。建议如下:

# echo 'min_power' > '/sys/class/scsi_host/host0/link_power_management_policy'`

这已经让您知道硬件在哪里:在 /sys/class/scsi_host 中。您可以使用以下命令验证这一点:

# udevadm info -a -p /sys/class/scsi_host/host?
  looking at device '/devices/pci0000:00/0000:00:1f.2/ata1/host0/scsi_host/host0':
    KERNEL=="host0"
    SUBSYSTEM=="scsi_host"
    ATTR{eh_deadline}=="0"
    ATTR{link_power_management_policy}=="max_performance"
    ATTR{host_busy}=="0"

最好不要触碰 /lib/udev/rules.d/ 中的系统 udev 规则,而是在 /etc/udev/rules.d/ 中大约 60 级处创建自己的 udev 规则文件。例如,使用 nano 编辑器:

$ nano /etc/udev/rules.d/60-power.rules

其他一些示例编写规则如下:

KERNEL=="host[0-5]", SUBSYSTEM=="scsi_host", ATTR{link_power_management_policy}="min_power"

我会建议不要这样做,而应仅在将链接电源管理策略设置为 max_performance 时应用该规则,这样可以使您的规则更好。看一下其中的细微差别(查找双等式符号):

KERNEL=="host[0-5]", SUBSYSTEM=="scsi_host", ATTR{link_power_management_policy}=="max_performance", ATTR{link_power_management_policy}="min_power"

使用以下命令测试你的规则udevadm test /devices/…

# udevadm test /devices/pci0000:00/0000:00:1f.2/ata1/host0/scsi_host/host0/link_power_management_policy
calling: test
version 204
This program is for debugging only, it does not run any program
specified by a RUN key. It may show incorrect results, because
some values may be different, or not available at a simulation run.

=== trie on-disk ===
tool version:          204
file size:         5660180 bytes
header size             80 bytes
strings            1265196 bytes
nodes              4394904 bytes
load module index
read rules file: /lib/udev/rules.d/40-crda.rules
read rules file: /lib/udev/rules.d/40-gnupg.rules
read rules file: /lib/udev/rules.d/40-hyperv-hotadd.rules
read rules file: /lib/udev/rules.d/42-usb-hid-pm.rules
read rules file: /lib/udev/rules.d/50-firmware.rules
read rules file: /lib/udev/rules.d/50-udev-default.rules
read rules file: /lib/udev/rules.d/55-dm.rules
read rules file: /lib/udev/rules.d/60-cdrom_id.rules
read rules file: /lib/udev/rules.d/60-keyboard.rules
read rules file: /lib/udev/rules.d/60-persistent-alsa.rules
read rules file: /lib/udev/rules.d/60-persistent-input.rules
read rules file: /lib/udev/rules.d/60-persistent-serial.rules
read rules file: /lib/udev/rules.d/60-persistent-storage-dm.rules
read rules file: /lib/udev/rules.d/60-persistent-storage-tape.rules
read rules file: /lib/udev/rules.d/60-persistent-storage.rules
read rules file: /lib/udev/rules.d/60-persistent-v4l.rules
read rules file: /etc/udev/rules.d/60-power.rules
read rules file: /lib/udev/rules.d/61-accelerometer.rules
read rules file: /lib/udev/rules.d/64-btrfs.rules
read rules file: /etc/udev/rules.d/70-persistent-net.rules
read rules file: /lib/udev/rules.d/70-power-switch.rules
read rules file: /lib/udev/rules.d/70-uaccess.rules
read rules file: /lib/udev/rules.d/71-biosdevname.rules
read rules file: /lib/udev/rules.d/71-seat.rules
read rules file: /lib/udev/rules.d/73-idrac.rules
read rules file: /lib/udev/rules.d/73-seat-late.rules
read rules file: /lib/udev/rules.d/75-net-description.rules
read rules file: /lib/udev/rules.d/75-persistent-net-generator.rules
read rules file: /lib/udev/rules.d/75-probe_mtd.rules
read rules file: /lib/udev/rules.d/75-tty-description.rules
read rules file: /lib/udev/rules.d/78-graphics-card.rules
read rules file: /lib/udev/rules.d/78-sound-card.rules
read rules file: /lib/udev/rules.d/80-drivers.rules
read rules file: /lib/udev/rules.d/85-hdparm.rules
read rules file: /lib/udev/rules.d/85-keyboard-configuration.rules
read rules file: /lib/udev/rules.d/85-regulatory.rules
read rules file: /lib/udev/rules.d/95-udev-late.rules
rules contain 24576 bytes tokens (2048 * 12 bytes), 11335 bytes strings
1814 strings (22027 bytes), 1179 de-duplicated (11328 bytes), 636 trie nodes used
ATTR '/sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/scsi_host/host0/link_power_management_policy' writing 'min_power' /etc/udev/rules.d/60-power.rules:1
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:1f.2/ata1/host0/scsi_host/host0
SUBSYSTEM=scsi_host
USEC_INITIALIZED=1203444595
unload module index

我找不到应用该规则的方法,因此在这种情况下,我重新启动以应用新创建的 udev 规则。

相关内容