blog/How To Disable CPU Power Management on Linux for Low Latency Operation

    Disable C-states

    C-states occur (available on all modern AMD and Intel CPUs) power down parts of the chip to save power. However, that incurs a latency penalty when a core must wake up to service a hardware request. Minimal latency is often desirable when working on certain tasks, such as audio-processing tasks. This is especially true when using advanced Linux audio systems like JACK. You can instruct your kernel to minimize latency by running the following command in a terminal: cat >/dev/cpu_dma_latency and then writing 0x00000000 and hitting enter. It cannot be shortened to 0x0 or 0 as this will not have the same effect. After having done so, the kernel will attempt to maintain minimum latency until the cat command is closed with control-D.

    Disable Intel Turbo Boost

    Intel turbo boost is, in Intel’s own words:

    Intel® Turbo Boost Technology 2.01 accelerates processor and graphics performance for peak loads, automatically allowing processor cores to run faster than the rated operating frequency if they’re operating below power, current, and temperature specification limits.

    Essentially, it operates by changing the clock speed of your processor depending on the load. Unfortunately, it may change the clock speed quite frequently, and changing the clock speed also incurs a latency penalty. You can disable Intel Turbo Boost on recent machines and kernels with the command: echo 1 >>/sys/devices/system/cpu/intel_pstate/no_turbo. I recommend doing this if you disable C-states with the above method to prevent your CPU from overheating. Most systems will not overheat, but disabling turbo forces the CPU to run at its stated speed rather than any turbo speeds, making it less prone to overheating and crashing, or overheating and then slowing itself down due to heat which could impact your low-latency tasks! For example, I have a 2.4Ghz i7 CPU with a maximum turbo speed of 3.4Ghz. If I disable C-states but do not disable turbo, the CPU runs at 3.1Ghz and causes my laptop fans to spin up. However, if I disable turbo, the CPU runs at 2.4Ghz and remains fairly cool.

    Set Frequency to Maximum

    Linux contains a system called cpufreq to adjust the CPU frequency based on a number of policies. Select the “performance” policy to have the kernel run your CPU at its maximum frequency with the following command: for i in /sys/devices/system/cpu/cpu*/cpuidle/state5/disable ; do echo 1 >>$i ; cat $i ; done. Depending on your system, this might have no effect, because many CPUs (including my Haswell mobile i7-4700MQ) will manage their own clockspeed automatically, leaving the OS with limited control.