OpenCPN-low-energy/cpu-tuning-and-pm-profiler

Jump to: navigation, search

cpupower

cpupower is the new version of cpufreq-utils. It allows quite fine tunning for the CPU :

  • set up a governor
  • limit the CPUs frequency

The governor

A governor is a little watchdog that adjust the CPU "load" according to the number of tasks. In our case the ondemand governor is interesting (the other one is performance). We won't use it with cpupower but with pm-profiler.

Limit the CPU frequency

cpupower offer us the possibility to set up a maximal frequency that governors can't exceed.

Because each computer is different we can't set the same maximal frequency for any computer, in deed, each CPU as its minimal and maximal limits. So we have to extract the minimum CPU frequency before setting up a maximal limit, those lines of bash does it for us :

FREQ=$(cpupower frequency-info -l |tail -n 1 |cut -d " " -f 1) # we assume that all cores have the same limit than core 0
cpupower -c all frequency-set -u $FREQ # we don't touch the governor here, pm-profiles does it for us

pm-profiler

pm-profiler is a script that enable or disable functions of the computers by parsing a configuration file. We won't loiter about the whole configuration file but just on the points we changed.

We created a new profile called "opencpn", put the governor in the ondemand mode and activate the task scheduler. We also slow down the write of kernel buffers into file. In addition we are working on increase the "read ahead" cache.

Stopping CPUs

Linux allows you to stop all cores except core 0. There is two way of doing this

  • "On the fly"
  • grub argument

We start by counting the number of enabled cores we have by doing this :

$ grep -c processor /proc/cpuinfo 
4

The "On the fly" way

This is the easiest approach because you only need a root shell. Interesting files are located here :

# ls -1 /sys/devices/system/cpu/cpu*/online
/sys/devices/system/cpu/cpu1/online
/sys/devices/system/cpu/cpu2/online
/sys/devices/system/cpu/cpu3/online

As you can see the cpu0 doesn't have an online option.

The content of the file is 0 (means down) or 1 (means up). So we easily made this script to stop all cores (except core 0) :

for i in /sys/devices/system/cpu/cpu*/online; do 
    echo 0 > $i
done

The grub way

We used grub2 for this, it might be possible with grub but we let you find how !

You can also specify the maximal number of CPUs that Linux will use in the /etc/default/grub file by setting maxcpus=X (X is a number) in the line : GRUB_CMDLINE_LINUX_DEFAULT. Don't forget to "rebuild" your grub :

# grub2-mkconfig -o /boot/grub2/grub.cfg

Results

All measures have been taken on a 0.1.5 installation.

We have been confronted with unexpected results, thus, we took measures of the system when it was doing nothing :

1.2 GHz frequency :

  • Scheduler - 1 core
  • No scheduler - 1 core
  • No scheduler - all cores

2.6 GHz frequency :

  • No scheduler - 1 core
  • No scheduler - all cores

For all measures pm-profiler was running with our profile, a bunch of things were disabled :

  • GMixer applet
  • Parcellite applet
  • SSH Server
  • Bluetooth

We faced the fact that the scheduler (CPUFREQ_SCHED_MC_POWER_SAVINGS in pm-profiler settings) consumed (much) more than when he is off. Here is a chart that compares our measures :

Enhancements comparison.png

You can find the raw data here. In a nutshell, we saved 0.45 Watt between the lowest power average and the "reference" power average of the previous distribution (version 0.1.2).

Let's dig even further

We asked ourselves if all the cores we useful when the system is doing nothing, thus we took a measure at "cross-roads" with 2 cores instead of 4 running. The results were almost similar, only the height of the peak makes a difference. We had to took 2 measures when we usually took one because we didn't want to make a mistake and the results were very close.

Number of cores.png

Those results don't allow us to conclude flatly, however, it seems that having multiples cores smooth the peaks. You can find the raw data and the chart here.

Sources