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
- A power profile is a firmware preset that sets how the processor saves energy.
- P-states are speed levels for busy cores, and C-states are sleep depths for idle cores.
- Deep sleep saves power, but a core takes longer to wake and answer.
- Choose speed for production databases, and saving for quiet test clusters.
- Write down each host's profile, and test it under real load before you trust it.
What firmware controls: profiles, P-states and C-states
- Power profile: a preset, such as maximum performance, balanced, or letting the operating system decide.
- P-states: speed levels, meaning the frequency and voltage a busy core runs at. A busy core runs faster and draws more power.
- C-states: sleep depths, meaning how far an idle core switches parts of itself off. The deeper the sleep, the more power it saves, and the longer it takes to wake.
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
- Test cluster: saving power is a reasonable choice, because a slow reply there costs little.
- Production database: queries wait on the database, so fast wake-ups matter, and speed is the better choice.
- Quiet hours: deep sleep saves the most power when a host sits idle.
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.
cat /sys/devices/system/cpu/cpuidle/current_driverThe scaling governor shows the speed policy in use. Common names are powersave and performance.
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governorNote: 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.
Read the name of the driver that puts idle cores to sleep.
cat /sys/devices/system/cpu/cpuidle/current_driverWhat you should see: The file names the idle driver in use. The example host shows intel_idle.
Read the speed policy of the first CPU.
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governorWhat 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.