How to make powertop "Device Power Management" suggestion permanent? [duplicate]

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?


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

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.


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/