Rate This Document
Findability
Accuracy
Completeness
Readability

Enabling Cluster Scheduling Tuning in a Virtualization Environment

You need to enable cluster scheduling tuning before using it. The following describes how to enable this feature in a virtualization environment.

In a virtualization environment, the advanced configuration and power interface (ACPI) or DT information of a VM is generated by a virtualization component. The virtualization component generates an ACPI table or a DT based on the CPU topology information configured by users and loads the ACPI table or DT together with the VM kernel to the VM memory address space. In this way, the VM can detect the CPU topology information and optimize task scheduling.

The following describes how to set the vCPU topology information of a VM, verify that the VM has received the information, and enable cluster scheduling tuning.

Make sure you have the root permission.

  1. View the CPU topology and cluster grouping of the physical machine.

    The CPU cluster grouping varies according to the CPU model. Therefore, you need to check the CPU cluster grouping before using the CPU cluster.

    cat /sys/devices/system/cpu/cpu0/topology/cluster_cpus_list

    Expected result:

    0-3

    In this example, the cluster where CPU0 is located contains CPUs 0 to 3, that is, this cluster has four cores.

  2. Edit the VM's XML configuration file.

    For example, to configure a VM with 16 CPUs, set the vCPU topology configuration as follows.

    1. Use libvirt to manage VM configurations. Run the following command to open the XML configuration file of the VM. In the command, VM indicates the target VM name.
      virsh edit VM
    2. Press i to enter the insert mode and modify the VM XML file.

      Change <domain type='kvm'> in the first line to the following content:

      <domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>

      Add the following content to the domain section:

       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
        <cputune>
          <vcpupin vcpu='0' cpuset='32'/>
          <vcpupin vcpu='1' cpuset='33'/>
          <vcpupin vcpu='2' cpuset='34'/>
          <vcpupin vcpu='3' cpuset='35'/>
          <vcpupin vcpu='4' cpuset='36'/>
          <vcpupin vcpu='5' cpuset='37'/>
          <vcpupin vcpu='6' cpuset='38'/>
          <vcpupin vcpu='7' cpuset='39'/>
          <vcpupin vcpu='8' cpuset='40'/>
          <vcpupin vcpu='9' cpuset='41'/>
          <vcpupin vcpu='10' cpuset='42'/>
          <vcpupin vcpu='11' cpuset='43'/>
          <vcpupin vcpu='12' cpuset='44'/>
          <vcpupin vcpu='13' cpuset='45'/>
          <vcpupin vcpu='14' cpuset='46'/>
          <vcpupin vcpu='15' cpuset='47'/>
          <emulatorpin cpuset='32-47'/>
        </cputune>
        <qemu:commandline>
          <qemu:arg value='-smp'/>
          <qemu:arg value='cpus=16,maxcpus=16,sockets=1,dies=1,clusters=4,cores=4,threads=1'/>
        </qemu:commandline>
      
      • In vcpupin, vcpu indicates the CPU ID in the VM, and cpuset indicates the CPU ID in the physical machine. This parameter is used to bind vCPUs to physical CPUs in 1:1 mode.
      • The QEMU commandline describes that, in this example, the vCPU topology contains 16 CPUs and supports a maximum of 16 CPUs, with each CPU located on a socket. Each socket has a die, each die has four clusters each consisting of four cores, and each core can execute one thread. This topology helps optimize VM performance.
      • When configuring the vCPU topology, ensure that the vCPU topology complies with the physical CPU structure to ensure optimal performance optimization. When cores is set to 4, QEMU binds vCPUs 0 to 3 to a cluster. Therefore, when using vcpupin to bind vCPUs and physical CPUs, you need to bind four physical CPUs in the same cluster, for example, CPU 32-35. If the physical CPUs are not in the same cluster, the optimization result might be unsatisfactory.
    3. Press Esc, type :wq!, and press Enter to save the file and exit.
  3. Verify that the vCPU topology takes effect.
    1. Start the VM.
      virsh start VM --console
    1. After the VM is started, run the following command on the VM console to view the CPU ID list in the CPU cluster to which CPU0 belongs:
      cat /sys/devices/system/cpu/cpu0/topology/cluster_cpus_list

      Expected result:

      0-3

    According to the parameter description in 2, vCPUs 0 to 3 are bound to the same cluster, and the physical cores in the cluster are 32 to 35. The preceding information indicates that the topology has taken effect.

  4. Enable cluster scheduling tuning on the VM and set the scheduler of the Linux kernel as the cluster scheduler.
    echo 1 > /proc/sys/kernel/sched_cluster