HV: enable pcpu bitmap config for partition mode

All the legacy cpu configration in vm_description.c are all cleaned up;

Tracked-On: #2291

Signed-off-by: Victor Sun <victor.sun@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Victor Sun 2019-01-21 15:36:31 +08:00 committed by Eddie Dong
parent bc62ab79c2
commit 7bf9b1be2c
5 changed files with 38 additions and 56 deletions

View File

@ -91,6 +91,26 @@ static inline uint16_t get_vm_bsp_pcpu_id(const struct acrn_vm_config *vm_config
return (cpu_id < get_pcpu_nums()) ? cpu_id : INVALID_CPU_ID; return (cpu_id < get_pcpu_nums()) ? cpu_id : INVALID_CPU_ID;
} }
#ifdef CONFIG_PARTITION_MODE
/**
* @pre vm_config != NULL
*/
uint16_t get_vm_pcpu_nums(struct acrn_vm_config *vm_config)
{
uint16_t i, host_pcpu_num, pcpu_num = 0U;
uint64_t cpu_bitmap = vm_config->pcpu_bitmap;
host_pcpu_num = get_pcpu_nums();
for (i = 0U; i < host_pcpu_num ; i++) {
if (bitmap_test(i, &cpu_bitmap)) {
pcpu_num++;
}
}
return pcpu_num;
}
#endif
/** /**
* @pre vm_id < CONFIG_MAX_VM_NUM && vm_config != NULL && rtn_vm != NULL * @pre vm_id < CONFIG_MAX_VM_NUM && vm_config != NULL && rtn_vm != NULL
*/ */
@ -395,13 +415,8 @@ void prepare_vm(uint16_t vm_id, struct acrn_vm_config *vm_config)
if (err == 0) { if (err == 0) {
#ifdef CONFIG_PARTITION_MODE #ifdef CONFIG_PARTITION_MODE
mptable_build(vm); mptable_build(vm);
#endif
prepare_vcpu(vm, vm_config->vm_pcpu_ids[0]);
/* Prepare the AP for vm */
for (i = 1U; i < vm_config->vm_hw_num_cores; i++)
prepare_vcpu(vm, vm_config->vm_pcpu_ids[i]);
#else
for (i = 0U; i < get_pcpu_nums(); i++) { for (i = 0U; i < get_pcpu_nums(); i++) {
if (bitmap_test(i, &vm_config->pcpu_bitmap)) { if (bitmap_test(i, &vm_config->pcpu_bitmap)) {
err = prepare_vcpu(vm, i); err = prepare_vcpu(vm, i);
@ -410,7 +425,7 @@ void prepare_vm(uint16_t vm_id, struct acrn_vm_config *vm_config)
} }
} }
} }
#endif
} }
if (err == 0) { if (err == 0) {
@ -442,11 +457,7 @@ void launch_vms(uint16_t pcpu_id)
sos_vm_ptr = &vm_array[vm_id]; sos_vm_ptr = &vm_array[vm_id];
} }
#ifdef CONFIG_PARTITION_MODE
bsp_id = vm_config->vm_pcpu_ids[0];
#else
bsp_id = get_vm_bsp_pcpu_id(vm_config); bsp_id = get_vm_bsp_pcpu_id(vm_config);
#endif
if (pcpu_id == bsp_id) { if (pcpu_id == bsp_id) {
prepare_vm(vm_id, vm_config); prepare_vm(vm_id, vm_config);
} }

View File

@ -74,6 +74,9 @@ static uint8_t mpt_compute_checksum(void *base, size_t len)
return (256U - sum); return (256U - sum);
} }
/**
* @pre vm_config != NULL
*/
int32_t mptable_build(struct acrn_vm *vm) int32_t mptable_build(struct acrn_vm *vm)
{ {
char *startaddr; char *startaddr;
@ -82,9 +85,14 @@ int32_t mptable_build(struct acrn_vm *vm)
struct mpfps *mpfp; struct mpfps *mpfp;
size_t mptable_length; size_t mptable_length;
uint16_t i; uint16_t i;
uint16_t vcpu_num = vm->vm_config->vm_hw_num_cores; uint16_t vcpu_num;
uint64_t pcpu_bitmap = 0U;
struct mptable_info *mptable = &vm->mptable; struct mptable_info *mptable = &vm->mptable;
struct acrn_vm_config *vm_config;
vm_config = get_vm_config(vm->vm_id);
vcpu_num = get_vm_pcpu_nums(vm_config);
pcpu_bitmap = vm_config->pcpu_bitmap;
(void *)memcpy_s((void *)mptable, sizeof(struct mptable_info), (void *)memcpy_s((void *)mptable, sizeof(struct mptable_info),
(const void *)&mptable_template, sizeof(struct mptable_info)); (const void *)&mptable_template, sizeof(struct mptable_info));
@ -100,7 +108,7 @@ int32_t mptable_build(struct acrn_vm *vm)
} }
for (i = 0U; i < vcpu_num; i++) { for (i = 0U; i < vcpu_num; i++) {
uint16_t pcpu_id = *(vm->vm_config->vm_pcpu_ids + i); uint16_t pcpu_id = ffs64(pcpu_bitmap);
(void *)memcpy_s((void *)(mptable->proc_entry_array + i), sizeof(struct proc_entry), (void *)memcpy_s((void *)(mptable->proc_entry_array + i), sizeof(struct proc_entry),
(const void *)&proc_entry_template, sizeof(struct proc_entry)); (const void *)&proc_entry_template, sizeof(struct proc_entry));
@ -108,7 +116,7 @@ int32_t mptable_build(struct acrn_vm *vm)
if (i == 0) { if (i == 0) {
mptable->proc_entry_array[i].cpu_flags |= PROCENTRY_FLAG_BP; mptable->proc_entry_array[i].cpu_flags |= PROCENTRY_FLAG_BP;
} }
bitmap_clear_lock(pcpu_id, &pcpu_bitmap);
} }
/* Copy mptable info into guest memory */ /* Copy mptable info into guest memory */

View File

@ -216,13 +216,7 @@ struct acrn_vm_config {
struct acrn_vm_pci_ptdev_config *pci_ptdevs; /* point to PCI PT devices BDF list */ struct acrn_vm_pci_ptdev_config *pci_ptdevs; /* point to PCI PT devices BDF list */
struct acrn_vm_os_config os_config; /* OS information the VM */ struct acrn_vm_os_config os_config; /* OS information the VM */
/* The physical CPU IDs associated with this VM - The first CPU listed
* will be the VM's BSP
*/
uint16_t *vm_pcpu_ids;
uint16_t vm_hw_num_cores; /* Number of virtual cores */
#ifdef CONFIG_PARTITION_MODE #ifdef CONFIG_PARTITION_MODE
uint8_t vm_id;
uint64_t start_hpa; uint64_t start_hpa;
uint64_t mem_size; /* UOS memory size in hex */ uint64_t mem_size; /* UOS memory size in hex */
bool vm_vuart; bool vm_vuart;
@ -327,6 +321,7 @@ struct pcpu_vm_config_mapping {
extern const struct pcpu_vm_config_mapping pcpu_vm_config_map[]; extern const struct pcpu_vm_config_mapping pcpu_vm_config_map[];
extern struct vm_config_arraies vm_config_partition; extern struct vm_config_arraies vm_config_partition;
uint16_t get_vm_pcpu_nums(struct acrn_vm_config *vm_config);
void vrtc_init(struct acrn_vm *vm); void vrtc_init(struct acrn_vm *vm);
#endif #endif

View File

@ -7,18 +7,6 @@
#include <hypervisor.h> #include <hypervisor.h>
#include <e820.h> #include <e820.h>
/* Number of CPUs in VM1 */
#define VM1_NUM_CPUS 2U
/* Logical CPU IDs assigned to this VM */
uint16_t VM1_CPUS[VM1_NUM_CPUS] = {0U, 2U};
/* Number of CPUs in VM2 */
#define VM2_NUM_CPUS 2U
/* Logical CPU IDs assigned with this VM */
uint16_t VM2_CPUS[VM2_NUM_CPUS] = {3U, 1U};
static struct vpci_vdev_array vpci_vdev_array1 = { static struct vpci_vdev_array vpci_vdev_array1 = {
.num_pci_vdev = 2, .num_pci_vdev = 2,
@ -154,9 +142,7 @@ struct vm_config_arraies vm_config_partition = {
.vm_config_array = { .vm_config_array = {
{ {
.type = PRE_LAUNCHED_VM, .type = PRE_LAUNCHED_VM,
/* Internal variable, MUSTBE init to -1 */ .pcpu_bitmap = (PLUG_CPU(0) | PLUG_CPU(2)),
.vm_hw_num_cores = VM1_NUM_CPUS,
.vm_pcpu_ids = &VM1_CPUS[0],
.start_hpa = 0x100000000UL, .start_hpa = 0x100000000UL,
.mem_size = 0x20000000UL, /* uses contiguous memory from host */ .mem_size = 0x20000000UL, /* uses contiguous memory from host */
.vm_vuart = true, .vm_vuart = true,
@ -168,9 +154,7 @@ struct vm_config_arraies vm_config_partition = {
{ {
.type = PRE_LAUNCHED_VM, .type = PRE_LAUNCHED_VM,
/* Internal variable, MUSTBE init to -1 */ .pcpu_bitmap = (PLUG_CPU(1) | PLUG_CPU(3)),
.vm_hw_num_cores = VM2_NUM_CPUS,
.vm_pcpu_ids = &VM2_CPUS[0],
.start_hpa = 0x120000000UL, .start_hpa = 0x120000000UL,
.mem_size = 0x20000000UL, /* uses contiguous memory from host */ .mem_size = 0x20000000UL, /* uses contiguous memory from host */
.vm_vuart = true, .vm_vuart = true,

View File

@ -7,18 +7,6 @@
#include <hypervisor.h> #include <hypervisor.h>
#include <e820.h> #include <e820.h>
/* Number of CPUs in VM1*/
#define VM1_NUM_CPUS 4U
/* Logical CPU IDs assigned to this VM */
uint16_t VM1_CPUS[VM1_NUM_CPUS] = {0U, 2U, 4U, 6U};
/* Number of CPUs in VM2*/
#define VM2_NUM_CPUS 4U
/* Logical CPU IDs assigned with this VM */
uint16_t VM2_CPUS[VM2_NUM_CPUS] = {7U, 5U, 3U, 1U};
static struct vpci_vdev_array vpci_vdev_array1 = { static struct vpci_vdev_array vpci_vdev_array1 = {
.num_pci_vdev = 3, .num_pci_vdev = 3,
.vpci_vdev_list = { .vpci_vdev_list = {
@ -188,9 +176,7 @@ struct vm_config_arraies vm_config_partition = {
.vm_config_array = { .vm_config_array = {
{ {
.type = PRE_LAUNCHED_VM, .type = PRE_LAUNCHED_VM,
/* Internal variable, MUSTBE init to -1 */ .pcpu_bitmap = (PLUG_CPU(0) | PLUG_CPU(2) | PLUG_CPU(4) | PLUG_CPU(6)),
.vm_hw_num_cores = VM1_NUM_CPUS,
.vm_pcpu_ids = &VM1_CPUS[0],
.start_hpa = 0x100000000UL, .start_hpa = 0x100000000UL,
.mem_size = 0x80000000UL, /* uses contiguous memory from host */ .mem_size = 0x80000000UL, /* uses contiguous memory from host */
.vm_vuart = true, .vm_vuart = true,
@ -203,9 +189,7 @@ struct vm_config_arraies vm_config_partition = {
{ {
.type = PRE_LAUNCHED_VM, .type = PRE_LAUNCHED_VM,
/* Internal variable, MUSTBE init to -1 */ .pcpu_bitmap = (PLUG_CPU(1) | PLUG_CPU(3) | PLUG_CPU(5) | PLUG_CPU(7)),
.vm_hw_num_cores = VM2_NUM_CPUS,
.vm_pcpu_ids = &VM2_CPUS[0],
.start_hpa = 0x180000000UL, .start_hpa = 0x180000000UL,
.mem_size = 0x80000000UL, /* uses contiguous memory from host */ .mem_size = 0x80000000UL, /* uses contiguous memory from host */
.vm_vuart = true, .vm_vuart = true,