C-state controls the CPU power saving states when the CPU is idle. The C-state ranges from C0 to C6 in ascending order by level. C0 indicates that the CPU works in normal state and C6 indicates that the CPU works at the highest power saving level and enters the low power state. When the CPU enters a higher-level C-state, its wake-up latency increases, which impacts performance in scenarios with high real-time requirements. Therefore, if you require consistent performance, we recommend that you change the C-state to C1 to reduce vCPU response latency.
Background information
When the vCPU has few loads, keeping the vCPU at a low-level C-state helps reduce hypervisor-induced overheads of different instructions such as HLT and MWAIT and the wake-up latency of the vCPU. However, when the operating system sets the vCPU to a high-level C-state, a pecific period of time is required to wake up the vCPU such as when an interrupt occurs on the network interface card (NIC) and execute instructions. The wake-up time varies based on the CPU chip architecture. You can configure the operating system to disable the high-level C-state to reduce vCPU response latency.
Procedure
In this example, ecs.g8i.large and Alibaba Cloud Linux 3 are used to describe how to disable the high-level C-state for vCPU. The command output may vary based on the instance type and image.
Log on to the Elastic Compute Service (ECS) instance.
For more information, see Connect to a Linux instance by using a password or key.
Check the CPUidle driver of the current system and the supported C-states.
NoteIf the following command does not display the corresponding CPUidle driver, you may need to update the image.
cpupower idle-infoThe following figure shows the output.
Number of idle statesindicates the number of supported C-states, andAvailable idle statesindicates the supported C-states.
Modify the related parameters of C-states in the
/etc/default/grubfile.Open the /etc/default/grub file.
sudo vim /etc/default/grubPress the
ikey to enter Insert mode.Find the
GRUB_CMDLINE_LINUX=line and add intel_idle.max_cstate=1 and processor.max_cstate=1 at the end of the line to set the C-state of the idle vCPU to C1.
Press the
Esckey, enter:wq, and then press theEnterkey to save and close the configuration file.Regenerate the GRand Unified Bootloader (GRUB) configuration file.
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
Restart the instance for the changed configuration file to take effect.
sudo rebootCheck the CPUidle driver of the current system and the supported C-states.
cpupower idle-infoThe following figure shows the output, which indicates the system only supports two C-states: POLL and C1.
