Blog

Posted 2011/06/07

Increasing the number of P-states

Sometimes the ACPI cpufreq driver in Linux does not correctly enumerate the number of P-states available for a given processor. What this means is you get fewer usable CPU frequencies than you should.

On one of our test clusters we have compute nodes which by default only give you two frequencies - 1.0GHz and 1.8GHz. However we know for a fact that the CPU can also do 1.2, 1.4 and 1.6GHz.

vendor_id : AuthenticAMD
cpu family : 15
model : 33
model name : Dual Core AMD Opteron(tm) Processor 265
stepping : 2

In Linux, the P-states are discovered by a CPU specific driver that on most modern systems uses ACPI. For our AMD CPU the driver is powernow-k8.c. By modifying the driver you can override the P-state count and provide a hard coded list frequencies and voltages for each P-state. Here is what the changes look like for Linux 2.6.35.9.

$ diff arch/x86/kernel/cpu/cpufreq/powernow-k8.c powernow-k8.hard-coded 
845a846,848
>       /* hard code number of p-states */
>       data->acpi_data.state_count = 5;
> 
960,968c963,972
<               if (data->exttype) {
<                       status =  data->acpi_data.states[i].status;
<                       fid = status & EXT_FID_MASK;
<                       vid = (status >> VID_SHIFT) & EXT_VID_MASK;
<               } else {
<                       control =  data->acpi_data.states[i].control;
<                       fid = control & FID_MASK;
<                       vid = (control >> VID_SHIFT) & VID_MASK;
<               }
---
>               /* use hard coded values for each pstate */
>                 switch(i)
>                 {
>                   case 0: fid=0xa;vid=0x6;break;
>                   case 1: fid=0x8;vid=0x8;break;
>                   case 2: fid=0x6;vid=0xa;break;
>                   case 3: fid=0x4;vid=0xe;break;
>                   case 4: fid=0x2;vid=0xa;break;
>                   default: printk("Exceeded number of p-states");
>                 }

You can use this trick on your own Linux system if you look up the number of supported frequencies and voltages for your CPU.