Friday, January 30, 2015

PowerTop



Hello all,
Today, I would like to talk about a very interesting tool called Powetop. This tool is used for power consumption and power management and it finds and diagnosis different issues with powers. Using laptops when it’s on battery, this tool can help a lot to save battery and use laptop for longer time. For example, when you are editing a text file, there is no need to use wifi. And even though you are not using wifi, still it consumes power for its Idle time. So you can minimize power consumption of wifi when you are not using it and it’s idle. 

CPU is also consuming power a lot. When CPU is idle, operation system can put it to sleep mode to save more power. When OS commands CPU to enter to a low power state (there are different lower states), these “lower states” called CPU C-states and it operates on a per core basis. All C-states (C1 to Cn) put different parts of processor to power down. C0 means no sleep and it’s up and fully operational.

There is another term that you should know as well and it’s Package C-states or PCx. When all cores agree to enter a specific C-state, it’s called PCx. For example, if there are 2 cores and one is at C1 and the other one is C3, the Package C-state will be C1 (highest one).

You can install powertop tool either with yum command or by compiling actual package. The easiest way is yum command:
yum install powertool
However, if you want to download and install the latest version of powertool manually, do the followings:
tar -txvf powertop-2.7.tar.gz
cd powertop-2.7.tar.gz
./configure
make
make install

To run powetool:  
/usr/local/sbin/powertop

                                                                        Figure 1

Powetop has different tabs. The first tab is Overview and it shows the usage, number of event per second, category, description and power estimate of items. When you tune applications for power consumption, the number of wakeups per second should be less which means more system’s power. To see the power estimate column on Overview tab, make sure there is no file under /var/cache/powertop and system has to be running on battery power only. It takes time to calculate and measure power (in terms of Watt). "Kwork" in Category column is a placeholder process for kernel worker threads, which perform most of the actual processing for the kernel, especially in cases where there are interrupts, timers, I/O, etc.

Second tab is Idle State. It shows CPU’s usage currently in the system and also it shows the current C-state of each CPU. It also shows the same C-state by Core and Package(PCx). 

                                                                            Figure 2

Third tab is Frequency Stats which is frequency of cpu in terms of GHZ in relationship with the idle state.

                                                                            Figure 3

Fourth tab is Device Stats tab. It shows devices that consume power. Figure 4.

                                                                            Figure 4

Fifth tab is Tunables tab, which is my favorite tab. It lists all devices that are not tuned for power management and it’s marked as “Bad”. You can toggle it by pressing “enter” from Bad to Good. Now, remember that when you reboot the machine, it’s gone and system marks it as “Bad” again. If you want to save the setting permanently, the command that you have to put it in .bashrc file is showing on the top when you toggle it. In this case, it is:
echo ‘auto’ > /sys/bus/pci/devices/0000:00:15.0/power/control

                                                                               Figure 5

so, do this:
cd ~

vi .bashrc

echo ‘auto’ > /sys/bus/pci/devices/0000:00:15.0/power/control
save it.

Now, when you run powertop without any options, it goes to interactive mode. You can store the report on html or csv file format:
powertop --html=mypowertop.html
or
powertop --csv=mypowertop.csv
Also, you can let it run for some amount of seconds:
powertop --html=mypowertop.html --time=10

                                                                                   Figure 6
Hope you enjoyed.
Khosro Taraghi