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

@@ -218,7 +218,8 @@ static inline uint16_t get_vm_bsp_pcpu_id(const struct acrn_vm_config *vm_config
{
uint16_t cpu_id = INVALID_CPU_ID;
cpu_id = ffs64(vm_config->vcpu_affinity[BSP_CPU_ID]);
/* The set least significant bit represents the pCPU ID for BSP */
cpu_id = ffs64(vm_config->cpu_affinity_bitmap);
return (cpu_id < get_pcpu_nums()) ? cpu_id : INVALID_CPU_ID;
}
@@ -401,7 +402,6 @@ int32_t create_vm(uint16_t vm_id, struct acrn_vm_config *vm_config, struct acrn_
{
struct acrn_vm *vm = NULL;
int32_t status = 0;
uint32_t i;
uint16_t pcpu_id;
/* Allocate memory for virtual machine */
@@ -504,10 +504,12 @@ int32_t create_vm(uint16_t vm_id, struct acrn_vm_config *vm_config, struct acrn_
if (status == 0) {
/* We have assumptions:
* 1) vcpus used by SOS has been offlined by DM before UOS re-use it.
* 2) vcpu_affinity[] passed sanitization is OK for vcpu creating.
* 2) cpu_affinity_bitmap passed sanitization is OK for vcpu creating.
*/
for (i = 0U; i < vm_config->vcpu_num; i++) {
pcpu_id = ffs64(vm_config->vcpu_affinity[i]);
uint64_t pcpu_bitmap = vm_config->cpu_affinity_bitmap;
while (pcpu_bitmap != 0UL) {
pcpu_id = ffs64(pcpu_bitmap);
bitmap_clear_nolock(pcpu_id, &pcpu_bitmap);
status = prepare_vcpu(vm, pcpu_id);
if (status != 0) {
break;