93

I'm on a Compaq 615 and it's fan is loud. Not much you can do about that but I'm trying to keep the CPU/GPU as cool as possible. This is what Powertop has to say:

PowerTOP 1.97 - Overview - Idle stats - Frequency stats - Device stats - Tunables

If I change all of them to "good", the changes don't survive a reboot.

I added the line to the "grub"-file as suggested here

How do I make the Powertop suggested "Tunables" permanent?

H3R3T1K
  • 2,515
  • 11
  • 41
  • 69

12 Answers12

82

If you change all of them to good anyway, you could simply use the command

sudo powertop --auto-tune

Call powertop auto-tune automatically at boot time

1.

On systems using systemd as startup manager (like Ubuntu) install it as a service:

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.

On systems not using systemd, or if you want to use the old style with /etc/rc.local file, add this line at the end to /etc/rc.local:

powertop --auto-tune
exit 0

Note: if the script already contains exit 0 be sure you place all commands before that line, cause that exits the script

If you want to set all to good but one line you could first auto-tune and then disable one setting with an extra line, for example, if you want to re-enable the touchscreen-device (at usb 2-7), add this before the exit 0:

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

Note: on Linux with systemd, make sure /etc/rc.local is executed at startup by the compatibility service

systemctl status rc-local.service
Hi-Angel
  • 4,810
rubo77
  • 34,024
  • 52
  • 172
  • 299
26

Here's how you can make the changes permanent:

sudo powertop --html

This will generate a powertop-xxxxxxxxxx-xxxxxx.html file.

Now either open that up in the browser and copy the echo commands from "... in need of Tuning" to /etc/rc.local.

Or extract the commands using something like this:

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

If rc.local contains exit 0 you need to make sure to put the commands before this line.

Eliah Kagan
  • 119,640
15

You need to download and compile it because no one have the latest version

Download powertop https://01.org/powertop/downloads/2013/powertop-v2.3

powertop-2.3.tar.gz < < < Click & Download Me

Before compiling you need to install dependencies

Installing Dependencies ( Just copy paste the following commands )

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

Installing Powertop

To build and install PowerTOP type the following commands,

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

You can also use -j2 for how many cores you want to use in ./make.Replace -j2 with whatever number of CPU cores you want to use for the compilation process. for example i have used ./make -j8

Powertop is installed you can unplugged ac power and can run

sudo powertop

However, most of the settings are not saved and they are lost after a reboot. You, can, however, make them permanent, by using the commands provided in the PowerTOP html report. To generate an HTML report, run the following command: webupd8.org

sudo powertop --html=powertop.html

Implementing Powertop Suggestion On Battery And Back To Maximize Performance On Ac Power

For that you need to make a script that run powertop suggestion on battery and maximize the performance on ac power

Place it in /etc/pm/power.d/ and give execution rights

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

Copy paste the following the following in 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

Now you need to assign execution permission of power script

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

Now when you Unplugged, Powertop suggestion will take over and maximize the battery life & you Plugged in AC power you will have Max Performance.

Helpfull Links

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

For -j Option http://dnscrypt.org/

Qasim
  • 22,162
9

It's not the answer you're asking for, but you can try running in laptop-mode. To do this:

open a terminal and type:

gksu gedit /etc/default/acpi-support

enter password and then go to the bottom and in the section where it talks about laptop-mode write true instead of false, close document and save of course

Then enter:

gksu gedit /etc/laptop-mode/laptop-mode.conf

this file is a bit longer, but here is how I edited mine. I added # before the default line on those line I modified, like this:

#
# Should laptop mode tools add the "noatime" option to the mount options when 
# laptop mode is enabled?
#
#CONTROL_NOATIME=0
CONTROL_NOATIME=1

the default was 0 and I turned it to 1, modify only the lines I modified. There are a few options in here you'll want to review and toggle as you see fit. When you're close and save.

After this is done you will want to type:

gksu gedit

now in the text editor click open and go into /etc/laptop-mode/conf.d/ folder, there are various files, you probably are interested in usb autosuspend, hda audio, iwl intel wireless, intel sata and sched mc powersaving. Open these files one by one and read them, they're written in a perfect standard english and explain everything very well. You will know what to do, remember that 0 stands for off and 1 for on most of the time.

When you're done close and save each file.

Now restart and admire laptop-mode in action, then:

sudo powertop

and examine power consumption, if you've done everything correctly powertop won't have any addition suggestion to make because you've tweaked all there is to tweak (more or less).

Source: http://ubuntuforums.org/showthread.php?t=1157408&p=7271995#post7271995 (by Axx83)

Pro Backup
  • 3,248
rlemon
  • 1,861
  • 4
  • 19
  • 38
9

Udev rules

For permanent power savings that configure settings directly at the source, instead of creating scripts or relying on possible not installed packages. Thus as soon as hardware gets added by udev your settings are applied.

A correct udev rule makes the settings not apply when the hardware is not there, thus making the configuration more portable. And you learn more about the inner workings of your Linux kernel :-). The configuration made this way, do also apply when not running on battery.

An example for tunable Enable SATA link power Managmenet for host0. The suggestion is to:

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

This already gives you an idea where the hardware is: in /sys/class/scsi_host. You can verify this with:

# 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"

Better not touch the system udev rules in /lib/udev/rules.d/ and create your own udev rule file roughly at level 60 in /etc/udev/rules.d/. For example with the nano editor:

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

Some other examples write rules like:

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

I would say don't and make your rule even better by only applying it when the link power management policy is set to max_performance. Have a look at the little difference (look for the double equation sign):

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

Test you rule with 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

I can't find a way to apply the rule, so in this case I did a reboot to apply the newly created udev rule.

Pro Backup
  • 3,248
6

systemd makes it easy:

# /etc/systemd/system/powertop-autotune.service
[Unit]
Description=Auto-tune power savings (oneshot)

[Service]
Type=oneshot
ExecStart=/usr/bin/powertop --auto-tune
RemainAfterExit=true

[Install]
WantedBy=multi-user.target

Save the unit file, kill -HUP 1, systemctl enable --now powertop-autotune.service, done!


P.S. if you need any exceptions to what --auto-tune does, just add more ExecStart lines to set your own settings.

#...
ExecStart=/usr/bin/powertop --auto-tune
ExecStart=/bin/sh -c "echo on > /sys/bus/usb/devices/2-7/power/control"

#...
ulidtko
  • 5,988
3

You can use TLP to set your power saving settings from Powertop, and by enabling the service they will be set on each boot.

rusins
  • 161
2

This link talks about the same is talking about the same issue:

https://bbs.archlinux.org/viewtopic.php?pid=860406

I am interested in the solution by myself and will try later. Tell me If you can manage to implement this solution.

I couldnt get it running as the system always told me permission denied to run the executable file.

However this seems to work:

http://philatwarrimoo.blogspot.com/2011/06/powertop-howto-enable-device-power.html

I used the short command and run it with sudo.

As a semi automatic solution I created a launcher:

enter image description here

the script is as follows:

enter image description here

Is there a way to prevent asking for my password?

dago
  • 2,384
2

I solved this by creating a dash script /root/power_save.sh:

#!/bin/dash
find /sys/devices/pci* -path "*power/control" -exec bash -c "echo auto > '{}'" \;

Set it as executable:

sudo chmod u+x /root/power_save.sh

And add it to root crontab with sudo crontab -e:

@reboot /root/power_save.sh
1

Per rubo77's answer, I'm running powertop --auto-tune in /etc/rc.local and then undoing one of the changes it does by default to a USB device that I don't want to do.

However, since the device I want to disable auto power control for is an external USB device that could potentially appear with a different /sys tree device number, I did a bit more scripting to dynamically identify it:

/usr/local/sbin/powertop --auto-tune

export VENDOR=aaaa export PRODUCT=bbbb

for d in /sys/bus/usb/devices/*; do if [ -f $d/idVendor ] &&
[ "$(cat $d/idVendor)" == "${VENDOR}" ] &&
[ -f $d/idProduct ] &&
[ "$(cat $d/idProduct)" == "${PRODUCT}" ]; then echo 'on' > $d/power/control fi
done

exit 0

where VENDOR and PRODUCT are set to the USB vendor and product IDs in lower case hex.

These are available by

  • identifying the device in the lsusb output (IDs appear there in the form aaaa:bbbb), or

  • observing the command that powertop runs when you toggle the power setting, going to the device's current /sys/bus/usb/devices/* directory, and getting the values from the current idProduct and idVendor files.

rakslice
  • 203
0

Although this is an old topic, I came across a very, in my opinion, elegant solution using tmpfiles.d. See here for source (all credits to Ropid): How to configure /sys/devices

Quoting his post:

$ cat /etc/tmpfiles.d/acpi-wakeup.conf
#Type  Path  Mode  UID  GID  Age  Argument
w /sys/bus/pnp/devices/00:05/power/wakeup        - - - - disabled
w /sys/bus/pci/devices/0000:03:00.0/power/wakeup - - - - disabled
w /sys/bus/pci/devices/0000:00:1d.0/power/wakeup - - - - disabled
w /sys/bus/pci/devices/0000:00:1a.0/power/wakeup - - - - disabled
w /sys/bus/pci/devices/0000:00:14.0/power/wakeup - - - - disabled

The lines that start with "#" are comments. The lines that start with "w" are a write command. In this example here it's writing into files named "wakeup" somewhere inside /sys. Those four "-" you see mean that you don't use that particular argument to the "w" command. The word "disabled" you see at the end of the lines is the text you are writing into the file.

-2

I've been having a similar problem and after reading a question on this site found out that the program "powertop" is, apparently, more suited to developers.

How do I install powertop 1.13?

The version, more useful, for users is "powertop-1.13" found in the repositories. It shows power saving suggestions as well as the command that it uses to carry out the suggestion.

This Red Hat Docs site has further instructions for making these changes permanent.

Specifically:

To help you make the changes permanent, PowerTOP displays the exact command it runs to perform this optimization. Add the command to your /etc/rc.local file with your preferred text editor so that it takes effect every time that the computer starts.

Good luck!

Neil
  • 1