It is often needed for a virtual machine to use specific cores of those available. On a multi-core system, one or more cores can be assigned for each virtual machine to improve performance. By default a virtual machine will use any available core. Assuming that there is a machine with 4 cores and a virtual machine needs to use two of them, the following entries in the guest’s configuration file will present the virtual machine with two virtual CPUs and will map them between the 3rd and the 4th physical cores.
cpus = "2,3" vcpus = 2
A longer range, let’s say on a 8core machine, can be specified as “2-8” for example.
Which CPU is used for each VCPU can be seen with the xm vcpu-list command:
# xm vcpu-list node1 Name ID VCPUs CPU State Time(s) CPU Affinity node1 4 0 2 -b- 1.9 2-3 node1 4 1 3 -b- 2.8 2-3
If there’s no cpus definition in the config file, each VCPU will use any of the available physical ones. The following host is configured to have 4 VCPUS:
# xm vcpu-list node3 Name ID VCPUs CPU State Time(s) CPU Affinity node3 2 0 3 -b- 2.1 any cpu node3 2 1 0 -b- 1.2 any cpu node3 2 2 2 -b- 0.9 any cpu node3 2 3 1 -b- 2.9 any cpu
However, I noticed that Xen will assign different CPU to each VCPU at different times, and many times the same CPU will be mapped to more than one VCPUs:
# xm vcpu-list node2 Name ID VCPUs CPU State Time(s) CPU Affinity node2 8 0 2 -b- 4.1 0-2 node2 8 1 1 -b- 1.6 0-2 node2 8 2 1 -b- 1.5 0-2