xref: /cloud-hypervisor/docs/cpu.md (revision 6b0df31e5d4134c9a15b0fb22aedac5d4a5de58b)
17c53896fSSebastien Boeuf# CPU
27c53896fSSebastien Boeuf
37c53896fSSebastien BoeufCloud Hypervisor has many options when it comes to the creation of virtual
47c53896fSSebastien BoeufCPUs. This document aims to explain what Cloud Hypervisor is capable of and
57c53896fSSebastien Boeufhow it can be used to meet the needs of very different use cases.
67c53896fSSebastien Boeuf
77c53896fSSebastien Boeuf## Options
87c53896fSSebastien Boeuf
97c53896fSSebastien Boeuf`CpusConfig` or what is known as `--cpus` from the CLI perspective is the way
107c53896fSSebastien Boeufto set vCPUs options for Cloud Hypervisor.
117c53896fSSebastien Boeuf
127c53896fSSebastien Boeuf```rust
137c53896fSSebastien Boeufstruct CpusConfig {
147c53896fSSebastien Boeuf    boot_vcpus: u8,
157c53896fSSebastien Boeuf    max_vcpus: u8,
167c53896fSSebastien Boeuf    topology: Option<CpuTopology>,
177c53896fSSebastien Boeuf    kvm_hyperv: bool,
187c53896fSSebastien Boeuf    max_phys_bits: u8,
197c53896fSSebastien Boeuf    affinity: Option<Vec<CpuAffinity>>,
20*6b0df31eSWilliam Douglas    features: CpuFeatures,
217c53896fSSebastien Boeuf}
227c53896fSSebastien Boeuf```
237c53896fSSebastien Boeuf
247c53896fSSebastien Boeuf```
25*6b0df31eSWilliam Douglas--cpus boot=<boot_vcpus>,max=<max_vcpus>,topology=<threads_per_core>:<cores_per_die>:<dies_per_package>:<packages>,kvm_hyperv=on|off,max_phys_bits=<maximum_number_of_physical_bits>,affinity=<list_of_vcpus_with_their_associated_cpuset>,features=<list_of_features_to_enable>
267c53896fSSebastien Boeuf```
277c53896fSSebastien Boeuf
287c53896fSSebastien Boeuf### `boot`
297c53896fSSebastien Boeuf
307c53896fSSebastien BoeufNumber of vCPUs present at boot time.
317c53896fSSebastien Boeuf
327c53896fSSebastien BoeufThis option allows to define a specific number of vCPUs to be present at the
337c53896fSSebastien Boeuftime the VM is started. This option is mandatory when using the `--cpus`
347c53896fSSebastien Boeufparameter. If `--cpus` is not specified, this option takes the default value
357c53896fSSebastien Boeufof `1`, starting the VM with a single vCPU.
367c53896fSSebastien Boeuf
377c53896fSSebastien BoeufValue is an unsigned integer of 8 bits.
387c53896fSSebastien Boeuf
397c53896fSSebastien Boeuf_Example_
407c53896fSSebastien Boeuf
417c53896fSSebastien Boeuf```
427c53896fSSebastien Boeuf--cpus boot=2
437c53896fSSebastien Boeuf```
447c53896fSSebastien Boeuf
457c53896fSSebastien Boeuf### `max`
467c53896fSSebastien Boeuf
477c53896fSSebastien BoeufMaximum number of vCPUs.
487c53896fSSebastien Boeuf
497c53896fSSebastien BoeufThis option defines the maximum number of vCPUs that can be assigned to the VM.
507c53896fSSebastien BoeufIn particular, this option is used when looking for CPU hotplug as it lets the
517c53896fSSebastien Boeufprovide an indication about how many vCPUs might be needed later during the
527c53896fSSebastien Boeufruntime of the VM.
537c53896fSSebastien BoeufFor instance, if booting the VM with 2 vCPUs and a maximum of 6 vCPUs, it means
547c53896fSSebastien Boeufup to 4 vCPUs can be added later at runtime by resizing the VM.
557c53896fSSebastien Boeuf
567c53896fSSebastien BoeufThe value must be greater than or equal to the number of boot vCPUs.
577c53896fSSebastien BoeufThe value is an unsigned integer of 8 bits.
587c53896fSSebastien Boeuf
597c53896fSSebastien BoeufBy default this option takes the value of `boot`, meaning vCPU hotplug is not
607c53896fSSebastien Boeufexpected and can't be performed.
617c53896fSSebastien Boeuf
627c53896fSSebastien Boeuf_Example_
637c53896fSSebastien Boeuf
647c53896fSSebastien Boeuf```
657c53896fSSebastien Boeuf--cpus max=3
667c53896fSSebastien Boeuf```
677c53896fSSebastien Boeuf
687c53896fSSebastien Boeuf### `topology`
697c53896fSSebastien Boeuf
707c53896fSSebastien BoeufTopology of the guest platform.
717c53896fSSebastien Boeuf
727c53896fSSebastien BoeufThis option gives the user a way to describe the exact topology that should be
737c53896fSSebastien Boeufexposed to the guest. It can be useful to describe to the guest the same
747c53896fSSebastien Boeuftopology found on the host as it allows for proper usage of the resources and
757c53896fSSebastien Boeufis a way to achieve better performances.
767c53896fSSebastien Boeuf
777c53896fSSebastien BoeufThe topology is described through the following structure:
787c53896fSSebastien Boeuf
797c53896fSSebastien Boeuf```rust
807c53896fSSebastien Boeufstruct CpuTopology {
817c53896fSSebastien Boeuf    threads_per_core: u8,
827c53896fSSebastien Boeuf    cores_per_die: u8,
837c53896fSSebastien Boeuf    dies_per_package: u8,
847c53896fSSebastien Boeuf    packages: u8,
857c53896fSSebastien Boeuf}
867c53896fSSebastien Boeuf```
877c53896fSSebastien Boeuf
887c53896fSSebastien Boeufor the following syntax through the CLI:
897c53896fSSebastien Boeuf
907c53896fSSebastien Boeuf```
917c53896fSSebastien Boeuftopology=<threads_per_core>:<cores_per_die>:<dies_per_package>:<packages>
927c53896fSSebastien Boeuf```
937c53896fSSebastien Boeuf
947c53896fSSebastien BoeufBy default the topology will be `1:1:1:1`.
957c53896fSSebastien Boeuf
967c53896fSSebastien Boeuf_Example_
977c53896fSSebastien Boeuf
987c53896fSSebastien Boeuf```
997c53896fSSebastien Boeuf--cpus boot=2,topology=1:1:2:1
1007c53896fSSebastien Boeuf```
1017c53896fSSebastien Boeuf
1027c53896fSSebastien Boeuf### `kvm_hyperv`
1037c53896fSSebastien Boeuf
1047c53896fSSebastien BoeufEnable KVM Hyper-V emulation.
1057c53896fSSebastien Boeuf
1067c53896fSSebastien BoeufWhen turned on, this option relies on KVM to emulate the synthetic interrupt
1077c53896fSSebastien Boeufcontroller (SynIC) along with synthetic timers expected by a Windows guest.
1087c53896fSSebastien BoeufA Windows guest usually runs on top of Microsoft Hyper-V, therefore expects
1097c53896fSSebastien Boeufthese synthetic devices to be present. That's why KVM provides a way to emulate
1107c53896fSSebastien Boeufthem and avoids failures running a Windows guest with Cloud Hypervisor.
1117c53896fSSebastien Boeuf
1127c53896fSSebastien BoeufBy default this option is turned off.
1137c53896fSSebastien Boeuf
1147c53896fSSebastien Boeuf_Example_
1157c53896fSSebastien Boeuf
1167c53896fSSebastien Boeuf```
1177c53896fSSebastien Boeuf--cpus kvm_hyperv=on
1187c53896fSSebastien Boeuf```
1197c53896fSSebastien Boeuf
1207c53896fSSebastien Boeuf### `max_phys_bits`
1217c53896fSSebastien Boeuf
1227c53896fSSebastien BoeufMaximum size for guest's addressable space.
1237c53896fSSebastien Boeuf
1247c53896fSSebastien BoeufThis option defines the maximum number of physical bits for all vCPUs, which
1257c53896fSSebastien Boeufsets a limit for the size of the guest's addressable space. This is mainly
1267c53896fSSebastien Boeufuseful for debug purpose.
1277c53896fSSebastien Boeuf
1287c53896fSSebastien BoeufThe value is an unsigned integer of 8 bits.
1297c53896fSSebastien Boeuf
1307c53896fSSebastien Boeuf_Example_
1317c53896fSSebastien Boeuf
1327c53896fSSebastien Boeuf```
1337c53896fSSebastien Boeuf--cpus max_phys_bits=40
1347c53896fSSebastien Boeuf```
1357c53896fSSebastien Boeuf
1367c53896fSSebastien Boeuf### `affinity`
1377c53896fSSebastien Boeuf
1387c53896fSSebastien BoeufAffinity of each vCPU.
1397c53896fSSebastien Boeuf
1407c53896fSSebastien BoeufThis option gives the user a way to provide the host CPU set associated with
1417c53896fSSebastien Boeufeach vCPU. It is useful for achieving CPU pinning, ensuring multiple VMs won't
1427c53896fSSebastien Boeufaffect the performance of each other. It might also be used in the context of
1437c53896fSSebastien BoeufNUMA as it is way of making sure the VM can run on a specific host NUMA node.
1447c53896fSSebastien BoeufIn general, this option is used to increase the performances of a VM depending
1457c53896fSSebastien Boeufon the host platform and the type of workload running in the guest.
1467c53896fSSebastien Boeuf
1477c53896fSSebastien BoeufThe affinity is described through the following structure:
1487c53896fSSebastien Boeuf
1497c53896fSSebastien Boeuf```rust
1507c53896fSSebastien Boeufstruct CpuAffinity {
1517c53896fSSebastien Boeuf    vcpu: u8,
1527c53896fSSebastien Boeuf    host_cpus: Vec<u8>,
1537c53896fSSebastien Boeuf}
1547c53896fSSebastien Boeuf```
1557c53896fSSebastien Boeuf
1567c53896fSSebastien Boeufor the following syntax through the CLI:
1577c53896fSSebastien Boeuf
1587c53896fSSebastien Boeuf```
1597c53896fSSebastien Boeufaffinity=[<vcpu_id1>@[<host_cpu_id1>, <host_cpu_id2>], <vcpu_id2>@[<host_cpu_id3>, <host_cpu_id4>]]
1607c53896fSSebastien Boeuf```
1617c53896fSSebastien Boeuf
1627c53896fSSebastien BoeufThe outer brackets define the list of vCPUs. And for each vCPU, the inner
1637c53896fSSebastien Boeufbrackets attached to `@` define the list of host CPUs the vCPU is allowed to
1647c53896fSSebastien Boeufrun onto.
1657c53896fSSebastien Boeuf
1667c53896fSSebastien BoeufMultiple values can be provided to define each list. Each value is an unsigned
1677c53896fSSebastien Boeufinteger of 8 bits.
1687c53896fSSebastien Boeuf
1697c53896fSSebastien BoeufFor instance, if one needs to run vCPU 0 on host CPUs from 0 to 4, the syntax
1707c53896fSSebastien Boeufusing `-` will help define a contiguous range with `affinity=0@[0-4]`. The
1717c53896fSSebastien Boeufsame example could also be described with `affinity=0@[0,1,2,3,4]`.
1727c53896fSSebastien Boeuf
1737c53896fSSebastien BoeufA combination of both `-` and `,` separators is useful when one might need to
1747c53896fSSebastien Boeufdescribe a list containing host CPUs from 0 to 99 and the host CPU 255, as it
1757c53896fSSebastien Boeufcould simply be described with `affinity=0@[0-99,255]`.
1767c53896fSSebastien Boeuf
1777c53896fSSebastien BoeufAs soon as one tries to describe a list of values, `[` and `]` must be used to
1787c53896fSSebastien Boeufdemarcate the list.
1797c53896fSSebastien Boeuf
1807c53896fSSebastien BoeufBy default each vCPU runs on the entire host CPU set.
1817c53896fSSebastien Boeuf
1827c53896fSSebastien Boeuf_Example_
1837c53896fSSebastien Boeuf
1847c53896fSSebastien Boeuf```
1857c53896fSSebastien Boeuf--cpus boot=3,affinity=[0@[2,3],1@[0,1]]
1867c53896fSSebastien Boeuf```
1877c53896fSSebastien Boeuf
1887c53896fSSebastien BoeufIn this example, assuming the host has 4 CPUs, vCPU 0 will run exclusively on
1897c53896fSSebastien Boeufhost CPUs 2 and 3, while vCPU 1 will run exclusively on host CPUs 0 and 1.
1907c53896fSSebastien BoeufBecause nothing is defined for vCPU 2, it can run on any of the 4 host CPUs.
191*6b0df31eSWilliam Douglas
192*6b0df31eSWilliam Douglas### `features`
193*6b0df31eSWilliam Douglas
194*6b0df31eSWilliam DouglasSet of CPU features to enable.
195*6b0df31eSWilliam Douglas
196*6b0df31eSWilliam DouglasThis option allows the user to enable a set of CPU features that are disabled
197*6b0df31eSWilliam Douglasby default otherwise.
198*6b0df31eSWilliam Douglas
199*6b0df31eSWilliam DouglasThe currently available feature set is: `amx`.
200*6b0df31eSWilliam Douglas
201*6b0df31eSWilliam DouglasThe `amx` feature will enable the x86 extension adding hardware units for
202*6b0df31eSWilliam Douglasmatrix operations (int and float dot products). The goal of the extension is to
203*6b0df31eSWilliam Douglasprovide performance enhancements for these common operations.
204*6b0df31eSWilliam Douglas
205*6b0df31eSWilliam Douglas_Example_
206*6b0df31eSWilliam Douglas
207*6b0df31eSWilliam Douglas```
208*6b0df31eSWilliam Douglas--cpus features=amx
209*6b0df31eSWilliam Douglas```
210*6b0df31eSWilliam Douglas
211*6b0df31eSWilliam DouglasIn this example the amx CPU feature will be enabled for the VMM.
212