Power profiles, C-states and P-states

Video 096 of 140 in Virtualization Foundations, in the unit “Firmware settings that matter on a virtualization host”. 2:50, with English and Hindi audio.

A server draws power even when it is quiet, and firmware decides how hard the processor works to save that power. These choices trade electricity for speed. This article explains the power profile, P-states and C-states, why deep sleep costs time on wake-up, how to choose a profile for each kind of host, and how to read the idle driver and the speed policy from Linux.

What you will learn

What firmware controls: profiles, P-states and C-states

Firmware usually offers a few presets, and each one sets the states together. Some boards also let you change the states one at a time.

Why sleep costs time to leave

Picture a core that has been idle all night. Under a power-saving profile, it has gone into a deep C-state to save power. A request arrives, and the core must wake before it can work. Waking from a deep sleep takes time, so the reply is slower.

With a performance profile, the core stays in a light sleep. It wakes at once and answers quickly. Neither choice is wrong. Saving power suits a quiet test cluster, while busy queries usually want speed.

Choosing the profile for each host

The profile is set in firmware on each host, so write down each host's choice. Choose by the work the host does, then test it under real load before you trust it.

Read the idle driver and speed policy from Linux

Linux shows which driver puts idle cores to sleep. The file that names it is read with cat.

Show the idle driver in use
cat /sys/devices/system/cpu/cpuidle/current_driver

The scaling governor shows the speed policy in use. Common names are powersave and performance.

Show the speed policy of the first CPU
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

Note: The values depend on the processor and the firmware profile, so read them on each host.

Read the idle driver and speed policy

You need a Linux host and a shell. Your values depend on the processor and the firmware profile, so compare them with the choice written down for that host.

  1. Read the name of the driver that puts idle cores to sleep.

    cat /sys/devices/system/cpu/cpuidle/current_driver

    What you should see: The file names the idle driver in use. The example host shows intel_idle.

  2. Read the speed policy of the first CPU.

    cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

    What you should see: The scaling governor shows the speed policy in use. The example host shows performance, and other names are powersave and performance.

Terms

P-state
A speed level for a busy processor core, set by its frequency and voltage.
C-state
A sleep depth for an idle processor core. A deeper sleep saves more power but takes longer to wake.

Check yourself

What is the difference between a P-state and a C-state?

A P-state is a speed level for a busy core. A C-state is a sleep depth for an idle core.

Why can a deep C-state slow down a query?

A core in deep sleep takes time to wake before it can work on the request, so the reply is slower.

Which kind of host should choose speed, and why?

A production database, because queries wait on it, so fast wake-ups matter.

Previous: Hyper-threading on or off in firmware. Next: NUMA and sub-NUMA settings in firmware.