hv: replace vcpu_affinity array with cpu_affinity_bitmap

Currently the vcpu_affinity[] array fixes the vCPU to pCPU mapping.
While the new cpu_affinity_bitmap doesn't explicitly sepcify this
mapping, instead, it implicitly assumes that vCPU0 maps to the pCPU
with lowest pCPU ID, vCPU1 maps to the second lowest pCPU ID, and
so on.

This makes it possible for post-launched VM to run vCPUs on a subset of
these pCPUs only, and not all of them.

acrn-dm may launch post-launched VMs with the current approach: indicate
VM UUID and hypervisor launches all VCPUs from the PCPUs that are masked
in cpu_affinity_bitmap.

Also acrn-dm can choose to launch the VM on a subset of PCPUs that is
defined in cpu_affinity_bitmap. In this way, acrn-dm must specify the
subset of PCPUs in the CREATE_VM hypercall.

Additionally, with this change, a guest's vcpu_num can be easily calculated
from cpu_affinity_bitmap, so don't assign vcpu_num in vm_configuration.c.

Tracked-On: #4616
Signed-off-by: Zide Chen <zide.chen@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Zide Chen
2020-04-08 12:24:11 -07:00
committed by wenlingz
parent 3e79287cd3
commit 9150284ca7
13 changed files with 63 additions and 84 deletions

View File

@@ -189,7 +189,8 @@
#ifndef ASSEMBLER
#define AP_MASK (((1UL << get_pcpu_nums()) - 1UL) & ~(1UL << 0U))
#define ALL_CPUS_MASK ((1UL << get_pcpu_nums()) - 1UL)
#define AP_MASK (ALL_CPUS_MASK & ~(1UL << BSP_CPU_ID))
/**
*

View File

@@ -81,7 +81,6 @@
#define DEFAULT_DEST_MODE IOAPIC_RTE_DESTMODE_LOGICAL
#define DEFAULT_DELIVERY_MODE IOAPIC_RTE_DELMODE_LOPRI
#define ALL_CPUS_MASK (uint32_t) (((uint32_t)1U << (uint32_t) get_pcpu_nums()) - (uint32_t)1U)
#define IRQ_ALLOC_BITMAP_SIZE INT_DIV_ROUNDUP(NR_IRQS, 64U)

View File

@@ -17,7 +17,7 @@
#define CONFIG_MAX_VM_NUM (PRE_VM_NUM + SOS_VM_NUM + MAX_POST_VM_NUM)
#define AFFINITY_CPU(n) (1U << (n))
#define AFFINITY_CPU(n) (1UL << (n))
#define MAX_VCPUS_PER_VM MAX_PCPU_NUM
#define MAX_VUART_NUM_PER_VM 2U
#define MAX_VM_OS_NAME_LEN 32U
@@ -147,8 +147,9 @@ struct acrn_vm_config {
const uint8_t uuid[16]; /* UUID of the VM */
uint16_t vcpu_num; /* Number of vCPUs for the VM */
uint8_t severity; /* severity of the VM */
uint64_t vcpu_affinity[MAX_VCPUS_PER_VM];/* bitmaps for vCPUs' affinity */
uint64_t cpu_affinity_bitmap; /* The set bits represent the pCPUs the vCPUs of
* the VM may run on.
*/
uint64_t guest_flags; /* VM flags that we want to configure for guest
* Now we have two flags:
* GUEST_FLAG_SECURE_WORLD_ENABLED
@@ -160,6 +161,12 @@ struct acrn_vm_config {
uint16_t pci_dev_num; /* indicate how many PCI devices in VM */
struct acrn_vm_pci_dev_config *pci_devs; /* point to PCI devices BDF list */
struct acrn_vm_os_config os_config; /* OS information the VM */
/*
* below are varaible length members (per build).
* SOS can get the vm_configs[] array through hypercall, but SOS may not
* need to parse these members.
*/
uint16_t clos[MAX_VCPUS_PER_VM]; /* Class of Service, effective only if CONFIG_RDT_ENABLED
* is defined on CAT capable platforms
*/