From ae6e107d9c6d2984e5a3a4e0803268ddae993fbd Mon Sep 17 00:00:00 2001 From: Shuang Zheng Date: Tue, 25 Aug 2020 10:44:42 +0800 Subject: [PATCH] acrn-config: add maxcpus to sos kernel cmdline in hybrid scenario We use sos kernel cmdline maxcpus to limit the pCPU number of SOS for hybrid or hybrid_rt scenarios by vcpu numbers calculation. v2: add SOS CPU affinity calculation by total pCPU plus pCPUs occupied by pre-launched VMs when no pcpuid configured in SOS. Tracked-On: #5216 Signed-off-by: Shuang Zheng Reviewed-by: Victor Sun --- misc/acrn-config/board_config/misc_cfg_h.py | 22 ++++++++++++++++++++ misc/acrn-config/config_app/views.py | 4 ++++ misc/acrn-config/library/scenario_cfg_lib.py | 13 ++++++++++-- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/misc/acrn-config/board_config/misc_cfg_h.py b/misc/acrn-config/board_config/misc_cfg_h.py index 2ff07ca45..1c927ad1c 100644 --- a/misc/acrn-config/board_config/misc_cfg_h.py +++ b/misc/acrn-config/board_config/misc_cfg_h.py @@ -173,6 +173,28 @@ def generate_file(config): # sos command lines information sos_cmdlines = [i for i in sos_cmdlines[0].split() if i != ''] + # add maxcpus parameter into sos cmdlines if there are pre-launched VMs + pcpu_list = board_cfg_lib.get_processor_info() + cpu_affinity = common.get_leaf_tag_map(common.SCENARIO_INFO_FILE, "cpu_affinity", "pcpu_id") + pre_cpu_list = [] + sos_cpu_num = 0 + for vmid, cpu_list in cpu_affinity.items(): + if vmid in common.VM_TYPES and cpu_list != [None]: + vm_type = common.VM_TYPES[vmid] + load_type = '' + if vm_type in scenario_cfg_lib.VM_DB: + load_type = scenario_cfg_lib.VM_DB[vm_type]['load_type'] + if load_type == "PRE_LAUNCHED_VM": + pre_cpu_list += cpu_list + elif load_type == "SOS_VM": + sos_cpu_num += len(cpu_list) + if sos_cpu_num == 0: + sos_cpu_num_max = len(list(set(pcpu_list) - set(pre_cpu_list))) + else: + sos_cpu_num_max = sos_cpu_num + if sos_cpu_num_max > 0: + sos_cmdlines.append('maxcpus='+str(sos_cpu_num_max)) + # get native rootfs list from board_info.xml (root_devs, root_dev_num) = board_cfg_lib.get_rootfs(common.BOARD_INFO_FILE) diff --git a/misc/acrn-config/config_app/views.py b/misc/acrn-config/config_app/views.py index 6f97b0256..f8d762d0e 100644 --- a/misc/acrn-config/config_app/views.py +++ b/misc/acrn-config/config_app/views.py @@ -159,6 +159,8 @@ def save_scenario(): old_scenario_name = scenario_config_data['old_scenario_name'] scenario_config.set_curr(old_scenario_name) for key in scenario_config_data: + if scenario_config_data[key] in [None, 'None']: + scenario_config_data[key] = '' if key not in ['old_scenario_name', 'new_scenario_name', 'generator', 'add_vm_type']: if isinstance(scenario_config_data[key], list): scenario_config.set_curr_list(scenario_config_data[key], *tuple(key.split(','))) @@ -285,6 +287,8 @@ def save_launch(): 'user_defined', scenario_name + '.xml') for key in launch_config_data: + if launch_config_data[key] in [None, 'None']: + launch_config_data[key] = '' if key not in ['old_launch_name', 'new_launch_name', 'generator', 'add_launch_type', 'scenario_name']: if isinstance(launch_config_data[key], list): launch_config.set_curr_list(launch_config_data[key], *tuple(key.split(','))) diff --git a/misc/acrn-config/library/scenario_cfg_lib.py b/misc/acrn-config/library/scenario_cfg_lib.py index b1c1479f2..2dd24e498 100644 --- a/misc/acrn-config/library/scenario_cfg_lib.py +++ b/misc/acrn-config/library/scenario_cfg_lib.py @@ -517,9 +517,18 @@ def cpus_assignment(cpus_per_vm, index): """ vm_cpu_bmp = {} if "SOS_VM" == common.VM_TYPES[index]: - if index not in cpus_per_vm: + if index not in cpus_per_vm or cpus_per_vm[index] == [None]: sos_extend_all_cpus = board_cfg_lib.get_processor_info() - cpus_per_vm[index] = sos_extend_all_cpus + pre_all_cpus = [] + for vmid, cpu_list in cpus_per_vm.items(): + if vmid in common.VM_TYPES: + vm_type = common.VM_TYPES[vmid] + load_type = '' + if vm_type in VM_DB: + load_type = VM_DB[vm_type]['load_type'] + if load_type == "PRE_LAUNCHED_VM": + pre_all_cpus += cpu_list + cpus_per_vm[index] = list(set(sos_extend_all_cpus) - set(pre_all_cpus)) for i in range(len(cpus_per_vm[index])): if i == 0: