Thursday, October 23, 2014

openSUSE 13.x / Factory processor P-States and Performance

Since the introduction of P-States in the Intel SandyBridge and newer processors and the introduction of the P-States driver in the kernel since 3.9 there have been some changes to the power management on systems in regards to userspace tools. It has moved from cpufreq to cpupower and you may have written a script in times past to help set the right power management governor for your system. On a system with P-States you find that using cpupower has no effect on the performance whatsoever when you change the governor with cpupower. In order to get high performance out of your system with P-States you will need to look at some parameters into sysfs and change them using the userspace tool cpupower. Lets have a look at what there is for P-States.
Change your directory to /sys/devices/system/cpu/intel_pstate

system:/sys/devices/system/cpu/intel_pstate # l
total 0
drwxr-xr-x  2 root root    0 Oct 21 18:45 ./
drwxr-xr-x 14 root root    0 Oct 21 18:45 ../
-rw-r--r--  1 root root 4096 Oct 21 18:45 max_perf_pct
-rw-r--r--  1 root root 4096 Oct 21 18:45 min_perf_pct
-rw-r--r--  1 root root 4096 Oct 21 18:45 no_turbo
We have the max_perf_pct and the min_perf_pct and if we cat these files we can see their values.
# cat max_perf_pct
100
# cat min_perf_pct
32
This is the default for a powersave governor which you can gather from running the following command.
# cpupower frequency-info
  analyzing CPU 0:
  driver: intel_pstate
  CPUs which run at the same hardware frequency: 0
  CPUs which need to have their frequency coordinated by software: 0
  maximum transition latency: 0.97 ms.
  hardware limits: 1.20 GHz - 3.70 GHz
  available cpufreq governors: performance, powersave
  current policy: frequency should be within 1.20 GHz and 3.70 GHz.
                  The governor "powersave" may decide which speed to use
                  within this range.
  current CPU frequency is 3.53 GHz (asserted by call to hardware).
  boost state support:
    Supported: yes
    Active: yes
    3500 MHz max turbo 4 active cores
    3500 MHz max turbo 3 active cores
    3600 MHz max turbo 2 active cores
    3700 MHz max turbo 1 active cores
Notice the driver is intel_pstate and the current policy is set to powersave

We want the performance governor. So we will need to change our governor to performance. Execute the following.
# cpupower frequency-set -g performance

# cpupower frequency-info
analyzing CPU 0:
  driver: intel_pstate
  CPUs which run at the same hardware frequency: 0
  CPUs which need to have their frequency coordinated by software: 0
  maximum transition latency: 0.97 ms.
  hardware limits: 1.20 GHz - 3.70 GHz
  available cpufreq governors: performance, powersave
  current policy: frequency should be within 1.20 GHz and 3.70 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
  current CPU frequency is 2.83 GHz (asserted by call to hardware).
  boost state support:
    Supported: yes
    Active: yes
    3500 MHz max turbo 4 active cores
    3500 MHz max turbo 3 active cores
    3600 MHz max turbo 2 active cores
    3700 MHz max turbo 1 active cores
Also if we cat /sys/devices/system/cpu/intel_pstate/min_perf_pct you will notice that it has changed to 100

Thats good its all at 100% but wait we still are not done. There is another setting for P-States. Its called Performance Bias. From the man page cpupower-set you can read the following about it.

----snip----
Options
--perf-bias, -b
Sets a register on supported Intel processore which allows software to convey its policy for the relative importance of performance versus energy savings to the processor.

The range of valid numbers is 0-15, where 0 is maximum performance and 15 ismaximum energy efficiency.

The processor uses this information in model-specific ways when it must select trade-offs between performance and energy efficiency.

This policy hint does not supersede Processor Performance states (P-states) or CPUIdle power states (C-states), but allows software to have influence where it would otherwise be unable to express a preference.

For example, this setting may tell the hardware how aggressively or conservatively to control frequency in the "turbo range" above the explicitly OS-controlled P-state frequency range.It may also tell the hardware how aggressively it should enter the OS requested C-states.

This option can be applied to individual cores only via the --cpu option, cpupower(1).

Setting the performance bias value on one CPU can modify the setting on related CPUs as well (for example all CPUs on one socket), because of hardware restrictions. Use cpupower -c all info -b to verify.

This options needs the msr kernel driver (CONFIG_X86_MSR) loaded.
----snip----

So lets set our bias to 0 so we can get absolute maximum performance. The default is 8 on openSUSE. Execute the following.
# cpupower set -b 0
and to check it.
# cpupower info
analyzing CPU 0:
perf-bias: 0
even though it only shows CPU 0 it applies for all and you can see that by adding the -c all switch before info.
Now you have a system running at full performance with P-States.
Note: This will run the CPU's hot and the fans will kick in full speed all the time. So when your away from your system or don't need full performance you will want to put it back in powersave. I'm not responsible for overheating of your CPU. :-)

No comments: