All Products
Search
Document Center

Elastic Compute Service:Change the C-state to reduce vCPU response latency

Last Updated:Aug 09, 2024

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.

  1. Log on to the Elastic Compute Service (ECS) instance.

    For more information, see Connect to a Linux instance by using a password or key.

  2. Check the CPUidle driver of the current system and the supported C-states.

    Note

    If the following command does not display the corresponding CPUidle driver, you may need to update the image.

    cpupower idle-info

    The following figure shows the output. Number of idle states indicates the number of supported C-states, and Available idle states indicates the supported C-states.

    image

  3. Modify the related parameters of C-states in the /etc/default/grub file.

    1. Open the /etc/default/grub file.

      sudo vim /etc/default/grub
    2. Press the i key to enter Insert mode.

    3. 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.

      image

    4. Press the Esc key, enter :wq, and then press the Enter key to save and close the configuration file.

    5. Regenerate the GRand Unified Bootloader (GRUB) configuration file.

      sudo grub2-mkconfig -o /boot/grub2/grub.cfg
  4. Restart the instance for the changed configuration file to take effect.

    sudo reboot
  5. Check the CPUidle driver of the current system and the supported C-states.

    cpupower idle-info

    The following figure shows the output, which indicates the system only supports two C-states: POLL and C1.

    image